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.

200 lines
6.0KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2010 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. /* Scrolling group suitable for containing a single child (a
  19. * pack). When the Fl_Packscroller is resized, the child will be resized
  20. * too. No scrollbars are displayed, but the widget responds to
  21. * FL_MOUSEWHEEL events. */
  22. #pragma once
  23. #include <FL/Fl_Group.H>
  24. #include <FL/fl_draw.H>
  25. #include <FL/Fl.H>
  26. /* FIXME: Optimize scroll */
  27. class Fl_Packscroller : public Fl_Group
  28. {
  29. int _increment;
  30. int _yposition;
  31. static const int sbh = 15; /* scroll button height */
  32. public:
  33. Fl_Packscroller ( int X, int Y, int W, int H, const char *L = 0 ) : Fl_Group( X, Y, W, H, L )
  34. {
  35. clip_children( 1 );
  36. _increment = 30;
  37. _yposition = 0;
  38. // color( FL_WHITE );
  39. }
  40. int increment ( void ) const { return _increment; }
  41. void increment ( int v ) { _increment = v; }
  42. void yposition ( int v )
  43. {
  44. if ( ! children() )
  45. return;
  46. int Y = v;
  47. if ( Y > 0 )
  48. Y = 0;
  49. const int H = h() - (sbh * 2);
  50. Fl_Widget *o = child( 0 );
  51. if ( o->h() > H &&
  52. Y + o->h() < H )
  53. Y = H - o->h();
  54. else if ( o->h() < H )
  55. Y = 0;
  56. if ( _yposition != Y )
  57. {
  58. _yposition = Y;
  59. damage( FL_DAMAGE_SCROLL );
  60. }
  61. }
  62. int yposition ( void ) const
  63. {
  64. if ( children() )
  65. return child( 0 )->y() - (y() + sbh);
  66. return 0;
  67. }
  68. void bbox ( int &X, int &Y, int &W, int &H )
  69. {
  70. X = x();
  71. Y = y() + sbh;
  72. W = w();
  73. H = h() - (sbh * 2);
  74. }
  75. virtual void
  76. draw ( void )
  77. {
  78. if ( ! children() )
  79. return;
  80. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  81. return;
  82. // draw_box();
  83. Fl_Widget *o = child( 0 );
  84. o->position( x(), y() + sbh + _yposition );
  85. if ( damage() != FL_DAMAGE_CHILD )
  86. {
  87. fl_rectf( x(), y(), w(), h(), color() );
  88. fl_font( FL_HELVETICA, 12 );
  89. if ( o->y() != y() + sbh )
  90. {
  91. fl_draw_box( box(), x(), y(), w(), sbh, color() );
  92. fl_color( FL_BLACK );
  93. fl_draw( "@2<", x(), y(), w(), sbh, FL_ALIGN_CENTER );
  94. }
  95. if ( o->h() > h() - (sbh * 2) && o->y() + o->h() != y() + h() - sbh )
  96. {
  97. fl_draw_box( box(), x(), y() + h() - sbh, w(), sbh, color() );
  98. fl_color( FL_BLACK );
  99. fl_draw( "@2>", x(), y() + h() - sbh, w(), sbh, FL_ALIGN_CENTER );
  100. }
  101. }
  102. fl_push_clip( x(), y() + sbh, w(), h() - (sbh * 2 ) );
  103. draw_children();
  104. fl_pop_clip();
  105. }
  106. virtual int
  107. handle ( int m )
  108. {
  109. if ( Fl_Group::handle( m ) )
  110. return 1;
  111. switch ( m )
  112. {
  113. case FL_PUSH:
  114. {
  115. if ( Fl::event_button1() )
  116. {
  117. if ( Fl::event_inside( x(), y(), w(), sbh ) )
  118. {
  119. yposition( yposition() + ( h() / 4 ) );
  120. return 1;
  121. }
  122. else if ( Fl::event_inside( x(), y() + h() - sbh, w(), sbh ) )
  123. {
  124. yposition( yposition() - (h() / 4 ) );
  125. return 1;
  126. }
  127. return 0;
  128. }
  129. }
  130. case FL_ENTER:
  131. case FL_LEAVE:
  132. return 1;
  133. case FL_FOCUS:
  134. case FL_UNFOCUS:
  135. return 1;
  136. case FL_KEYBOARD:
  137. {
  138. if ( Fl::event_key() == FL_Up )
  139. {
  140. yposition( yposition() + ( h() / 4 ) );
  141. return 1;
  142. }
  143. else if ( Fl::event_key() == FL_Down )
  144. {
  145. yposition( yposition() - (h() / 4 ) );
  146. return 1;
  147. }
  148. return 0;
  149. }
  150. case FL_MOUSEWHEEL:
  151. {
  152. yposition( yposition() - ( Fl::event_dy() * _increment ) );
  153. return 1;
  154. }
  155. }
  156. return 0;
  157. }
  158. };