File: widgets.hpp

package info (click to toggle)
guichan 0.8.2-21
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,724 kB
  • sloc: cpp: 15,578; sh: 10,130; makefile: 255
file content (182 lines) | stat: -rw-r--r-- 5,879 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
 * Code to populate a global Gui object with all the widgets
 * of Guichan.
 */

namespace widgets
{
    gcn::ImageFont* font;
    gcn::Container* top;
    gcn::Label* label;
    gcn::Icon* icon;
    gcn::Button* button;
    gcn::TextField* textField;
    gcn::TextBox* textBox;
    gcn::ScrollArea* textBoxScrollArea;
    gcn::ListBox* listBox;
    gcn::DropDown* dropDown;
    gcn::CheckBox* checkBox1;
    gcn::CheckBox* checkBox2;
    gcn::RadioButton* radioButton1;
    gcn::RadioButton* radioButton2;
    gcn::RadioButton* radioButton3;
    gcn::Slider* slider;
    gcn::Image *image;
    gcn::Window *window;
    gcn::Image *darkbitsImage;
    gcn::Icon* darkbitsIcon;
    gcn::TabbedArea* tabbedArea;
    gcn::Button* tabOneButton;
    gcn::CheckBox* tabTwoCheckBox;

    /*
     * List boxes and drop downs need an instance of a list model
     * in order to display a list.
     */
    class DemoListModel : public gcn::ListModel
    {
    public:
        int getNumberOfElements()
        {
            return 5;
        }

        std::string getElementAt(int i)
        {
            switch(i)
            {
              case 0:
                  return std::string("zero");
              case 1:
                  return std::string("one");
              case 2:
                  return std::string("two");
              case 3:
                  return std::string("three");
              case 4:
                  return std::string("four");
              default: // Just to keep warnings away
                  return std::string("");
            }
        }
    };

    DemoListModel demoListModel;

    /**
     * Initialises the widgets example by populating the global Gui
     * object.
     */
    void init()
    {
        // We first create a container to be used as the top widget.
        // The top widget in Guichan can be any kind of widget, but
        // in order to make the Gui contain more than one widget we
        // make the top widget a container.
        top = new gcn::Container();
        // We set the dimension of the top container to match the screen.
        top->setDimension(gcn::Rectangle(0, 0, 640, 480));
        // Finally we pass the top widget to the Gui object.
        globals::gui->setTop(top);

        // Now we load the font used in this example.
        font = new gcn::ImageFont("fixedfont.bmp", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
        // Widgets may have a global font so we don't need to pass the
        // font object to every created widget. The global font is static.
        gcn::Widget::setGlobalFont(font);

        // Now we create the widgets

        label = new gcn::Label("Label");

        image = gcn::Image::load("gui-chan.bmp");
        icon = new gcn::Icon(image);

        button = new gcn::Button("Button");

        textField = new gcn::TextField("Text field");

        textBox = new gcn::TextBox("Multiline\nText box");
        textBoxScrollArea = new gcn::ScrollArea(textBox);
        textBoxScrollArea->setWidth(200);
        textBoxScrollArea->setHeight(100);
        textBoxScrollArea->setFrameSize(1);

        listBox = new gcn::ListBox(&demoListModel);
        listBox->setFrameSize(1);
        dropDown = new gcn::DropDown(&demoListModel);
        
        checkBox1 = new gcn::CheckBox("Checkbox 1");
        checkBox2 = new gcn::CheckBox("Checkbox 2");

        radioButton1 = new gcn::RadioButton("RadioButton 1", "radiogroup", true);
        radioButton2 = new gcn::RadioButton("RadioButton 2", "radiogroup");
        radioButton3 = new gcn::RadioButton("RadioButton 3", "radiogroup");

        slider = new gcn::Slider(0, 10);
        slider->setSize(100, 10);

        window = new gcn::Window("I am a window  Drag me");
        window->setBaseColor(gcn::Color(255, 150, 200, 190));

        darkbitsImage = gcn::Image::load("darkbitslogo_by_haiko.bmp");
        darkbitsIcon = new gcn::Icon(darkbitsImage);
        window->add(darkbitsIcon);
        window->resizeToContent();

        tabbedArea = new gcn::TabbedArea();
        tabbedArea->setSize(200, 100);
        tabOneButton = new gcn::Button("A button in tab 1");
        tabbedArea->addTab("Tab 1", tabOneButton);
        tabTwoCheckBox = new gcn::CheckBox("A check box in tab 2");
        tabbedArea->addTab("Tab 2", tabTwoCheckBox);

        // Now it's time to add the widgets to the top container
        // so they will be conected to the GUI.
        
        top->add(label, 10, 10);
        top->add(icon, 10, 30);
        top->add(button, 200, 10);
        top->add(textField, 250, 10);
        top->add(textBoxScrollArea, 200, 50);
        top->add(listBox, 200, 200);
        top->add(dropDown, 500, 10);
        top->add(checkBox1, 500, 130);
        top->add(checkBox2, 500, 150);
        top->add(radioButton1, 500, 200);
        top->add(radioButton2, 500, 220);
        top->add(radioButton3, 500, 240);
        top->add(slider, 500, 300);
        top->add(window, 50, 350);
        top->add(tabbedArea, 400, 350);
    }
    
    /**
     * Halts the widgets example.
     */
    void halt()
    {
        delete font;
        delete top;
        delete label;
        delete icon;
        delete button;
        delete textField;
        delete textBox;
        delete textBoxScrollArea;
        delete listBox;
        delete dropDown;
        delete checkBox1;
        delete checkBox2;
        delete radioButton1;
        delete radioButton2;
        delete radioButton3;
        delete slider;
        delete window;
        delete darkbitsIcon;
        delete darkbitsImage;
        delete tabbedArea;
        delete tabOneButton;
        delete tabTwoCheckBox;
    }
}