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 4.9KB

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