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.

251 lines
6.9KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 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. /* Fl_Scalepack
  19. This is similar to an Fl_Pack, but instead of the pack resizing
  20. itself to enclose its children, this pack resizes its children to
  21. fit itself. Of course, this only works well with highly flexible
  22. widgets, but the task comes up often enough to warrent this class.
  23. If and child happens to be the resizable() widget, then it will be
  24. resized so the all the other children can fit around it, with their
  25. current sizes (and the size of the Fl_Scalepack) maintained.
  26. NOTES: An Fl_Pack as a direct child will not work, because Fl_Pack
  27. changes its size in draw(), which throws off our resize
  28. calculation. The whole idea of widgets being able to resize
  29. themselves within draw() is horribly broken...
  30. */
  31. #include "Fl_Scalepack.H"
  32. #include <FL/Fl.H>
  33. #include <FL/fl_draw.H>
  34. #include <stdio.h>
  35. Fl_Scalepack::Fl_Scalepack ( int X, int Y, int W, int H, const char *L ) :
  36. Fl_Group( X, Y, W, H, L )
  37. {
  38. resizable( 0 );
  39. _spacing = 0;
  40. }
  41. void
  42. Fl_Scalepack::resize ( int X, int Y, int W, int H )
  43. {
  44. /* Fl_Group's resize will change our child widget sizes, which
  45. interferes with our own resizing method. */
  46. long dx = X - x();
  47. long dy = Y - y();
  48. bool r = W != w() || H != h();
  49. Fl_Widget::resize( X, Y, W, H );
  50. Fl_Widget*const* a = array();
  51. for (int i=children(); i--;)
  52. {
  53. Fl_Widget* o = *a++;
  54. o->position( o->x() + dx, o->y() + dy );
  55. }
  56. if ( r )
  57. redraw();
  58. }
  59. void
  60. Fl_Scalepack::draw ( void )
  61. {
  62. if ( resizable() == this )
  63. /* this resizable( this ) is the default for Fl_Group and is
  64. * reset by Fl_Group::clear(), but it is not our default... */
  65. resizable( 0 );
  66. int tx = x() + Fl::box_dx( box() );
  67. int ty = y() + Fl::box_dy( box() );
  68. int tw = w() - Fl::box_dw( box() );
  69. int th = h() - Fl::box_dh( box() );
  70. if ( damage() & FL_DAMAGE_ALL )
  71. {
  72. draw_box();
  73. draw_label();
  74. }
  75. int v = 0;
  76. int cth = 0;
  77. int ctw = 0;
  78. Fl_Widget * const * a = array();
  79. for ( int i = children(); i--; )
  80. {
  81. Fl_Widget *o = *a++;
  82. if ( o->visible() )
  83. {
  84. ++v;
  85. if ( o != this->resizable() )
  86. {
  87. cth += o->h();
  88. ctw += o->w();
  89. }
  90. cth += _spacing;
  91. ctw += _spacing;
  92. }
  93. }
  94. ctw -= _spacing;
  95. cth -= _spacing;
  96. if ( 0 == v )
  97. return;
  98. if ( this->resizable() )
  99. {
  100. int pos = 0;
  101. Fl_Widget * const * a = array();
  102. for ( int i = children(); i--; )
  103. {
  104. Fl_Widget *o = *a++;
  105. if ( o->visible() )
  106. {
  107. int X, Y, W, H;
  108. if ( type() == HORIZONTAL )
  109. {
  110. X = tx + pos;
  111. Y = ty;
  112. W = o->w();
  113. H = th;
  114. }
  115. else
  116. {
  117. X = tx;
  118. Y = ty + pos;
  119. W = tw;
  120. H = o->h();
  121. }
  122. if ( this->resizable() == o )
  123. {
  124. if ( type() == HORIZONTAL )
  125. W = tw - ctw - 3;
  126. else
  127. H = th - cth;
  128. }
  129. if (X != o->x() || Y != o->y() || W != o->w() || H != o->h() )
  130. {
  131. o->resize(X,Y,W,H);
  132. o->clear_damage(FL_DAMAGE_ALL);
  133. }
  134. if ( damage() & FL_DAMAGE_ALL )
  135. {
  136. draw_child( *o );
  137. draw_outside_label( *o );
  138. }
  139. else
  140. update_child( *o );
  141. /* if ( this->resizable() == o ) */
  142. /* fl_rect( o->x(), o->y(), o->w(), o->h(), type() == VERTICAL ? FL_GREEN : FL_BLUE ); */
  143. if ( type() == HORIZONTAL )
  144. pos += o->w() + spacing();
  145. else
  146. pos += o->h() + spacing();
  147. }
  148. }
  149. }
  150. else
  151. {
  152. int sz = 0;
  153. int pos = 0;
  154. if ( type() == HORIZONTAL )
  155. sz = (tw - (_spacing * (v - 1))) / v;
  156. else
  157. sz = (th - (_spacing * (v - 1))) / v;
  158. Fl_Widget * const * a = array();
  159. for ( int i = children(); i--; )
  160. {
  161. Fl_Widget *o = *a++;
  162. if ( o->visible() )
  163. {
  164. int X, Y, W, H;
  165. if ( type() == HORIZONTAL )
  166. {
  167. X = tx + pos;
  168. Y = ty;
  169. W = sz;
  170. H = th;
  171. }
  172. else
  173. {
  174. X = tx;
  175. Y = ty + pos;
  176. W = tw;
  177. H = sz;
  178. }
  179. if (X != o->x() || Y != o->y() || W != o->w() || H != o->h() )
  180. {
  181. o->resize(X,Y,W,H);
  182. o->clear_damage(FL_DAMAGE_ALL);
  183. }
  184. if ( damage() & FL_DAMAGE_ALL )
  185. {
  186. draw_child( *o );
  187. draw_outside_label( *o );
  188. }
  189. else
  190. update_child( *o );
  191. // fl_rect( o->x(), o->y(), o->w(), o->h(), type() == VERTICAL ? FL_RED : FL_YELLOW );
  192. if ( type() == HORIZONTAL )
  193. pos += o->w() + spacing();
  194. else
  195. pos += o->h() + spacing();
  196. }
  197. }
  198. }
  199. }