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.

228 lines
6.1KB

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