comparison ext/guichan-0.8.1/examples/widgets.hpp @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /**
2 * Code to populate a global Gui object with all the widgets
3 * of Guichan.
4 */
5
6 namespace widgets
7 {
8 gcn::ImageFont* font;
9 gcn::Container* top;
10 gcn::Label* label;
11 gcn::Icon* icon;
12 gcn::Button* button;
13 gcn::TextField* textField;
14 gcn::TextBox* textBox;
15 gcn::ScrollArea* textBoxScrollArea;
16 gcn::ListBox* listBox;
17 gcn::DropDown* dropDown;
18 gcn::CheckBox* checkBox1;
19 gcn::CheckBox* checkBox2;
20 gcn::RadioButton* radioButton1;
21 gcn::RadioButton* radioButton2;
22 gcn::RadioButton* radioButton3;
23 gcn::Slider* slider;
24 gcn::Image *image;
25 gcn::Window *window;
26 gcn::Image *darkbitsImage;
27 gcn::Icon* darkbitsIcon;
28 gcn::TabbedArea* tabbedArea;
29 gcn::Button* tabOneButton;
30 gcn::CheckBox* tabTwoCheckBox;
31
32 /*
33 * List boxes and drop downs need an instance of a list model
34 * in order to display a list.
35 */
36 class DemoListModel : public gcn::ListModel
37 {
38 public:
39 int getNumberOfElements()
40 {
41 return 5;
42 }
43
44 std::string getElementAt(int i)
45 {
46 switch(i)
47 {
48 case 0:
49 return std::string("zero");
50 case 1:
51 return std::string("one");
52 case 2:
53 return std::string("two");
54 case 3:
55 return std::string("three");
56 case 4:
57 return std::string("four");
58 default: // Just to keep warnings away
59 return std::string("");
60 }
61 }
62 };
63
64 DemoListModel demoListModel;
65
66 /**
67 * Initialises the widgets example by populating the global Gui
68 * object.
69 */
70 void init()
71 {
72 // We first create a container to be used as the top widget.
73 // The top widget in Guichan can be any kind of widget, but
74 // in order to make the Gui contain more than one widget we
75 // make the top widget a container.
76 top = new gcn::Container();
77 // We set the dimension of the top container to match the screen.
78 top->setDimension(gcn::Rectangle(0, 0, 640, 480));
79 // Finally we pass the top widget to the Gui object.
80 globals::gui->setTop(top);
81
82 // Now we load the font used in this example.
83 font = new gcn::ImageFont("fixedfont.bmp", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
84 // Widgets may have a global font so we don't need to pass the
85 // font object to every created widget. The global font is static.
86 gcn::Widget::setGlobalFont(font);
87
88 // Now we create the widgets
89
90 label = new gcn::Label("Label");
91
92 image = gcn::Image::load("gui-chan.bmp");
93 icon = new gcn::Icon(image);
94
95 button = new gcn::Button("Button");
96
97 textField = new gcn::TextField("Text field");
98
99 textBox = new gcn::TextBox("Multiline\nText box");
100 textBoxScrollArea = new gcn::ScrollArea(textBox);
101 textBoxScrollArea->setWidth(200);
102 textBoxScrollArea->setHeight(100);
103 textBoxScrollArea->setFrameSize(1);
104
105 listBox = new gcn::ListBox(&demoListModel);
106 listBox->setFrameSize(1);
107 dropDown = new gcn::DropDown(&demoListModel);
108
109 checkBox1 = new gcn::CheckBox("Checkbox 1");
110 checkBox2 = new gcn::CheckBox("Checkbox 2");
111
112 radioButton1 = new gcn::RadioButton("RadioButton 1", "radiogroup", true);
113 radioButton2 = new gcn::RadioButton("RadioButton 2", "radiogroup");
114 radioButton3 = new gcn::RadioButton("RadioButton 3", "radiogroup");
115
116 slider = new gcn::Slider(0, 10);
117 slider->setSize(100, 10);
118
119 window = new gcn::Window("I am a window Drag me");
120 window->setBaseColor(gcn::Color(255, 150, 200, 190));
121
122 darkbitsImage = gcn::Image::load("darkbitslogo_by_haiko.bmp");
123 darkbitsIcon = new gcn::Icon(darkbitsImage);
124 window->add(darkbitsIcon);
125 window->resizeToContent();
126
127 tabbedArea = new gcn::TabbedArea();
128 tabbedArea->setSize(200, 100);
129 tabOneButton = new gcn::Button("A button in tab 1");
130 tabbedArea->addTab("Tab 1", tabOneButton);
131 tabTwoCheckBox = new gcn::CheckBox("A check box in tab 2");
132 tabbedArea->addTab("Tab 2", tabTwoCheckBox);
133
134 // Now it's time to add the widgets to the top container
135 // so they will be conected to the GUI.
136
137 top->add(label, 10, 10);
138 top->add(icon, 10, 30);
139 top->add(button, 200, 10);
140 top->add(textField, 250, 10);
141 top->add(textBoxScrollArea, 200, 50);
142 top->add(listBox, 200, 200);
143 top->add(dropDown, 500, 10);
144 top->add(checkBox1, 500, 130);
145 top->add(checkBox2, 500, 150);
146 top->add(radioButton1, 500, 200);
147 top->add(radioButton2, 500, 220);
148 top->add(radioButton3, 500, 240);
149 top->add(slider, 500, 300);
150 top->add(window, 50, 350);
151 top->add(tabbedArea, 400, 350);
152 }
153
154 /**
155 * Halts the widgets example.
156 */
157 void halt()
158 {
159 delete font;
160 delete top;
161 delete label;
162 delete icon;
163 delete button;
164 delete textField;
165 delete textBox;
166 delete textBoxScrollArea;
167 delete listBox;
168 delete dropDown;
169 delete checkBox1;
170 delete checkBox2;
171 delete radioButton1;
172 delete radioButton2;
173 delete radioButton3;
174 delete slider;
175 delete window;
176 delete darkbitsIcon;
177 delete darkbitsImage;
178 delete tabbedArea;
179 delete tabOneButton;
180 delete tabTwoCheckBox;
181 }
182 }