source: rtems-graphics-toolkit/fltk-1.3.0/test/curve.cxx @ 46c28a1

Last change on this file since 46c28a1 was f5c9e9c, checked in by Alexandru-Sever Horin <alex.sever.h@…>, on 07/05/12 at 09:33:03

Aded FLTK 1.3.0

  • Property mode set to 100644
File size: 3.2 KB
Line 
1//
2// "$Id: curve.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $"
3//
4// Curve 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
28#include <FL/Fl.H>
29#include <FL/Fl_Double_Window.H>
30#include <FL/Fl_Hor_Value_Slider.H>
31#include <FL/fl_draw.H>
32#include <FL/Fl_Toggle_Button.H>
33
34double args[9] = {
35  20,20, 50,200, 100,20, 200,200, 0};
36const char* name[9] = {
37  "X0", "Y0", "X1", "Y1", "X2", "Y2", "X3", "Y3", "rotate"};
38
39int points;
40
41class Drawing : public Fl_Widget {
42  void draw() {
43    fl_push_clip(x(),y(),w(),h());
44    fl_color(FL_DARK3);
45    fl_rectf(x(),y(),w(),h());
46    fl_push_matrix();
47    if (args[8]) {
48      fl_translate(x()+w()/2.0, y()+h()/2.0);
49      fl_rotate(args[8]);
50      fl_translate(-(x()+w()/2.0), -(y()+h()/2.0));
51    }
52    fl_translate(x(),y());
53    if (!points) {
54    fl_color(FL_WHITE);
55    fl_begin_complex_polygon();
56   fl_curve(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
57    fl_end_complex_polygon();
58    }
59    fl_color(FL_BLACK);
60    fl_begin_line();
61    fl_vertex(args[0],args[1]);
62    fl_vertex(args[2],args[3]);
63    fl_vertex(args[4],args[5]);
64    fl_vertex(args[6],args[7]);
65    fl_end_line();
66    fl_color(points ? FL_WHITE : FL_RED);
67    points ? fl_begin_points() : fl_begin_line();
68   fl_curve(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
69    points ? fl_end_points() : fl_end_line();
70    fl_pop_matrix();
71    fl_pop_clip();
72  }
73public:
74  Drawing(int X,int Y,int W,int H) : Fl_Widget(X,Y,W,H) {}
75};
76
77Drawing *d;
78
79void points_cb(Fl_Widget* o, void*) {
80  points = ((Fl_Toggle_Button*)o)->value();
81  d->redraw();
82}
83
84void slider_cb(Fl_Widget* o, void* v) {
85  Fl_Slider* s = (Fl_Slider*)o;
86  args[fl_intptr_t(v)] = s->value();
87  d->redraw();
88}
89
90int main(int argc, char** argv) {
91  Fl_Double_Window window(300,555);
92  Drawing drawing(10,10,280,280);
93  d = &drawing;
94
95  int y = 300;
96  for (int n = 0; n<9; n++) {
97    Fl_Slider* s = new Fl_Hor_Value_Slider(50,y,240,25,name[n]); y += 25;
98    s->minimum(0); s->maximum(280);
99    if (n == 8) s->maximum(360);
100    s->step(1);
101    s->value(args[n]);
102    s->align(FL_ALIGN_LEFT);
103    s->callback(slider_cb, (void*)n);
104  }
105  Fl_Toggle_Button but(50,y,50,25,"points");
106  but.callback(points_cb);
107
108  window.end();
109  window.show(argc,argv);
110  return Fl::run();
111}
112
113//
114// End of "$Id: curve.cxx 7978 2010-12-08 14:00:35Z AlbrechtS $".
115//
Note: See TracBrowser for help on using the repository browser.