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.

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