Use Scaling to Position GUI Objects

Although straightforward use of the GUI functions enables the drawing of a large number of graphic objects, it is sometimes desirable to position an object, such as a GUIButton, based on the value of some variable or parameter.

Since the first four parameters of all GUI functions must be constants (see Constants), the side scaling parameters must be used. To position a GUI object according to a variable's value, parameters 1 through 4 are used to define a unit box, while the side scaling parameters (5 through 8) are used to position and size the object being drawn. Since there is no restriction on these parameters (i.e. they do not have to be constants), variables may be used to set the object's position.

For example, to position a GUIRectangle using the side scaling parameters:

left = 10;

bottom = 80;

right = 100;

top = 10;

...

GUIRectangle(0, 1, 1, 0 { Unit bounding box },

1 - (left) { Left scaling }, 

bottom { Bottom }, 

right { Right scaling }, 

1 - (top) { Top scaling }, 

1 { No scaling as a whole }, 

0, 0 { No movement }, 

1, 0, 0, 0, 0 { Visible, not selectable }, 

14, 12 { Yellow interior, red outline }); 

 

Note that in the example above you can simply substitute the appropriate scaling coordinates into the formula in the positions held by left, bottom, right and top.

This rectangle will be identical to one drawn using:

GUIRectangle(10, 80, 100, 10 { Unit bounding box },

1, 1, 1, 1, 1 { No scaling }, 

0, 0 { No movement }, 

1, 0, 0, 0, 0 { Visible, not selectable }, 

14, 12 { Yellow interior, red outline }); 

 

As a final example, suppose that you have created the rectangle depicted in the first case above, and that you now want to draw another rectangle that is green with black trim, smaller by 3 pixels in all directions, and perfectly centered within the first rectangle

GUIRectangle(0, 1, 1, 0 { Unit bounding box },

1 - (left + 3) { Left scaling }, 

bottom - 3 { Bottom }, 

right - 3 { Right scaling }, 

1 - (top + 3) { Top scaling }, 

1 { No scaling as a whole }, 

0, 0 { No movement }, 

1, 0, 0, 0, 0 { Visible, not selectable }, 

10, 0 { Green interior, black outline }); 

 

Again, simply substitute the appropriate scaling coordinates into the formula in the positions held by left, bottom, right and top.

Additional information on scaling objects can be found in the descriptions for the following functions and statements: GUIArc, GUIBitmap, GUIButton, GUIChord, GUIEllipse, GUIPie, GUIPipe, GUIPolygon, GUIRectangle, GUIText, GUITransform