Introducing Zinzala - page 6
Now that we have a working application, we can use it to find out how many calories you and your buddies have burned during your last marathon.
With a normal application, if you wanted to compute the calories burned in a marathon for a series of different weights (eg. 50 55 60 65 70 75 80 85), you would have to manually enter each weight and then press the Compute button each time. This is fine, however, with the Zinzala SDK, there is an easier
way to go about it, if you are confortable with the command line.
By making just minor changes to the application, we are now going to make it fully compliant for outside control through the yo tool (available with the SDK). This command line tool allows the user to send special messages to an application. It is the responsibility of the application to process these messages. Fortunately, the windows and widgets in Zinzala are already setup for this. Scripting is not allowed by default, but we can allow these requests by setting the "allow scripting" flag.
First, we are going to allow the application to be scripted:
01 int main()
02 {
03 // Create the application
04 cApplication lMyApp("hexaZen/phalorieburn",0);
05
06 if(lMyApp.IsValid())
07 {
08 // Start the app (and the Photon connection)
09 lMyApp.Run();
10
11 // Allow application scripting from local source
12 lMyApp.AllowScripting(eLocal);
13
14 // Create window
15 cCalcWindow lWin;
16
17 // show the window now
18 lWin.Show();
19
20 // Wait for the end of the app
21 lMyApp.WaitEnd();
22 }
23 else
24 fprintf(stderr,"Failed to init the application");
25 }
Line 12 allows the application to honor scripting messages from the local computer. We are now going to use the same AllowScripting method on all the widgets that we want to be scriptable. To be able to target a specific widget from outside the application, we need to give each of these widgets a distinct name:
01 cCalcWindow::cCalcWindow()
02 : cWindow(uRect(0,0),"calc",eWinNormal,
03 kFlgResizeToFit | kFlgNotResizable | kFlgNotZoomable,
04 kFlgCurrentWorkspace)
05 {
06 cGroupView *lFrame;
07 cFloatEntryView *lDistance;
08 cFloatEntryView *lWeight;
09 cComboBoxView *lDistanceUnit;
10 cComboBoxView *lWeightUnit;
11 cButtonView *lCompute;
12
13 // Set the inital values
14 iDistance = 0;
15 iWeight = 0;
16 iDistanceUnit = 2;
17 iWeightUnit = 2;
18
19 // Set some settings of the window
20 SetPadding(5,5);
21 SetTitle("Calorie burner Calculator");
22 MoveTo(10,10);
23 AllowScripting(eLocal);
24
25 // Create widget to group all the widgets to put on the window
26 lFrame = new cGroupView(uRect(0,0),NULL,eHorizontal,0,
27 kFlgForceEqualSize | kFlgResizeToFit);
28 lFrame->SetSlicing(3);
29 lFrame->SetSpacing(5,5);
30
31 // Create and set widget to enter the distance
32 lDistance = new cFloatEntryView(uRect(60,20),"distance",d,
33 new cMessage(kUidDistanceChanged),0,kFlgUpDown);
34 lDistance->SetPrecision(1);
35 lDistance->SetRange(0,200);
36 lDistance->AllowScripting(eLocal);
37
38 // Create and set widget to enter weight
39 lWeight = new cFloatEntryView(uRect(60,20),"weight",w,
40 new cMessage(kUidWeightChanged),0,kFlgUpDown);
41 lWeight->SetPrecision(1);
42 lWeight->SetRange(0,400);
43 lWeight->AllowScripting(eLocal);
44
45 // Create and set widget to select distance unit
46 lDistanceUnit = new cComboBoxView(uRect(60,20),"dunit",
47 new cMessage(kUidDistanceUnitChanged),0,kFlgNotEditable);
48 lDistanceUnit->SetItems(kDistanceLabels,2);
49 lDistanceUnit->SetSelectedItem(iDistanceUnit);
50 lDistanceUnit->AllowScripting(eLocal);
51
52 // Create and set widget to select weight unit
53 lWeightUnit = new cComboBoxView(uRect(60,20),"wunit",
54 new cMessage(kUidWeightUnitChanged),0,kFlgNotEditable);
55 lWeightUnit->SetItems(kWeightLabels,2);
56 lWeightUnit->SetSelectedItem(iWeightUnit);
57 lWeightUnit->AllowScripting(eLocal);
58
59 // Create and set widget to display the computation result
60 iResult = new cStringView(uRect(0,0),"result","",0,0);
61 iResult->SetFGColor(kColorBlue);
62 iResult->SetAlignment(eCenter);
63 iResult->AllowScripting(eLocal);
64
65 // Create and set the compute button
66 lCompute = new cButtonView(uRect(0,0),"compute","Compute",
67 new cMessage(kUidCompute),0,0);
68 lCompute->AllowScripting(eLocal);
69
70 // Add all the widget to the group
71 lFrame->AddChild(new cStringView(uRect(0,0),NULL,"Distance run",0,0));
72 lFrame->AddChild(lDistance)
73 lFrame->AddChild(lDistanceUnit);
74 lFrame->AddChild(new cStringView(uRect(0,0),NULL,"Weight",0,0));
75 lFrame->AddChild(lWeight);
76 lFrame->AddChild(lWeightUnit);
77 lFrame->AddChild(lCompute);
78 lFrame->AddChild(iResult);
79
80 // Add the group to the window
81 AddChild(lFrame);
82 }
Previous
1 | 2 | 3 | 4 | 5 | 6 | 7 | Next
Print version