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_Scalepack.C 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. }