void Menu_attribute_controller::Handle_event(const Ustring& event_handle, const Event& event) {
	Menu* widget = dynamic_cast<Menu*>(layout_controller->Get_current_widget());
	if(widget) {
		if(event_handle == "add_option") {
			Inputbox* option_text = dynamic_cast<Inputbox*>(controller_layout.Get_widget("option text"));
			widget->Add_option(option_text->Get_text());
		}
		if(event_handle == "remove_option") {
			widget->Remove_option(widget->Get_selected_option());
		}
	}
}
示例#2
0
Vector2 Dropdown_menu_view::Request_size(const Widget& widget) const
{
    const Dropdown_menu& dropdown_menu = dynamic_cast<const Dropdown_menu&>(widget);
    Vector2 size;
    //const Ustring& text = dropdown_menu.Get_text();
    Menu *child = dynamic_cast<Menu*>(dropdown_menu.Get_child());
    if(child) {
        const Ustring& text = child->Get_option(child->Get_selected_option());
        size.x = font->Get_ustr_width(text.Astring()) + 6;
    }
    size.y = al_get_font_line_height(font->Afont()) + 6;
    float lh = size.y/4+6;

    size.x += size.y/2;
    return size;
}
示例#3
0
void Dropdown_menu_view::Render(const Widget& widget) const
{
    const Dropdown_menu& dropdown_menu = dynamic_cast<const Dropdown_menu&>(widget);

    Vector2 p = widget.Get_position();
    Vector2 s = widget.Get_size();
    ALLEGRO_COLOR text_color = al_map_rgb_f(1, 1, 1);
    ALLEGRO_COLOR tri_color = al_map_rgb_f(1, 1, 1);
    ALLEGRO_COLOR edge_color = al_map_rgb_f(0.5, 0.5, 0.5);
    ALLEGRO_COLOR select_color = al_map_rgb_f(0.0, 0, 0.8);

    //const Ustring& text = dropdown_menu.Get_text();
    float h = al_get_font_line_height(font->Afont());

    Menu *child = dynamic_cast<Menu*>(dropdown_menu.Get_child());
    if(child) {
        const Ustring& text = child->Get_option(child->Get_selected_option());
        float text_width = font->Get_ustr_width(text.Astring());
        al_draw_ustr(font->Afont(), text_color, p.x+6+h/2, p.y+3, 0, text.Astring());
    }


    float top = h*0.25;
    float middle = h*0.5;
    float bottom = h*0.75;

    if(dropdown_menu.Is_open())
    {
        al_draw_filled_triangle(p.x+3, p.y+3+middle, p.x+3+middle, p.y+3+middle, p.x+3+top, p.y+3+bottom, tri_color);
        al_draw_triangle       (p.x+3, p.y+3+middle, p.x+3+middle, p.y+3+middle, p.x+3+top, p.y+3+bottom, edge_color, 0);
    }
    else
    {
        al_draw_filled_triangle(p.x+3, p.y+3+top, p.x+3+top, p.y+3+middle, p.x+3, p.y+3+bottom, tri_color);
        al_draw_triangle       (p.x+3, p.y+3+top, p.x+3+top, p.y+3+middle, p.x+3, p.y+3+bottom, edge_color, 0);
    }
}