Programmable real-time audio signal processing application
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Fl_Splitter.cpp 5.0KB

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