|
 | Part One - Introduction |
In this tutorial you will make a simple application to learn how to use the BlitzUI Editor (WYSIWYG Designer) and add basic
interaction between some of the controls.
 | Part Two - Creating the layout |
There are two ways to create a GUI layout for your application... the hard way is to open structure.bb and manually code
the controls and guess the positions and sizes. The easy way is to open BlitzUI Editor.exe and click and drag controls onto
a window and use the spinners to make fine adjustments to the positions and sizes of them.
For this tutorial I'm going to assume you'll use the BlitzUI Editor to design the GUI. You can find BlitzUI Editor in the main BlitzUI
folder. When you open it you should see a blank screen with 1 window to the far left. This window is what you'll use to create and
modify the GUI.
The default size of a BlitzUI application is 640x480, but you can increase/decrease this by opening the Project menu and clicking
Settings.
On to the design... this is going to be a very simple application consisting of a window, a label, a button and a textbox. To create
a Window simply click on the button called "Window" and click and drag a rectangle (the initial position and size of the window)
anywhere in open space. When you release the mouse button a window will be created where you just made the rectangle. If you click
on the Modify tab you can now edit the position and size of the window (Clicking anywhere on the window and dragging will also allow
you to move the window), and change the title bar text. One of the most important properties is the Handle. When you send messages
to a control you need to know how to identify which control to send the message to... the handle is how you identity it, so change it
to something more descriptive like winMain. The size of the window isn't important for this application, just make it big enough to hold a few controls.
Go back to the Create tab and create a label, a button and a textbox in exactly the same way as the window. Position and size are not
important. Once you've done that, select the label and go to the Modify tab... change the Text property to be the same as the window's
title bar text (default is Window), and change the Handle property to lblWindowText (The handle of any control is what you will
reference it by when adding interaction). Select the button and change the Handle to btnChangeText, and the Text to
Change
Select the textbox and give it a handle of txtWindowText. Delete the value in the Text property so that it starts with nothing
in it.
That's it! You've designed the application, so all that's left to do is to Save it and/or Compile it. To save the layout click Save
from the File menu or press Ctrl+S. Browse to the folder where you want to save it to and type in a name for it (The extension is
.gui but you can leave that bit out. Now click Save to save it.
Compiling a GUI layout produces Blitz code which can then be opened and compiled using any of the Blitz products (Blitz2D, Blitz3D and
even BlitzPlus). Click Compile from the Projects menu or press F5 to bring up the compile dialog. Choose somewhere to compile it to
and then click Compile. You can now close BlitzUI Editor and open the newly created .bb file in your favourite IDE (NOTE: If you
overwrite a file you didn't want to while compiling don't worry... if you specify an existing file to compile to, BlitzUI Editor
creates a backup for you under the same name but with a .backup extension added to it.
 | Part Three - Interaction |
Part two was the largest part of this tutorial... from here on there's much less to do. Interaction is an integral part of any
application, without it nothing would happen when a user clicked a button or a menu item etc. For this tutorial I will show you
how to change the label's text and the windows title bar text to whatever's inside the textbox when you click the button.
Open the .bb file you created in the step above. If you compile that it will work but as I said above, nothing will happen when
you click on the button. Scroll down the code a bit and you will notice a section that starts and ends with:
This is where we will add the interaction. Go down to the bit that looks like:
This is where the Handle property comes into play. If you went by the tutorial you should have changed the buttons handle to
btnChangeText. If you didn't, or you can't remember what it is, scroll up and find the code that creates the button:
Now add a Case statement for the button in the app\GadgetEvent Select statement. It should then look something like this:
For this next bit you will need to know the handles of the label, the textbox and the window. Add the following lines to the buttons
Case statement.
The first line sends a message to the textbox telling it that you want to know what text is contained inside it. The following two
lines send messages to the label and the window telling them that you want to change their text values and replace them with the
value returned by the textbox.
That's it for this tutorial... if you have any problems just go back and check what you've done, and if you still can't find the
problem send me an email to chrisfuller@ntlworld.com.
|