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.

218 lines
5.7KB

  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. /* static int ox, oy; */
  86. /* static bool dragging = false; */
  87. int X = Fl::event_x();
  88. int Y = Fl::event_y();
  89. Logger _log( this );
  90. switch ( m )
  91. {
  92. case FL_ENTER:
  93. fl_cursor( FL_CURSOR_HAND );
  94. return 1;
  95. case FL_LEAVE:
  96. fl_cursor( FL_CURSOR_DEFAULT );
  97. return 1;
  98. case FL_PUSH:
  99. {
  100. /* ox = x() - X; */
  101. /* oy = y() - Y; */
  102. if ( Fl::event_state() & FL_CTRL &&
  103. Fl::event_button() == 3 )
  104. {
  105. // log_destroy();
  106. redraw();
  107. _track->queue_delete( this );
  108. return 0;
  109. }
  110. return 1;
  111. }
  112. case FL_RELEASE:
  113. if ( _drag )
  114. {
  115. _log.release();
  116. delete _drag;
  117. _drag = NULL;
  118. }
  119. fl_cursor( FL_CURSOR_DEFAULT );
  120. return 1;
  121. case FL_DRAG:
  122. {
  123. if ( ! _drag )
  124. {
  125. _drag = new Drag( x() - X, y() - Y );
  126. _log.hold();
  127. }
  128. const int ox = _drag->x;
  129. // _current->_drag->x;
  130. /* const int ox = _drag->x; */
  131. /* const int oy = _drag->y; */
  132. redraw();
  133. if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() )
  134. {
  135. int nx = (ox + X) - _track->x();
  136. // _offset = timeline->x_to_ts( nx ) + timeline->xoffset;
  137. offset( timeline->x_to_ts( nx ) + timeline->xoffset );
  138. if ( Track_Widget::_current == this )
  139. _track->snap( this );
  140. }
  141. // _track->redraw();
  142. fl_cursor( FL_CURSOR_MOVE );
  143. if ( X >= _track->x() + _track->w() ||
  144. X <= _track->x() )
  145. {
  146. /* this drag needs to scroll */
  147. nframes_t pos = timeline->xoffset;
  148. nframes_t d = timeline->x_to_ts( 100 );
  149. if ( X <= _track->x() )
  150. {
  151. if ( pos > d )
  152. pos -= d;
  153. else
  154. pos = 0;
  155. }
  156. else
  157. pos += d;
  158. timeline->position( timeline->ts_to_x( pos ) );
  159. _track->redraw();
  160. // timeline->redraw();
  161. }
  162. return 1;
  163. }
  164. default:
  165. return 0;
  166. }
  167. }