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.

199 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. _increment = 30;
  36. _yposition = 0;
  37. // color( FL_WHITE );
  38. }
  39. int increment ( void ) const { return _increment; }
  40. void increment ( int v ) { _increment = v; }
  41. void yposition ( int v )
  42. {
  43. if ( ! children() )
  44. return;
  45. int Y = v;
  46. if ( Y > 0 )
  47. Y = 0;
  48. const int H = h() - (sbh * 2);
  49. Fl_Widget *o = child( 0 );
  50. if ( o->h() > H &&
  51. Y + o->h() < H )
  52. Y = H - o->h();
  53. else if ( o->h() < H )
  54. Y = 0;
  55. if ( _yposition != Y )
  56. {
  57. _yposition = Y;
  58. damage( FL_DAMAGE_SCROLL );
  59. }
  60. }
  61. int yposition ( void ) const
  62. {
  63. if ( children() )
  64. return child( 0 )->y() - (y() + sbh);
  65. return 0;
  66. }
  67. void bbox ( int &X, int &Y, int &W, int &H )
  68. {
  69. X = x();
  70. Y = y() + sbh;
  71. W = w();
  72. H = h() - (sbh * 2);
  73. }
  74. virtual void
  75. draw ( void )
  76. {
  77. if ( ! children() )
  78. return;
  79. if ( ! fl_not_clipped( x(), y(), w(), h() ) )
  80. return;
  81. // draw_box();
  82. Fl_Widget *o = child( 0 );
  83. o->position( x(), y() + sbh + _yposition );
  84. if ( damage() != FL_DAMAGE_CHILD )
  85. {
  86. fl_rectf( x(), y(), w(), h(), color() );
  87. fl_font( FL_HELVETICA, 12 );
  88. if ( o->y() != y() + sbh )
  89. {
  90. fl_draw_box( box(), x(), y(), w(), sbh, color() );
  91. fl_color( FL_BLACK );
  92. fl_draw( "@2<", x(), y(), w(), sbh, FL_ALIGN_CENTER );
  93. }
  94. if ( o->h() > h() - (sbh * 2) && o->y() + o->h() != y() + h() - sbh )
  95. {
  96. fl_draw_box( box(), x(), y() + h() - sbh, w(), sbh, color() );
  97. fl_color( FL_BLACK );
  98. fl_draw( "@2>", x(), y() + h() - sbh, w(), sbh, FL_ALIGN_CENTER );
  99. }
  100. }
  101. fl_push_clip( x(), y() + sbh, w(), h() - (sbh * 2 ) );
  102. draw_children();
  103. fl_pop_clip();
  104. }
  105. virtual int
  106. handle ( int m )
  107. {
  108. if ( Fl_Group::handle( m ) )
  109. return 1;
  110. switch ( m )
  111. {
  112. case FL_PUSH:
  113. {
  114. if ( Fl::event_button1() )
  115. {
  116. if ( Fl::event_inside( x(), y(), w(), sbh ) )
  117. {
  118. yposition( yposition() + ( h() / 4 ) );
  119. return 1;
  120. }
  121. else if ( Fl::event_inside( x(), y() + h() - sbh, w(), sbh ) )
  122. {
  123. yposition( yposition() - (h() / 4 ) );
  124. return 1;
  125. }
  126. return 0;
  127. }
  128. }
  129. return 0;
  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. };