Clean up some inconsistencies in themes.
[ntk.git] / test / shape.cxx
blobd6fbfcc14039ddbbdbd802ca5dbdc98292f75b4c
1 //
2 // "$Id: shape.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
3 //
4 // Tiny OpenGL demo 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.
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.
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.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 #include <config.h>
29 #include <FL/Fl.H>
30 #include <FL/Fl_Window.H>
31 #include <FL/Fl_Hor_Slider.H>
32 #include <FL/math.h>
34 #if HAVE_GL
36 #include <FL/gl.h>
37 #include <FL/Fl_Gl_Window.H>
39 class shape_window : public Fl_Gl_Window {
40 void draw();
41 public:
42 int sides;
43 shape_window(int x,int y,int w,int h,const char *l=0);
46 shape_window::shape_window(int x,int y,int w,int h,const char *l) :
47 Fl_Gl_Window(x,y,w,h,l) {
48 sides = 3;
51 void shape_window::draw() {
52 // the valid() property may be used to avoid reinitializing your
53 // GL transformation for each redraw:
54 if (!valid()) {
55 valid(1);
56 glLoadIdentity();
57 glViewport(0, 0, w(), h());
59 // draw an amazing graphic:
60 glClear(GL_COLOR_BUFFER_BIT);
61 glColor3f(.5,.6,.7);
62 glBegin(GL_POLYGON);
63 for (int j=0; j<sides; j++) {
64 double ang = j*2*M_PI/sides;
65 glVertex3f(cos(ang),sin(ang),0);
67 glEnd();
70 #else
72 #include <FL/Fl_Box.H>
73 class shape_window : public Fl_Box {
74 public:
75 int sides;
76 shape_window(int x,int y,int w,int h,const char *l=0)
77 :Fl_Box(FL_DOWN_BOX,x,y,w,h,l){
78 label("This demo does\nnot work without GL");
82 #endif
84 // when you change the data, as in this callback, you must call redraw():
85 void sides_cb(Fl_Widget *o, void *p) {
86 shape_window *sw = (shape_window *)p;
87 sw->sides = int(((Fl_Slider *)o)->value());
88 sw->redraw();
91 int main(int argc, char **argv) {
93 Fl_Window window(300, 330);
95 // the shape window could be it's own window, but here we make it
96 // a child window:
97 shape_window sw(10, 10, 280, 280);
98 // make it resize:
99 window.resizable(&sw);
100 // window.size_range(300,330,0,0,1,1,1);
101 // add a knob to control it:
102 Fl_Hor_Slider slider(50, 295, window.w()-60, 30, "Sides:");
103 slider.align(FL_ALIGN_LEFT);
104 slider.callback(sides_cb,&sw);
105 slider.value(sw.sides);
106 slider.step(1);
107 slider.bounds(3,40);
109 window.end();
110 window.show(argc,argv);
112 return Fl::run();
116 // End of "$Id: shape.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".