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.

239 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 "Track_Widget.H"
  25. list <Track_Widget *> Track_Widget::_selection;
  26. Track_Widget * Track_Widget::_current = NULL;
  27. Track_Widget * Track_Widget::_pushed = NULL;
  28. Track_Widget * Track_Widget::_original = NULL;
  29. Track_Widget * Track_Widget::_belowmouse = NULL;
  30. void
  31. Track_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 += 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_ENGRAVED_LABEL;
  54. lab.value = label;
  55. lab.font = FL_HELVETICA;
  56. lab.size = 14;
  57. int lw, lh;
  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. if ( abs_x() < scroll_x() )
  72. dx = min( 32767, scroll_x() - abs_x() );
  73. {
  74. const Fl_Boxtype b = FL_ROUND_UP_BOX;
  75. const int bx = Fl::box_dx( b );
  76. const int bw = Fl::box_dw( b );
  77. if ( align & FL_ALIGN_BOTTOM )
  78. fl_draw_box( b, X - dx - bx, Y + H - lh, lw + bw, lh, FL_GRAY );
  79. else
  80. if ( align & FL_ALIGN_LEFT )
  81. fl_draw_box( b, X - dx, Y, lw + bw, lh, FL_GRAY );
  82. else
  83. fl_draw_box( b, X - dx - bx + ((W / 2) - (lw / 2)), Y + ((H / 2) - (lh / 2)), lw + bw, lh, FL_GRAY );
  84. }
  85. lab.draw( X - dx, Y, W, H, align );
  86. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  87. }
  88. int
  89. Track_Widget::dispatch ( int m )
  90. {
  91. Track_Widget::_current = this;
  92. if ( selected() )
  93. {
  94. Loggable::block_start();
  95. int r = 0;
  96. for ( list <Track_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. Track_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 0;
  130. }
  131. else
  132. if ( Fl::event_button1() )
  133. return 1;
  134. return 0;
  135. }
  136. case FL_RELEASE:
  137. if ( _drag )
  138. {
  139. _log.release();
  140. delete _drag;
  141. _drag = NULL;
  142. }
  143. fl_cursor( FL_CURSOR_HAND );
  144. return 1;
  145. case FL_DRAG:
  146. case FL_DND_DRAG:
  147. {
  148. if ( ! _drag )
  149. {
  150. _drag = new Drag( x() - X, y() - Y );
  151. _log.hold();
  152. }
  153. fl_cursor( FL_CURSOR_MOVE );
  154. const int ox = _drag->x;
  155. redraw();
  156. if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() )
  157. {
  158. int nx = (ox + X) - _track->x();
  159. // _offset = timeline->x_to_ts( nx ) + timeline->xoffset;
  160. offset( timeline->x_to_ts( nx ) + timeline->xoffset );
  161. if ( Track_Widget::_current == this )
  162. _track->snap( this );
  163. }
  164. if ( X >= _track->x() + _track->w() ||
  165. X <= _track->x() )
  166. {
  167. /* this drag needs to scroll */
  168. nframes_t pos = timeline->xoffset;
  169. nframes_t d = timeline->x_to_ts( 100 );
  170. if ( X <= _track->x() )
  171. {
  172. if ( pos > d )
  173. pos -= d;
  174. else
  175. pos = 0;
  176. }
  177. else
  178. pos += d;
  179. timeline->xposition( timeline->ts_to_x( pos ) );
  180. _track->redraw();
  181. }
  182. return 1;
  183. }
  184. default:
  185. return 0;
  186. }
  187. }