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.

247 lines
6.1KB

  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, 38, 38, 38 },
  31. { FULL, 255, 69, 0 },
  32. { PARTIAL, 0, 0, 0 },
  33. { CONTINUED, 80, 80, 80 },
  34. { LINE, 26, 26, 26 },
  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. void
  42. init_colors ( void )
  43. {
  44. unsigned int i;
  45. /* velocity colors */
  46. for ( i = 128; i--; )
  47. velocity_colors[i] = fl_rgb_color( i * 2, 255 - i * 2, 32 );
  48. state_colors = (Fl_Color*)malloc(sizeof( Fl_Color ) * MAX_STATE );
  49. for ( i = elementsof( color_defs ); i--; )
  50. {
  51. state_colors[ color_defs[i].state ] = fl_rgb_color( color_defs[i].r,
  52. color_defs[i].g,
  53. color_defs[i].b );
  54. }
  55. }
  56. int
  57. gui_draw_ruler ( int x, int y, int w, int div_w, int div, int ofs, int p1, int p2 )
  58. {
  59. /* Across the top */
  60. fl_font( FL_TIMES, ruler_height );
  61. int h = ruler_height;
  62. fl_color( canvas_background_color );
  63. // fl_rectf( x, y, x + (div_w * w), y + h );
  64. fl_rectf( x, y, (div_w * w), h );
  65. fl_color( FL_RED );
  66. fl_line( x + div_w / 2, y, x + div_w * w, y );
  67. char pat[40];
  68. int z = div;
  69. int i;
  70. for ( i = 0; i < w; i++ )
  71. if ( 0 == i % z )
  72. {
  73. int nx = x + (i * div_w) + (div_w / 2);
  74. fl_color( FL_RED );
  75. fl_line( nx, y, nx, y + h );
  76. int k = ofs + i;
  77. sprintf( pat, "%i", 1 + (k / z ));
  78. fl_color( FL_WHITE );
  79. fl_draw( pat, nx + div_w / 2, y + h + 1 / 2 );
  80. }
  81. if ( p1 != p2 )
  82. {
  83. if ( p1 >= 0 )
  84. {
  85. if ( p1 < p2 )
  86. fl_color( FL_GREEN );
  87. else
  88. fl_color( FL_RED );
  89. fl_rectf( x + (div_w * p1), y + h / 2, div_w, h / 2 );
  90. }
  91. if ( p2 >= 0 )
  92. {
  93. if ( p2 < p1 )
  94. fl_color( FL_GREEN );
  95. else
  96. fl_color( FL_RED );
  97. fl_rectf( x + (div_w * p2), y + h / 2, div_w, h / 2 );
  98. }
  99. }
  100. return h;
  101. }
  102. void
  103. gui_clear_area ( int x, int y, int w, int h )
  104. {
  105. fl_color( canvas_background_color );
  106. fl_rectf( x, y, w, h );
  107. }
  108. int
  109. gui_draw_string ( int x, int y, int w, int h, int color, const char *s, bool draw )
  110. {
  111. int rw;
  112. if ( ! s )
  113. return 0;
  114. fl_font( FL_COURIER, min( h, 18 ) );
  115. rw = fl_width( s );
  116. if ( fl_not_clipped( x, y, rw, h ) && draw )
  117. {
  118. gui_clear_area( x, y, w, h );
  119. if ( color )
  120. fl_color( velocity_colors[ color ] );
  121. else
  122. fl_color( FL_DARK_CYAN );
  123. fl_draw( s, x, y + h / 2 + fl_descent() );
  124. }
  125. return rw;
  126. }
  127. void
  128. gui_draw_shape ( int x, int y, int w, int h, int bw, int shape, int state, int flags, int color )
  129. {
  130. /* take advantage of FLTK's clipping */
  131. if ( ! fl_not_clipped( x, y, w, h ) )
  132. return;
  133. if ( flags & F_PLAYHEAD )
  134. state = state == FULL ? HIT : PLAYHEAD;
  135. else
  136. if ( flags & F_SELECTED )
  137. state = SELECTED;
  138. if ( state == FULL && color )
  139. fl_color( velocity_colors[ color ] );
  140. else
  141. fl_color( state_colors[ state ] );
  142. switch ( shape )
  143. {
  144. case CIRCLE:
  145. fl_pie( x + bw / 2, y + bw / 2, w - bw, h - bw, 0, 360 );
  146. break;
  147. case SQUARE:
  148. fl_rectf( x + bw, y + bw, w - bw * 2, h - bw * 2 );
  149. break;
  150. case HALF_CIRCLE:
  151. fl_pie( x + bw / 2, y + bw / 2, w - bw, h - bw, 0, 360 / 2);
  152. break;
  153. case DIAMOND:
  154. 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 );
  155. break;
  156. default:
  157. ASSERTION( "unknown shape" );
  158. break;
  159. }
  160. if ( flags & F_P1 || flags & F_P2 )
  161. {
  162. if ( flags & F_P1 )
  163. fl_color( FL_GREEN );
  164. else
  165. fl_color( FL_RED );
  166. int rw = w / 4;
  167. int rh = h / 4;
  168. fl_rectf( x + (w / 2) - (rw / 2), y + (h / 2) - (rh / 2), rw, rh );
  169. }
  170. }
  171. extern UI *ui;
  172. static
  173. void
  174. clear_status ( void *arg )
  175. {
  176. ui->status->value( "" );
  177. }
  178. /** inform the user of something via a status bar */
  179. void
  180. gui_status ( const char *fmt, ... )
  181. {
  182. va_list args;
  183. static char pat[256];
  184. if ( fmt )
  185. {
  186. va_start( args, fmt );
  187. vsnprintf( pat, 256, fmt, args );
  188. va_end( args );
  189. }
  190. ui->status->value( pat );
  191. Fl::add_timeout( 5.0f, clear_status );
  192. }