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.

237 lines
6.7KB

  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. Fl_Widget::resize( X, Y, W, H );
  47. }
  48. void
  49. Fl_Scalepack::draw ( void )
  50. {
  51. if ( resizable() == this )
  52. /* this resizable( this ) is the default for Fl_Group and is
  53. * reset by Fl_Group::clear(), but it is not our default... */
  54. resizable( 0 );
  55. int tx = x() + Fl::box_dx( box() );
  56. int ty = y() + Fl::box_dy( box() );
  57. int tw = w() - Fl::box_dw( box() );
  58. int th = h() - Fl::box_dh( box() );
  59. if ( damage() & FL_DAMAGE_ALL )
  60. {
  61. if ( box() == FL_NO_BOX )
  62. fl_rectf( x(), y(), w(), h(), FL_BACKGROUND_COLOR );
  63. else
  64. draw_box();
  65. draw_label();
  66. }
  67. int v = 0;
  68. int cth = 0;
  69. int ctw = 0;
  70. Fl_Widget * const * a = array();
  71. for ( int i = children(); i--; )
  72. {
  73. Fl_Widget *o = *a++;
  74. if ( o->visible() )
  75. {
  76. ++v;
  77. if ( o != this->resizable() )
  78. {
  79. cth += o->h();
  80. ctw += o->w();
  81. }
  82. cth += _spacing;
  83. ctw += _spacing;
  84. }
  85. }
  86. ctw -= _spacing;
  87. cth -= _spacing;
  88. if ( 0 == v )
  89. return;
  90. if ( this->resizable() )
  91. {
  92. int pos = 0;
  93. Fl_Widget * const * a = array();
  94. for ( int i = children(); i--; )
  95. {
  96. Fl_Widget *o = *a++;
  97. if ( o->visible() )
  98. {
  99. int X, Y, W, H;
  100. if ( type() == HORIZONTAL )
  101. {
  102. X = tx + pos;
  103. Y = ty;
  104. W = o->w();
  105. H = th;
  106. }
  107. else
  108. {
  109. X = tx;
  110. Y = ty + pos;
  111. W = tw;
  112. H = o->h();
  113. }
  114. if ( this->resizable() == o )
  115. {
  116. if ( type() == HORIZONTAL )
  117. W = tw - ctw - 3;
  118. else
  119. H = th - cth;
  120. }
  121. if (X != o->x() || Y != o->y() || W != o->w() || H != o->h() )
  122. {
  123. o->resize(X,Y,W,H);
  124. o->clear_damage(FL_DAMAGE_ALL);
  125. }
  126. if ( damage() & FL_DAMAGE_ALL )
  127. {
  128. draw_child( *o );
  129. draw_outside_label( *o );
  130. }
  131. else
  132. update_child( *o );
  133. /* if ( this->resizable() == o ) */
  134. /* fl_rect( o->x(), o->y(), o->w(), o->h(), type() == VERTICAL ? FL_GREEN : FL_BLUE ); */
  135. if ( type() == HORIZONTAL )
  136. pos += o->w() + spacing();
  137. else
  138. pos += o->h() + spacing();
  139. }
  140. }
  141. }
  142. else
  143. {
  144. int sz = 0;
  145. int pos = 0;
  146. if ( type() == HORIZONTAL )
  147. sz = (tw - (_spacing * (v - 1))) / v;
  148. else
  149. sz = (th - (_spacing * (v - 1))) / v;
  150. Fl_Widget * const * a = array();
  151. for ( int i = children(); i--; )
  152. {
  153. Fl_Widget *o = *a++;
  154. if ( o->visible() )
  155. {
  156. int X, Y, W, H;
  157. if ( type() == HORIZONTAL )
  158. {
  159. X = tx + pos;
  160. Y = ty;
  161. W = sz;
  162. H = th;
  163. }
  164. else
  165. {
  166. X = tx;
  167. Y = ty + pos;
  168. W = tw;
  169. H = sz;
  170. }
  171. if (X != o->x() || Y != o->y() || W != o->w() || H != o->h() )
  172. {
  173. o->resize(X,Y,W,H);
  174. o->clear_damage(FL_DAMAGE_ALL);
  175. }
  176. if ( damage() & FL_DAMAGE_ALL )
  177. {
  178. draw_child( *o );
  179. draw_outside_label( *o );
  180. }
  181. else
  182. update_child( *o );
  183. // fl_rect( o->x(), o->y(), o->w(), o->h(), type() == VERTICAL ? FL_RED : FL_YELLOW );
  184. if ( type() == HORIZONTAL )
  185. pos += o->w() + spacing();
  186. else
  187. pos += o->h() + spacing();
  188. }
  189. }
  190. }
  191. }