Fix behavior of vertical sliders.

This commit is contained in:
Jonathan Moore Liles 2013-10-12 15:38:45 -07:00
parent 23107541c8
commit 1aafc5330f
2 changed files with 72 additions and 77 deletions

View File

@ -26,6 +26,8 @@
void void
Fl_SliderX::draw ( int X, int Y, int W, int H) Fl_SliderX::draw ( int X, int Y, int W, int H)
{ {
slider_size( horizontal() ? H / (float)W : W / (float)H );
int act = active_r(); int act = active_r();
if (damage()&FL_DAMAGE_ALL) draw_box(); if (damage()&FL_DAMAGE_ALL) draw_box();
@ -125,7 +127,7 @@ Fl_SliderX::slider_position ( double value, int w )
if (B == A) return 0; if (B == A) return 0;
bool flip = B < A; bool flip = B < A;
if (flip) {A = B; B = minimum();} if (flip) {A = B; B = minimum();}
if (!horizontal()) flip = !flip; // if (!horizontal()) flip = !flip;
// if both are negative, make the range positive: // if both are negative, make the range positive:
if (B <= 0) {flip = !flip; double t = A; A = -B; B = -t; value = -value;} if (B <= 0) {flip = !flip; double t = A; A = -B; B = -t; value = -value;}
double fraction; double fraction;
@ -161,7 +163,7 @@ Fl_SliderX::slider_value ( int X, int w )
double B = maximum(); double B = maximum();
bool flip = B < A; bool flip = B < A;
if (flip) {A = B; B = minimum();} if (flip) {A = B; B = minimum();}
if (!horizontal()) flip = !flip; // if (!horizontal()) flip = !flip;
if (flip) X = w-X; if (flip) X = w-X;
double fraction = double(X)/w; double fraction = double(X)/w;
if (fraction <= 0) return A; if (fraction <= 0) return A;
@ -223,12 +225,11 @@ int Fl_SliderX::handle(int event, int X, int Y, int W, int H) {
int ww = (horizontal() ? W : H); int ww = (horizontal() ? W : H);
if ( event == FL_PUSH ) if ( event == FL_PUSH )
{ {
int x = slider_position( value(), ww ); int x = slider_position( value(), ww );
offcenter = (Fl::event_x()-X) - x; offcenter = (horizontal() ? (Fl::event_x()-X) - x : (Fl::event_y()-Y) - x );
} }
try_again: try_again:
@ -236,11 +237,16 @@ int Fl_SliderX::handle(int event, int X, int Y, int W, int H) {
int mx = (horizontal() ? Fl::event_x()-X : Fl::event_y()-Y) - offcenter; int mx = (horizontal() ? Fl::event_x()-X : Fl::event_y()-Y) - offcenter;
double v = slider_value( mx, ww ); double v = slider_value( mx, ww );
if (event == FL_PUSH && v == value()) { if (event == FL_PUSH ) // && v == value()) {
offcenter = int(slider_size()*ww+0.5)/2; {
int os = int(slider_size()*ww+0.5)/2;
if ( abs( offcenter ) > os )
{
offcenter = os;
event = FL_DRAG; event = FL_DRAG;
goto try_again; goto try_again;
} }
}
handle_drag(clamp(v)); handle_drag(clamp(v));
} return 1; } return 1;
@ -333,11 +339,3 @@ int Fl_SliderX::handle(int event) {
w()-Fl::box_dw(box()), w()-Fl::box_dw(box()),
h()-Fl::box_dh(box())); h()-Fl::box_dh(box()));
} }
void
Fl_SliderX::resize ( int X, int Y, int W, int H )
{
Fl_Slider::resize(X,Y,W,H);
slider_size( horizontal() ? H / (float)W : W / (float)H );
}

View File

@ -47,7 +47,4 @@ public:
virtual int handle(int event, int X, int Y, int W, int H); virtual int handle(int event, int X, int Y, int W, int H);
virtual int handle(int event); virtual int handle(int event);
virtual void resize ( int X, int Y, int W, int H );
}; };