Psion Siena Kingdom - Lesson5 Lesson #5

Graphics

When working with any graphics it is important to know the size of the screen.

Psion Siena: 240 x 160 pixels

Pixels are defined by co-ordinates of the form (x,y), i.e. 10,5 means that a pixel will be 10 pixels from the top left hand corner (0,0) and 5 pixels down. The following program draws a line near the top left hand corner.

PROC lines:
 gMOVE 10,10
 gLINEBY 100,0
 GET
ENDP

In the last example, you may have noticed that I used a lowercase G, the reason for this is that it shows graphics commands more easily. Remember that OPL is not case-sensitive.

gMOVE moves the current position by a specified amount, 10 pixels to the right and 10 pixels down. gLINEBY draws a line from the current position to a point 100,0 from 10,10, i.e. 110,10

When drawing a horizontal line, the line that is displayes includes the pixel with the lower x co-ordinate and excludes the pixel with the higher x co-ordinate. When drawing a vertical line, the line includes the pixel with the lower y co-ordinate and excludes the pixel with the higher y co-ordinate.

If when you are designing a program involving graphics, you do not want to have to keep working out the relative positions as used by the commands gLINEBY and gMOVE, you could use gAT and gLINETO instead.

The gAT specifies the pixel that you move to and the gLINETO draws a line from the current position to an absolute position.

If you want to draw a dot, use the following code:

gAT 20,40
gLINEBY 0,0

To clear the screen, use the command gCLS.

Grey

If you wish to draw in grey, you will have to place DEFAULTWIN 1 at start of your program. Note that grey is not available unless you place that code in the program and grey graphics require twice the amount of memory and so it takes longer to scroll or move. If you wish to get rid of grey, use DEFAULTWIN 0, but be careful because both commands clear the screen on use.

Below, I have written a simple program to demonstrate using black and grey lines.

PROC lines:
 DEFAULTWIN 1
 gGREY 0
 gLINEBY 50,50
 gGREY 1
 gLINEBY 40,80
 gGREY 2
 gLINEBY 50,-100
 GET
ENDP

When DEFAULTWIN 1 has been entered, the current black only screen is cleared and replaced with one that contains a black and grey planes.

The black plane is in front of the grey plane, and thus the pixel will only appear grey provided that the black plane is clear. If you draw a pixel using both black and grey, it will appear black, but, if you then clear the black plane only, the pixel will appear grey.

The gGREY 0 draws to the black plane, gGREY 1 draws to the grey plane and gGREY 2 draws to both planes.

The following example illustrates what happens when you clear the black plane using the command gCLS with gGREY 0.

PROC lines:
 DEFAULTWIN 1
 gGREY 0
 gLINEBY 50,50
 gGREY 1
 gLINEBY 40,80
 gGREY 2
 gLINEBY 50,-100
 GET
 gGREY 0
 gCLS
 GET
ENDP

When the clear the black plane command has been executed, the first line drawn in black disappears and the grey line remains unaffected. However, the line drawn on both the black and grey planes becomes grey because the black plane in front of it has been cleared.

To clear the screen completely, you would have to use the following command...

gGREY 2
gCLS

Drawing rectangles is done using the gBOX command. The rectangle is drawn from the current position to a point 100 pixels to the right and 50 pixels down with the following code...

gBOX 100,50

Note that the current position is not changed with the gBOX command.

Buttons

Below, I have listed some code that I have been playing about with. The program draws a button, and when you press a key, the button becomes depressed and then rises again. This will be more than useful for making menus.

PROC button:
 gBUTTON "C",0,30,20,0 REM Button unpushed
 GET
 gBUTTON "C",0,30,20,1 REM Semi-sunken
 PAUSE 3
 gBUTTON "C",0,30,20,2 REM Sunken
 PAUSE 3
 gBUTTON "C",0,30,20,1 REM Semi-sunken
 PAUSE 3
 button:
ENDP

The 20,30 defines the size of the button and the last integer defines its position (i.e. unsunken, semi-sunken or fully sunken).

The keyword gDRAWOBJECT can be used to draw a lozenge (rectangle with rounded corners). The following code draws a lozenge around my name. Note that the top left hand corner is at the current graphics cursor position.

PROC lozenge:
 DEFAULTWIN 1
 AT 2,1
 PRINT "Chris"
 gDRAWOBJECT 0,2,50,20
 GET
ENDP

The size is determined by the last two numbers (in this case 50,20) and the type by the number currently set at 2. 0 would give normal roundness, 1 would make it more rounded and 2 makes it very rounded. Note that an error is raised if the current window does not have a grey plane.

Text

By now, you are probably sick of having to stare at small text, so this section should relieve the problem. On the Siena, you can have Mono, Roman or Swiss. To view the different fonts, use the keyword gFONT a% where a% is one of the numbers in the table below.
 
 
Number  Font  Number Font
4 Mono 8 x 8 5 Roman 8
6 Roman 11 7 Roman 13
Roman 16 9 Swiss 8
10 Swiss 11 11 Swiss 13
12  Swiss 16 13 Mono 6 x 6

The following simple code displays one of the fonts and thus could be altered to check-out the other fonts instead of having to write a long piece of code.

PROC text:
 gAT 10,10
 gFONT 5
 gPRINT "Roman 8"
 GET
ENDP

As well as having different fonts, you can also have different styles. Use the keyword gSTYLE a%, where a% is a number from the table below.
 
 
Number Style Number Style
1 Bold 2 Underlined
Inverse 8 Double height
16 Mono 32  Italic
So, if for example, you want a bold Roman 11 font, you could use the following source code...

PROC text:
 gAT 10,10
 gFONT 6
 gSTYLE 1
 PRINT "Bold Roman 11"
 GET
ENDP

Use gSTYLE 0 to reset to the normal style.

Text can be left or right aligned or centred. Use the following syntax to make the text appear as you want. The t$ is the text that you want displayed in a cleared both of width w% pixels. al% sets the alignment: use 1 for right aligned, 2 for left aligned or 3 for centred. tp% and bt% are the clearance between the top and bottom of the box respectively. m% sets the margins.

gPRINTB t$,w%,al%,tp%,bt%,m%

The following code displays my name in the centre of the screen with a Roman 11 font in bold.

PROC text:
 gAT 0,10
 gFONT 6
 gSTYLE 1
 gPRINTB "Chris",240,3
 GET
ENDP


Back to Index