X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fdropdown.cpp;h=6ec88fe10e30ad8be3e0dc89279f48b448705b6f;hb=43a75e4e9be56c58be5e224f19016bb14b56a7ef;hp=cff5387408a2b7551d308f014fcf91f7e1f674c5;hpb=b92c878a286036af106e969a29b2689876aa5f65;p=libs%2Fgltk.git diff --git a/source/dropdown.cpp b/source/dropdown.cpp index cff5387..6ec88fe 100644 --- a/source/dropdown.cpp +++ b/source/dropdown.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007-2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include "dropdown.h" #include "list.h" @@ -33,16 +26,19 @@ void Dropdown::autosize() return; Widget::autosize(); + list.autosize_all(); geom.w = max(geom.w, list.get_geometry().w); if(const Part *text_part = style->get_part("text")) { const Sides &margin = text_part->get_margin(); - const GL::Font *font = style->get_font(); - float font_size = font->get_default_size(); - unsigned line_height = static_cast((font->get_ascent()-font->get_descent())*font_size); + const GL::Font &font = style->get_font(); + float font_size = style->get_font_size(); + unsigned line_height = static_cast((font.get_ascent()-font.get_descent())*font_size); geom.h = max(geom.h, line_height+margin.top+margin.bottom); } + + rebuild(); } void Dropdown::append(const string &item) @@ -85,15 +81,21 @@ int Dropdown::get_selected_index() const return list.get_selected_index(); } -void Dropdown::render_special(const Part &part) const +void Dropdown::rebuild_special(const Part &part, CachedPart &cache) { if(part.get_name()=="text") { if(list.get_selected_index()>=0) - Text(*style, list.get_selected()).render(part, geom); + Text(*style, list.get_selected()).build(part, geom, cache); + else + cache.texture = 0; } - else if(part.get_name()=="list" && dropped) - list.render(); +} + +void Dropdown::render_special(const Part &part, GL::Renderer &renderer) const +{ + if(part.get_name()=="list" && dropped) + list.render(renderer); } void Dropdown::button_press(int x, int y, unsigned btn) @@ -104,14 +106,14 @@ void Dropdown::button_press(int x, int y, unsigned btn) if(!click_focus) { dropped = false; - state &= ~ACTIVE; + clear_state(ACTIVE); signal_ungrab_pointer.emit(); } } else if(btn==1) { dropped = true; - state |= ACTIVE; + set_state(ACTIVE); signal_grab_pointer.emit(); } } @@ -167,11 +169,12 @@ void Dropdown::list_item_selected(unsigned index, const std::string &item) if(dropped) { dropped = false; - state &= ~ACTIVE; + clear_state(ACTIVE); signal_ungrab_pointer.emit(); } signal_item_selected.emit(index, item); + rebuild(); }