2 /*******************************************************************************/
3 /* Copyright (C) 2008 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
22 #include <FL/Fl_Widget.H>
23 #include <FL/fl_draw.H>
31 class Panner : public Fl_Widget
34 void draw_the_box( int, int, int, int );
40 /* distance from center (from 0 to 1) */
45 Point ( ) : d( 0.0f ), a( 0.0f ) { }
46 Point ( float D, float A ) : d( D ), a( A ) { }
48 /** translate angle /a/ into x/y coords and place the result in /X/ and /Y/ */
50 axes ( float *X, float *Y ) const
53 float A = ( 270 - a ) * ( M_PI / 180 );
59 float azimuth ( void ) const
61 return a > 180.0f ? a - 360.0f : a;
65 float elevation ( void ) const
67 return ( 1.0f - d ) * 90.0f;
70 void azimuth ( float v )
72 a = v < 0.0f ? v + 360.0f : v;
73 a = a < 0.0f ? 0.0f : a > 360.0f ? 360.0f : a;
76 void elevation ( float v )
78 d = 1.0f - ( v / 90.0f );
79 d = d < 0.0f ? 0.0f : d > 1.0f ? 1.0f : d;
82 /** set point position in X, Y coordinates (0.0 to 1.0) */
84 angle ( float X1, float Y1 )
93 t = atan2( X2 - X1, Y2 - Y1 );
102 /* standard distance calculation */
103 d = sqrt( pow( X2 - X1, 2 ) + pow( Y2 - Y1, 2 ) );
109 /** return the distance between the point and that referenced by /p/ */
111 distance ( const Point &p )
113 /* first, transform point coords */
115 float x1, y1, x2, y2;
120 /* standard distance calculation */
121 return sqrt( pow( x1 - x2, 2 ) + pow( y1 - y2, 2 ) );
127 /* channel configuration */
133 vector <Point> _points;
135 static int pw ( void ) { return 12; }
136 static int ph ( void ) { return 12; }
138 static int _configs[][12];
140 void bbox ( int &X, int &Y, int &W, int &H ) const
142 W = w() - Fl::box_dw( box() );
143 H = h() - Fl::box_dh( box() );
144 X = x() + Fl::box_dx( box() );
145 Y = y() + Fl::box_dy( box() );
148 void point_bbox ( const Point *p, int *X, int *Y, int *W, int *H ) const;
150 Point * event_point ( void );
151 Point angle_to_axes ( float a );
168 virtual void draw ( void );
169 virtual int handle ( int );
174 Panner ( int X, int Y, int W, int H, const char *L = 0 ) :
175 Fl_Widget( X, Y, W, H, L )
185 // _points.push_back( Point( 1, FL ) );
186 _points.push_back( Point( 1, C ) );
188 /* _points.push_back( Point( 1, FR ) ); */
189 /* _points.push_back( Point( 1, RL ) ); */
190 /* _points.push_back( Point( 1, RR ) ); */
195 virtual ~Panner ( ) { }
197 Panner::Point *point ( int i );