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.

212 lines
5.6KB

  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 )
  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 = 0;
  43. lab.type = FL_SHADOW_LABEL;
  44. lab.value = label;
  45. lab.font = FL_HELVETICA;
  46. lab.size = 14;
  47. int W = w();
  48. int H = h();
  49. if ( align & FL_ALIGN_INSIDE )
  50. {
  51. X += Fl::box_dx( box() );
  52. Y += Fl::box_dy( box() );
  53. W -= Fl::box_dw( box() );
  54. H -= Fl::box_dh( box() );
  55. }
  56. if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );
  57. int dx = 0;
  58. if ( abs_x() < scroll_x() )
  59. dx = min( 32767, scroll_x() - abs_x() );
  60. lab.draw( X - dx, Y, W, H, align );
  61. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  62. }
  63. int
  64. Track_Widget::dispatch ( int m )
  65. {
  66. Track_Widget::_current = this;
  67. if ( selected() )
  68. {
  69. Loggable::block_start();
  70. int r = 0;
  71. for ( list <Track_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
  72. if ( *i != this )
  73. r |= (*i)->handle( m );
  74. r |= handle( m );
  75. Loggable::block_end();
  76. return r;
  77. }
  78. else
  79. return handle( m );
  80. }
  81. /* base hanlde just does basic dragging */
  82. int
  83. Track_Widget::handle ( int m )
  84. {
  85. int X = Fl::event_x();
  86. int Y = Fl::event_y();
  87. Logger _log( this );
  88. switch ( m )
  89. {
  90. case FL_ENTER:
  91. fl_cursor( FL_CURSOR_HAND );
  92. return 1;
  93. case FL_LEAVE:
  94. fl_cursor( FL_CURSOR_DEFAULT );
  95. return 1;
  96. case FL_PUSH:
  97. {
  98. if ( Fl::event_state() & FL_CTRL &&
  99. Fl::event_button3() )
  100. {
  101. redraw();
  102. _track->queue_delete( this );
  103. return 0;
  104. }
  105. else
  106. if ( Fl::event_button1() )
  107. return 1;
  108. return 0;
  109. }
  110. case FL_RELEASE:
  111. if ( _drag )
  112. {
  113. _log.release();
  114. delete _drag;
  115. _drag = NULL;
  116. }
  117. fl_cursor( FL_CURSOR_HAND );
  118. return 1;
  119. case FL_DRAG:
  120. {
  121. if ( ! _drag )
  122. {
  123. _drag = new Drag( x() - X, y() - Y );
  124. _log.hold();
  125. }
  126. const int ox = _drag->x;
  127. // _current->_drag->x;
  128. /* const int ox = _drag->x; */
  129. /* const int oy = _drag->y; */
  130. redraw();
  131. if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() )
  132. {
  133. int nx = (ox + X) - _track->x();
  134. // _offset = timeline->x_to_ts( nx ) + timeline->xoffset;
  135. offset( timeline->x_to_ts( nx ) + timeline->xoffset );
  136. if ( Track_Widget::_current == this )
  137. _track->snap( this );
  138. }
  139. // _track->redraw();
  140. fl_cursor( FL_CURSOR_MOVE );
  141. if ( X >= _track->x() + _track->w() ||
  142. X <= _track->x() )
  143. {
  144. /* this drag needs to scroll */
  145. nframes_t pos = timeline->xoffset;
  146. nframes_t d = timeline->x_to_ts( 100 );
  147. if ( X <= _track->x() )
  148. {
  149. if ( pos > d )
  150. pos -= d;
  151. else
  152. pos = 0;
  153. }
  154. else
  155. pos += d;
  156. timeline->position( timeline->ts_to_x( pos ) );
  157. _track->redraw();
  158. // timeline->redraw();
  159. }
  160. return 1;
  161. }
  162. default:
  163. return 0;
  164. }
  165. }