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.

270 lines
6.6KB

  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 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. if ( flags & F_SELECTION )
  155. fl_color( fl_darker( fl_color() ) );
  156. int bw = 1;
  157. switch ( shape )
  158. {
  159. case SQUARE:
  160. // fl_rectf( x, y, w, h, FL_BLACK );
  161. fl_color( c1 );
  162. fl_rectf( x + bw, y + bw, w - bw * 2, h - bw * 2 );
  163. if ( draw_borders )
  164. {
  165. fl_color( c2 );
  166. fl_line_style( FL_SOLID, 2 );
  167. fl_rect( x + bw + 1, y + bw + 1, w - (bw+1) * 2, h - (bw+1) * 2 );
  168. fl_line_style( FL_SOLID, 0 );
  169. }
  170. break;
  171. case BOX:
  172. fl_draw_box( FL_THIN_UP_BOX, x + bw, y + bw, w - bw * 2, h - bw * 2, c1 );
  173. break;
  174. default:
  175. ASSERTION( "unknown shape" );
  176. break;
  177. }
  178. if ( flags & F_P1 || flags & F_P2 )
  179. {
  180. if ( flags & F_P1 )
  181. fl_color( FL_GREEN );
  182. else
  183. fl_color( FL_RED );
  184. int rw = w / 4;
  185. int rh = h / 4;
  186. fl_rectf( x + (w / 2) - (rw / 2), y + (h / 2) - (rh / 2), rw, rh );
  187. }
  188. }
  189. extern UI *ui;
  190. static
  191. void
  192. clear_status ( void * )
  193. {
  194. ui->status->label( NULL );
  195. }
  196. /** inform the user of something via a status bar */
  197. void
  198. gui_status ( const char *fmt, ... )
  199. {
  200. va_list args;
  201. static char pat[256];
  202. if ( fmt )
  203. {
  204. va_start( args, fmt );
  205. vsnprintf( pat, 256, fmt, args );
  206. va_end( args );
  207. }
  208. ui->status->label( pat );
  209. Fl::add_timeout( 5.0f, clear_status );
  210. }