Introducing Zinzala - page 2

We are now going to add a simple window to our application. This is done by instantiating the cWindow class:

01 // Create the application 02 cApplication lMyApp("hexaZen/phalorieburn",0); 03 04 // Check that the application is initialized correctly 05 if(lMyApp.IsValid()) 06 { 07 // Start the application 08 lMyApp.Run(); 09 10 // Create window 11 cWindow lWin(uRect(250,100),"calc",eWinNormal,0,kCurrentWorkspace); 12 lWin.SetTitle("Calorie burner Calculator"); 13 lWin.MoveTo(10,10); 14 15 // show the window now 16 lWin.Show(); 17 18 // Wait for the end of the app 19 lMyApp.WaitEnd(); 20 } 21 else 22 fprintf(stderr,"Failed to init the application");

Line 11 instantiates the window and sets its size to 250x100. The flag kCurrentWorkspace indicates that we want this window to be located on the current workspace. If we wanted to have this window positioned on the third workspace for example, we would have to put the value 3 instead. Line 12 and 13 sets the window's title and the window's position respectively.

The result of the above code can be seen below. The source code can be downloaded here:

step1 - calories burned calculator

The philosophy behind the GUI development with Zinzala SDK is based on message passing. Every component of the user interface has the ability to send, receive and process messages. For example, when a button is pressed, a message is sent to the window that contains it. This message has been specified earlier by the developer and will be the basis for determining what response the user will receive. The developer can then perform processing accordingly.

The class cMessage implements a bundle of data that is exchanged between widgets and windows or even between applications. It provides a way of storing and retreiving typed and named information.

Next, we will derive the class cWindow. This derived class is necessary to process messages such as the one from a Compute button of the user interface:

01 class ccCalcWindowdow : public cWindow 02 { 03 public: 04 cCalcWindow(); 05 protected: 06 void MessageReceived(cMessage *aMessage); 07 }; 08 09 cCalcWindow::cCalcWindow() 10 : cWindow(uRec(250,100),"calc",eWinNormal, 11 0, 12 kCurrentWorkspace) 13 { 14 // Set some settings of the window 15 SetTitle("Calorie burner Calculator"); 16 MoveTo(10,10); 17 } 18 19 void cCalcWindow::MessageReceived(cMessage *aMessage) 20 { 21 switch(aMessage->iWhat) 22 { 23 default: 24 cWindow::MessageReceived(aMessage); 25 } 26 }

The protected method MessageReceived performs the processing of the messages received by the window. If there is nothing to be done with the message received, identified by its iWhat field, the parent method needs to be called, otherwise the window will not work correctly.

Now, we will modify the main of our application to use this class cCalcWindow

01 // Create the application 02 cApplication lMyApp("hexaZen/phalorieburn",0); 03 04 // Check that the application is initialized correctly 05 if(lMyApp.IsValid()) 06 { 07 // Start the application 08 lMyApp.Run(); 09 10 // Create window 11 cCalcWindow lWin; 12 13 // show the window now 14 lWin.Show(); 15 16 // Wait for the end of the app 17 lMyApp.WaitEnd(); 18 } 19 else 20 fprintf(stderr,"Failed to init the application");

The result of this simple application is the same as earlier. The source code can be downloaded here.

Let's now add the widgets for the user interface of the calculator. Zinzala SDK offers a complete range of widgets for the developer to choose from. Most of these widgets are based on the ones which already exist in Photon. For our example, we are going to use the following:

Print version

All content © 2004-2007, hexaZen - Vancouver BC, Canada