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.am8
-rw-r--r--src/ui/menu.cc2
-rw-r--r--src/ui/menuview.cc94
-rw-r--r--src/ui/menuview.h42
-rw-r--r--src/ui/ui.cc207
-rw-r--r--src/ui/ui.h3
6 files changed, 24 insertions, 332 deletions
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index a89cdaa..1fb8e24 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -8,10 +8,10 @@ noinst_LTLIBRARIES = libui.la
endif
noinst_HEADERS = bitmap.h button.h console.h container.h definitions.h font.h \
- inputbox.h label.h menu.h menuview.h paint.h palette.h scrollpane.h toolbar.h ui.h \
- widget.h window.h
+ inputbox.h label.h menu.h paint.h palette.h scrollpane.h toolbar.h ui.h widget.h \
+ window.h
libui_la_SOURCES = bitmap.cc button.cc console.cc console.h container.cc \
- font.cc inputbox.cc label.cc menu.cc menuview.cc paint.cc palette.cc \
- scrollpane.cc toolbar.cc ui.cc widget.cc window.cc
+ font.cc inputbox.cc label.cc menu.cc paint.cc palette.cc scrollpane.cc \
+ toolbar.cc ui.cc widget.cc window.cc
libui_la_LDFLAGS = -avoid-version -no-undefined
diff --git a/src/ui/menu.cc b/src/ui/menu.cc
index a7e2d68..f1364ac 100644
--- a/src/ui/menu.cc
+++ b/src/ui/menu.cc
@@ -58,7 +58,7 @@ void Menu::resize()
{
set_size(parent()->size());
menu_background->set_size(size());
- menu_container->set_location(UI::elementsize.width() * 0.25, (height() - menu_container->height()) / 2.0f);
+ menu_container->set_location(ui::UI::elementsize.height(), (height() - menu_container->height()) / 2.0f);
}
}
diff --git a/src/ui/menuview.cc b/src/ui/menuview.cc
deleted file mode 100644
index 43757e1..0000000
--- a/src/ui/menuview.cc
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- ui/menuview.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/menuview.h"
-#include "ui/ui.h"
-
-namespace ui
-{
-
-MenuView::MenuView(Window *parent, const char * label) : Window(parent)
-{
- set_border(false);
- set_background(false);
- set_label(label);
-
- menu_container = new Container(this);
- menu_label = new Label(this);
-
- hide();
-}
-
-MenuView::~MenuView()
-{
-}
-
-void MenuView::resize()
-{
- set_size(parent()->size());
- menu_label->set_location(UI::elementsize.width() * 0.25, UI::elementsize.width() * 0.25);
- menu_label->set_size(UI::elementsize.width() * 1.5f, UI::elementsize.height());
-
- menu_container->set_location(UI::elementsize.width() * 0.25, (height() - menu_container->height()) / 2.0f);
-}
-
-void MenuView::generate(core::Entity *entity, const char *menulabel)
-{
- if (!menulabel)
- return;
-
- //con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl;
-
- remove_children();
- menu_container = new Container(this);
-
- menu_label = new Label(this, entity->name().c_str());
- menu_label->set_background(true);
- menu_label->set_alignment(AlignCenter);
- menu_label->set_font(ui::root()->font_large());
-
- core::MenuDescription *menudescr = 0;
- for (core::Entity::Menus::iterator it = entity->menus().begin(); it != entity->menus().end(); it++) {
- if ((*it)->label().compare(menulabel) == 0) {
- menudescr = (*it);
- }
- }
-
- if (!menudescr) {
- menu_container->event_resize();
- resize();
- return;
- }
-
- if (menudescr->text().size()) {
- Label *label = new Label(menu_container);
- label->set_text(menudescr->text());
- label->set_alignment(AlignCenter);
- label->set_border(false);
- label->set_font(ui::root()->font_large());
- }
-
- for (core::MenuDescription::Buttons::iterator it = menudescr->buttons().begin(); it != menudescr->buttons().end(); it++) {
- core::ButtonDescription *buttondescr = (*it);
- Button *button = new Button(menu_container, buttondescr->text().c_str(), buttondescr->command().c_str());
- switch (buttondescr->alignment()) {
- case core::ButtonDescription::Center:
- button->set_alignment(AlignCenter);
- break;
- case core::ButtonDescription::Left:
- button->set_alignment(AlignLeft | AlignVCenter);
- break;
- case core::ButtonDescription::Right:
- button->set_alignment(AlignRight | AlignVCenter);
- break;
- }
- }
-
- menu_container->event_resize();
- resize();
-}
-
-}
diff --git a/src/ui/menuview.h b/src/ui/menuview.h
deleted file mode 100644
index 041d71a..0000000
--- a/src/ui/menuview.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- ui/menuview.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_MENUVIEW_H__
-#define __INCLUDED_UI_MENUVIEW_H__
-
-#include "core/entity.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 MenuView : public Window
-{
-public:
- /// create a new menu
- MenuView(Window *parent, const char * label);
- ~MenuView();
-
- /// generate a menu from menu descriptions
- void generate(core::Entity *entity, const char *menulabel);
-
-protected:
- /// resize event
- virtual void resize();
-
-private:
- Container *menu_container;
- Label *menu_label;
-};
-
-}
-
-#endif // __INCLUDED_UI_MENUVIEW_H__
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index ff6810f..f96f692 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -17,7 +17,6 @@
#include "ui/button.h"
#include "ui/label.h"
#include "ui/menu.h"
-#include "ui/menuview.h"
#include "ui/paint.h"
#include "ui/ui.h"
#include "ui/widget.h"
@@ -34,129 +33,6 @@ math::Vector2f UI::elementsize(256, 48);
UI *global_ui = 0;
-void func_list_ui(std::string const &args)
-{
- if (global_ui) {
- global_ui->list();
- }
-}
-
-void func_ui_restart(std::string const &args)
-{
- if (global_ui) {
- global_ui->load_menus();
- global_ui->load_settings();
- global_ui->apply_render_options();
- }
-}
-
-
-void func_ui_console(std::string const &args)
-{
- console()->toggle();
-}
-
-void func_list_menu(std::string const &args)
-{
- if (global_ui) {
- global_ui->list_menus();
- }
-}
-
-void help()
-{
- con_print << "^BUser interface functions" << std::endl;
- con_print << " ui help show this help" << std::endl;
- con_print << " ui debug toggle debug mode" << std::endl;
- con_print << " ui list list widgets" << std::endl;
- con_print << " ui restart reload user interface files" << std::endl;
-}
-
-void func_ui(std::string const &args)
-{
- if (!global_ui) {
- con_warn << "User Interface not available!" << std::endl;
- return;
- }
-
- if (!args.size()) {
- help();
- return;
- }
- std::stringstream argstr(args);
- std::string command;
- argstr >> command;
- aux::to_label(command);
-
- if (command.compare("help") == 0) {
- help();
- } else if (command.compare("debug") == 0) {
- UI::ui_debug = !UI::ui_debug;
- } else if (command.compare("list") == 0) {
- global_ui->list();
- } else if (command.compare("restart") == 0) {
- global_ui->load_menus();
- global_ui->load_settings();
- global_ui->apply_render_options();
- } else {
- help();
- }
-}
-
-void help_menu()
-{
- con_print << "^Bmenu functions" << std::endl;
- con_print << " menu help show this help" << std::endl;
- con_print << " menu list list available menus" << std::endl;
- con_print << " menu [name] show a menu" << std::endl;
- con_print << " menu back return to the previous menu" << std::endl;
- con_print << " menu previous return to the previous menu" << std::endl;
- con_print << " menu close close the current menu" << std::endl;
- con_print << " menu hide hide the current menu" << std::endl;
- root()->list_menus();
-}
-
-void func_menu(std::string const &args)
-{
- if (!global_ui) {
- con_warn << "User Interface not available!" << std::endl;
- return;
- }
-
- if (!args.size()) {
- return;
- }
- std::stringstream argstr(args);
- std::string command;
- argstr >> command;
-
- aux::to_label(command);
-
- if (command.compare("hide") == 0) {
- root()->hide_menu();
-
- } else if (command.compare("close") == 0) {
- root()->hide_menu();
-
- } else if (command.compare("back") == 0) {
- root()->previous_menu();
-
- } else if (command.compare("previous") == 0) {
- root()->previous_menu();
-
- } else if (command.compare("list") == 0) {
- root()->list_menus();
- } else if (command.compare("view") == 0) {
- std::string label;
- if (!(argstr >> label)) {
- label.assign("main");
- }
- root()->show_menuview(label);
- } else {
- root()->show_menu(command.c_str());
- }
-}
-
UI *root()
{
return global_ui;
@@ -175,36 +51,12 @@ void init()
global_ui->load_menus();
global_ui->load_settings();
-
- core::Func *func = core::Func::add("list_ui", func_list_ui);
- func->set_info("list user interface widgets");
-
- func = core::Func::add("list_menu", func_list_menu);
- func->set_info("list available menus");
-
- func = core::Func::add("ui", func_ui);
- func->set_info("[command] user interface functions");
-
- func = core::Func::add("ui_restart", func_ui_restart);
- func->set_info("reload user interface files");
-
- func = core::Func::add("ui_console", func_ui_console);
- func->set_info("toggle console on or off");
-
- func = core::Func::add("menu", func_menu);
- func->set_info("[command] menu functions");
}
void shutdown()
{
con_print << "^BShutting down user interface..." << std::endl;
-
- core::Func::remove("list_ui");
- core::Func::remove("list_menu");
- core::Func::remove("menu");
- core::Func::remove("ui_console");
- core::Func::remove("ui");
-
+
if (global_ui) {
delete global_ui;
global_ui = 0;
@@ -257,9 +109,6 @@ void UI::load_menus()
}
ui_menus.clear();
- // add specia view menu
- add_menu(new MenuView(this, "view"));
-
std::string filename("menu");
filesystem::IniFile ini;
ini.open(filename);
@@ -588,20 +437,6 @@ void UI::add_menu(Window *menu)
}
-void UI::show_menuview(const std::string &label)
-{
- if (!core::localplayer()->view())
- return;
-
- if (!core::localplayer()->view()->menus().size())
- return;
-
- MenuView *menuview = static_cast<MenuView *>(find_menu("view"));
- menuview->generate(core::localplayer()->view(), label.c_str());
-
- show_menu("view");
-}
-
void UI::show_menu(const char *label)
{
Window *menu = find_menu(label);
@@ -655,7 +490,14 @@ 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) {
+ f->event_mouse(mouse_cursor);
+ }
+ ui_mouse_focus = f;
+
event_draw();
if (visible())
@@ -670,11 +512,6 @@ void UI::frame()
void UI::input_mouse(const float x, const float y)
{
mouse_cursor.assign(x, y);
- Widget *f = find_mouse_focus(mouse_cursor);
- if (f) {
- f->event_mouse(mouse_cursor);
- }
- ui_mouse_focus = f;
}
bool UI::input_key(const bool pressed, const int key, const unsigned int modifier)
@@ -688,7 +525,13 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie
}
ui_input_focus = f;
} else {
- // mosue buttons
+ // mouse buttons
+ Widget *f = find_mouse_focus(mouse_cursor);
+ if (f) {
+ f->event_mouse(mouse_cursor);
+ }
+ ui_mouse_focus = f;
+
if (ui_mouse_focus)
handled = ui_mouse_focus->event_key(pressed, key, modifier);
}
@@ -701,21 +544,9 @@ bool UI::on_keypress(const int key, const unsigned int modifier)
case SDLK_ESCAPE:
if (active()) {
- if (active()->label().compare("view") == 0) {
- if (core::application()->connected()) {
- show_menu("game");
- audio::play("ui/menu");
- }
- } else {
- hide_menu();
- audio::play("ui/menu");
- }
- } else {
- if (core::application()->connected()) {
- show_menu("game");
- audio::play("ui/menu");
- }
- }
+ hide_menu();
+ audio::play("ui/menu");
+ }
return true;
break;
default:
diff --git a/src/ui/ui.h b/src/ui/ui.h
index fae827e..6216ba7 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -42,9 +42,6 @@ public:
/// make a window the active window
void show_menu(const char *label);
-
- /// make the entity view menu the active window
- void show_menuview(const std::string &label);
/// hide the active window
void hide_menu();