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.

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