Programming AmigaOS in BASIC

Gadgets

Intuition introduced gadgets but were flat and rather dull affairs. So, with AmigaOS 2, the Gadtools.library was introduced to update gadgets to use more 3D style gadgets which certainly looked better than their Intuition counterparts. Windows come with system gadgets such as the closw window, back/front, size and so on. You can define your own gadgets using the GADGET statement.

GADGET id, status [,gadval, rectangle, type [,style] [,font, size, textstyle]]


where the arguments are as follows:

id - Gadget id from 1 to 255
status - Enable (1) or disable (0) gadget
gadval - A string or long integer value depedning on type of gadget.
rectangle - Position and size of the gadget in format (x1, y1)-(x2, y2).
type - Gadget type. Boolean or button (1), String (2), Longint (3), Horiz. slider (4) or Vertical slider (5)
or use key words, BUTTON, STRING, LONGINT, POTX, POTY.
style - Value from 1 to 3 determines gadget style e.g. justification and borderless.
The final three values only apply to Button gadgets:
font - Name of font
size - Size of font
textstyle - Bold, underline, italics etc.

Other Gadgets Statements

GADGET(n) - Returns information about a gadget (n=0 to 4).
GADGET CLOSE id - Removes the gadget from current window.
GADGET MOD id, pos, max-pos - Modifies proportional values of slider gadgets.
GADGET ON | OFF | STOP - Enable, disables, or suspends a gadget event trapping
GADGET OUTPUT id - Sets the current gadget so information can be gathered.
GADGET WAIT id - Program is put to sleep until an event occurs.
ON GADGET statement - Gadget event trapping.

27. An example of using Gadgets in a Window

WINDOW 1, "My Window", (10,15)-(290,195), 31
ON WINDOW GOSUB HandleWindow
WINDOW ON
' Set font
FONT "topaz", 8
' String gadget
LOCATE 4,1
PRINT "Name"
GADGET 1, 1, "", (63,26)-(239,46), STRING ' Integer gadget LOCATE 7,1 PRINT "Age" GADGET 2, 1, "0", (62,50)-(239,70), LONGINT ' Button or boolean gadget GADGET 3, 1, "Calc", (111,105)-(165,136), BUTTON ON GADGET GOSUB HandleGadget GADGET ON done = -1 WHILE done = -1 SLEEP WEND WINDOW CLOSE 1 END HandleWindow: done = 0 RETURN HandleGadget: ' Find out which gadget pressed gadno=GADGET(0) RETURN Next page