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.

220 lines
6.0KB

  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. if ( _flow )
  96. {
  97. H = 0;
  98. W = 0;
  99. }
  100. else
  101. {
  102. H = _initial_height;
  103. W = _initial_width;
  104. }
  105. for ( int i = 0; i < children(); ++i )
  106. {
  107. Fl_Widget *o = child( i );
  108. if ( ! o->visible() )
  109. continue;
  110. if ( _flow )
  111. {
  112. if ( _flowdown )
  113. {
  114. if ( (Y - RY) + o->h() < RH )
  115. {
  116. /* if it'll fit in this column, put it below the previous widget */
  117. X = LX;
  118. }
  119. else
  120. Y = 0;
  121. }
  122. else if ( X + o->w() >= _initial_width )
  123. {
  124. /* maybe wrap to the next row */
  125. H += RH + _vspacing;
  126. RY = Y;
  127. RH = 0;
  128. if ( X > W )
  129. W = X;
  130. X = 0;
  131. }
  132. else
  133. {
  134. /* otherwise, put it in the next column */
  135. Y = H;
  136. }
  137. }
  138. RH = o->h() > RH ? o->h() : RH;
  139. LW = o->w();
  140. LH = o->h();
  141. LX = X;
  142. LY = Y;
  143. if ( _flow )
  144. {
  145. if ( _flowdown )
  146. Y += LH + _vspacing;
  147. else
  148. Y += RH + _vspacing;
  149. X += LW + _hspacing;
  150. }
  151. else
  152. {
  153. if ( type() == Fl_Pack::HORIZONTAL )
  154. {
  155. X += LW + _hspacing;
  156. LH = _initial_height;
  157. W = X;
  158. }
  159. else
  160. {
  161. Y += LH + _vspacing;
  162. LW = _initial_width;
  163. H = Y;
  164. }
  165. }
  166. if ( ! ( o->x() == x() + LX &&
  167. o->y() == y() + LY &&
  168. o->w() == LW &&
  169. o->h() == LH ) )
  170. o->resize( x() + LX,
  171. y() + LY,
  172. LW,
  173. LH);
  174. }
  175. if ( _flow )
  176. {
  177. H += RH;
  178. if ( X > W )
  179. W = X;
  180. }
  181. Fl_Group::resize( x(), y(), W, H );
  182. }
  183. };