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