Difference between revisions of "Blitz:GadTools"

From Amiga Coding
Jump to: navigation, search
(Attaching GadTools to Your Window)
(How to Use GadTools)
Line 2: Line 2:
  
 
==How to Use GadTools==
 
==How to Use GadTools==
GadTools gadgets are defined using a unique ID to identify each object, and a GTList object number to which the gadgets belong. All gadgets require you to specify the size and position of the gadget. Once the gadgets are defined, the GTList containing them can be attached to a standard [[Blitz:Windows|Intuition window]] for use. Only one GTList can be attached to a window at any one time, and a GTList can only be attached to one window at any one time. Once attached, the gadgets will trigger standard [[Blitz:Events|IDCMP events]] when used.
+
GadTools gadgets are used in a similar fashion to the standard [[Blitz:IntuitionGadgets|Intuition gadgets]]. They are declared using a unique ID to identify each object, and a GTList object number to which the gadgets belong. All gadgets require you to specify the size and position of the gadget. Once the gadgets are defined, the GTList containing them can be attached to a standard [[Blitz:Windows|Intuition window]] for use. Only one GTList can be attached to a window at any one time, and a GTList can only be attached to one window at any one time. Once attached, the gadgets will trigger standard [[Blitz:Events|IDCMP events]] when used.
  
 
==Defining GadTools Objects==
 
==Defining GadTools Objects==

Revision as of 13:11, 28 August 2015

GadTools is an updated system of gadgets that was introduced in OS 2.0, and is supported in all versions from 2.0 on. It offers some large improvements over the standard Intuition gadgets and is the standard, familiar look from OS 2.0 to 3.1. It is quite low level meaning, and it lacks some more advanced features from the more modern toolkits such as MUI, but has a very low footprint and doesn't need any external toolkits installed to work.

How to Use GadTools

GadTools gadgets are used in a similar fashion to the standard Intuition gadgets. They are declared using a unique ID to identify each object, and a GTList object number to which the gadgets belong. All gadgets require you to specify the size and position of the gadget. Once the gadgets are defined, the GTList containing them can be attached to a standard Intuition window for use. Only one GTList can be attached to a window at any one time, and a GTList can only be attached to one window at any one time. Once attached, the gadgets will trigger standard IDCMP events when used.

Defining GadTools Objects

GadTools objects are defined using straightforward commands for each gadget type. The specifics of each command vary from gadget to gadget, but many parameters are the same. Some properties can also be changed after gadget creation, such as the state of a checkbox or the selected item in a cycle gadget.

Flags and Tags

Most GadTools gadget setup commands accept a flags parameter to control certain aspects of its appearance or functionality. These flags are constant values that are defined in the amigalibs.res resident file and are listed in the Blitz documentation. Some important ones are as follows:

#PLACETEXT_IN
Places the text in the middle of the gadget
#PLACETEXT_LEFT
Places the text to the left of the gadget
#PLACETEXT_RIGHT
Places the text to the right of the gadget
#PLACETEXT_ABOVE
Places the text above gadget
#PLACETEXT_BELOW
Places the text below the gadget

Tags can also be set prior to gadget creation using the GTTags command. These set various attributes of the gadget to be created, and are listed in the official [GadTools Autodocs]. Many are specific to a certain type of gadget. Some useful ones are as follows:

#GA_Disabled
Gadget is initially disabled and ghosted if this is set to True
#GA_Immediate
Gadget reports button down events as well as the normal button up events if this is set to True
#GTCB_Checked
Checkbox gadget is initially checked if this is set to True, unchecked if set to False (default)
#GTCB_Scaled
Checkbox gadget is scaled to the dimensions given instead of simply fitting them (this is important for OS4 and any setups that offer a pixel ratio other than 1:2)
#GTCY_Active
The index of the currently selected option of a cycle gadget

The GTTags command applies to the next gadget creation command only. It can be used as follows: GTTags #GA_Disabled, True, #GTCY_Active, 3 This example will set the next gadget created (which should be a cycle gadget) to be disabled initially and to start with the 4th option selected (option indices start at 0). The tags must be in pairs of tag, value. Any number of pairs can be set using this command.

Certain tags can also be set after creation of the gadget using the GTSetAttrs command, and can be read from the gadget using the GTGetAttrs command. For example, the #GTCB_Checked and #GTGY_Active attributes: GTSetAttrs #enableviewcheckbox, True mychoice = GTGetAttrs(#cyclegadget1, #GTCY_Active)

General Parameters

Many gadget commands require the same parameters, such as the following:

GTList
This is the ID of the GTList to which the button will belong
id
This is the unique ID of the new button
X and Y
These are the co-ordinates of the top left corner of the gadget relative to the top left corner of the window
W and H
These are the width and height of the gadget in pixels
Text$
This is a string containing the label to be used for the gadget
flags
This is a flag value based on the required values from the GadTools flags listed above, usually used for positioning the label.

Buttons

Buttons are set up using the GTButton command with the form: GTButton GTList, id, X, Y, W, H, Text$, flags All of the parameters are standard and explained above. An example of use: GTButton #maingtlist, #continuebutton, 20, 20, 100, 20, "Continue", #PLACETEXT_IN The flag #PLACETEXT_IN is normal for a button since normally the text is in the middle of the button.

Checkboxes

Checkboxes are small boxes you can place a tick in, usually to turn an option on or off. The are created using the following command: GTCheckBox GTList, id, X, Y, W, H, Text$, flags Again, all parameters are explained above. Unlike the button gadget, it's probably better to put the label to the left, right, or above or below the gadget... It's important to set the tag GTCB_Scaled to True at creation time if your program is going to be used on OS4 or some graphics card setups, otherwise the gadget may appear squashed.

Cycle Gadgets

Cycle gadgets allow the user to select one choice from a predetermined list of choices by cycling through them. Most modern implementations also include a drop-down menu that lists all the options available. To set up a cycle gadget, use the following: GTCycle GTList, id, X, Y, W, H, Text$, flags, Options$ All the parameters are as before except Options$. This is a string containing all the options you wish your gadget to contain, separated by a pipe character (|). For example: GTCycle #maingtlist, #cycle1, 100, 40, 100, 20, "Choose a size", #PLACETEXT_LEFT, "Tiny|Small|Medium|Large|Huge" This gadget contains the five size options given, with the label to the left of the gadget. The tag #GTCY_Active can be set to the index value of an option to set the currently selected option, starting at 0 for the first option. Similarly, the currently selected option can be read by reading the same tag.

Attaching GadTools to Your Window

When you open a standard window, you can attach your gadgets to the window using the AttachGTList command. This command takes the ID of the GTList object and the ID of the window. Once complete, the gadgets will be drawn at their relevant locations and will be ready to use. For example: AttachGTList #maingtlist, #mainwindow

Detecting Gadget Events

Gadget events are handled through the standard Intuition Events system, so no special consideration is needed. Examples are given in the Gadget section of the Events page.