diff options
Diffstat (limited to 'src/ui/menu.cc')
-rw-r--r-- | src/ui/menu.cc | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/src/ui/menu.cc b/src/ui/menu.cc index 2a1829f..6931bd4 100644 --- a/src/ui/menu.cc +++ b/src/ui/menu.cc @@ -17,17 +17,12 @@ Menu::Menu(Window *parent, const char *label) : Window(parent) { set_label(label); set_border(false); - - menu_element_width = 256.0f; - menu_element_height = 48.0f; - menu_element_margin = 24.0f; + set_background(false); menu_background = new Bitmap(this); - menu_container = new Window(this); - menu_container->set_border(true); - menu_container->set_background(true); - - menu_container->set_label("container"); + menu_container = new Container(this); + + hide(); } Menu::~Menu() @@ -52,6 +47,9 @@ void Menu::load() std::string strval; Button *button = 0; Label *label = 0; + float w = menu_container->childsize().width(); + float h = menu_container->childsize().height(); + float m = menu_container->margin(); while (ini.getline()) { if (ini.got_section()) { @@ -76,13 +74,13 @@ void Menu::load() if (ini.in_section("menu")) { if (ini.got_key_string("background", strval)) { - set_background(strval.c_str()); - } else if (ini.got_key_float("elementwidth", menu_element_width)) { - continue; - } else if (ini.got_key_float("elementheight", menu_element_height)) { - continue; - } else if (ini.got_key_float("elementmargin", menu_element_margin)) { - continue; + menu_background->set_texture(strval); + } else if (ini.got_key_float("elementwidth", w)) { + menu_container->set_childsize(w,h); + } else if (ini.got_key_float("elementheight", h)) { + menu_container->set_childsize(w,h); + } else if (ini.got_key_float("elementmargin", m)) { + menu_container->set_margin(m); } else { ini.unkown_key(); } @@ -133,7 +131,7 @@ void Menu::load() ini.close(); } -void Menu::set_background(const char *texture) +void Menu::set_background_texture(const char *texture) { menu_background->set_texture(texture); } @@ -156,19 +154,7 @@ void Menu::resize() { set_size(parent()->size()); menu_background->set_size(size()); - - float n = (float) menu_container->children().size(); - menu_container->set_size(1.5f * menu_element_width, n * (menu_element_height + menu_element_margin) + menu_element_height); - menu_container->set_location(menu_element_width * 0.25, (height() - menu_container->height()) / 2.0f); - - // reposition all children within the container - size_t i = 0; - for (Children::iterator it = menu_container->children().begin(); it != menu_container->children().end(); it++) { - Widget *w = (*it); - w->set_size(menu_element_width, menu_element_height); - w->set_location(menu_element_width * 0.25f, menu_element_height * 0.5f + i * (menu_element_height + menu_element_margin)); - i++; - } + menu_container->set_location(menu_container->childsize().width() * 0.25, (height() - menu_container->height()) / 2.0f); } } |