Programming AmigaOS in C

4. How to add gadgets to a MUI Window?

Once you have you window defined, you can now add gadgets to the window. MUI is very smart and flexible. Unlike Intuition, you do not need to specify loads of structures for gadgets and you do not need to work out the position and size of your gadgets, MUI does this for you.

After the Window definition, you need to specify the following line which will allow you to specify objects of the window and layout gadgets vertically (use HGroup for horizonal layout):

SubWindow, VGroup,

For AmigaOS 4, VGroup needs replacing with IMUIMaster->MUI_NewObject(MUIC_Group, . See libraries/mui.h for definitions of other objects.

There are many gadget classes you can use, here are a few of them:

1. String("string", maxlength)

Inserts a string gadget for text input. Specify the maximum length of the result for that string, I always add 1 more to length to allow for space after the string. Normally you would put the result into a variable for later retreival. The value in quotes can be empty or a default value.

e.g. Child, ST_Name = String("name", 25),

2. Labeln("string")

Provides a desriptive label for a gadget, group of gadgets. There are different types of label as follows:
Label1 = For use with standard frames e.g. checkmarks.
Label2 = For use with double high frames e.g. strings
Label3 = For use with objects without a frame.

e.g. Child, Label2("Age:"), Child, ST_Age = String("0", 4), Child, 

3. Slider(min, max, level)

This produces a slider which the user can slide a button along to choose a value such as a print density, screen resolution and so on. Three values are required: a minimum and maximum value and a default level.

e.g. Child, SL_Value = Slider( 1, 7, 4),

4. Radio(name, array)

This produces a list of radio objects where only one value can be selected. The array is a single dimension array, the list item must be a NULL value.

e.g.
static STRPTR fruitlist[5];
fruits[0] = "orange";
fruits[1] = "orange";
fruits[2] = "banana":
fruits[3] = "peach";
fruits[4] = NULL;
Child, RA_Fruits = Radio("Fruits", fruitlist),

5. CheckMark(boolvalue)

This produces a checkmark gadget with a simple arguement to state when its ticked or not.

e.g.
APTR chk1, chk2, chk3;
   
Child, Label1("Train"), Child, chk1 = CheckMark(FALSE), Child, Label1("Plane"), Child, chk2 = Checkmark(FALSE), 
Child, Label1("Car"), Child, chk3= CheckMark(TRUE),

6. SimpleButton(label) and KeyButton(label, key)

This creates buttons you can press to do specific tasks. SimpleButton creates a button with a label inside it. KeyButton also creates a button and also provides a keyboard shortcut (usually small case letters).

e.g.
APTR but1, but2;
   
Child, but1 = SimpleButton("Calculate"),
Child, but2 = KeyButton("Save", "s"),

Next Page