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.

302 lines
7.9KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2007-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. /* This file contains ALL platform specific drawing code required by the canvas */
  19. #include "ui.H"
  20. #include "draw.H"
  21. #include "../common.h"
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include "../canvas.H"
  25. struct color_table {
  26. int state;
  27. unsigned char r, g, b;
  28. };
  29. struct color_table color_defs[] = {
  30. { EMPTY, 18, 18, 18 },
  31. { FULL, 255, 69, 0 },
  32. { PARTIAL, 0, 0, 0 },
  33. { CONTINUED, 80, 80, 80 },
  34. { LINE, 10, 10, 10 },
  35. { HIT, 255, 255, 255 },
  36. { PLAYHEAD, 10, 69, 10 },
  37. { SELECTED, 255, 10, 255 },
  38. };
  39. Fl_Color *state_colors;
  40. Fl_Color velocity_colors[128];
  41. Fl_Color velocity2_colors[128];
  42. bool draw_borders = 1;
  43. void
  44. init_colors ( void )
  45. {
  46. unsigned int i;
  47. /* velocity colors */
  48. for ( i = 128; i--; )
  49. {
  50. velocity_colors[i] = fl_color_average( FL_GRAY, fl_rgb_color( i * 2, 255 - i * 2, 32 ), 0.4 );
  51. velocity2_colors[i] = fl_color_average( FL_WHITE, velocity_colors[i], 0.5 );
  52. }
  53. state_colors = (Fl_Color*)malloc(sizeof( Fl_Color ) * MAX_STATE );
  54. for ( i = elementsof( color_defs ); i--; )
  55. {
  56. state_colors[ color_defs[i].state ] = fl_rgb_color( color_defs[i].r,
  57. color_defs[i].g,
  58. color_defs[i].b );
  59. }
  60. }
  61. int
  62. gui_draw_ruler ( int x, int y, int w, int div_w, int div, int ofs, int p1, int p2 )
  63. {
  64. /* Across the top */
  65. fl_font( FL_TIMES, ruler_height );
  66. int h = ruler_height;
  67. fl_color( canvas_background_color );
  68. // fl_rectf( x, y, x + (div_w * w), y + h );
  69. fl_rectf( x, y, (div_w * w), h );
  70. fl_color( FL_RED );
  71. fl_line( x + div_w / 2, y, x + div_w * w, y );
  72. char pat[40];
  73. int z = div;
  74. int i;
  75. for ( i = 0; i < w; i++ )
  76. if ( 0 == i % z )
  77. {
  78. int nx = x + (i * div_w) + (div_w / 2);
  79. fl_color( FL_RED );
  80. fl_line( nx, y, nx, y + h );
  81. int k = ofs + i;
  82. sprintf( pat, "%i", 1 + (k / z ));
  83. fl_color( FL_WHITE );
  84. fl_draw( pat, nx + div_w / 2, y + h + 1 / 2 );
  85. }
  86. if ( p1 != p2 )
  87. {
  88. if ( p1 >= 0 )
  89. {
  90. if ( p1 < p2 )
  91. fl_color( FL_GREEN );
  92. else
  93. fl_color( FL_RED );
  94. fl_rectf( x + (div_w * p1), y + h / 2, div_w, h / 2 );
  95. }
  96. if ( p2 >= 0 )
  97. {
  98. if ( p2 < p1 )
  99. fl_color( FL_GREEN );
  100. else
  101. fl_color( FL_RED );
  102. fl_rectf( x + (div_w * p2), y + h / 2, div_w, h / 2 );
  103. }
  104. }
  105. return h;
  106. }
  107. void
  108. gui_clear_area ( int x, int y, int w, int h )
  109. {
  110. fl_color( canvas_background_color );
  111. fl_rectf( x, y, w, h );
  112. }
  113. int
  114. gui_draw_string ( int x, int y, int w, int h, int color, const char *s, bool draw )
  115. {
  116. int rw;
  117. if ( ! s )
  118. return 0;
  119. fl_font( FL_COURIER, min( h, 18 ) );
  120. rw = fl_width( s );
  121. if ( fl_not_clipped( x, y, rw, h ) && draw )
  122. {
  123. gui_clear_area( x, y, w, h );
  124. if ( color )
  125. fl_color( velocity_colors[ color ] );
  126. else
  127. fl_color( FL_DARK_CYAN );
  128. fl_draw( s, x, y + h / 2 + fl_descent() );
  129. }
  130. return rw;
  131. }
  132. void
  133. gui_draw_shape ( int x, int y, int w, int h, int bw, int shape, int state, int flags, int color )
  134. {
  135. /* take advantage of FLTK's clipping */
  136. if ( ! fl_not_clipped( x, y, w, h ) )
  137. return;
  138. if ( flags & F_PLAYHEAD )
  139. {
  140. state = state == FULL ? HIT : PLAYHEAD;
  141. flags &= ~ F_SELECTION;
  142. }
  143. Fl_Color c1, c2;
  144. if ( state == FULL && color )
  145. {
  146. c1 = velocity_colors[ color ];
  147. c2 = velocity2_colors[ color ];
  148. }
  149. else
  150. {
  151. c1 = state_colors[ state ];
  152. c2 = fl_color_average( FL_WHITE, c1, 0.1 );
  153. }
  154. int thickness = 2;
  155. /* if ( state == EMPTY && shape == SQUARE ) */
  156. /* shape = HOLLOW_SQUARE; */
  157. if ( flags & F_SELECTION )
  158. fl_color( fl_darker( fl_color() ) );
  159. switch ( shape )
  160. {
  161. case CIRCLE:
  162. fl_color( c1 );
  163. fl_pie( x + bw / 2, y + bw / 2, w - bw, h - bw, 0, 360 );
  164. if ( draw_borders )
  165. {
  166. fl_color( c2 );
  167. fl_line_style( FL_SOLID, thickness );
  168. fl_arc( x + bw / 2, y + bw / 2, w - bw, h - bw, 0, 360 );
  169. fl_line_style( FL_SOLID, 0 );
  170. }
  171. break;
  172. case SQUARE:
  173. fl_color( c1 );
  174. fl_rectf( x + bw, y + bw, w - bw * 2, h - bw * 2 );
  175. if ( draw_borders )
  176. {
  177. fl_color( c2 );
  178. fl_line_style( FL_SOLID, thickness );
  179. fl_rect( x + bw, y + bw, w - bw * 2, h - bw * 2 );
  180. fl_line_style( FL_SOLID, 0 );
  181. }
  182. break;
  183. case HALF_CIRCLE:
  184. fl_color( c1 );
  185. fl_pie( x + bw / 2, y + bw / 2, w - bw, h - bw, 0, 360 / 2);
  186. if ( draw_borders )
  187. {
  188. fl_color( c2 );
  189. fl_line_style( FL_SOLID, thickness );
  190. fl_pie( x + bw / 2, y + bw / 2, w - bw, h - bw, 0, 360 / 2);
  191. fl_line_style( FL_SOLID, 0 );
  192. }
  193. break;
  194. case DIAMOND:
  195. fl_color( c1 );
  196. fl_polygon( x + w / 2, y + bw / 2, x + w - bw / 2, y + h / 2, x + w / 2, y + h - bw / 2, x + bw / 2, y + h / 2 );
  197. if ( draw_borders )
  198. {
  199. fl_color( c2 );
  200. fl_line_style( FL_SOLID, thickness );
  201. fl_loop( x + w / 2, y + bw / 2, x + w - bw / 2, y + h / 2, x + w / 2, y + h - bw / 2, x + bw / 2, y + h / 2 );
  202. fl_line_style( FL_SOLID, 0 );
  203. }
  204. break;
  205. default:
  206. ASSERTION( "unknown shape" );
  207. break;
  208. }
  209. if ( flags & F_P1 || flags & F_P2 )
  210. {
  211. if ( flags & F_P1 )
  212. fl_color( FL_GREEN );
  213. else
  214. fl_color( FL_RED );
  215. int rw = w / 4;
  216. int rh = h / 4;
  217. fl_rectf( x + (w / 2) - (rw / 2), y + (h / 2) - (rh / 2), rw, rh );
  218. }
  219. }
  220. extern UI *ui;
  221. static
  222. void
  223. clear_status ( void * )
  224. {
  225. ui->status->label( NULL );
  226. }
  227. /** inform the user of something via a status bar */
  228. void
  229. gui_status ( const char *fmt, ... )
  230. {
  231. va_list args;
  232. static char pat[256];
  233. if ( fmt )
  234. {
  235. va_start( args, fmt );
  236. vsnprintf( pat, 256, fmt, args );
  237. va_end( args );
  238. }
  239. ui->status->label( pat );
  240. Fl::add_timeout( 5.0f, clear_status );
  241. }