1998-10-20 00:46:58 +04:00
|
|
|
//
|
2001-01-22 18:13:41 +03:00
|
|
|
// "$Id: Fl_Dial.cxx,v 1.12.2.3 2001/01/22 15:13:39 easysw Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Circular dial widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2001-01-22 18:13:41 +03:00
|
|
|
// Copyright 1998-2001 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Dial.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <FL/math.h>
|
|
|
|
|
1999-03-10 11:17:43 +03:00
|
|
|
// All angles are measured with 0 to the right and counter-clockwise
|
1999-03-09 00:44:32 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
void Fl_Dial::draw(int x, int y, int w, int h) {
|
1998-10-19 21:53:09 +04:00
|
|
|
if (damage()&FL_DAMAGE_ALL) draw_box(box(), x, y, w, h, color());
|
1998-10-06 22:21:25 +04:00
|
|
|
x += Fl::box_dx(box());
|
|
|
|
y += Fl::box_dy(box());
|
|
|
|
w -= Fl::box_dw(box());
|
|
|
|
h -= Fl::box_dh(box());
|
1999-03-09 00:44:32 +03:00
|
|
|
double angle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
|
1998-10-06 22:21:25 +04:00
|
|
|
if (type() == FL_FILL_DIAL) {
|
|
|
|
// 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());
|
1999-03-10 11:17:43 +03:00
|
|
|
fl_pie(x, y, w-1, h-1, 270-a1, angle > a1 ? 360+270-angle : 270-360-angle);
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_color(selection_color());
|
1999-03-10 03:13:52 +03:00
|
|
|
fl_pie(x, y, w-1, h-1, 270-angle, 270-a1);
|
1998-10-06 22:21:25 +04:00
|
|
|
if (foo) {
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_arc(x, y, w, h, 0, 360);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1998-10-19 21:53:09 +04:00
|
|
|
if (!(damage()&FL_DAMAGE_ALL)) {
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_color(color());
|
|
|
|
fl_pie(x+1, y+1, w-2, h-2, 0, 360);
|
|
|
|
}
|
|
|
|
fl_push_matrix();
|
|
|
|
fl_translate(x+w/2-.5, y+h/2-.5);
|
|
|
|
fl_scale(w-1, h-1);
|
1999-03-10 03:13:52 +03:00
|
|
|
fl_rotate(45-angle);
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_color(selection_color());
|
1999-03-10 11:17:43 +03:00
|
|
|
if (type()) { // FL_LINE_DIAL
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_begin_polygon();
|
|
|
|
fl_vertex(0.0, 0.0);
|
|
|
|
fl_vertex(-0.04, 0.0);
|
|
|
|
fl_vertex(-0.25, 0.25);
|
|
|
|
fl_vertex(0.0, 0.04);
|
|
|
|
fl_end_polygon();
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_begin_loop();
|
|
|
|
fl_vertex(0.0, 0.0);
|
|
|
|
fl_vertex(-0.04, 0.0);
|
|
|
|
fl_vertex(-0.25, 0.25);
|
|
|
|
fl_vertex(0.0, 0.04);
|
|
|
|
fl_end_loop();
|
|
|
|
} else {
|
|
|
|
fl_begin_polygon(); fl_circle(-0.20, 0.20, 0.07); fl_end_polygon();
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_begin_loop(); fl_circle(-0.20, 0.20, 0.07); fl_end_loop();
|
|
|
|
}
|
|
|
|
fl_pop_matrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Dial::draw() {
|
|
|
|
draw(x(), y(), w(), h());
|
|
|
|
draw_label();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Dial::handle(int event, int x, int y, int w, int h) {
|
|
|
|
switch (event) {
|
|
|
|
case FL_PUSH:
|
|
|
|
handle_push();
|
|
|
|
case FL_DRAG: {
|
|
|
|
int mx = Fl::event_x()-x-w/2;
|
|
|
|
int my = Fl::event_y()-y-h/2;
|
|
|
|
if (!mx && !my) return 1;
|
1999-03-10 11:17:43 +03:00
|
|
|
double angle = 270-atan2((float)-my, (float)mx)*180/M_PI;
|
|
|
|
double oldangle = (a2-a1)*(value()-minimum())/(maximum()-minimum()) + a1;
|
1999-03-09 10:26:28 +03:00
|
|
|
while (angle < oldangle-180) angle += 360;
|
|
|
|
while (angle > oldangle+180) angle -= 360;
|
1999-03-10 11:17:43 +03:00
|
|
|
double val;
|
|
|
|
if ((a1<a2) ? (angle <= a1) : (angle >= a1)) {
|
1999-03-09 10:26:28 +03:00
|
|
|
val = minimum();
|
1999-03-10 11:17:43 +03:00
|
|
|
} else if ((a1<a2) ? (angle >= a2) : (angle <= a2)) {
|
1999-03-09 10:26:28 +03:00
|
|
|
val = maximum();
|
1999-03-09 00:44:32 +03:00
|
|
|
} else {
|
|
|
|
val = minimum() + (maximum()-minimum())*(angle-a1)/(a2-a1);
|
|
|
|
}
|
|
|
|
handle_drag(clamp(round(val)));
|
|
|
|
} return 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
case FL_RELEASE:
|
|
|
|
handle_release();
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Dial::handle(int e) {
|
|
|
|
return handle(e, x(), y(), w(), h());
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
1999-03-10 11:17:43 +03:00
|
|
|
a1 = 45;
|
|
|
|
a2 = 315;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
2001-01-22 18:13:41 +03:00
|
|
|
// End of "$Id: Fl_Dial.cxx,v 1.12.2.3 2001/01/22 15:13:39 easysw Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|