From bc50666e86d5739ccde633eb630cc75b3e0fcb71 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 7 Oct 2008 20:35:52 +0000 Subject: libui updates --- src/ui/ui.cc | 64 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 20 deletions(-) (limited to 'src/ui/ui.cc') diff --git a/src/ui/ui.cc b/src/ui/ui.cc index 0700c37..d6c53f0 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -168,8 +168,8 @@ void shutdown() UI::UI() : Window(0) { - set_palette(new Palette()); - set_label("user interface"); + set_palette(&ui_palette); + set_label("root"); set_size(1024, 768); set_border(false); @@ -237,16 +237,16 @@ void UI::load() } else if (ini.in_section("colors")) { if (ini.got_key_color("foreground", color)) { - widget_palette->set_foreground(color); + ui_palette.set_foreground(color); continue; } else if (ini.got_key_color("highlight", color)) { - widget_palette->set_highlight(color); + ui_palette.set_highlight(color); continue; } else if (ini.got_key_color("background", color)) { - widget_palette->set_background(color); + ui_palette.set_background(color); continue; } else if (ini.got_key_color("border", color)) { - widget_palette->set_border(color); + ui_palette.set_border(color); continue; } else { ini.unkown_key(); @@ -257,6 +257,24 @@ void UI::load() con_debug << " " << ini.name() << " " << window_children.size() << " menus" << std::endl; ini.close(); + + // fallback main menu + if (!find_window("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_window("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"); + } } UI::~UI() @@ -297,22 +315,30 @@ void UI::remove_window(Window *window) Window::remove_window(window); } -void UI::show_window(char const *label) +Window *UI::find_window(const char *label) { - Windows::iterator it; - for (it = window_children.begin(); it != window_children.end(); it++) { + for (Windows::iterator it = window_children.begin(); it != window_children.end(); it++) { if ((*it)->label().compare(label) == 0) { + return (*it); + } + } + return 0; +} + +void UI::show_window(const char *label) +{ + Window *window = find_window(label); + + if (window) { if (ui_active_window) ui_active_window->hide(); - ui_active_window = (*it); + ui_active_window = window; ui_active_window->event_resize(); ui_active_window->show(); - ui_focus = this; - return; - } + ui_focus = window; + } else { + con_warn << "Unknown window '" << label << "'" << std::endl; } - - con_warn << "Unknown window '" << label << "'" << std::endl; } void UI::hide_window() @@ -329,21 +355,19 @@ void UI::frame() event_draw(); } -void UI::event_mousecursor(float x, float y) +void UI::event_mousemove(float x, float y) { mouse_cursor.assign(x, y); } void UI::event_keypress(unsigned int key, unsigned int modifier) { - if (ui_focus != this) - ui_focus->event_keypress(key, modifier); + ui_focus->keypress(key, modifier); } void UI::event_keyrelease(unsigned int key, unsigned int modifier) { - if (ui_focus != this) - ui_focus->event_keyrelease(key, modifier); + ui_focus->keyrelease(key, modifier); } } -- cgit v1.2.3