Changes to dial so that counter-clockwise motion is supported if you
set angle2 < angle1. Deleted the unimplemented direction() control. Fixed the documentation, this new code allows any 2 values for the angles as long as abs(a-b)<=360. git-svn-id: file:///fltk/svn/fltk/trunk@399 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
170c31cada
commit
b6115887c8
16
FL/Fl_Dial.H
16
FL/Fl_Dial.H
@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: Fl_Dial.H,v 1.6 1999/03/08 21:44:28 carl Exp $"
|
||||
// "$Id: Fl_Dial.H,v 1.7 1999/03/10 08:17:40 bill Exp $"
|
||||
//
|
||||
// Dial header file for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@ -35,13 +35,9 @@
|
||||
#define FL_LINE_DIAL 1
|
||||
#define FL_FILL_DIAL 2
|
||||
|
||||
#define FL_DIAL_CW 0
|
||||
#define FL_DIAL_CCW 1
|
||||
|
||||
class Fl_Dial : public Fl_Valuator {
|
||||
|
||||
short a1,a2;
|
||||
uchar direction_;
|
||||
|
||||
protected:
|
||||
|
||||
@ -54,14 +50,16 @@ public:
|
||||
|
||||
FL_EXPORT int handle(int);
|
||||
FL_EXPORT Fl_Dial(int x,int y,int w,int h, const char *l = 0);
|
||||
void angles(short a, short b);
|
||||
void direction(uchar d) {direction_ = d;}
|
||||
uchar direction() const {return direction_;}
|
||||
short angle1() const {return a1;}
|
||||
void angle1(short a) {a1 = a;}
|
||||
short angle2() const {return a2;}
|
||||
void angle2(short a) {a2 = a;}
|
||||
void angles(short a, short b) {a1 = a; a2 = b;}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
// End of "$Id: Fl_Dial.H,v 1.6 1999/03/08 21:44:28 carl Exp $".
|
||||
// End of "$Id: Fl_Dial.H,v 1.7 1999/03/10 08:17:40 bill Exp $".
|
||||
//
|
||||
|
10
FL/forms.H
10
FL/forms.H
@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: forms.H,v 1.6 1999/02/16 21:59:48 mike Exp $"
|
||||
// "$Id: forms.H,v 1.7 1999/03/10 08:17:40 bill Exp $"
|
||||
//
|
||||
// Forms emulation header file for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@ -618,10 +618,10 @@ inline void fl_get_dial_bounds(Fl_Widget* o, float* a, float* b) {
|
||||
inline void fl_set_dial_return(Fl_Widget* o, int i) {
|
||||
((Fl_Dial*)o)->when((Fl_When)(i|FL_WHEN_RELEASE));}
|
||||
inline void fl_set_dial_angles(Fl_Widget* o, int a, int b) {
|
||||
((Fl_Dial*)o)->angles(a,b);}
|
||||
((Fl_Dial*)o)->angles(a, b);}
|
||||
//inline void fl_set_dial_cross(Fl_Widget* o, int);
|
||||
inline void fl_set_dial_direction(Fl_Widget* o, uchar d) {
|
||||
((Fl_Dial*)o)->direction(d);}
|
||||
// inline void fl_set_dial_direction(Fl_Widget* o, uchar d) {
|
||||
// ((Fl_Dial*)o)->direction(d);}
|
||||
inline void fl_set_dial_step(Fl_Widget* o, double v) {
|
||||
((Fl_Dial*)o)->step(v);}
|
||||
|
||||
@ -841,5 +841,5 @@ inline void fl_draw() {Fl::flush();}
|
||||
#endif /* define __FORMS_H__ */
|
||||
|
||||
//
|
||||
// End of "$Id: forms.H,v 1.6 1999/02/16 21:59:48 mike Exp $".
|
||||
// End of "$Id: forms.H,v 1.7 1999/03/10 08:17:40 bill Exp $".
|
||||
//
|
||||
|
@ -23,6 +23,8 @@ single floating point value.
|
||||
<UL>
|
||||
<LI><A href=#Fl_Dial.Fl_Dial>Fl_Dial</A></LI>
|
||||
<LI><A href=#Fl_Dial.~Fl_Dial>~Fl_Dial</A></LI>
|
||||
<LI><A href=#Fl_Dial.angles>angle1</A></LI>
|
||||
<LI><A href=#Fl_Dial.angles>angle2</A></LI>
|
||||
<LI><A href=#Fl_Dial.angles>angles</A></LI>
|
||||
<LI><A href=#Fl_Dial.type>type</A></LI>
|
||||
</UL>
|
||||
@ -32,14 +34,22 @@ h, const char *label = 0)</A></H4>
|
||||
and label string. The default type is <TT>FL_NORMAL_DIAL</TT>.
|
||||
<H4><A name=Fl_Dial.~Fl_Dial>virtual Fl_Dial::~Fl_Dial()</A></H4>
|
||||
Destroys the valuator.
|
||||
<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
|
||||
these are 0 and 360, respectively. (0 degrees is straight down and the
|
||||
angles progress clockwise.) The angles specified should be greater than
|
||||
or equal to 0 and less than or equal to 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.angles>
|
||||
short Fl_Dial::angle1() const;<br>
|
||||
void Fl_Dial::angle1(short);<br>
|
||||
short Fl_Dial::angle2() const;<br>
|
||||
void Fl_Dial::angle2(short);<br>
|
||||
void Fl_Dial::angles(short a, short b);
|
||||
</A>
|
||||
</H4>
|
||||
|
||||
Sets the angles used for the minimum and maximum values. The default
|
||||
values are 45 and 315 (0 degrees is straight down and the angles
|
||||
progress clockwise). Normally angle1 is less than angle2, but if you
|
||||
reverse them the dial moves counter-clockwise.
|
||||
|
||||
<H4><A name=Fl_Dial.type>type(uchar)</A></H4>
|
||||
Sets the type of the dial to:
|
||||
<UL>
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// "$Id: Fl_Dial.cxx,v 1.11 1999/03/10 00:13:52 carl Exp $"
|
||||
// "$Id: Fl_Dial.cxx,v 1.12 1999/03/10 08:17:42 bill Exp $"
|
||||
//
|
||||
// Circular dial widget for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
@ -29,14 +29,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <FL/math.h>
|
||||
|
||||
// For XForms compatability, all angles are measured with 0 being straight
|
||||
// up and positive numbers going clockwise.
|
||||
|
||||
void Fl_Dial::angles(short a, short b) {
|
||||
a1=a;
|
||||
a2=b;
|
||||
if (a2 < a1) a2 += 360; // necessary for XForms compatability
|
||||
}
|
||||
// All angles are measured with 0 to the right and counter-clockwise
|
||||
|
||||
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());
|
||||
@ -50,7 +43,7 @@ void Fl_Dial::draw(int x, int y, int w, int h) {
|
||||
int foo = (box() > _FL_ROUND_UP_BOX && Fl::box_dx(box()));
|
||||
if (foo) {x--; y--; w+=2; h+=2;}
|
||||
fl_color(color());
|
||||
fl_pie(x, y, w-1, h-1, 270-a1, 360+270-angle);
|
||||
fl_pie(x, y, w-1, h-1, 270-a1, angle > a1 ? 360+270-angle : 270-360-angle);
|
||||
fl_color(selection_color());
|
||||
fl_pie(x, y, w-1, h-1, 270-angle, 270-a1);
|
||||
if (foo) {
|
||||
@ -66,15 +59,9 @@ void Fl_Dial::draw(int x, int y, int w, int h) {
|
||||
fl_push_matrix();
|
||||
fl_translate(x+w/2-.5, y+h/2-.5);
|
||||
fl_scale(w-1, h-1);
|
||||
/* CET - Why is this here? This code is never reached!
|
||||
if (type() == FL_FILL_DIAL) {
|
||||
fl_rotate(225);
|
||||
fl_begin_line(); fl_vertex(0, 0); fl_vertex(.5, 0); fl_end_line();
|
||||
}
|
||||
*/
|
||||
fl_rotate(45-angle);
|
||||
fl_color(selection_color());
|
||||
if (type() == FL_LINE_DIAL) {
|
||||
if (type()) { // FL_LINE_DIAL
|
||||
fl_begin_polygon();
|
||||
fl_vertex(0.0, 0.0);
|
||||
fl_vertex(-0.04, 0.0);
|
||||
@ -106,24 +93,20 @@ int Fl_Dial::handle(int event, int x, int y, int w, int h) {
|
||||
case FL_PUSH:
|
||||
handle_push();
|
||||
case FL_DRAG: {
|
||||
double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
|
||||
double angle;
|
||||
static double last = 0.0;
|
||||
double val = value();
|
||||
int mx = Fl::event_x()-x-w/2;
|
||||
int my = Fl::event_y()-y-h/2;
|
||||
if (!mx && !my) return 1;
|
||||
angle = atan2((float)-my, (float)-mx) + M_PI;
|
||||
angle = (angle*360) / (2*M_PI) + 270;
|
||||
double angle = 270-atan2((float)-my, (float)mx)*180/M_PI;
|
||||
double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
|
||||
while (angle < oldangle-180) angle += 360;
|
||||
while (angle > oldangle+180) angle -= 360;
|
||||
if (angle <= a1) {
|
||||
double val;
|
||||
if ((a1<a2) ? (angle <= a1) : (angle >= a1)) {
|
||||
val = minimum();
|
||||
} else if (angle >= a2) {
|
||||
} else if ((a1<a2) ? (angle >= a2) : (angle <= a2)) {
|
||||
val = maximum();
|
||||
} else {
|
||||
val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1);
|
||||
last = angle;
|
||||
}
|
||||
handle_drag(clamp(round(val)));
|
||||
} return 1;
|
||||
@ -143,9 +126,10 @@ Fl_Dial::Fl_Dial(int x, int y, int w, int h, const char* l)
|
||||
: Fl_Valuator(x, y, w, h, l) {
|
||||
box(FL_OVAL_BOX);
|
||||
selection_color(FL_INACTIVE_COLOR); // was 37
|
||||
angles(0,360);
|
||||
a1 = 45;
|
||||
a2 = 315;
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id: Fl_Dial.cxx,v 1.11 1999/03/10 00:13:52 carl Exp $".
|
||||
// End of "$Id: Fl_Dial.cxx,v 1.12 1999/03/10 08:17:42 bill Exp $".
|
||||
//
|
||||
|
@ -147,7 +147,7 @@ fflush(stdout);}
|
||||
callback {printf("%g \\r",o->value());
|
||||
fflush(stdout);}
|
||||
xywh {475 280 65 65} type Fill color 10 selection_color 1 labelsize 8
|
||||
code0 {o->angles(45,315);}
|
||||
code0 {o->angles(0,360);}
|
||||
code1 {o->value(1.0);}
|
||||
}
|
||||
Fl_Box {} {
|
||||
|
Loading…
Reference in New Issue
Block a user