Programmable real-time audio signal processing application
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_Splitter.cpp 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //| Copyright: (C) 2019-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. // Code based on: http://www.mail-archive.com/fltk@easysw.com/msg04573.html
  4. // Lucas Sanner/Ian MacArthur
  5. #include "Fl_Splitter.h"
  6. void Fl_HSplitter::draw()
  7. {
  8. Fl_Group::draw();
  9. Fl_Color c = fl_color();
  10. fl_color(FL_BLACK);
  11. fl_line_style( FL_DOT, 1);
  12. if(splitFl && Fl::event_button1() != 0)
  13. {
  14. fl_push_clip(x(), y(), w(), h());
  15. yPos = Fl::event_y();
  16. if(Fl::event_y() > h() - (border * 2))
  17. yPos = h() - (border * 2);
  18. if(Fl::event_y() < y() + (border * 2))
  19. yPos = y() + (border * 2);
  20. fl_line( x() + border, yPos - 1, x() + w() - (border*2), yPos - 1 );
  21. fl_line( x() + border, yPos , x() + w() - (border*2), yPos );
  22. fl_line( x() + border, yPos + 1, x() + w() - (border*2), yPos + 1 );
  23. /*
  24. fl_line(
  25. x() + border,
  26. yPos,
  27. x() + w() - (border*2),
  28. yPos );
  29. fl_line(
  30. x() + border,
  31. yPos + 1,
  32. x() + w() - (border*2),
  33. yPos + 1 );
  34. */
  35. fl_pop_clip();
  36. }
  37. else
  38. {
  39. fl_push_clip(x(), y(), w(), h());
  40. fl_pop_clip();
  41. }
  42. fl_color(c);
  43. fl_line_style(0);
  44. }
  45. int Fl_HSplitter::handle(int e)
  46. {
  47. int ret = Fl_Group::handle(e);
  48. switch(e)
  49. {
  50. case FL_MOVE:
  51. if(hCtnl - border < Fl::event_y() && Fl::event_y() < hCtnl + border)
  52. {
  53. fl_cursor(FL_CURSOR_NS);
  54. splitFl = true;
  55. }
  56. else
  57. {
  58. fl_cursor(FL_CURSOR_DEFAULT);
  59. splitFl = false;
  60. }
  61. return 1;
  62. case FL_PUSH:
  63. if(Fl::event_button() == FL_LEFT_MOUSE && splitFl)
  64. {
  65. redraw();
  66. }
  67. return 1;
  68. case FL_RELEASE:
  69. if(Fl::event_button() == FL_LEFT_MOUSE && splitFl)
  70. {
  71. c0->resize(x(), y(), w(), yPos - y());
  72. hCtnl = yPos;
  73. c1->resize(x(),hCtnl, w(), h() - (yPos - y()));
  74. if( stretchTopFl )
  75. init_sizes();
  76. splitFl = false;
  77. redraw();
  78. }
  79. return 1;
  80. case FL_DRAG:
  81. if(splitFl && Fl::event_state(FL_BUTTON1) != 0)
  82. redraw();
  83. return 1;
  84. }
  85. return(ret);
  86. }
  87. Fl_HSplitter::Fl_HSplitter(int x, int y, int w, int h, int h1, const char *l, bool stretchBotFl)
  88. : Fl_Group(x, y, w, h, l)
  89. {
  90. int h2 = h - h1;
  91. begin();
  92. c0 = new Splitter_Container(x, y, w, h1);
  93. //c0->color((Fl_Color) FL_RED);
  94. end();
  95. begin();
  96. c1 = new Splitter_Container(x, y + h1, w, h2);
  97. //c1->color((Fl_Color) FL_BLUE);
  98. end();
  99. hCtnl = y + h1;
  100. splitFl = false;
  101. stretchTopFl = !stretchBotFl;
  102. border = Fl::box_dy(FL_DOWN_BOX);
  103. if( stretchTopFl )
  104. resizable(c0);
  105. }
  106. void Fl_HSplitter::resize(int x, int y, int w, int h)
  107. {
  108. Fl_Group::resize(x, y, w, h);
  109. if( stretchTopFl )
  110. {
  111. hCtnl = c0->h() + y;
  112. yPos = hCtnl;
  113. //printf("hCtnl:%i\n",hCtnl);
  114. }
  115. else
  116. {
  117. c0->resize(x, y, w, hCtnl - y);
  118. c1->resize(x, hCtnl, w, h - (hCtnl - y));
  119. }
  120. }
  121. void Fl_VSplitter::draw()
  122. {
  123. Fl_Group::draw();
  124. Fl_Color c = fl_color();
  125. fl_color(FL_BLACK);
  126. fl_line_style( FL_DOT, 1);
  127. if(splitFl && Fl::event_button1() != 0)
  128. {
  129. fl_push_clip(x(), y(), w(), h());
  130. xPos = Fl::event_x();
  131. if(Fl::event_x() > w() - (border * 2))
  132. xPos = w() - (border * 2);
  133. if(Fl::event_x() < x() + (border * 2))
  134. xPos = x() + (border * 2);
  135. fl_line(xPos - 1, y() + border, xPos - 1, y() + h() - (border * 2));
  136. fl_line(xPos, y() + border, xPos, y() + h() - (border * 2));
  137. fl_line(xPos + 1, y() + border, xPos + 1, y() + h() - (border * 2));
  138. fl_pop_clip();
  139. }
  140. else
  141. {
  142. fl_push_clip(x(), y(), w(), h());
  143. fl_pop_clip();
  144. }
  145. fl_color(c);
  146. fl_line_style(0); // restore line style to defaults
  147. }
  148. int Fl_VSplitter::handle(int e)
  149. {
  150. int ret = Fl_Group::handle(e);
  151. switch(e)
  152. {
  153. case FL_MOVE:
  154. if(Fl::event_x() > wCtn1 - border && Fl::event_x() < wCtn1 + border)
  155. {
  156. fl_cursor(FL_CURSOR_WE);
  157. splitFl = true;
  158. }
  159. else
  160. {
  161. fl_cursor(FL_CURSOR_DEFAULT);
  162. splitFl = false;
  163. }
  164. return 1;
  165. case FL_PUSH:
  166. if(Fl::event_button() == FL_LEFT_MOUSE && splitFl)
  167. {
  168. redraw();
  169. }
  170. return 1;
  171. case FL_RELEASE:
  172. if(Fl::event_button() == FL_LEFT_MOUSE && splitFl)
  173. {
  174. c0->resize(x(), y(), xPos, h());
  175. wCtn1 = xPos;
  176. c1->resize(wCtn1, y(), w() - wCtn1, h());
  177. splitFl = false;
  178. redraw();
  179. }
  180. return 1;
  181. case FL_DRAG:
  182. if(splitFl && Fl::event_state(FL_BUTTON1) != 0)
  183. redraw();
  184. return 1;
  185. }
  186. return(ret);
  187. }
  188. Fl_VSplitter::Fl_VSplitter(int x, int y, int w, int h, const char *l)
  189. : Fl_Group(x, y, w, h, l)
  190. {
  191. begin();
  192. c0 = new Splitter_Container(x, y, w / 2, h);
  193. //c0->color((Fl_Color) FL_RED);
  194. end();
  195. begin();
  196. c1 = new Splitter_Container(x + (w / 2), y, w / 2, h);
  197. //c1->color((Fl_Color) FL_BLUE);
  198. end();
  199. wCtn1 = w / 2;
  200. splitFl = false;
  201. border = Fl::box_dx(FL_DOWN_BOX);
  202. }
  203. void Fl_VSplitter::resize_splitter(int x, int y, int w, int h)
  204. {
  205. resize(x, y, w, h);
  206. c0->resize(x, y, wCtn1, h);
  207. c1->resize(wCtn1, y, w - wCtn1, h);
  208. }