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.

235 lines
6.5KB

  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 += 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_ENGRAVED_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. if ( abs_x() < scroll_x() )
  71. dx = min( 32767, scroll_x() - abs_x() );
  72. {
  73. const Fl_Boxtype b = FL_ROUND_UP_BOX;
  74. const int bx = Fl::box_dx( b );
  75. const int bw = Fl::box_dw( b );
  76. if ( align & FL_ALIGN_BOTTOM )
  77. fl_draw_box( b, X - dx - bx, Y + H - lh, lw + bw, lh, FL_GRAY );
  78. else if ( align == FL_ALIGN_LEFT )
  79. fl_draw_box( b, X - dx, Y + ((H / 2) - (lh / 2)), lw + bw, lh, FL_GRAY );
  80. else if ( align & FL_ALIGN_TOP )
  81. fl_draw_box( b, X - dx - bx + ((W / 2) - (lw / 2)), Y + ((H / 2) - (lh / 2)), lw + bw, lh, FL_GRAY );
  82. }
  83. lab.draw( X - dx, Y, W, H, align );
  84. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  85. }
  86. int
  87. Sequence_Widget::dispatch ( int m )
  88. {
  89. Sequence_Widget::_current = this;
  90. if ( selected() )
  91. {
  92. Loggable::block_start();
  93. int r = 0;
  94. for ( list <Sequence_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
  95. if ( *i != this )
  96. r |= (*i)->handle( m );
  97. r |= handle( m );
  98. Loggable::block_end();
  99. return r;
  100. }
  101. else
  102. return handle( m );
  103. }
  104. /* base hanlde just does basic dragging */
  105. int
  106. Sequence_Widget::handle ( int m )
  107. {
  108. int X = Fl::event_x();
  109. int Y = Fl::event_y();
  110. Logger _log( this );
  111. switch ( m )
  112. {
  113. case FL_ENTER:
  114. fl_cursor( FL_CURSOR_HAND );
  115. return 1;
  116. case FL_LEAVE:
  117. fl_cursor( FL_CURSOR_DEFAULT );
  118. return 1;
  119. case FL_PUSH:
  120. {
  121. /* deletion */
  122. if ( Fl::event_state() & FL_CTRL &&
  123. Fl::event_button3() )
  124. {
  125. redraw();
  126. _track->queue_delete( this );
  127. return 1;
  128. }
  129. else
  130. if ( Fl::event_button1() )
  131. return 1;
  132. return 0;
  133. }
  134. case FL_RELEASE:
  135. if ( _drag )
  136. {
  137. end_drag();
  138. _log.release();
  139. }
  140. fl_cursor( FL_CURSOR_HAND );
  141. return 1;
  142. case FL_DRAG:
  143. case FL_DND_DRAG:
  144. {
  145. if ( ! _drag )
  146. {
  147. begin_drag ( Drag( x() - X, y() - Y ) );
  148. _log.hold();
  149. }
  150. fl_cursor( FL_CURSOR_MOVE );
  151. const int ox = _drag->x;
  152. redraw();
  153. if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() )
  154. {
  155. int nx = (ox + X) - _track->x();
  156. // _r->offset = timeline->x_to_ts( nx ) + timeline->xoffset;
  157. offset( timeline->x_to_ts( nx ) + timeline->xoffset );
  158. if ( Sequence_Widget::_current == this )
  159. _track->snap( this );
  160. }
  161. if ( X >= _track->x() + _track->w() ||
  162. X <= _track->x() )
  163. {
  164. /* this drag needs to scroll */
  165. nframes_t pos = timeline->xoffset;
  166. nframes_t d = timeline->x_to_ts( 100 );
  167. if ( X <= _track->x() )
  168. {
  169. if ( pos > d )
  170. pos -= d;
  171. else
  172. pos = 0;
  173. }
  174. else
  175. pos += d;
  176. timeline->xposition( timeline->ts_to_x( pos ) );
  177. _track->redraw();
  178. }
  179. return 1;
  180. }
  181. default:
  182. return 0;
  183. }
  184. }