blob: 43757e1f711f9994f3bf8715caf0bb24b039f4d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*
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();
}
}
|