diff --git a/Src/gui/widgets.hpp b/Src/gui/widgets.hpp index 711fb84..15e6c2f 100644 --- a/Src/gui/widgets.hpp +++ b/Src/gui/widgets.hpp @@ -5,160 +5,181 @@ namespace widgets { - gcn::ImageFont* font; - gcn::Container* top; - 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::Window *window; - gcn::Image *darkbitsImage; - gcn::Icon* darkbitsIcon; - gcn::TabbedArea* tabbedArea; - gcn::Button* tabOneButton; - gcn::CheckBox* tabTwoCheckBox; +gcn::ImageFont* font; +gcn::ImageFont* title_font; +gcn::Container* top; +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::Window *window; +gcn::Image *darkbitsImage; +gcn::Icon* darkbitsIcon; +gcn::TabbedArea* tabbedArea; +gcn::Button* tabOneButton; +gcn::CheckBox* tabTwoCheckBox; - class BackgroundContainer : public gcn::Container, gcn::Icon - { - public: - BackgroundContainer(const char *fn) : gcn::Icon(fn), gcn::Container() - { - } +class BackgroundContainer : public gcn::Container +{ +public: + BackgroundContainer(gcn::ImageFont *fnt, const char *bg, const char *title) : gcn::Container() + { + this->bg = new gcn::Icon(bg); + this->fnt = fnt; + // We set the dimension of the top container to match the screen. + this->setDimension(gcn::Rectangle(0, 0, 640, 480)); + this->title = new gcn::Label(title); + this->title->setFont(fnt); + this->add(this->title); + this->title->adjustSize(); + this->title->setPosition(140, 0); + } - void draw(gcn::Graphics *graphics) - { - graphics->drawImage(mImage, 0, 0); - this->drawChildren(graphics); - } - }; - /* - * 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; - } + void draw(gcn::Graphics *graphics) + { + this->bg->draw(graphics); + this->drawChildren(graphics); + } - 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(""); - } - } - }; +private: + gcn::Icon *bg; + gcn::Font *fnt; + gcn::Label *title; +}; - DemoListModel demoListModel; +/* + * 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; + } - /** - * 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 BackgroundContainer("data/menu_background.png"); - // 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); + 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"); + case 5: + return std::string("four"); + case 6: + return std::string("four"); + case 7: + return std::string("four"); + default: // Just to keep warnings away + return std::string(""); + } + } + }; - // Now we load the font used in this example. - font = new gcn::ImageFont("data/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); + DemoListModel demoListModel; - // Now we create the widgets - button = new gcn::Button("Button"); + /** + * Initialises the widgets example by populating the global Gui + * object. + */ + void init() + { + // Now we load the font used in this example. + font = new gcn::ImageFont("data/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); - textField = new gcn::TextField("Text field"); + title_font = new gcn::ImageFont("data/techyfontbig.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + // 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 BackgroundContainer(title_font, "data/menu_background.png", "Main menu"); + // Finally we pass the top widget to the Gui object. + globals::gui->setTop(top); - textBox = new gcn::TextBox("Multiline\nText box"); - textBoxScrollArea = new gcn::ScrollArea(textBox); - textBoxScrollArea->setWidth(200); - textBoxScrollArea->setHeight(100); - textBoxScrollArea->setFrameSize(1); + // Now we create the widgets + button = new gcn::Button("Button"); - 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"); + textField = new gcn::TextField("Text field"); - window = new gcn::Window("I am a window Drag me"); - window->setBaseColor(gcn::Color(255, 150, 200, 190)); + textBox = new gcn::TextBox("Multiline\nText box"); + textBoxScrollArea = new gcn::ScrollArea(textBox); + textBoxScrollArea->setWidth(200); + textBoxScrollArea->setHeight(100); + textBoxScrollArea->setFrameSize(1); - darkbitsImage = gcn::Image::load("data/darkbitslogo_by_haiko.bmp"); - darkbitsIcon = new gcn::Icon(darkbitsImage); - window->add(darkbitsIcon); - window->resizeToContent(); + listBox = new gcn::ListBox(&demoListModel); + listBox->setFrameSize(1); + dropDown = new gcn::DropDown(&demoListModel); - 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); + checkBox1 = new gcn::CheckBox("Checkbox 1"); + checkBox2 = new gcn::CheckBox("Checkbox 2"); - // Now it's time to add the widgets to the top container - // so they will be conected to the GUI. - - 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(window, 50, 350); - top->add(tabbedArea, 400, 350); - } - - /** - * Halts the widgets example. - */ - void halt() - { - delete font; - delete top; - delete button; - delete textField; - delete textBox; - delete textBoxScrollArea; - delete listBox; - delete dropDown; - delete checkBox1; - delete checkBox2; - delete window; - delete darkbitsIcon; - delete darkbitsImage; - delete tabbedArea; - delete tabOneButton; - delete tabTwoCheckBox; - } + window = new gcn::Window("I am a window Drag me"); + window->setBaseColor(gcn::Color(255, 150, 200, 190)); + + darkbitsImage = gcn::Image::load("data/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(button, 200, 80); + top->add(textField, 250, 80); + top->add(textBoxScrollArea, 200, 50); + top->add(listBox, 200, 200); + top->add(dropDown, 500, 80); + top->add(checkBox1, 500, 130); + top->add(checkBox2, 500, 150); + top->add(window, 50, 350); + top->add(tabbedArea, 400, 350); + } + + /** + * Halts the widgets example. + */ + void halt() + { + delete font; + delete title_font; + delete top; + delete button; + delete textField; + delete textBox; + delete textBoxScrollArea; + delete listBox; + delete dropDown; + delete checkBox1; + delete checkBox2; + delete window; + delete darkbitsIcon; + delete darkbitsImage; + delete tabbedArea; + delete tabOneButton; + delete tabTwoCheckBox; + } } diff --git a/data/menu_background.png b/data/menu_background.png index 79266a1..9a9c76c 100644 Binary files a/data/menu_background.png and b/data/menu_background.png differ diff --git a/data/techyfontbig.png b/data/techyfontbig.png new file mode 100644 index 0000000..12e28c7 Binary files /dev/null and b/data/techyfontbig.png differ