]> git.tdb.fi Git - libs/gltk.git/commitdiff
Jump 10 steps when slider trough is clicked
authorMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2008 15:09:51 +0000 (15:09 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2008 15:09:51 +0000 (15:09 +0000)
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

source/button.cpp
source/button.h
source/geometry.cpp
source/hslider.cpp
source/list.cpp
source/toggle.cpp
source/vslider.cpp

index 20e0ed9241d616a36c2a1f154358931f8d92acf3..f6cf56c1f07ecbd8b0fa41a7b49e13d269b50156 100644 (file)
@@ -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
index 63159ee2318dcc6cd1ecf81e47d8b22797b2fee9..4464c446b4a11d1859a37026b89f3e96d0d8b103 100644 (file)
@@ -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;
index 584a1aac55d934185e7bc68e793329a11d935a68..0e46743b626ecf9edfffaa3b2b2de00bd0d2d25b 100644 (file)
@@ -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<unsigned>((pw-geom.w)*w);
                geom.x+=static_cast<int>((pw-geom.w)*x);
        }
-       if(parent.h>geom.h)
+       if(ph>geom.h)
        {
                geom.h+=static_cast<unsigned>((ph-geom.h)*h);
                geom.y+=static_cast<int>((ph-geom.h)*y);
index e9db05f16cf950860cccd69002e82356c79c71dd..1575072fe782cc16689ac2009e33a94f86b4846c 100644 (file)
@@ -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<int>((geom.w-slider_size)*(value-min)/(max-min));
-               if(btn==1 && x>=sx && x<static_cast<int>(sx+slider_size))
+               if(x<sx)
+                       set_value(value-step*10);
+               else if(x>=static_cast<int>(sx+slider_size))
+                       set_value(value+step*10);
+               else
                        start_drag(x);
        }
 }
index 04adb399cc2adf237b3384384ac807ea5b6b5ff3..924cfb55d37b68f99e2091c844db7e91aafd6b90 100644 (file)
@@ -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<unsigned>(font->get_default_size());
+               const unsigned row_height=static_cast<unsigned>((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<unsigned>(font_size);
+               const unsigned row_height=static_cast<unsigned>((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<unsigned>(font_size);
+                       const unsigned row_height=static_cast<unsigned>((font->get_ascent()-font->get_descent())*font_size);
                        const Sides &margin=part.get_margin();
 
                        Geometry pgeom=geom;
index 8c727d6c333e023e03bc77c113fbd921dabb5bde..8c264e4c9b4486194cfca18978c64c1d52a0a8c1 100644 (file)
@@ -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);
index 57f98d53ac4de5bb6c512ac4f442fb177a838575..954bb19520702a24033468cecfbf8089bbf3e168 100644 (file)
@@ -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<int>((geom.h-slider_size)*(value-min)/(max-min));
-               if(btn==1 && y>=sy && y<static_cast<int>(sy+slider_size))
+               if(y<sy)
+                       set_value(value-step*10);
+               else if(y>=static_cast<int>(sy+slider_size))
+                       set_value(value+step*10);
+               else
                        start_drag(y);
        }
 }