This adds support for the Fl_Dial::angles() method. This seems to work
correctly, but it is likely that someone who remembers their high school math could make it _much_ more efficient (I just hacked away 'till it worked). -Carl git-svn-id: file:///fltk/svn/fltk/trunk@376 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
1f2b1e5470
commit
e42ff9a65c
@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// "$Id: Fl_Dial.H,v 1.5 1999/02/16 21:59:37 mike Exp $"
|
// "$Id: Fl_Dial.H,v 1.6 1999/03/08 21:44:28 carl Exp $"
|
||||||
//
|
//
|
||||||
// Dial header file for the Fast Light Tool Kit (FLTK).
|
// Dial header file for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -54,7 +54,7 @@ public:
|
|||||||
|
|
||||||
FL_EXPORT int handle(int);
|
FL_EXPORT int handle(int);
|
||||||
FL_EXPORT Fl_Dial(int x,int y,int w,int h, const char *l = 0);
|
FL_EXPORT Fl_Dial(int x,int y,int w,int h, const char *l = 0);
|
||||||
void angles(short a, short b) {a1=a; a2=b;}
|
void angles(short a, short b);
|
||||||
void direction(uchar d) {direction_ = d;}
|
void direction(uchar d) {direction_ = d;}
|
||||||
uchar direction() const {return direction_;}
|
uchar direction() const {return direction_;}
|
||||||
|
|
||||||
@ -63,5 +63,5 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id: Fl_Dial.H,v 1.5 1999/02/16 21:59:37 mike Exp $".
|
// End of "$Id: Fl_Dial.H,v 1.6 1999/03/08 21:44:28 carl Exp $".
|
||||||
//
|
//
|
||||||
|
@ -34,7 +34,12 @@ and label string. The default type is <TT>FL_NORMAL_DIAL</TT>.
|
|||||||
Destroys the valuator.
|
Destroys the valuator.
|
||||||
<H4><A name=Fl_Dial.angles>void Fl_Dial::angles(short a, short b)</A></H4>
|
<H4><A name=Fl_Dial.angles>void Fl_Dial::angles(short a, short b)</A></H4>
|
||||||
Sets the angles used for the minimum and maximum values. By default
|
Sets the angles used for the minimum and maximum values. By default
|
||||||
these are 0 and 360, respectively.
|
these are 225 and 135, respectively. (0 degrees is straight up and the
|
||||||
|
angles progress clockwise.) The angles specified should be greater than
|
||||||
|
or equal to 0 and less than 360. The progress of the dial always starts at
|
||||||
|
the minimum angle and progresses clockwise to the maximum angle. Currently,
|
||||||
|
counter-clockwise progression is not supported (but user code can always
|
||||||
|
use 1/value()).
|
||||||
<H4><A name=Fl_Dial.type>type(uchar)</A></H4>
|
<H4><A name=Fl_Dial.type>type(uchar)</A></H4>
|
||||||
Sets the type of the dial to:
|
Sets the type of the dial to:
|
||||||
<UL>
|
<UL>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// "$Id: Fl_Dial.cxx,v 1.7 1999/02/22 20:58:23 mike Exp $"
|
// "$Id: Fl_Dial.cxx,v 1.8 1999/03/08 21:44:30 carl Exp $"
|
||||||
//
|
//
|
||||||
// Circular dial widget for the Fast Light Tool Kit (FLTK).
|
// Circular dial widget for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -29,22 +29,28 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <FL/math.h>
|
#include <FL/math.h>
|
||||||
|
|
||||||
|
void Fl_Dial::angles(short a, short b) {
|
||||||
|
a1=a;
|
||||||
|
a2=b;
|
||||||
|
if (a2 < a1) a2 += 360;
|
||||||
|
}
|
||||||
|
|
||||||
void Fl_Dial::draw(int x, int y, int w, int h) {
|
void Fl_Dial::draw(int x, int y, int w, int h) {
|
||||||
if (damage()&FL_DAMAGE_ALL) draw_box(box(), x, y, w, h, color());
|
if (damage()&FL_DAMAGE_ALL) draw_box(box(), x, y, w, h, color());
|
||||||
x += Fl::box_dx(box());
|
x += Fl::box_dx(box());
|
||||||
y += Fl::box_dy(box());
|
y += Fl::box_dy(box());
|
||||||
w -= Fl::box_dw(box());
|
w -= Fl::box_dw(box());
|
||||||
h -= Fl::box_dh(box());
|
h -= Fl::box_dh(box());
|
||||||
double angle = 270.0*(value()-minimum())/(maximum()-minimum());
|
double angle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
|
||||||
if (type() == FL_FILL_DIAL) {
|
if (type() == FL_FILL_DIAL) {
|
||||||
double a = angle; if (a < 0) a = 0;
|
double a = angle; if (a < 0) a = 0;
|
||||||
// foo: draw this nicely in certain round box types
|
// foo: draw this nicely in certain round box types
|
||||||
int foo = (box() > _FL_ROUND_UP_BOX && Fl::box_dx(box()));
|
int foo = (box() > _FL_ROUND_UP_BOX && Fl::box_dx(box()));
|
||||||
if (foo) {x--; y--; w+=2; h+=2;}
|
if (foo) {x--; y--; w+=2; h+=2;}
|
||||||
fl_color(color());
|
fl_color(color());
|
||||||
fl_pie(x, y, w-1, h-1, 225, 225+360-a);
|
fl_pie(x, y, w-1, h-1, (360-a1)+90, (360-a)+360+90);
|
||||||
fl_color(selection_color());
|
fl_color(selection_color());
|
||||||
fl_pie(x, y, w-1, h-1, 225-a, 225);
|
fl_pie(x, y, w-1, h-1, (360-a1)+90, (360-a)+90);
|
||||||
if (foo) {
|
if (foo) {
|
||||||
fl_color(FL_BLACK);
|
fl_color(FL_BLACK);
|
||||||
fl_arc(x, y, w, h, 0, 360);
|
fl_arc(x, y, w, h, 0, 360);
|
||||||
@ -58,11 +64,13 @@ void Fl_Dial::draw(int x, int y, int w, int h) {
|
|||||||
fl_push_matrix();
|
fl_push_matrix();
|
||||||
fl_translate(x+w/2-.5, y+h/2-.5);
|
fl_translate(x+w/2-.5, y+h/2-.5);
|
||||||
fl_scale(w-1, h-1);
|
fl_scale(w-1, h-1);
|
||||||
|
/* CET - Why is this here? This code is never reached!
|
||||||
if (type() == FL_FILL_DIAL) {
|
if (type() == FL_FILL_DIAL) {
|
||||||
fl_rotate(225);
|
fl_rotate(225);
|
||||||
fl_begin_line(); fl_vertex(0, 0); fl_vertex(.5, 0); fl_end_line();
|
fl_begin_line(); fl_vertex(0, 0); fl_vertex(.5, 0); fl_end_line();
|
||||||
}
|
}
|
||||||
fl_rotate(-angle);
|
*/
|
||||||
|
fl_rotate(225-angle);
|
||||||
fl_color(selection_color());
|
fl_color(selection_color());
|
||||||
if (type() == FL_LINE_DIAL) {
|
if (type() == FL_LINE_DIAL) {
|
||||||
fl_begin_polygon();
|
fl_begin_polygon();
|
||||||
@ -97,16 +105,24 @@ int Fl_Dial::handle(int event, int x, int y, int w, int h) {
|
|||||||
handle_push();
|
handle_push();
|
||||||
case FL_DRAG: {
|
case FL_DRAG: {
|
||||||
double angle;
|
double angle;
|
||||||
|
static double last = 0.0;
|
||||||
double val = value();
|
double val = value();
|
||||||
int mx = Fl::event_x()-x-w/2;
|
int mx = Fl::event_x()-x-w/2;
|
||||||
int my = Fl::event_y()-y-h/2;
|
int my = Fl::event_y()-y-h/2;
|
||||||
if (!mx && !my) return 1;
|
if (!mx && !my) return 1;
|
||||||
angle = atan2((float)-my, (float)-mx) + 0.25 * M_PI;
|
angle = atan2((float)-my, (float)-mx) + M_PI;
|
||||||
if (angle<(-0.25*M_PI)) angle += 2.0*M_PI;
|
angle = (angle*360) / (2*M_PI) + 90;
|
||||||
val = minimum() + (maximum()-minimum())*angle/(1.5*M_PI);
|
if (angle >= 360.0) angle -= 360.0;
|
||||||
if (fabs(val-value()) < (maximum()-minimum())/2.0)
|
if (a2 >= 360 && angle <= (a2-360)) angle += 360;
|
||||||
handle_drag(clamp(round(val)));
|
if (angle < a1 || angle > a2) {
|
||||||
} return 1;
|
if ((last - a1) < (a2 - last)) val = minimum();
|
||||||
|
else val = maximum();
|
||||||
|
} else {
|
||||||
|
val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1);
|
||||||
|
last = angle;
|
||||||
|
}
|
||||||
|
handle_drag(clamp(round(val)));
|
||||||
|
} return 1;
|
||||||
case FL_RELEASE:
|
case FL_RELEASE:
|
||||||
handle_release();
|
handle_release();
|
||||||
return 1;
|
return 1;
|
||||||
@ -123,8 +139,9 @@ Fl_Dial::Fl_Dial(int x, int y, int w, int h, const char* l)
|
|||||||
: Fl_Valuator(x, y, w, h, l) {
|
: Fl_Valuator(x, y, w, h, l) {
|
||||||
box(FL_OVAL_BOX);
|
box(FL_OVAL_BOX);
|
||||||
selection_color(FL_INACTIVE_COLOR); // was 37
|
selection_color(FL_INACTIVE_COLOR); // was 37
|
||||||
|
angles(225,135);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id: Fl_Dial.cxx,v 1.7 1999/02/22 20:58:23 mike Exp $".
|
// End of "$Id: Fl_Dial.cxx,v 1.8 1999/03/08 21:44:30 carl Exp $".
|
||||||
//
|
//
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
# data file for the Fltk User Interface Designer (fluid)
|
# data file for the Fltk User Interface Designer (fluid)
|
||||||
version 0.99
|
version 1.00
|
||||||
|
header_name {.h}
|
||||||
|
code_name {.cxx}
|
||||||
gridx 5
|
gridx 5
|
||||||
gridy 5
|
gridy 5
|
||||||
snap 3
|
snap 3
|
||||||
@ -7,12 +9,12 @@ Function {} {open
|
|||||||
} {
|
} {
|
||||||
Fl_Window {} {
|
Fl_Window {} {
|
||||||
label {Valuator classes, showing values for type()} open
|
label {Valuator classes, showing values for type()} open
|
||||||
xywh {548 340 567 506} color 43 selection_color 43
|
xywh {414 83 567 506} color 43 selection_color 43
|
||||||
code0 {\#include <stdio.h>} visible
|
code0 {\#include <stdio.h>} visible
|
||||||
} {
|
} {
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Slider
|
label Fl_Slider
|
||||||
xywh {10 10 280 210} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {10 10 280 210} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Slider {} {
|
Fl_Slider {} {
|
||||||
label 0
|
label 0
|
||||||
@ -34,7 +36,7 @@ fflush(stdout);}
|
|||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Value_Slider
|
label Fl_Value_Slider
|
||||||
xywh {10 230 280 205} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {10 230 280 205} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Value_Slider {} {
|
Fl_Value_Slider {} {
|
||||||
label 0
|
label 0
|
||||||
@ -86,7 +88,7 @@ fflush(stdout);}
|
|||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Adjuster
|
label Fl_Adjuster
|
||||||
xywh {430 10 125 120} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {430 10 125 120} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Value_Slider {} {
|
Fl_Value_Slider {} {
|
||||||
label FL_HOR_NICE_SLIDER
|
label FL_HOR_NICE_SLIDER
|
||||||
@ -108,35 +110,37 @@ fflush(stdout);}
|
|||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Counter
|
label Fl_Counter
|
||||||
xywh {345 135 210 115} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {345 135 210 115} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Counter {} {
|
Fl_Counter {} {
|
||||||
label 0
|
label 0
|
||||||
callback {printf("%g \\r",o->value());
|
callback {printf("%g \\r",o->value());
|
||||||
fflush(stdout);}
|
fflush(stdout);}
|
||||||
xywh {360 160 180 30} labelsize 8 minimum -1e+06 maximum 1e+06
|
xywh {360 160 180 30} labelsize 8
|
||||||
}
|
}
|
||||||
Fl_Counter {} {
|
Fl_Counter {} {
|
||||||
label FL_SIMPLE_COUNTER
|
label FL_SIMPLE_COUNTER
|
||||||
callback {printf("%g \\r",o->value());
|
callback {printf("%g \\r",o->value());
|
||||||
fflush(stdout);}
|
fflush(stdout);}
|
||||||
xywh {360 205 180 30} type Simple labelsize 8 minimum -1e+06 maximum 1e+06
|
xywh {360 205 180 30} type Simple labelsize 8
|
||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Dial
|
label Fl_Dial
|
||||||
xywh {300 260 255 105} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {300 260 255 105} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Dial {} {
|
Fl_Dial {} {
|
||||||
label 0
|
label 0
|
||||||
callback {printf("%g \\r",o->value());
|
callback {printf("%g \\r",o->value());
|
||||||
fflush(stdout);}
|
fflush(stdout);} selected
|
||||||
xywh {315 280 65 65} color 10 selection_color 1 labelsize 8
|
xywh {315 280 65 65} color 10 selection_color 1 labelsize 8
|
||||||
|
code0 {o->angles(180,135);}
|
||||||
}
|
}
|
||||||
Fl_Dial {} {
|
Fl_Dial {} {
|
||||||
label FL_LINE_DIAL
|
label FL_LINE_DIAL
|
||||||
callback {printf("%g \\r",o->value());
|
callback {printf("%g \\r",o->value());
|
||||||
fflush(stdout);}
|
fflush(stdout);}
|
||||||
xywh {395 280 65 65} type Line color 10 selection_color 1 labelsize 8
|
xywh {395 280 65 65} type Line color 10 selection_color 1 labelsize 8
|
||||||
|
code0 {o->angles(0,360);}
|
||||||
}
|
}
|
||||||
Fl_Dial {} {
|
Fl_Dial {} {
|
||||||
label FL_FILL_DIAL
|
label FL_FILL_DIAL
|
||||||
@ -146,7 +150,7 @@ fflush(stdout);}
|
|||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Roller
|
label Fl_Roller
|
||||||
xywh {300 375 145 120} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {300 375 145 120} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Roller {} {
|
Fl_Roller {} {
|
||||||
label 0
|
label 0
|
||||||
@ -162,7 +166,7 @@ fflush(stdout);}
|
|||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Value_Input
|
label Fl_Value_Input
|
||||||
xywh {10 445 140 50} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {10 445 140 50} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label {Some widgets have color(FL_GREEN) and color2(FL_RED) to show the areas these effect.}
|
label {Some widgets have color(FL_GREEN) and color2(FL_RED) to show the areas these effect.}
|
||||||
@ -170,12 +174,12 @@ fflush(stdout);}
|
|||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label Fl_Value_Output
|
label Fl_Value_Output
|
||||||
xywh {155 445 135 50} box ENGRAVED_BOX labelfont 1 labelsize 12 align 17
|
xywh {155 445 135 50} box ENGRAVED_BOX labelfont 1 align 17
|
||||||
}
|
}
|
||||||
Fl_Value_Input {} {
|
Fl_Value_Input {} {
|
||||||
label 0
|
label 0
|
||||||
callback {printf("%g \\r",o->value());
|
callback {printf("%g \\r",o->value());
|
||||||
fflush(stdout);} selected
|
fflush(stdout);}
|
||||||
xywh {30 460 110 30} labelsize 8 maximum 100 step 0.1
|
xywh {30 460 110 30} labelsize 8 maximum 100 step 0.1
|
||||||
}
|
}
|
||||||
Fl_Value_Output {} {
|
Fl_Value_Output {} {
|
||||||
@ -186,7 +190,7 @@ fflush(stdout);}
|
|||||||
}
|
}
|
||||||
Fl_Box {} {
|
Fl_Box {} {
|
||||||
label { Fl_Scrollbar}
|
label { Fl_Scrollbar}
|
||||||
xywh {295 10 130 120} box ENGRAVED_BOX labelfont 1 labelsize 12 align 21
|
xywh {295 10 130 120} box ENGRAVED_BOX labelfont 1 align 21
|
||||||
}
|
}
|
||||||
Fl_Scrollbar {} {
|
Fl_Scrollbar {} {
|
||||||
label 0
|
label 0
|
||||||
|
Loading…
Reference in New Issue
Block a user