summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FL/Fl_Dial.H6
-rw-r--r--documentation/Fl_Dial.html7
-rw-r--r--src/Fl_Dial.cxx41
-rw-r--r--test/valuators.fl34
4 files changed, 57 insertions, 31 deletions
diff --git a/FL/Fl_Dial.H b/FL/Fl_Dial.H
index c6a5d5622..438f2abb2 100644
--- a/FL/Fl_Dial.H
+++ b/FL/Fl_Dial.H
@@ -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).
//
@@ -54,7 +54,7 @@ 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) {a1=a; a2=b;}
+ void angles(short a, short b);
void direction(uchar d) {direction_ = d;}
uchar direction() const {return direction_;}
@@ -63,5 +63,5 @@ public:
#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 $".
//
diff --git a/documentation/Fl_Dial.html b/documentation/Fl_Dial.html
index ff70b6db1..a320d7df5 100644
--- a/documentation/Fl_Dial.html
+++ b/documentation/Fl_Dial.html
@@ -34,7 +34,12 @@ and label string. The default type is <TT>FL_NORMAL_DIAL</TT>.
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.
+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>
Sets the type of the dial to:
<UL>
diff --git a/src/Fl_Dial.cxx b/src/Fl_Dial.cxx
index 10ac4b02d..f8a1744f9 100644
--- a/src/Fl_Dial.cxx
+++ b/src/Fl_Dial.cxx
@@ -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).
//
@@ -29,22 +29,28 @@
#include <stdlib.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) {
if (damage()&FL_DAMAGE_ALL) draw_box(box(), x, y, w, h, color());
x += Fl::box_dx(box());
y += Fl::box_dy(box());
w -= Fl::box_dw(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) {
double a = angle; if (a < 0) a = 0;
// foo: draw this nicely in certain round box types
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, 225, 225+360-a);
+ fl_pie(x, y, w-1, h-1, (360-a1)+90, (360-a)+360+90);
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) {
fl_color(FL_BLACK);
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_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(-angle);
+*/
+ fl_rotate(225-angle);
fl_color(selection_color());
if (type() == FL_LINE_DIAL) {
fl_begin_polygon();
@@ -97,16 +105,24 @@ int Fl_Dial::handle(int event, int x, int y, int w, int h) {
handle_push();
case FL_DRAG: {
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) + 0.25 * M_PI;
- if (angle<(-0.25*M_PI)) angle += 2.0*M_PI;
- val = minimum() + (maximum()-minimum())*angle/(1.5*M_PI);
- if (fabs(val-value()) < (maximum()-minimum())/2.0)
- handle_drag(clamp(round(val)));
- } return 1;
+ angle = atan2((float)-my, (float)-mx) + M_PI;
+ angle = (angle*360) / (2*M_PI) + 90;
+ if (angle >= 360.0) angle -= 360.0;
+ if (a2 >= 360 && angle <= (a2-360)) angle += 360;
+ if (angle < a1 || angle > a2) {
+ 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:
handle_release();
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) {
box(FL_OVAL_BOX);
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 $".
//
diff --git a/test/valuators.fl b/test/valuators.fl
index f84809065..582a7d6f4 100644
--- a/test/valuators.fl
+++ b/test/valuators.fl
@@ -1,5 +1,7 @@
# data file for the Fltk User Interface Designer (fluid)
-version 0.99
+version 1.00
+header_name {.h}
+code_name {.cxx}
gridx 5
gridy 5
snap 3
@@ -7,12 +9,12 @@ Function {} {open
} {
Fl_Window {} {
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
} {
Fl_Box {} {
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 {} {
label 0
@@ -34,7 +36,7 @@ fflush(stdout);}
}
Fl_Box {} {
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 {} {
label 0
@@ -86,7 +88,7 @@ fflush(stdout);}
}
Fl_Box {} {
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 {} {
label FL_HOR_NICE_SLIDER
@@ -108,35 +110,37 @@ fflush(stdout);}
}
Fl_Box {} {
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 {} {
label 0
callback {printf("%g \\r",o->value());
fflush(stdout);}
- xywh {360 160 180 30} labelsize 8 minimum -1e+06 maximum 1e+06
+ xywh {360 160 180 30} labelsize 8
}
Fl_Counter {} {
label FL_SIMPLE_COUNTER
callback {printf("%g \\r",o->value());
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 {} {
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 {} {
label 0
callback {printf("%g \\r",o->value());
-fflush(stdout);}
+fflush(stdout);} selected
xywh {315 280 65 65} color 10 selection_color 1 labelsize 8
+ code0 {o->angles(180,135);}
}
Fl_Dial {} {
label FL_LINE_DIAL
callback {printf("%g \\r",o->value());
fflush(stdout);}
xywh {395 280 65 65} type Line color 10 selection_color 1 labelsize 8
+ code0 {o->angles(0,360);}
}
Fl_Dial {} {
label FL_FILL_DIAL
@@ -146,7 +150,7 @@ fflush(stdout);}
}
Fl_Box {} {
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 {} {
label 0
@@ -162,7 +166,7 @@ fflush(stdout);}
}
Fl_Box {} {
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 {} {
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 {} {
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 {} {
label 0
callback {printf("%g \\r",o->value());
-fflush(stdout);} selected
+fflush(stdout);}
xywh {30 460 110 30} labelsize 8 maximum 100 step 0.1
}
Fl_Value_Output {} {
@@ -186,7 +190,7 @@ fflush(stdout);}
}
Fl_Box {} {
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 {} {
label 0