Updated Fl_Dial to use atan2() to avoid possible math errors and reduce
code size. git-svn-id: file:///fltk/svn/fltk/trunk@277 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
7b82bc3509
commit
18312d3c1f
@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// "$Id: Fl_Dial.cxx,v 1.5 1999/01/07 19:17:19 mike Exp $"
|
// "$Id: Fl_Dial.cxx,v 1.6 1999/02/16 17:23:55 mike Exp $"
|
||||||
//
|
//
|
||||||
// Circular dial widget for the Fast Light Tool Kit (FLTK).
|
// Circular dial widget for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -101,15 +101,7 @@ int Fl_Dial::handle(int event, int x, int y, int w, int h) {
|
|||||||
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;
|
||||||
if (abs(mx) > abs(my)) {
|
angle = atan2(-my, -mx) + 0.25 * M_PI;
|
||||||
angle = atan(-(double)my/mx);
|
|
||||||
if (mx>0) angle = 1.25*M_PI - angle;
|
|
||||||
else angle = 0.25*M_PI - angle;
|
|
||||||
} else {
|
|
||||||
angle = atan(-(double)mx/my);
|
|
||||||
if (my<0) angle = 0.75*M_PI + angle;
|
|
||||||
else angle = -0.25*M_PI + angle;
|
|
||||||
}
|
|
||||||
if (angle<(-0.25*M_PI)) angle += 2.0*M_PI;
|
if (angle<(-0.25*M_PI)) angle += 2.0*M_PI;
|
||||||
val = minimum() + (maximum()-minimum())*angle/(1.5*M_PI);
|
val = minimum() + (maximum()-minimum())*angle/(1.5*M_PI);
|
||||||
if (fabs(val-value()) < (maximum()-minimum())/2.0)
|
if (fabs(val-value()) < (maximum()-minimum())/2.0)
|
||||||
@ -134,5 +126,5 @@ Fl_Dial::Fl_Dial(int x, int y, int w, int h, const char* l)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id: Fl_Dial.cxx,v 1.5 1999/01/07 19:17:19 mike Exp $".
|
// End of "$Id: Fl_Dial.cxx,v 1.6 1999/02/16 17:23:55 mike Exp $".
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user