summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Spitzak <spitzak@gmail.com>1999-03-10 08:17:43 +0000
committerBill Spitzak <spitzak@gmail.com>1999-03-10 08:17:43 +0000
commitb6115887c86b6f3fa9591becb23a77af19fc2b95 (patch)
tree6d7d47819b1dfa77f7641d70fc7b7d27b37d0eae
parent170c31cada99660d123aa81993da0b995778be83 (diff)
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
-rw-r--r--FL/Fl_Dial.H16
-rw-r--r--FL/forms.H10
-rw-r--r--documentation/Fl_Dial.html26
-rw-r--r--src/Fl_Dial.cxx40
-rw-r--r--test/valuators.fl2
5 files changed, 43 insertions, 51 deletions
diff --git a/FL/Fl_Dial.H b/FL/Fl_Dial.H
index 438f2abb2..ce6fdb312 100644
--- a/FL/Fl_Dial.H
+++ b/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 $".
//
diff --git a/FL/forms.H b/FL/forms.H
index 635d75fb5..ac84dc421 100644
--- a/FL/forms.H
+++ b/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 $".
//
diff --git a/documentation/Fl_Dial.html b/documentation/Fl_Dial.html
index db0659f8e..395f4ce9e 100644
--- a/documentation/Fl_Dial.html
+++ b/documentation/Fl_Dial.html
@@ -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>
diff --git a/src/Fl_Dial.cxx b/src/Fl_Dial.cxx
index aa83e70aa..bb171c485 100644
--- a/src/Fl_Dial.cxx
+++ b/src/Fl_Dial.cxx
@@ -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 $".
//
diff --git a/test/valuators.fl b/test/valuators.fl
index 70dc3ea13..bd75c772b 100644
--- a/test/valuators.fl
+++ b/test/valuators.fl
@@ -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 {} {