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.

236 lines
6.4KB

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