Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

333 lines
8.5KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Fl_Arc_Dial.H"
  19. #include <FL/fl_draw.H>
  20. #include <FL/Fl.H>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <math.h>
  24. #include <algorithm>
  25. int Fl_Arc_Dial::_default_style = Fl_Arc_Dial::PLASTIC_DIAL;
  26. /** This simple box is suitable for use with knob-type widgets. It
  27. * comprises a border with shadow, and a cap with glare-lines akin
  28. * to those seen on burnished aluminum knobs. */
  29. static void
  30. burnished_oval_box ( int x, int y, int w, int h, Fl_Color c )
  31. {
  32. /* draw background */
  33. fl_color( fl_darker( c ) );
  34. fl_pie( x, y, w, h, 0, 360 );
  35. fl_color( fl_darker( fl_darker( c ) ) );
  36. fl_pie( x, y, w, h, 180 + 215, 180 + 45 );
  37. /* shrink */
  38. x += 4;
  39. y += 4;
  40. w -= 7;
  41. h -= 7;
  42. /* draw cap */
  43. fl_color( c );
  44. fl_pie( x, y, w, h, 0, 360 );
  45. /* draw glare */
  46. const int a1 = 10;
  47. const int a2 = 90;
  48. fl_color( fl_color_average( FL_WHITE, c, 0.15f ) );
  49. fl_pie( x, y, w, h, a1, a2 );
  50. fl_pie( x, y, w, h, 180 + a1, 180 + a2 );
  51. fl_color( fl_color_average( FL_WHITE, c, 0.25f ) );
  52. const int d = (a2 - a1) / 2;
  53. fl_pie( x, y, w, h, a1 + (d / 2), a2 - (d / 2) );
  54. fl_pie( x, y, w, h, 180 + a1 + (d / 2), 180 + a2 - (d / 2) );
  55. }
  56. void
  57. Fl_Arc_Dial::draw_box ( void )
  58. {
  59. }
  60. int
  61. Fl_Arc_Dial::handle ( int m )
  62. {
  63. /* Fl_Dial and friends should really handle mousewheel, but they don't in FTLK1 */
  64. switch ( m )
  65. {
  66. case FL_MOUSEWHEEL:
  67. {
  68. if ( this != Fl::belowmouse() )
  69. return 0;
  70. int steps = 16;
  71. if ( Fl::event_ctrl() )
  72. steps = 128;
  73. float step = fabs( maximum() - minimum() ) / (float)steps;
  74. float d = ((float)Fl::event_dy()) * step;
  75. double v = value() + d;
  76. if ( maximum() > minimum() )
  77. {
  78. if ( v < minimum() )
  79. v = minimum();
  80. else if ( v > maximum() )
  81. v = maximum();
  82. }
  83. else
  84. {
  85. if ( v > minimum() )
  86. v = minimum();
  87. else if ( v < maximum() )
  88. v = maximum();
  89. }
  90. value( v );
  91. do_callback();
  92. return 1;
  93. }
  94. }
  95. int X, Y, S;
  96. get_knob_dimensions ( &X, &Y, &S );
  97. return Fl_Dial::handle( m, X, Y, S, S );
  98. }
  99. void
  100. Fl_Arc_Dial::draw ( void )
  101. {
  102. int X, Y, S;
  103. get_knob_dimensions ( &X, &Y, &S);
  104. draw_box();
  105. draw_label();
  106. double angle = ( angle2() - angle1() ) * ( value() - minimum()) / ( maximum() - minimum() ) + angle1();
  107. if ( type() == ARC_DIAL )
  108. {
  109. /* fl_line_style( FL_SOLID, 0 ); */
  110. if ( type() == ARC_DIAL )
  111. fl_draw_box( FL_ROUNDED_BOX, X, Y, S, S, color() );
  112. /* shrink a bit */
  113. X += S / 8.0;
  114. Y += S / 8.0;
  115. S -= S / 4;
  116. fl_line_style( FL_SOLID, S / 6 );
  117. /* background arc */
  118. fl_color( fl_darker( color() ) );
  119. fl_arc( X, Y, S, S, 270 - angle1(), 270 - angle2() );
  120. /* foreground arc */
  121. fl_color( selection_color() );
  122. fl_arc( X, Y, S, S, 270 - angle1(), 270 - angle );
  123. fl_line_style( FL_SOLID, 0 );
  124. fl_color( fl_contrast( labelcolor(), color() ) );
  125. }
  126. else if ( type() == PLASTIC_DIAL || type() == BURNISHED_DIAL )
  127. {
  128. draw_knob();
  129. draw_cursor( X, Y, S);
  130. }
  131. /* Some strange bug in FLTK prevents us from always been able to draw text
  132. * here, so don't even try for now. */
  133. /* char s[10]; */
  134. /* fl_font( FL_HELVETICA, 8 ); */
  135. /* snprintf( s, sizeof( s ), "%.1f", value() ); */
  136. /* /\* fl_rectf( X, Y + S, S, 14, FL_BACKGROUND2_COLOR ); *\/ */
  137. /* fl_color( FL_WHITE ); */
  138. /* fl_draw( s, X, Y + S, S, 14, FL_ALIGN_CENTER ); */
  139. }
  140. void
  141. Fl_Arc_Dial::get_knob_dimensions ( int *X, int *Y, int *S )
  142. {
  143. int ox, oy, ww, hh, side;
  144. ox = x();
  145. oy = y();
  146. ww = w();
  147. hh = h();
  148. if (ww > hh)
  149. {
  150. side = hh;
  151. ox = ox + (ww - side) / 2;
  152. }
  153. else
  154. {
  155. side = ww;
  156. oy = oy + (hh - side) / 2;
  157. }
  158. side = w() > h() ? hh : ww;
  159. *X = ox;
  160. *Y = oy;
  161. *S = side;
  162. }
  163. void
  164. Fl_Arc_Dial::draw_cursor ( int ox, int oy, int side )
  165. {
  166. double angle;
  167. // fl_color(fl_color_average(FL_BACKGROUND_COLOR, FL_BLACK, .7f));
  168. angle = ( angle2() - angle1() ) * ( value() - minimum()) / ( maximum() - minimum() ) + angle1();
  169. fl_color( fl_contrast( selection_color(), FL_BACKGROUND_COLOR ) );
  170. fl_line_style( FL_SOLID, side / 8 );
  171. const int d = 6;
  172. /* account for edge conditions */
  173. angle = angle < angle1() + d ? angle1() + d : angle;
  174. angle = angle > angle2() - d ? angle2() - d : angle;
  175. ox += side / 4;
  176. oy += side / 4;
  177. side -= side / 2;
  178. fl_arc( ox, oy, side, side, 270 - (angle - d), 270 - (angle + d) );
  179. fl_line_style( FL_SOLID, 0 );
  180. }
  181. void
  182. Fl_Arc_Dial::draw_knob ( void )
  183. {
  184. int ox, oy, ww, hh, side;
  185. get_knob_dimensions ( &ox, &oy, &side );
  186. ww = w();
  187. hh = h();
  188. draw_label();
  189. fl_clip(ox, oy, ww, hh);
  190. // background
  191. /* fl_color(FL_BACKGROUND_COLOR); */
  192. /* fl_rectf(ox, oy, side, side); */
  193. /* scale color */
  194. fl_color(fl_color_average(color(), FL_BACKGROUND2_COLOR, .6));
  195. fl_pie(ox + 1, oy + 3, side - 2, side - 12, 0, 360);
  196. // scale
  197. draw_scale(ox, oy, side);
  198. Fl_Color c = active_r() ? fl_color_average(FL_BACKGROUND_COLOR, FL_WHITE, .7) : FL_INACTIVE_COLOR;
  199. if ( type() == BURNISHED_DIAL )
  200. {
  201. burnished_oval_box( ox + 5, oy + 5, side - 12, side - 12, c );
  202. }
  203. else
  204. {
  205. fl_color(FL_BACKGROUND_COLOR);
  206. fl_pie(ox + 6, oy + 6, side - 12, side - 12, 0, 360);
  207. // shadow
  208. fl_color(fl_color_average(FL_BACKGROUND_COLOR, FL_BLACK, .8f));
  209. fl_pie(ox + 8, oy + 12, side - 16, side - 16, 0, 360);
  210. fl_color(fl_color_average(FL_BACKGROUND_COLOR, FL_BLACK, .2f));
  211. fl_pie(ox + 9, oy + 12, side - 18, side - 18, 0, 360);
  212. // knob edge
  213. fl_color( c);
  214. fl_pie(ox + 8, oy + 8, side - 16, side - 16, 0, 360);
  215. fl_color(fl_color_average(FL_BACKGROUND_COLOR, FL_WHITE, .6));
  216. fl_pie(ox + 10, oy + 10, side - 20, side - 20, 0, 360);
  217. }
  218. fl_pop_clip();
  219. }
  220. void
  221. Fl_Arc_Dial::draw_scale ( int ox, int oy, int side )
  222. {
  223. float x1, y1, x2, y2, rds, cx, cy, ca, sa;
  224. rds = side / 2;
  225. cx = ox + side / 2;
  226. cy = oy + side / 2;
  227. if (_scaleticks == 0)
  228. return;
  229. double a_step = (10.0 * 3.14159 / 6.0) / _scaleticks;
  230. double a_orig = -(3.14159 / 3.0);
  231. for (int a = 0; a <= _scaleticks; a++)
  232. {
  233. double na = a_orig + a * a_step;
  234. ca = cos(na);
  235. sa = sin(na);
  236. x1 = cx + (rds) * ca;
  237. y1 = cy - (rds) * sa;
  238. x2 = cx + (rds - 6) * ca;
  239. y2 = cy - (rds - 6) * sa;
  240. fl_color(FL_BACKGROUND_COLOR);
  241. fl_line(x1, y1, x2, y2);
  242. }
  243. }
  244. void
  245. Fl_Arc_Dial::scaleticks ( int tck )
  246. {
  247. _scaleticks = tck;
  248. if (_scaleticks < 0)
  249. _scaleticks = 0;
  250. if (_scaleticks > 31)
  251. _scaleticks = 31;
  252. if (visible())
  253. damage(FL_DAMAGE_ALL);
  254. }