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.

188 lines
5.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.H"
  19. #include "Region.H"
  20. #include "Timeline.H"
  21. #include <FL/fl_draw.H>
  22. #include <FL/Fl.H>
  23. #include <FL/Fl_Group.H>
  24. #include <FL/Fl_Widget.H>
  25. #include <stdio.h>
  26. extern Timeline timeline;
  27. Region::Region ( int X, int Y, int W, int H, const char *L=0 ) : Waveform( X, Y, W, H, L )
  28. {
  29. align( FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_BOTTOM | FL_ALIGN_CLIP );
  30. labeltype( FL_SHADOW_LABEL );
  31. labelcolor( FL_WHITE );
  32. box( FL_PLASTIC_UP_BOX );
  33. _track = NULL;
  34. }
  35. void
  36. Region::trim ( enum trim_e t, int X )
  37. {
  38. switch ( t )
  39. {
  40. case LEFT:
  41. {
  42. int d = X - x();
  43. _start += d;
  44. resize( x() + d, y(), w() - d, h() );
  45. break;
  46. }
  47. case RIGHT:
  48. {
  49. int d = (x() + w()) - X;
  50. _end -= d;
  51. resize( x(), y(), w() - d, h() );
  52. break;
  53. }
  54. default:
  55. return;
  56. }
  57. redraw();
  58. parent()->redraw();
  59. }
  60. int
  61. Region::handle ( int m )
  62. {
  63. if ( Fl_Widget::handle( m ) )
  64. return 1;
  65. static int ox, oy;
  66. static enum trim_e trimming;
  67. switch ( m )
  68. {
  69. case FL_PUSH:
  70. {
  71. int X = Fl::event_x();
  72. int Y = Fl::event_y();
  73. if ( Fl::event_state() & FL_CTRL )
  74. {
  75. switch ( Fl::event_button() )
  76. {
  77. case 1:
  78. trim( trimming = LEFT, X );
  79. break;
  80. case 3:
  81. trim( trimming = RIGHT, X );
  82. break;
  83. default:
  84. return 0;
  85. }
  86. fl_cursor( FL_CURSOR_WE );
  87. return 1;
  88. }
  89. else
  90. {
  91. ox = x() - Fl::event_x();
  92. oy = y() - Fl::event_y();
  93. if ( Fl::event_button() == 2 )
  94. {
  95. // _track->add( new Region( *this ) );
  96. }
  97. return 1;
  98. }
  99. return 0;
  100. break;
  101. }
  102. case FL_RELEASE:
  103. fl_cursor( FL_CURSOR_DEFAULT );
  104. return 1;
  105. case FL_DRAG:
  106. if ( Fl::event_state() & FL_CTRL )
  107. if ( trimming )
  108. {
  109. trim( trimming, Fl::event_x() );
  110. return 1;
  111. }
  112. else
  113. return 0;
  114. if ( ox + Fl::event_x() >= _track->x() )
  115. position( ox + Fl::event_x(), y() );
  116. if ( Fl::event_y() > y() + h() )
  117. {
  118. if ( _track->next() )
  119. _track->next()->add( this );
  120. }
  121. else
  122. if ( Fl::event_y() < y() )
  123. {
  124. if ( _track->prev() )
  125. _track->prev()->add( this );
  126. }
  127. // if ( Fl::event_y() - oy >= h() )
  128. parent()->redraw();
  129. fl_cursor( FL_CURSOR_MOVE );
  130. if ( Fl::event_x() >= timeline.scroll->x() + timeline.scroll->w() ||
  131. Fl::event_x() <= timeline.scroll->x() )
  132. {
  133. int d;
  134. if ( Fl::event_x() <= timeline.scroll->x() )
  135. d = -100;
  136. else
  137. d = 100;
  138. /* this drag needs to scroll */
  139. timeline.scroll->position( timeline.scroll->xposition() + d, timeline.scroll->yposition() );
  140. }
  141. return 1;
  142. default:
  143. return 0;
  144. break;
  145. }
  146. }
  147. void
  148. Region::draw ( void )
  149. {
  150. draw_box();
  151. // fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );
  152. Waveform::draw();
  153. // fl_pop_clip();
  154. draw_label();
  155. }