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.

Fl_Flowpack.H 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. };