Non reinvents the DAW. Powerful enough to form a complete studio, fast and light enough to run on low-end hardware like the eeePC or Raspberry Pi, and so reliable that it can be used live https://non.tuxfamily.org/
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.

213 lines
6.6KB

  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();
  49. // - (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 * top_sb_visible() );
  72. W = w();
  73. H = h() - ( sbh * ( top_sb_visible() + bottom_sb_visible() ) );
  74. }
  75. int top_sb_visible ( void )
  76. {
  77. return children() && child(0)->y() != y() ? 1 : 0;
  78. }
  79. int bottom_sb_visible ( void )
  80. {
  81. if ( children() )
  82. {
  83. Fl_Widget *o = child( 0 );
  84. if ( o->h() > h() && o->y() + o->h() != y() + h() )
  85. return 1;
  86. }
  87. return 0;
  88. }
  89. virtual void
  90. draw ( void )
  91. {
  92. if ( damage() & FL_DAMAGE_ALL )
  93. {
  94. fl_rectf( x(), y(), w(), h(), color() );
  95. }
  96. if ( ! children() )
  97. return;
  98. Fl_Widget *o = child( 0 );
  99. o->position( x(), y() + _yposition );
  100. const int top_sb = top_sb_visible();
  101. const int bottom_sb = bottom_sb_visible();
  102. fl_push_clip( x(), y() + ( sbh * top_sb ), w(), h() - (sbh * (top_sb + bottom_sb) ));
  103. draw_children();
  104. fl_pop_clip();
  105. fl_font( FL_HELVETICA, 12 );
  106. if ( top_sb )
  107. {
  108. fl_draw_box( box(), x(), y(), w(), sbh, color() );
  109. fl_color( fl_contrast( FL_FOREGROUND_COLOR, color() ) );
  110. fl_draw( "@2<", x(), y(), w(), sbh, FL_ALIGN_CENTER );
  111. }
  112. if ( bottom_sb )
  113. {
  114. fl_draw_box( box(), x(), y() + h() - sbh, w(), sbh, color() );
  115. fl_color( fl_contrast( FL_FOREGROUND_COLOR, color() ) );
  116. fl_draw( "@2>", x(), y() + h() - sbh, w(), sbh, FL_ALIGN_CENTER );
  117. }
  118. }
  119. virtual int
  120. handle ( int m )
  121. {
  122. switch ( m )
  123. {
  124. case FL_PUSH:
  125. if ( top_sb_visible() &&
  126. Fl::event_inside( x(), y(), w(), sbh ) )
  127. {
  128. return 1;
  129. }
  130. else if ( bottom_sb_visible() &&
  131. Fl::event_inside( x(), y() + h() - sbh, w(), sbh ) )
  132. {
  133. return 1;
  134. }
  135. break;
  136. case FL_RELEASE:
  137. {
  138. if ( top_sb_visible() &&
  139. Fl::event_inside( x(), y(), w(), sbh ) )
  140. {
  141. yposition( yposition() + ( h() / 4 ) );
  142. return 1;
  143. }
  144. else if ( bottom_sb_visible() &&
  145. Fl::event_inside( x(), y() + h() - sbh, w(), sbh ) )
  146. {
  147. yposition( yposition() - (h() / 4 ) );
  148. return 1;
  149. }
  150. break;
  151. }
  152. case FL_KEYBOARD:
  153. {
  154. if ( Fl::event_key() == FL_Up )
  155. {
  156. yposition( yposition() + ( h() / 4 ) );
  157. return 1;
  158. }
  159. else if ( Fl::event_key() == FL_Down )
  160. {
  161. yposition( yposition() - (h() / 4 ) );
  162. return 1;
  163. }
  164. break;
  165. }
  166. case FL_MOUSEWHEEL:
  167. {
  168. yposition( yposition() - ( Fl::event_dy() * _increment ) );
  169. return 1;
  170. }
  171. }
  172. return Fl_Group::handle( m );
  173. }
  174. };