From: Mikko Rasa Date: Thu, 22 Nov 2007 15:27:08 +0000 (+0000) Subject: Support loading Panels from datafiles X-Git-Tag: 0.9~27 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b23464cda4e4f2c7b69b18549f18c2c893c3fe2d;p=libs%2Fgltk.git Support loading Panels from datafiles Refactor the Panel focus logic Add visibility property to widgets --- diff --git a/source/panel.cpp b/source/panel.cpp index c93d430..efe857e 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -29,13 +29,12 @@ void Panel::button_press(int x, int y, unsigned btn) pointer_focus->button_press(x-geom.x, y-geom.y, btn); else if(geom.is_inside(x, y)) { - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - { - (*i)->button_press(x-geom.x, y-geom.y, btn); - pointer_grab=btn; - set_input_focus(*i); - } + if(Widget *wdg=get_child_at(x, y)) + { + wdg->button_press(x-geom.x, y-geom.y, btn); + pointer_grab=btn; + set_input_focus(wdg); + } } } @@ -49,19 +48,13 @@ void Panel::button_release(int x, int y, unsigned btn) { pointer_grab=0; - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - { - set_pointer_focus(*i); - break; - } + set_pointer_focus(get_child_at(x, y)); } } else if(geom.is_inside(x, y)) { - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - (*i)->button_release(x-geom.x, y-geom.y, btn); + if(Widget *wdg=get_child_at(x, y)) + wdg->button_release(x-geom.x, y-geom.y, btn); } } @@ -71,17 +64,10 @@ void Panel::pointer_motion(int x, int y) pointer_focus->pointer_motion(x-geom.x, y-geom.y); else if(geom.is_inside(x, y)) { - bool found=false; - for(ChildSeq::iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) - { - set_pointer_focus(*i); - (*i)->pointer_motion(x-geom.x, y-geom.y); - found=true; - } - - if(!found) - set_pointer_focus(0); + Widget *wdg=get_child_at(x, y); + set_pointer_focus(wdg); + if(wdg) + wdg->pointer_motion(x-geom.x, y-geom.y); } } @@ -112,7 +98,8 @@ void Panel::render_part(const Part &part) const if(part.get_name()=="children") { for(ChildSeq::const_iterator i=children.begin(); i!=children.end(); ++i) - (*i)->render(); + if((*i)->is_visible()) + (*i)->render(); } else Widget::render_part(part); @@ -146,23 +133,41 @@ void Panel::set_input_focus(Widget *wdg) } } +Widget *Panel::get_child_at(int x, int y) +{ + for(ChildSeq::reverse_iterator i=children.rbegin(); i!=children.rend(); ++i) + if((*i)->is_visible() && (*i)->get_geometry().is_inside(x-geom.x, y-geom.y)) + return *i; + + return 0; +} + Panel::Loader::Loader(Panel &p, map &m): Widget::Loader(p), - panel(p), + pnl(p), wdg_map(m) { add("label", &Loader::child