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.

242 lines
6.7KB

  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. /* TODO:
  19. What if we solve the continuous-modification/sync issue by making a
  20. copy of the 'pushed' widget, and operating on that instead (hiding
  21. the original), then when the widget is released, copy its data into
  22. the original?
  23. */
  24. #include "Sequence_Widget.H"
  25. list <Sequence_Widget *> Sequence_Widget::_selection;
  26. Sequence_Widget * Sequence_Widget::_current = NULL;
  27. Sequence_Widget * Sequence_Widget::_pushed = NULL;
  28. Sequence_Widget * Sequence_Widget::_belowmouse = NULL;
  29. Fl_Color Sequence_Widget::_selection_color = FL_MAGENTA;
  30. void
  31. Sequence_Widget::draw_label ( const char *label, Fl_Align align, Fl_Color color )
  32. {
  33. int X, Y;
  34. X = x();
  35. Y = y();
  36. /* FIXME: why do we have to to this here? why doesn't Fl_Lable::draw take care of this stuff? */
  37. if ( ! (align & FL_ALIGN_INSIDE) )
  38. {
  39. if ( align & FL_ALIGN_RIGHT )
  40. {
  41. X += abs_w();
  42. align = (Fl_Align)((align & ~FL_ALIGN_RIGHT) | FL_ALIGN_LEFT);
  43. }
  44. if ( align & FL_ALIGN_BOTTOM )
  45. {
  46. Y += h();
  47. align = (Fl_Align)((align & ~FL_ALIGN_BOTTOM) | FL_ALIGN_TOP);
  48. }
  49. }
  50. Fl_Label lab;
  51. lab.color = color;
  52. // lab.type = FL_SHADOW_LABEL;
  53. lab.type = FL_NORMAL_LABEL;
  54. lab.value = label;
  55. lab.font = FL_HELVETICA;
  56. lab.size = 14;
  57. int lw = 0, lh = 0;
  58. fl_font( lab.font, lab.size );
  59. fl_measure( lab.value, lw, lh );
  60. int W = w();
  61. int H = h();
  62. if ( align & FL_ALIGN_INSIDE )
  63. {
  64. X += Fl::box_dx( box() );
  65. Y += Fl::box_dy( box() );
  66. W -= Fl::box_dw( box() );
  67. H -= Fl::box_dh( box() );
  68. }
  69. if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );
  70. int dx = 0;
  71. /* adjust for scrolling */
  72. if ( abs_x() < scroll_x() )
  73. dx = min( 32767, scroll_x() - abs_x() );
  74. // const Fl_Boxtype b = FL_ROUND_UP_BOX;
  75. const Fl_Boxtype b = FL_ROUNDED_BOX;
  76. const int bx = Fl::box_dx( b ) + 1;
  77. const int bw = Fl::box_dw( b ) + 1;
  78. if ( align & FL_ALIGN_BOTTOM )
  79. fl_draw_box( b, X - dx - bx, Y + H - lh, lw + bw, lh, FL_GRAY );
  80. else if ( align == FL_ALIGN_LEFT )
  81. fl_draw_box( b, X - dx, Y + ((H >> 1) - (lh >> 1)), lw + bw, lh, FL_GRAY );
  82. else if ( align & FL_ALIGN_TOP )
  83. fl_draw_box( b, X - dx - bx + ((W >> 1) - (lw >> 1)), Y + ((H >> 1) - (lh >> 1)), lw + bw, lh, FL_GRAY );
  84. // lab.draw( X - dx, Y, W, H, align );
  85. fl_color( color );
  86. fl_draw( label, ( X - dx ) + bx, Y, W, H, align );
  87. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  88. }
  89. int
  90. Sequence_Widget::dispatch ( int m )
  91. {
  92. Sequence_Widget::_current = this;
  93. if ( selected() )
  94. {
  95. Loggable::block_start();
  96. int r = 0;
  97. for ( list <Sequence_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
  98. if ( *i != this )
  99. r |= (*i)->handle( m );
  100. r |= handle( m );
  101. Loggable::block_end();
  102. return r;
  103. }
  104. else
  105. return handle( m );
  106. }
  107. /* base hanlde just does basic dragging */
  108. int
  109. Sequence_Widget::handle ( int m )
  110. {
  111. int X = Fl::event_x();
  112. int Y = Fl::event_y();
  113. Logger _log( this );
  114. switch ( m )
  115. {
  116. case FL_ENTER:
  117. fl_cursor( FL_CURSOR_HAND );
  118. return 1;
  119. case FL_LEAVE:
  120. fl_cursor( _track->cursor() );
  121. return 1;
  122. case FL_PUSH:
  123. {
  124. /* deletion */
  125. if ( Fl::event_state() & FL_CTRL &&
  126. Fl::event_button3() )
  127. {
  128. redraw();
  129. _track->queue_delete( this );
  130. return 1;
  131. }
  132. else
  133. if ( Fl::event_button1() )
  134. return 1;
  135. return 0;
  136. }
  137. case FL_RELEASE:
  138. if ( _drag )
  139. {
  140. end_drag();
  141. _log.release();
  142. }
  143. fl_cursor( FL_CURSOR_HAND );
  144. return 1;
  145. case FL_DRAG:
  146. {
  147. if ( ! _drag )
  148. {
  149. begin_drag ( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
  150. _log.hold();
  151. }
  152. fl_cursor( FL_CURSOR_MOVE );
  153. redraw();
  154. {
  155. const nframes_t of = timeline->x_to_offset( X );
  156. if ( of >= _drag->offset )
  157. {
  158. _r->offset = of - _drag->offset;
  159. if ( Sequence_Widget::_current == this )
  160. _track->snap( this );
  161. }
  162. else
  163. _r->offset = 0;
  164. }
  165. if ( X >= _track->x() + _track->w() ||
  166. X <= _track->x() )
  167. {
  168. /* this drag needs to scroll */
  169. nframes_t pos = timeline->xoffset;
  170. nframes_t d = timeline->x_to_ts( 100 );
  171. if ( X <= _track->x() )
  172. {
  173. if ( pos > d )
  174. pos -= d;
  175. else
  176. pos = 0;
  177. }
  178. else
  179. pos += d;
  180. timeline->xposition( timeline->ts_to_x( pos ) );
  181. /* FIXME: why isn't this enough? */
  182. // _track->redraw();
  183. timeline->redraw();
  184. }
  185. return 1;
  186. }
  187. default:
  188. return 0;
  189. }
  190. }