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.

179 lines
4.9KB

  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. void
  21. Track_Widget::draw_label ( const char *label, Fl_Align align )
  22. {
  23. int X, Y;
  24. X = x();
  25. Y = y();
  26. /* FIXME: why do we have to to this here? why doesn't Fl_Lable::draw take care of this stuff? */
  27. if ( ! (align & FL_ALIGN_INSIDE) )
  28. {
  29. if ( align & FL_ALIGN_RIGHT )
  30. {
  31. X += w();
  32. align = (Fl_Align)((align & ~FL_ALIGN_RIGHT) | FL_ALIGN_LEFT);
  33. }
  34. if ( align & FL_ALIGN_BOTTOM )
  35. {
  36. Y += h();
  37. align = (Fl_Align)((align & ~FL_ALIGN_BOTTOM) | FL_ALIGN_TOP);
  38. }
  39. }
  40. Fl_Label lab;
  41. lab.color = 0;
  42. lab.type = FL_SHADOW_LABEL;
  43. lab.value = label;
  44. lab.font = FL_HELVETICA;
  45. lab.size = 14;
  46. int W = w();
  47. int H = h();
  48. if ( align & FL_ALIGN_INSIDE )
  49. {
  50. X += Fl::box_dx( box() );
  51. Y += Fl::box_dy( box() );
  52. W -= Fl::box_dw( box() );
  53. H -= Fl::box_dh( box() );
  54. }
  55. if ( align & FL_ALIGN_CLIP ) fl_push_clip( X, Y, W, H );
  56. int dx = 0;
  57. if ( abs_x() < scroll_x() )
  58. dx = min( 32767, scroll_x() - abs_x() );
  59. lab.draw( X - dx, Y, W, H, align );
  60. if ( align & FL_ALIGN_CLIP ) fl_pop_clip();
  61. }
  62. /* base hanlde just does basic dragging */
  63. int
  64. Track_Widget::handle ( int m )
  65. {
  66. static int ox, oy;
  67. static bool dragging = false;
  68. int X = Fl::event_x();
  69. int Y = Fl::event_y();
  70. Logger _log( this );
  71. switch ( m )
  72. {
  73. case FL_ENTER:
  74. fl_cursor( FL_CURSOR_HAND );
  75. return 1;
  76. case FL_LEAVE:
  77. fl_cursor( FL_CURSOR_DEFAULT );
  78. return 1;
  79. case FL_PUSH:
  80. {
  81. ox = x() - X;
  82. oy = y() - Y;
  83. if ( Fl::event_state() & FL_CTRL &&
  84. Fl::event_button() == 3 )
  85. {
  86. // log_destroy();
  87. redraw();
  88. _track->queue_delete( this );
  89. return 0;
  90. }
  91. return 1;
  92. }
  93. case FL_RELEASE:
  94. if ( dragging )
  95. _log.release();
  96. dragging = false;
  97. fl_cursor( FL_CURSOR_DEFAULT );
  98. return 1;
  99. case FL_DRAG:
  100. {
  101. if ( ! dragging )
  102. {
  103. dragging = true;
  104. _log.hold();
  105. }
  106. redraw();
  107. if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() )
  108. {
  109. int nx = (ox + X) - _track->x();
  110. // _offset = timeline->x_to_ts( nx ) + timeline->xoffset;
  111. offset( timeline->x_to_ts( nx ) + timeline->xoffset );
  112. _track->snap( this );
  113. }
  114. // _track->redraw();
  115. fl_cursor( FL_CURSOR_MOVE );
  116. if ( X >= _track->x() + _track->w() ||
  117. X <= _track->x() )
  118. {
  119. /* this drag needs to scroll */
  120. nframes_t pos = timeline->xoffset;
  121. nframes_t d = timeline->x_to_ts( 100 );
  122. if ( X <= _track->x() )
  123. {
  124. if ( pos > d )
  125. pos -= d;
  126. else
  127. pos = 0;
  128. }
  129. else
  130. pos += d;
  131. timeline->position( timeline->ts_to_x( pos ) );
  132. _track->redraw();
  133. // timeline->redraw();
  134. }
  135. return 1;
  136. }
  137. default:
  138. return 0;
  139. }
  140. }