Fix behavior of vertical sliders.
This commit is contained in:
parent
23107541c8
commit
1aafc5330f
146
FL/Fl_SliderX.C
146
FL/Fl_SliderX.C
|
@ -26,88 +26,90 @@
|
||||||
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();
|
||||||
|
|
||||||
|
|
||||||
int ww = (horizontal() ? W : H);
|
int ww = (horizontal() ? W : H);
|
||||||
int hh = (horizontal() ? H : W);
|
int hh = (horizontal() ? H : W);
|
||||||
int xx, S;
|
int xx, S;
|
||||||
|
|
||||||
xx = slider_position( value(), ww );
|
xx = slider_position( value(), ww );
|
||||||
|
|
||||||
S = (horizontal() ? H : W );
|
S = (horizontal() ? H : W );
|
||||||
|
|
||||||
int xsl, ysl, wsl, hsl;
|
int xsl, ysl, wsl, hsl;
|
||||||
if (horizontal()) {
|
if (horizontal()) {
|
||||||
xsl = X+xx;
|
xsl = X+xx;
|
||||||
wsl = S;
|
wsl = S;
|
||||||
ysl = Y + hh/2;
|
ysl = Y + hh/2;
|
||||||
hsl = hh/4;
|
hsl = hh/4;
|
||||||
} else {
|
} else {
|
||||||
ysl = Y+xx;
|
ysl = Y+xx;
|
||||||
hsl = S;
|
hsl = S;
|
||||||
xsl = X + hh/2;
|
xsl = X + hh/2;
|
||||||
wsl = hh/4;
|
wsl = hh/4;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
fl_push_clip(X, Y, W, H);
|
fl_push_clip(X, Y, W, H);
|
||||||
draw_box();
|
draw_box();
|
||||||
fl_pop_clip();
|
fl_pop_clip();
|
||||||
}
|
}
|
||||||
//draw_bg(X, Y, W, H);
|
//draw_bg(X, Y, W, H);
|
||||||
|
|
||||||
fl_line_style( FL_SOLID, hh/6 );
|
fl_line_style( FL_SOLID, hh/6 );
|
||||||
|
|
||||||
Fl_Color c = fl_darker(color());
|
Fl_Color c = fl_darker(color());
|
||||||
|
|
||||||
if ( !act )
|
if ( !act )
|
||||||
c = fl_inactive(c);
|
c = fl_inactive(c);
|
||||||
|
|
||||||
fl_color(c);
|
fl_color(c);
|
||||||
|
|
||||||
if ( horizontal() )
|
if ( horizontal() )
|
||||||
fl_line ( X + S/2, Y + hh/2, X + W - S/2, Y + hh/2 );
|
fl_line ( X + S/2, Y + hh/2, X + W - S/2, Y + hh/2 );
|
||||||
else
|
else
|
||||||
fl_line ( X + hh/2, Y + S/2, X + hh/2, Y + H - S/2 );
|
fl_line ( X + hh/2, Y + S/2, X + hh/2, Y + H - S/2 );
|
||||||
|
|
||||||
c = selection_color();
|
c = selection_color();
|
||||||
|
|
||||||
if ( !act )
|
if ( !act )
|
||||||
c = fl_inactive(c);
|
c = fl_inactive(c);
|
||||||
|
|
||||||
fl_color( c );
|
fl_color( c );
|
||||||
|
|
||||||
if ( horizontal() )
|
if ( horizontal() )
|
||||||
fl_line ( X + S/2, ysl, xsl + S/2, ysl );
|
fl_line ( X + S/2, ysl, xsl + S/2, ysl );
|
||||||
else
|
else
|
||||||
fl_line ( X + S/2, Y + H - S/2, xsl, ysl + (S/2) );
|
fl_line ( X + S/2, Y + H - S/2, xsl, ysl + (S/2) );
|
||||||
|
|
||||||
fl_line_style( FL_SOLID, 0 );
|
fl_line_style( FL_SOLID, 0 );
|
||||||
|
|
||||||
if ( act )
|
if ( act )
|
||||||
{
|
{
|
||||||
fl_push_matrix();
|
fl_push_matrix();
|
||||||
if ( horizontal() )
|
if ( horizontal() )
|
||||||
fl_translate( xsl + (hh/2), ysl);
|
fl_translate( xsl + (hh/2), ysl);
|
||||||
else
|
else
|
||||||
fl_translate( xsl, ysl + (hh/2) );
|
fl_translate( xsl, ysl + (hh/2) );
|
||||||
|
|
||||||
fl_color( fl_color_add_alpha( FL_WHITE, 127 ));
|
fl_color( fl_color_add_alpha( FL_WHITE, 127 ));
|
||||||
fl_begin_polygon(); fl_circle(0.0,0.0, hh/3); fl_end_polygon();
|
fl_begin_polygon(); fl_circle(0.0,0.0, hh/3); fl_end_polygon();
|
||||||
fl_color( FL_WHITE );
|
fl_color( FL_WHITE );
|
||||||
fl_begin_polygon(); fl_circle(0.0,0.0, hh/6); fl_end_polygon();
|
fl_begin_polygon(); fl_circle(0.0,0.0, hh/6); fl_end_polygon();
|
||||||
|
|
||||||
fl_pop_matrix();
|
fl_pop_matrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_label(xsl, ysl, wsl, hsl);
|
draw_label(xsl, ysl, wsl, hsl);
|
||||||
|
|
||||||
if (Fl::focus() == this) {
|
if (Fl::focus() == this) {
|
||||||
draw_focus();
|
draw_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draw(x()+Fl::box_dx(box()), */
|
/* draw(x()+Fl::box_dx(box()), */
|
||||||
/* y()+Fl::box_dy(box()), */
|
/* y()+Fl::box_dy(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,10 +237,15 @@ 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;
|
{
|
||||||
event = FL_DRAG;
|
int os = int(slider_size()*ww+0.5)/2;
|
||||||
goto try_again;
|
if ( abs( offcenter ) > os )
|
||||||
|
{
|
||||||
|
offcenter = os;
|
||||||
|
event = FL_DRAG;
|
||||||
|
goto try_again;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_drag(clamp(v));
|
handle_drag(clamp(v));
|
||||||
|
@ -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 );
|
|
||||||
}
|
|
||||||
|
|
|
@ -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 );
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue