Computer Science Canada

[tutorial\Example]Commonly Used GUI Commands

Author:  Delta [ Tue Mar 25, 2003 9:12 am ]
Post subject:  [tutorial\Example]Commonly Used GUI Commands

This isn't really a tutorial but it should help
you with the most common GUI(Graphical User Interface)
commands.

code:

% Import the GUI library for use of GUI commands
import GUI in "%oot/lib/GUI"

var label1 : int % variable for label
var button1 : int % variable for button
var textBox1 : int % variable for textbox
var textField1 : int % variable for textfield

GUI.SetBackgroundColour (grey) % Set background colour grey

% GUI.CreateLabel (x, y, text)
label1 := GUI.CreateLabel (300, maxy - 150, "Label")

% GUI.CreateTextBox (x, y, width, height)
textBox1 := GUI.CreateTextBox (10, 100, 200, 200)

% Used as Action Procedure for textfield
procedure DoNothing (text:string)   
end DoNothing

% GUI.CreateTextField (x, y, width, text, procedureToCall)
textField1 := GUI.CreateTextField (10, 400, 200, "Text Here", DoNothing)

% Used as Action Procedure for button
procedure AddLine
    % Adds a line of text from the textfield to a specified textbox
    GUI.AddLine (textBox1, GUI.GetText (textField1))
end AddLine

% GUI.CreateButton (x, y, width, text, procedureToCall)
button1 := GUI.CreateButton (10, maxy - 50, 0, "Button", AddLine)

% These variables are all used for making a menu
var first, second : int % For the actual Menu
var item : array 1 .. 5 of int % The menu items.
% The name of the menu items
var name : array 1 .. 5 of string (20) := init ("Enable Button", "Disable Button", "Hide Label", "Show Label", "QUIT")

% NEXT FOUR PROCEDURES ARE FOR THE MENU ITEMS
procedure EnableButton
    GUI.Enable (button1)
end EnableButton

procedure DisableButton
    GUI.Disable (button1)
end DisableButton

procedure HideLabel
    GUI.Hide (label1)
end HideLabel

procedure ShowLabel
    GUI.Show (label1)
end ShowLabel

% Create the first menu
first := GUI.CreateMenu ("First Menu")
% Create the menu items for the first menu
item (1) := GUI.CreateMenuItem (name(1), EnableButton)
item (2) := GUI.CreateMenuItem (name(2), DisableButton)

% Create the second menu
second := GUI.CreateMenu ("Second Menu")
% Create the menu items for the second menu
item (3) := GUI.CreateMenuItem (name(3), HideLabel)
item (4) := GUI.CreateMenuItem (name(4), ShowLabel)
item (5) := GUI.CreateMenuItem (name(5), GUI.Quit) % QUIT

loop
    exit when GUI.ProcessEvent % This is needed inside the main loop
end loop

% Destroy these next three items
GUI.Dispose (button1)
delay (100)
GUI.Dispose (label1)
delay (100)
GUI.Dispose (textField1)


: