Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/Makefile.am4
-rw-r--r--src/ui/container.cc45
-rw-r--r--src/ui/container.h33
-rw-r--r--src/ui/menu.cc82
-rw-r--r--src/ui/menu.h54
-rw-r--r--src/ui/ui.cc242
-rw-r--r--src/ui/ui.h27
-rw-r--r--src/ui/widget.cc14
-rw-r--r--src/ui/widget.h2
9 files changed, 12 insertions, 491 deletions
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 36a1ac1..c753408 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -12,7 +12,6 @@ noinst_HEADERS = \
bitmap.h \
button.h \
console.h \
- container.h \
definitions.h \
font.h \
iconbutton.h \
@@ -20,7 +19,6 @@ noinst_HEADERS = \
label.h \
listitem.h \
listview.h \
- menu.h \
modelview.h \
paint.h \
palette.h \
@@ -36,14 +34,12 @@ libui_la_SOURCES = \
bitmap.cc \
button.cc \
console.cc \
- container.cc \
font.cc \
iconbutton.cc \
inputbox.cc \
label.cc \
listitem.cc \
listview.cc \
- menu.cc \
modelview.cc \
paint.cc \
palette.cc \
diff --git a/src/ui/container.cc b/src/ui/container.cc
deleted file mode 100644
index ebe2821..0000000
--- a/src/ui/container.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- ui/container.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-
-#include "ui/container.h"
-#include "ui/paint.h"
-#include "ui/ui.h"
-
-namespace ui
-{
-
-// TODO Container::direction
-Container::Container(Widget *parent) : Window(parent)
-{
- set_label("container");
- set_border(true);
- set_background(true);
-}
-
-Container::~Container()
-{
-}
-
-void Container::resize()
-{
- float w = UI::elementsize.width() * 1.5f;
- float h = children().size() * (UI::elementsize.height() + UI::elementmargin) + UI::elementsize.height();
- set_size(w, h);
-
- const float x = UI::elementsize.width() * 0.25f;
- float y = UI::elementsize.height() * 0.5f;
-
- // reposition all children within the container
- for (Children::iterator it = children().begin(); it != children().end(); it++) {
- Widget *w = (*it);
- w->set_size(UI::elementsize);
- w->set_location(x, y);
- y += UI::elementsize.height() + UI::elementmargin;
- }
-}
-
-}
diff --git a/src/ui/container.h b/src/ui/container.h
deleted file mode 100644
index 4dbf150..0000000
--- a/src/ui/container.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- ui/container.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-#ifndef __INCLUDED_UI_CONTAINER_H__
-#define __INCLUDED_UI_CONTAINER_H__
-
-#include <string>
-
-#include "ui/window.h"
-
-namespace ui
-{
-
-/// a widget containing childs of equal size
-class Container : public Window
-{
-public:
- Container(Widget *parent);
- ~Container();
-
-protected:
-
- virtual void resize();
-};
-
-}
-
-#endif // __INCLUDED_UI_CONTAINER_H__
-
-
diff --git a/src/ui/menu.cc b/src/ui/menu.cc
deleted file mode 100644
index c4dc214..0000000
--- a/src/ui/menu.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- ui/menu.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-#include "filesystem/filesystem.h"
-#include "ui/label.h"
-#include "ui/button.h"
-#include "ui/menu.h"
-#include "ui/ui.h"
-
-namespace ui
-{
-
-Menu::Menu(Window *parent, const char *label) : Window(parent)
-{
- set_label(label);
- set_border(false);
- set_background(false);
-
- menu_background = new Bitmap(this);
- menu_container = new Container(this);
-
- hide();
-}
-
-Menu::~Menu()
-{
- // menu_container and menu_background are deleted by Widget::~Widget()
-}
-
-void Menu::set_background_texture(const char *texture)
-{
- menu_background->set_texture(texture);
-}
-
-void Menu::set_background_texture(const std::string &texture)
-{
- menu_background->set_texture(texture);
-}
-
-Label *Menu::add_label(char const * text)
-{
- Label *label = new Label(menu_container, text);
- label->set_alignment(AlignCenter);
- label->set_border(false);
- label->set_font(ui::root()->font_large());
- return label;
-}
-
-Button *Menu::add_button(char const *text, char const *command)
-{
- return new Button(menu_container, text, command);
-}
-
-void Menu::resize()
-{
- set_size(parent()->size());
- menu_background->set_size(size());
- menu_container->set_location(ui::UI::elementsize.height(), (height() - menu_container->height()) / 2.0f);
-}
-
-bool Menu::on_keypress(const int key, const unsigned int modifier)
-{
- switch (key) {
-
- case SDLK_ESCAPE:
- if (visible()) {
- this->hide();
- return true;
- }
- break;
-
- default:
- break;
- }
-
- return Window::on_keypress(key, modifier);
-}
-
-}
diff --git a/src/ui/menu.h b/src/ui/menu.h
deleted file mode 100644
index 7fd211c..0000000
--- a/src/ui/menu.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- ui/menu.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
-*/
-
-#ifndef __INCLUDED_UI_MENU_H__
-#define __INCLUDED_UI_MENU_H__
-
-#include "ui/bitmap.h"
-#include "ui/container.h"
-#include "ui/button.h"
-#include "ui/label.h"
-#include "ui/window.h"
-
-namespace ui
-{
-
-/// a menu container
-class Menu : public Window
-{
-
-public:
- /// create a new menu
- Menu(Window *parent, const char * label = 0);
- ~Menu();
-
- /// set the background bitmap
- void set_background_texture(const char *texture);
-
- /// set the background bitmap
- void set_background_texture(const std::string &texture);
-
- /// add a label
- Label *add_label(char const * text = 0);
-
- /// add a button with a command
- Button *add_button(char const *text = 0, char const *command = 0);
-
-protected:
- /// resize event
- virtual void resize();
-
- /// keypress event
- virtual bool on_keypress(const int key, const unsigned int modifier);
-
-private:
- Bitmap *menu_background;
- Container *menu_container;
-};
-
-}
-
-#endif // __INCLUDED_UI_MENU_H__
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index 93b5e16..4977d03 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -16,7 +16,6 @@
#include "sys/sys.h"
#include "ui/button.h"
#include "ui/label.h"
-#include "ui/menu.h"
#include "ui/paint.h"
#include "ui/ui.h"
#include "ui/widget.h"
@@ -100,17 +99,8 @@ UI::~UI()
void UI::load_settings()
{
- ui_active_menu = 0;
ui_mouse_focus = this;
- // clear any existing menus
- Menus::iterator it;
- for (it = ui_menus.begin(); it != ui_menus.end(); it++) {
- Window *menu = (*it);
- remove_child(menu);
- }
- ui_menus.clear();
-
// open ui.ini
std::string filename("ini/ui");
filesystem::IniFile ini;
@@ -124,10 +114,6 @@ void UI::load_settings()
std::string strval;
math::Color color;
- Button *button = 0;
- Label *label = 0;
- Menu *menu = 0;
-
float w = elementsize.width();
float h = elementsize.height();
float m = elementmargin;
@@ -138,51 +124,20 @@ void UI::load_settings()
if (ini.got_section()) {
if (ini.got_section("ui")) {
- menu = 0;
continue;
// section default colors
} else if (ini.got_section("colors")) {
- menu = 0;
continue;
// section hud configuration
} else if (ini.got_section("hud")) {
- menu = 0;
continue;
// section text colors
} else if (ini.got_section("text")) {
- menu = 0;
- continue;
-
- // section menu
- } else if (ini.got_section("menu")) {
- label = 0;
- button = 0;
- menu = new Menu(this);
- add_menu(menu);
continue;
-
- // menu button
- } else if (ini.got_section("button")) {
-
- if (!menu) {
- ini.unknown_error("button section outside menu defintion");
- } else {
- button = menu->add_button();
- }
-
- // menu label
- } else if (ini.got_section("label")) {
-
- if (!menu) {
- ini.unknown_error("label section outside menu defintion");
- } else {
- label = menu->add_label();
- }
-
} else {
ini.unknown_section();
continue;
@@ -264,69 +219,6 @@ void UI::load_settings()
ui_palette->set_error(color);
}
- // menu definitions
-
- } else if (menu) {
-
- if (ini.in_section("menu")) {
-
- if (ini.got_key_string("label", strval)) {
- aux::to_label(strval);
- menu->set_label(strval);
- } else if (ini.got_key_string("background", strval)) {
- menu->set_background_texture(strval);
- } else {
- ini.unknown_key();
- }
-
- } else if (ini.in_section("button")) {
-
- if (ini.got_key_string("text", strval)) {
- aux::strip_quotes(strval);
- button->set_text(strval);
-
- } else if (ini.got_key_string("command", strval)) {
- for (size_t i = 0; i <= strval.size(); i++) {
- if (strval[i] == ',') strval[i] = ';';
- }
- aux::strip_quotes(strval);
- button->set_command(strval);
-
- } else if (ini.got_key_string("align", strval)) {
- aux::to_label(strval);
- if (strval.compare("left") == 0) {
- button->set_alignment(AlignLeft | AlignVCenter);
- } else if (strval.compare("center") == 0) {
- button->set_alignment(AlignCenter);
- } else if (strval.compare("right") == 0) {
- button->set_alignment(AlignRight | AlignVCenter);
- } else {
- ini.unknown_value();
- }
- } else {
- ini.unknown_key();
- }
-
- } else if (ini.in_section("label")) {
-
- if (ini.got_key_string("text", strval)) {
- label->set_text(strval);
- } else if (ini.got_key_string("align", strval)) {
- aux::to_label(strval);
- if (strval.compare("left") == 0) {
- label->set_alignment(AlignLeft | AlignHCenter);
- } else if (strval.compare("center") == 0) {
- label->set_alignment(AlignCenter);
- } else if (strval.compare("right") == 0) {
- label->set_alignment(AlignRight | AlignHCenter);
- } else {
- ini.unknown_value();
- }
- } else {
- ini.unknown_key();
- }
- }
-
}
}
}
@@ -339,35 +231,6 @@ void UI::load_settings()
Paint::assign_system_color('W', palette()->warning());
Paint::assign_system_color('E', palette()->error());
- con_debug << " " << ini.name() << " " << ui_menus.size() << " menus" << std::endl;
-
- // fallback main menu
- if (!find_menu("main")) {
- con_warn << "menu 'main' not found, using default" << std::endl;
- Menu *menu = new Menu(this, "main");
- menu->add_label("Main Menu");
- menu->add_button("Connect", "connect");
- menu->add_button("Quit", "quit");
- }
-
- // fallback game menu
- if (!find_menu("game")) {
- con_warn << "menu 'game' not found, using default" << std::endl;
- Menu *menu = new Menu(this, "game");
- menu->add_label("Game Menu");
- menu->add_button("Disconnect", "disconnect");
- menu->add_button("Quit", "quit");
- }
-
- // fallback join menu
- if (!find_menu("join")) {
- con_warn << "menu 'join' not found, using default" << std::endl;
- Menu *menu = new Menu(this, "join");
- menu->add_label("Join Menu");
- menu->add_button("Join", "join; menu hide");
- menu->add_button("Game menu", "menu game");
- }
-
ini.close();
}
@@ -383,100 +246,8 @@ void UI::list_visible() const
con_print << n << " visible user interface widgets" << std::endl;
}
-UI::Menus::iterator UI::find_menu(Window *menu)
-{
- Menus::iterator it;
- for (it = ui_menus.begin(); it != ui_menus.end(); it++) {
- if ((*it) == menu)
- return it;
- }
-
- return it;
-}
-
-Window *UI::find_menu(const char *label)
-{
- for (Menus::const_iterator it = ui_menus.begin(); it != ui_menus.end(); it++) {
- if ((*it)->label().compare(label) == 0) {
- return (*it);
- }
- }
-
- return 0;
-}
-
-void UI::list_menus() const
-{
- for (Menus::const_iterator it = ui_menus.begin(); it != ui_menus.end(); it++) {
- const Window *menu = (*it);
- con_print << " " << menu->label() << std::endl;
- }
- con_print << ui_menus.size() << " menus" << std::endl;
-}
-
-void UI::add_menu(Window *menu)
-{
- Menus::iterator it = find_menu(menu);
- if (it == ui_menus.end()) {
- ui_menus.push_back(menu);
- }
-
-}
-
-void UI::show_menu(const char *label)
-{
- Window *menu = find_menu(label);
-
- if (menu) {
- if (ui_active_menu) {
- ui_active_menu->hide();
- menu->set_previous(ui_active_menu);
- } else {
- menu->clear_previous();
- }
- ui_mouse_focus = this;
- ui_input_focus = this;
-
- ui_active_menu = menu;
- ui_active_menu->event_resize();
- ui_active_menu->show();
-
- set_pointer("pointer");
-
- // raise console if it is visible
- if (ui_console->visible())
- ui_console->show();
-
- } else {
- con_warn << "Unknown window '" << label << "'" << std::endl;
- }
-}
-
-void UI::hide_menu()
-{
- if (ui_active_menu) {
- ui_active_menu->hide();
- ui_active_menu = 0;
- }
-}
-
-void UI::previous_menu()
-{
- if (ui_active_menu) {
- if (ui_active_menu->previous().size()) {
- show_menu(ui_active_menu->previous().c_str());
- } else {
- hide_menu();
- }
- }
-}
-
void UI::frame()
{
- if (ui_active_menu && !ui_active_menu->visible()) {
- ui_active_menu = 0;
- }
-
ui_input_focus = find_input_focus();
Widget *f = find_mouse_focus(mouse_cursor);
if (f) {
@@ -532,19 +303,6 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie
bool UI::on_keypress(const int key, const unsigned int modifier)
{
- switch (key) {
-
- case SDLK_ESCAPE:
- if (active()) {
- hide_menu();
- //audio::play("ui/menu");
- }
- return true;
- break;
- default:
- break;
- }
-
return false;
}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index b3bb43b..cd2e38c 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -31,28 +31,11 @@ public:
/// list visible widgets
void list_visible() const;
- /// list meus
- void list_menus() const;
-
- /// make a window the active window
- void show_menu(const char *label);
-
- /// hide the active window
- void hide_menu();
-
- /// show previous window
- void previous_menu();
-
/// the console
inline Console *console() {
return ui_console;
}
- /// return the active menu
- Window *active() {
- return ui_active_menu;
- }
-
/// return the widget with global mouse focus
inline Widget *mouse_focus() const {
return ui_mouse_focus;
@@ -108,13 +91,6 @@ public:
static math::Vector2f elementsize;
protected:
- typedef std::list<Window *> Menus;
-
- Menus::iterator find_menu(Window *menu);
- Window *find_menu(const char *label);
-
- void add_menu(Window *window);
-
/* -- event handlers --------------------------------------- */
/// handle keypress events
@@ -131,14 +107,11 @@ private:
Font *ui_font_small;
Font *ui_font_large;
- Window *ui_active_menu;
Widget *ui_mouse_focus;
Widget *ui_input_focus;
Console *ui_console;
- Menus ui_menus;
-
/// TODO move to separate object to handle mouse cursor drawing
math::Vector2f mouse_cursor;
std::string mouse_pointer_bitmap;
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index 709731e..6d0fb84 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -76,10 +76,18 @@ void Widget::print(const size_t indent) const
{
if (indent) {
std::string marker;
- if (widget_focus)
- marker.assign("^B* ^N");
- else
+ if (!widget_enabled) {
+ marker.assign("^B- ");
+ } else if (widget_focus) {
+ marker.assign("^B* ");
+ } else {
marker.assign(" ");
+ }
+ if (widget_visible) {
+ marker.append("^N");
+ } else {
+ marker.append("^D");
+ }
con_print << aux::pad_left(marker, indent*2) << label() << std::endl;
}
}
diff --git a/src/ui/widget.h b/src/ui/widget.h
index 9aae10e..77a84c2 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -291,7 +291,7 @@ protected:
/// find the widget that has input focus
virtual Widget *find_input_focus();
- /// find widget that has mosue focus
+ /// find widget that has mouse focus
/** @param cursor mouse cursor position relative to this widget's location
*/
Widget *find_mouse_focus(const math::Vector2f & cursor);