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.

100 lines
2.7KB

  1. //
  2. // "$Id: arc.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $"
  3. //
  4. // Arc drawing test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-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_Hor_Value_Slider.H>
  30. #include <FL/fl_draw.H>
  31. double args[6] = {140, 140, 50, 0, 360, 0};
  32. const char* name[6] = {"X", "Y", "R", "start", "end", "rotate"};
  33. class Drawing : public Fl_Widget {
  34. void draw() {
  35. fl_push_clip(x(),y(),w(),h());
  36. fl_color(FL_DARK3);
  37. fl_rectf(x(),y(),w(),h());
  38. fl_push_matrix();
  39. if (args[5]) {
  40. fl_translate(x()+w()/2.0, y()+h()/2.0);
  41. fl_rotate(args[5]);
  42. fl_translate(-(x()+w()/2.0), -(y()+h()/2.0));
  43. }
  44. fl_color(FL_WHITE);
  45. fl_translate(x(),y());
  46. fl_begin_complex_polygon();
  47. fl_arc(args[0],args[1],args[2],args[3],args[4]);
  48. fl_gap();
  49. fl_arc(140,140,20,0,-360);
  50. fl_end_complex_polygon();
  51. fl_color(FL_RED);
  52. fl_begin_line();
  53. fl_arc(args[0],args[1],args[2],args[3],args[4]);
  54. fl_end_line();
  55. fl_pop_matrix();
  56. fl_pop_clip();
  57. }
  58. public:
  59. Drawing(int X,int Y,int W,int H) : Fl_Widget(X,Y,W,H) {}
  60. };
  61. Drawing *d;
  62. void slider_cb(Fl_Widget* o, void* v) {
  63. Fl_Slider* s = (Fl_Slider*)o;
  64. args[fl_intptr_t(v)] = s->value();
  65. d->redraw();
  66. }
  67. int main(int argc, char** argv) {
  68. Fl_Double_Window window(300,500);
  69. Drawing drawing(10,10,280,280);
  70. d = &drawing;
  71. int y = 300;
  72. for (int n = 0; n<6; n++) {
  73. Fl_Slider* s = new Fl_Hor_Value_Slider(50,y,240,25,name[n]); y += 25;
  74. if (n<3) {s->minimum(0); s->maximum(300);}
  75. else if (n==5) {s->minimum(0); s->maximum(360);}
  76. else {s->minimum(-360); s->maximum(360);}
  77. s->step(1);
  78. s->value(args[n]);
  79. s->align(FL_ALIGN_LEFT);
  80. s->callback(slider_cb, (void*)n);
  81. }
  82. window.end();
  83. window.show(argc,argv);
  84. return Fl::run();
  85. }
  86. //
  87. // End of "$Id: arc.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $".
  88. //