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.

238 lines
6.6KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2009 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. #pragma once
  19. #include <FL/Fl_Group.H>
  20. #include <FL/Fl_Pack.H>
  21. class Fl_Flowpack : public Fl_Group
  22. {
  23. int _hspacing;
  24. int _vspacing;
  25. bool _flow;
  26. bool _flowdown;
  27. int _initial_height;
  28. int _initial_width;
  29. public:
  30. Fl_Flowpack ( int X, int Y, int W, int H, const char *L = 0 )
  31. : Fl_Group( X, Y, W, H, L )
  32. {
  33. resizable( 0 );
  34. _hspacing = _vspacing = 0;
  35. _initial_width = W;
  36. _initial_height = H;
  37. _flow = true;
  38. _flowdown = false;
  39. }
  40. virtual ~Fl_Flowpack ( )
  41. {
  42. }
  43. void vspacing ( int v ) { _vspacing = v; }
  44. int vspacing ( void ) const { return _vspacing; };
  45. void hspacing ( int h ) { _hspacing = h; }
  46. int hspacing ( void ) const { return _hspacing; };
  47. bool flow ( void ) const { return _flow; }
  48. void flow ( bool v ) { _flow = v; }
  49. bool flowdown ( void ) const { return _flowdown; }
  50. void flowdown ( bool v ) { _flowdown = v; }
  51. void
  52. add ( Fl_Widget *w )
  53. {
  54. Fl_Group::add( w );
  55. dolayout();
  56. }
  57. void
  58. remove ( Fl_Widget *w )
  59. {
  60. Fl_Group::remove( w );
  61. dolayout();
  62. }
  63. void
  64. resize ( int X, int Y, int W, int H )
  65. {
  66. _initial_width = W;
  67. _initial_height = H;
  68. layout();
  69. Fl_Group::resize( X, Y, w(), h() );
  70. }
  71. void
  72. draw ( void )
  73. {
  74. layout();
  75. Fl_Group::draw();
  76. }
  77. void dolayout ( void )
  78. {
  79. layout();
  80. }
  81. void
  82. layout ( void )
  83. {
  84. resizable( 0 );
  85. int W;
  86. int H;
  87. int X = 0;
  88. int Y = 0;
  89. int LW = 0;
  90. int LH = 0;
  91. int LX = 0;
  92. int LY = 0;
  93. int RH = 0;
  94. // int RY = 0;
  95. int CW = 0;
  96. if ( _flow )
  97. {
  98. H = 0;
  99. W = 0;
  100. }
  101. else
  102. {
  103. H = _initial_height;
  104. W = _initial_width;
  105. }
  106. for ( int i = 0; i < children(); ++i )
  107. {
  108. Fl_Widget *o = child( i );
  109. if ( ! o->visible() )
  110. continue;
  111. if ( _flow )
  112. {
  113. if ( _flowdown )
  114. {
  115. if ( Y + o->h() <= _initial_height )
  116. {
  117. /* if it'll fit in this column, put it below the previous widget */
  118. X = LX;
  119. }
  120. else
  121. {
  122. Y = H;
  123. CW = 0;
  124. }
  125. CW = o->w() > CW ? o->w() : CW;
  126. RH = Y + o->h() > RH ? Y + o->h() : RH;
  127. }
  128. else
  129. {
  130. if ( X + o->w() >= _initial_width )
  131. {
  132. /* maybe wrap to the next row */
  133. H += RH + _vspacing;
  134. // RY = Y;
  135. RH = 0;
  136. if ( X > W )
  137. W = X;
  138. X = 0;
  139. }
  140. else
  141. {
  142. /* otherwise, put it in the next column */
  143. Y = H;
  144. }
  145. RH = o->h() > RH ? o->h() : RH;
  146. }
  147. }
  148. LW = o->w();
  149. LH = o->h();
  150. LX = X;
  151. LY = Y;
  152. if ( _flow )
  153. {
  154. if ( _flowdown )
  155. {
  156. Y += LH + _vspacing;
  157. X += CW + _hspacing;
  158. }
  159. else
  160. {
  161. Y += RH + _vspacing;
  162. X += LW + _hspacing;
  163. }
  164. }
  165. else
  166. {
  167. if ( type() == Fl_Pack::HORIZONTAL )
  168. {
  169. X += LW + _hspacing;
  170. LH = _initial_height;
  171. W = X;
  172. }
  173. else
  174. {
  175. Y += LH + _vspacing;
  176. LW = _initial_width;
  177. H = Y;
  178. }
  179. }
  180. if ( ! ( o->x() == x() + LX &&
  181. o->y() == y() + LY &&
  182. o->w() == LW &&
  183. o->h() == LH ) )
  184. o->resize( x() + LX,
  185. y() + LY,
  186. LW,
  187. LH);
  188. }
  189. if ( _flow )
  190. {
  191. H += RH;
  192. if ( X > W )
  193. W = X;
  194. /* if ( _flowdown ) */
  195. /* H = _initial_height; */
  196. }
  197. Fl_Group::resize( x(), y(), W, H );
  198. }
  199. };