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.

178 lines
5.2KB

  1. //
  2. // "$Id: line_style.cxx 7982 2010-12-08 23:58:32Z AlbrechtS $"
  3. //
  4. // Line style demo for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 2000-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. #include <FL/Fl.H>
  28. #include <FL/Fl_Double_Window.H>
  29. #include <FL/Fl_Value_Slider.H>
  30. #include <FL/fl_draw.H>
  31. #include <FL/Fl_Choice.H>
  32. #include <FL/Fl_Check_Button.H>
  33. #include <FL/Fl_Box.H>
  34. Fl_Double_Window *form;
  35. Fl_Slider *sliders[9];
  36. Fl_Choice *choice[3];
  37. Fl_Check_Button *draw_line;
  38. class test_box: public Fl_Double_Window {
  39. void draw();
  40. public:
  41. test_box(int x,int y,int w,int h,const char *l=0)
  42. : Fl_Double_Window(x,y,w,h,l) {}
  43. }*test;
  44. void test_box::draw() {
  45. Fl_Double_Window::draw();
  46. fl_color((uchar)(sliders[0]->value()),
  47. (uchar)(sliders[1]->value()),
  48. (uchar)(sliders[2]->value()));
  49. // dashes
  50. char dashes[5];
  51. dashes[0] = char(sliders[5]->value());
  52. dashes[1] = char(sliders[6]->value());
  53. dashes[2] = char(sliders[7]->value());
  54. dashes[3] = char(sliders[8]->value());
  55. dashes[4] = 0;
  56. fl_line_style(
  57. choice[0]->mvalue()->argument() +
  58. choice[1]->mvalue()->argument() +
  59. choice[2]->mvalue()->argument(),
  60. long(sliders[3]->value()), // width
  61. dashes);
  62. // draw the defined fl_rect and fl_vertex first and then
  63. // the additional one-pixel line, if enabled
  64. // sliders[4] = x/y coordinate translation (default = 10)
  65. for (int i=0; i<draw_line->value()+1; i++) {
  66. int move = (int)sliders[4]->value();
  67. fl_rect(move,move,w()-20,h()-20);
  68. fl_begin_line();
  69. fl_vertex(move+25, move+25);
  70. fl_vertex(w()-45+move, h()-45+move);
  71. fl_vertex(w()-50+move, move+25);
  72. fl_vertex(move+25, h()/2-10+move);
  73. fl_end_line();
  74. // you must reset the line type when done:
  75. fl_line_style(FL_SOLID);
  76. fl_color(FL_BLACK);
  77. }
  78. }
  79. Fl_Menu_Item style_menu[] = {
  80. {"FL_SOLID", 0, 0, (void*)FL_SOLID},
  81. {"FL_DASH", 0, 0, (void*)FL_DASH},
  82. {"FL_DOT", 0, 0, (void*)FL_DOT},
  83. {"FL_DASHDOT",0, 0, (void*)FL_DASHDOT},
  84. {"FL_DASHDOTDOT", 0, 0, (void*)FL_DASHDOTDOT},
  85. {0}
  86. };
  87. Fl_Menu_Item cap_menu[] = {
  88. {"default", 0, 0, 0},
  89. {"FL_CAP_FLAT", 0, 0, (void*)FL_CAP_FLAT},
  90. {"FL_CAP_ROUND", 0, 0, (void*)FL_CAP_ROUND},
  91. {"FL_CAP_SQUARE", 0, 0, (void*)FL_CAP_SQUARE},
  92. {0}
  93. };
  94. Fl_Menu_Item join_menu[] = {
  95. {"default", 0, 0, 0},
  96. {"FL_JOIN_MITER", 0, 0, (void*)FL_JOIN_MITER},
  97. {"FL_JOIN_ROUND", 0, 0, (void*)FL_JOIN_ROUND},
  98. {"FL_JOIN_BEVEL", 0, 0, (void*)FL_JOIN_BEVEL},
  99. {0}
  100. };
  101. void do_redraw(Fl_Widget*,void*)
  102. {
  103. test->redraw();
  104. }
  105. void makeform(const char *) {
  106. form = new Fl_Double_Window(500,250,"fl_line_style() test");
  107. sliders[0]= new Fl_Value_Slider(280,10,180,20,"R");
  108. sliders[0]->bounds(0,255);
  109. sliders[1]= new Fl_Value_Slider(280,30,180,20,"G");
  110. sliders[1]->bounds(0,255);
  111. sliders[2]= new Fl_Value_Slider(280,50,180,20,"B");
  112. sliders[2]->bounds(0,255);
  113. choice[0]= new Fl_Choice(280,70,180,20,"Style");
  114. choice[0]->menu(style_menu);
  115. choice[1]= new Fl_Choice(280,90,180,20,"Cap");
  116. choice[1]->menu(cap_menu);
  117. choice[2]= new Fl_Choice(280,110,180,20,"Join");
  118. choice[2]->menu(join_menu);
  119. sliders[3]= new Fl_Value_Slider(280,130,180,20,"Width");
  120. sliders[3]->bounds(0,20);
  121. sliders[4]= new Fl_Value_Slider(280,150,180,20,"Move");
  122. sliders[4]->bounds(-10,20);
  123. draw_line = new Fl_Check_Button(280,170,20,20,"&Line");
  124. draw_line->align(FL_ALIGN_LEFT);
  125. new Fl_Box (305,170,160,20,"add a 1-pixel black line");
  126. sliders[5] = new Fl_Slider(200,210,70,20,"Dash");
  127. sliders[5]->align(FL_ALIGN_TOP_LEFT);
  128. sliders[5]->bounds(0,40);
  129. sliders[6] = new Fl_Slider(270,210,70,20);
  130. sliders[6]->bounds(0,40);
  131. sliders[7] = new Fl_Slider(340,210,70,20);
  132. sliders[7]->bounds(0,40);
  133. sliders[8] = new Fl_Slider(410,210,70,20);
  134. sliders[8]->bounds(0,40);
  135. int i;
  136. for (i=0;i<9;i++) {
  137. sliders[i]->type(1);
  138. if (i<5) sliders[i]->align(FL_ALIGN_LEFT);
  139. sliders[i]->callback((Fl_Callback*)do_redraw);
  140. sliders[i]->step(1);
  141. }
  142. sliders[0]->value(255); // R
  143. sliders[1]->value(100); // G
  144. sliders[2]->value(100); // B
  145. sliders[4]->value(10); // move line coordinates
  146. draw_line->value(0);
  147. draw_line->callback((Fl_Callback*)do_redraw);
  148. for (i=0;i<3;i++) {
  149. choice[i]->value(0);
  150. choice[i]->callback((Fl_Callback*)do_redraw);
  151. }
  152. test = new test_box(0,0,200,200);
  153. test->end();
  154. form->resizable(test);
  155. form->end();
  156. }
  157. int main(int argc, char **argv) {
  158. makeform(argv[0]);
  159. form->show(argc,argv);
  160. return Fl::run();
  161. }
  162. //
  163. // End of "$Id: line_style.cxx 7982 2010-12-08 23:58:32Z AlbrechtS $".
  164. //