1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Circular dial widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
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>
|
2012-07-24 08:37:22 +04:00
|
|
|
#include <FL/Fl_Fill_Dial.H>
|
|
|
|
#include <FL/Fl_Line_Dial.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <FL/math.h>
|
|
|
|
|
2012-07-24 08:37:22 +04:00
|
|
|
|
1999-03-10 11:17:43 +03:00
|
|
|
// All angles are measured with 0 to the right and counter-clockwise
|
2008-09-21 18:40:31 +04:00
|
|
|
/**
|
|
|
|
Draws dial at given position and size.
|
|
|
|
\param[in] X, Y, W, H position and size
|
|
|
|
*/
|
2002-08-09 05:09:49 +04:00
|
|
|
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());
|
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()));
|
2002-08-09 05:09:49 +04:00
|
|
|
if (foo) {X--; Y--; W+=2; H+=2;}
|
2006-09-20 07:03:14 +04:00
|
|
|
if (active_r()) fl_color(color());
|
|
|
|
else fl_color(fl_inactive(color()));
|
2005-08-30 01:16:38 +04:00
|
|
|
fl_pie(X, Y, W, H, 270-a1, angle > a1 ? 360+270-angle : 270-360-angle);
|
2006-09-20 07:03:14 +04:00
|
|
|
if (active_r()) fl_color(selection_color());
|
|
|
|
else fl_color(fl_inactive(selection_color()));
|
2005-08-30 01:16:38 +04:00
|
|
|
fl_pie(X, Y, W, H, 270-angle, 270-a1);
|
1998-10-06 22:21:25 +04:00
|
|
|
if (foo) {
|
2006-09-20 07:03:14 +04:00
|
|
|
if (active_r()) fl_color(FL_FOREGROUND_COLOR);
|
|
|
|
else fl_color(fl_inactive(FL_FOREGROUND_COLOR));
|
2002-08-09 05:09:49 +04:00
|
|
|
fl_arc(X, Y, W, H, 0, 360);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1998-10-19 21:53:09 +04:00
|
|
|
if (!(damage()&FL_DAMAGE_ALL)) {
|
2006-09-20 07:03:14 +04:00
|
|
|
if (active_r()) fl_color(color());
|
|
|
|
else fl_color(fl_inactive(color()));
|
2002-08-09 05:09:49 +04:00
|
|
|
fl_pie(X+1, Y+1, W-2, H-2, 0, 360);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
fl_push_matrix();
|
2002-08-09 05:09:49 +04:00
|
|
|
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);
|
2006-09-20 07:03:14 +04:00
|
|
|
if (active_r()) fl_color(selection_color());
|
|
|
|
else fl_color(fl_inactive(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();
|
2006-09-20 07:03:14 +04:00
|
|
|
if (active_r()) fl_color(FL_FOREGROUND_COLOR);
|
|
|
|
else fl_color(fl_inactive(FL_FOREGROUND_COLOR));
|
1998-10-06 22:21:25 +04:00
|
|
|
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();
|
2006-09-20 07:03:14 +04:00
|
|
|
if (active_r()) fl_color(FL_FOREGROUND_COLOR);
|
|
|
|
else fl_color(fl_inactive(FL_FOREGROUND_COLOR));
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_begin_loop(); fl_circle(-0.20, 0.20, 0.07); fl_end_loop();
|
|
|
|
}
|
|
|
|
fl_pop_matrix();
|
|
|
|
}
|
|
|
|
|
2008-09-21 18:40:31 +04:00
|
|
|
/**
|
|
|
|
Draws dial at current position and size.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void Fl_Dial::draw() {
|
|
|
|
draw(x(), y(), w(), h());
|
|
|
|
draw_label();
|
|
|
|
}
|
|
|
|
|
2008-09-21 18:40:31 +04:00
|
|
|
/**
|
2008-10-03 11:48:38 +04:00
|
|
|
Allows subclasses to handle event based on given position and size.
|
|
|
|
\param[in] event, X, Y, W, H event to handle, related position and size.
|
2008-09-21 18:40:31 +04:00
|
|
|
*/
|
2002-08-09 05:09:49 +04:00
|
|
|
int Fl_Dial::handle(int event, int X, int Y, int W, int H) {
|
1998-10-06 22:21:25 +04:00
|
|
|
switch (event) {
|
2017-06-29 04:13:05 +03:00
|
|
|
case FL_PUSH:
|
1998-10-06 22:21:25 +04:00
|
|
|
handle_push();
|
2017-06-29 04:13:05 +03:00
|
|
|
/* FALLTHROUGH */
|
1998-10-06 22:21:25 +04:00
|
|
|
case FL_DRAG: {
|
2003-07-18 09:53:21 +04:00
|
|
|
int mx = (Fl::event_x()-X-W/2)*H;
|
|
|
|
int my = (Fl::event_y()-Y-H/2)*W;
|
1998-10-06 22:21:25 +04:00
|
|
|
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)));
|
2017-06-29 04:13:05 +03:00
|
|
|
return 1;
|
|
|
|
} /* NOTREACHED */
|
1998-10-06 22:21:25 +04:00
|
|
|
case FL_RELEASE:
|
|
|
|
handle_release();
|
|
|
|
return 1;
|
2017-06-29 04:13:05 +03:00
|
|
|
case FL_ENTER: /* FALLTHROUGH */
|
|
|
|
case FL_LEAVE:
|
2002-05-12 15:12:56 +04:00
|
|
|
return 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-21 18:40:31 +04:00
|
|
|
/**
|
|
|
|
Allow subclasses to handle event based on current position and size.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int Fl_Dial::handle(int e) {
|
|
|
|
return handle(e, x(), y(), w(), h());
|
|
|
|
}
|
|
|
|
|
2002-08-09 05:09:49 +04:00
|
|
|
Fl_Dial::Fl_Dial(int X, int Y, int W, int H, const char* l)
|
2008-09-14 19:45:27 +04:00
|
|
|
/**
|
|
|
|
Creates a new Fl_Dial widget using the given position, size,
|
|
|
|
and label string. The default type is FL_NORMAL_DIAL.
|
|
|
|
*/
|
|
|
|
: Fl_Valuator(X, Y, W, H, l) {
|
1998-10-06 22:21:25 +04:00
|
|
|
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
|
|
|
|
2012-07-24 08:37:22 +04:00
|
|
|
|
|
|
|
Fl_Fill_Dial::Fl_Fill_Dial(int X,int Y,int W,int H, const char *L)
|
|
|
|
: Fl_Dial(X,Y,W,H,L) {
|
|
|
|
type(FL_FILL_DIAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Fl_Line_Dial::Fl_Line_Dial(int X,int Y,int W,int H, const char *L)
|
2017-06-29 04:13:05 +03:00
|
|
|
: Fl_Dial(X,Y,W,H,L) {
|
2012-07-24 08:37:22 +04:00
|
|
|
type(FL_LINE_DIAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|