From: Mikko Rasa Date: Sat, 11 Oct 2008 15:09:51 +0000 (+0000) Subject: Jump 10 steps when slider trough is clicked X-Git-Tag: 1.0~3 X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=commitdiff_plain;h=3db68f2604b657e79f1b2b317c19c41c2d5a985b Jump 10 steps when slider trough is clicked Take both ascent and descent into account when determining list row size Use pointer motion instead of pointer leave event to unset active when the pointer leaves a button while the button is pressed Don't allow unsetting exclusive toggles Fix a but in Alignment --- diff --git a/source/button.cpp b/source/button.cpp index 20e0ed9..f6cf56c 100644 --- a/source/button.cpp +++ b/source/button.cpp @@ -45,10 +45,15 @@ void Button::button_release(int x, int y, unsigned btn) } } -void Button::pointer_leave() +void Button::pointer_motion(int x, int y) { - Widget::pointer_leave(); - state&=~ACTIVE; + if(pressed) + { + if(!geom.is_inside_relative(x, y)) + state&=~ACTIVE; + else + state|=ACTIVE; + } } void Button::render_special(const Part &part) const diff --git a/source/button.h b/source/button.h index 63159ee..4464c44 100644 --- a/source/button.h +++ b/source/button.h @@ -39,7 +39,7 @@ public: void set_text(const std::string &); virtual void button_press(int, int, unsigned); virtual void button_release(int, int, unsigned); - virtual void pointer_leave(); + virtual void pointer_motion(int, int); private: virtual const char *get_class() const { return "button"; } virtual void render_special(const Part &) const; diff --git a/source/geometry.cpp b/source/geometry.cpp index 584a1aa..0e46743 100644 --- a/source/geometry.cpp +++ b/source/geometry.cpp @@ -61,12 +61,12 @@ void Alignment::apply(Geometry &geom, const Geometry &parent, const Sides &margi geom.x+=margin.left; geom.y+=margin.bottom; - if(parent.w>geom.w) + if(pw>geom.w) { geom.w+=static_cast((pw-geom.w)*w); geom.x+=static_cast((pw-geom.w)*x); } - if(parent.h>geom.h) + if(ph>geom.h) { geom.h+=static_cast((ph-geom.h)*h); geom.y+=static_cast((ph-geom.h)*y); diff --git a/source/hslider.cpp b/source/hslider.cpp index e9db05f..1575072 100644 --- a/source/hslider.cpp +++ b/source/hslider.cpp @@ -23,10 +23,14 @@ HSlider::HSlider(const Resources &r): void HSlider::button_press(int x, int y, unsigned btn) { - if(geom.is_inside_relative(x, y) && max>min) + if(btn==1 && geom.is_inside_relative(x, y) && max>min) { int sx=static_cast((geom.w-slider_size)*(value-min)/(max-min)); - if(btn==1 && x>=sx && x(sx+slider_size)) + if(x=static_cast(sx+slider_size)) + set_value(value+step*10); + else start_drag(x); } } diff --git a/source/list.cpp b/source/list.cpp index 04adb39..924cfb5 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -108,7 +108,7 @@ void List::button_press(int x, int y, unsigned btn) else if(btn==1) { const GL::Font *const font=style->get_font(); - const unsigned row_height=static_cast(font->get_default_size()); + const unsigned row_height=static_cast((font->get_ascent()-font->get_descent())*font->get_default_size()); if(items_part) y+=items_part->get_margin().top; @@ -149,7 +149,7 @@ void List::render_special(const Part &part) const const GL::Font *const font=style->get_font(); const float font_size=font->get_default_size(); const GL::Color &color=style->get_font_color(); - const unsigned row_height=static_cast(font_size); + const unsigned row_height=static_cast((font->get_ascent()-font->get_descent())*font_size); const Sides &margin=part.get_margin(); Geometry pgeom=geom; @@ -180,7 +180,7 @@ void List::render_special(const Part &part) const { const GL::Font *const font=style->get_font(); const float font_size=font->get_default_size(); - const unsigned row_height=static_cast(font_size); + const unsigned row_height=static_cast((font->get_ascent()-font->get_descent())*font_size); const Sides &margin=part.get_margin(); Geometry pgeom=geom; diff --git a/source/toggle.cpp b/source/toggle.cpp index 8c727d6..8c264e4 100644 --- a/source/toggle.cpp +++ b/source/toggle.cpp @@ -58,7 +58,7 @@ void Toggle::button_release(int x, int y, unsigned btn) { if(pressed && btn==1) { - if(geom.is_inside_relative(x, y)) + if(geom.is_inside_relative(x, y) && (!value || !exclusive)) { set_value(!value); signal_toggled.emit(value); diff --git a/source/vslider.cpp b/source/vslider.cpp index 57f98d5..954bb19 100644 --- a/source/vslider.cpp +++ b/source/vslider.cpp @@ -23,10 +23,14 @@ VSlider::VSlider(const Resources &r): void VSlider::button_press(int x, int y, unsigned btn) { - if(geom.is_inside_relative(x, y) && max>min) + if(btn==1 && geom.is_inside_relative(x, y) && max>min) { int sy=static_cast((geom.h-slider_size)*(value-min)/(max-min)); - if(btn==1 && y>=sy && y(sy+slider_size)) + if(y=static_cast(sy+slider_size)) + set_value(value+step*10); + else start_drag(y); } }