Clean up some inconsistencies in themes.
[ntk.git] / test / fullscreen.cxx
blob57e8c58aefb4bcb2d784ed1bd0fcee495e98651a
1 //
2 // "$Id: fullscreen.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
3 //
4 // Fullscreen test program for the Fast Light Tool Kit (FLTK).
5 //
6 // This demo shows how to do many of the window manipulations that
7 // are popular on SGI programs, even though X does not really like
8 // them. You can toggle the border on/off, change the visual to
9 // switch between single/double buffer, and make the window take
10 // over the screen.
12 // Normally the program makes a single window with a child GL window.
13 // This simulates a program where the 3D display is surrounded by
14 // control knobs. Running the program with an argument will
15 // make it make a seperate GL window from the controls window. This
16 // simulates a (older?) style program where the graphics display is
17 // a different window than the controls.
19 // This program reports how many times it redraws the window to
20 // stdout, so you can see how much time it is wasting. It appears
21 // to be impossible to prevent X from sending redundant resize
22 // events, so there are extra redraws. But the way I have the
23 // code arranged here seems to be keeping that to a minimu.
25 // Apparently unavoidable bugs:
27 // Turning the border on causes an unnecessary redraw.
29 // Turning off full screen when the border is on causes an unnecessary
30 // resize and redraw when the program turns the border on.
32 // If it is a seperate window, turning double buffering on and off
33 // will cause the window to raise, deiconize, and possibly move. You
34 // can avoid this by making the Fl_Gl_Window a child of a normal
35 // window.
37 // Copyright 1998-2010 by Bill Spitzak and others.
39 // This library is free software; you can redistribute it and/or
40 // modify it under the terms of the GNU Library General Public
41 // License as published by the Free Software Foundation; either
42 // version 2 of the License, or (at your option) any later version.
44 // This library is distributed in the hope that it will be useful,
45 // but WITHOUT ANY WARRANTY; without even the implied warranty of
46 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47 // Library General Public License for more details.
49 // You should have received a copy of the GNU Library General Public
50 // License along with this library; if not, write to the Free Software
51 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
52 // USA.
54 // Please report all bugs and problems on the following page:
56 // http://www.fltk.org/str.php
59 #include <config.h>
60 #include <FL/Fl.H>
61 #include <FL/Fl_Single_Window.H>
62 #include <FL/Fl_Hor_Slider.H>
63 #include <FL/Fl_Toggle_Light_Button.H>
64 #include <FL/math.h>
65 #include <stdio.h>
67 #if HAVE_GL
68 #include <FL/gl.h>
69 #include <FL/Fl_Gl_Window.H>
71 class shape_window : public Fl_Gl_Window {
72 void draw();
73 public:
74 int sides;
75 shape_window(int x,int y,int w,int h,const char *l=0);
78 shape_window::shape_window(int x,int y,int w,int h,const char *l) :
79 Fl_Gl_Window(x,y,w,h,l) {
80 sides = 3;
83 void shape_window::draw() {
84 printf("drawing size %d %d\n",w(),h());
85 if (!valid()) {
86 valid(1);
87 // printf("init\n");
88 glLoadIdentity();
89 glViewport(0,0,w(),h());
91 glClear(GL_COLOR_BUFFER_BIT);
92 glColor3f(.5,.6,.7);
93 glBegin(GL_POLYGON);
94 for (int j = 0; j < sides; j ++) {
95 double ang = j*2*M_PI/sides;
96 glVertex3f(cos(ang),sin(ang),0);
98 glEnd();
101 #else
103 #include <FL/fl_draw.H>
105 class shape_window : public Fl_Window {
106 void draw();
107 public:
108 int sides;
109 shape_window(int x,int y,int w,int h,const char *l=0);
112 shape_window::shape_window(int x,int y,int w,int h,const char *l) :
113 Fl_Window(x,y,w,h,l) {
114 sides = 3;
117 void shape_window::draw() {
118 fl_color(0);
119 fl_rectf(0,0,w(),h());
120 fl_font(0,20);
121 fl_color(7);
122 fl_draw("This requires GL",0,0,w(),h(),FL_ALIGN_CENTER);
125 #endif
127 void sides_cb(Fl_Widget *o, void *p) {
128 shape_window *sw = (shape_window *)p;
129 sw->sides = int(((Fl_Slider *)o)->value());
130 sw->redraw();
133 #if HAVE_GL
134 void double_cb(Fl_Widget *o, void *p) {
135 shape_window *sw = (shape_window *)p;
136 int d = ((Fl_Button *)o)->value();
137 sw->mode(d ? Fl_Mode(FL_DOUBLE|FL_RGB) : FL_RGB);
139 #else
140 void double_cb(Fl_Widget *, void *) {}
141 #endif
143 void border_cb(Fl_Widget *o, void *p) {
144 Fl_Window *w = (Fl_Window *)p;
145 int d = ((Fl_Button *)o)->value();
146 w->border(d);
147 #if defined(WIN32) || defined(__APPLE__)
148 int wx = w->x(), wy = w->y();
149 w->hide(); w->show();
150 w->position(wx, wy);
151 #endif
154 int px,py,pw,ph;
155 Fl_Button *border_button;
156 void fullscreen_cb(Fl_Widget *o, void *p) {
157 Fl_Window *w = (Fl_Window *)p;
158 int d = ((Fl_Button *)o)->value();
159 if (d) {
160 px = w->x();
161 py = w->y();
162 pw = w->w();
163 ph = w->h();
164 #ifndef WIN32//necessary because fullscreen removes border
165 border_button->value(0);
166 border_button->do_callback();
167 #endif
168 w->fullscreen();
169 } else {
170 w->fullscreen_off(px,py,pw,ph);
174 #include <stdlib.h>
176 void exit_cb(Fl_Widget *, void *) {
177 exit(0);
180 #define NUMB 5
182 int twowindow = 0;
183 int initfull = 0;
184 int arg(int, char **argv, int &i) {
185 if (argv[i][1] == '2') {twowindow = 1; i++; return 1;}
186 if (argv[i][1] == 'f') {initfull = 1; i++; return 1;}
187 return 0;
190 int main(int argc, char **argv) {
192 int i=0;
193 if (Fl::args(argc,argv,i,arg) < argc)
194 Fl::fatal("Options are:\n -2 = 2 windows\n -f = startup fullscreen\n%s",Fl::help);
196 Fl_Single_Window window(300,300+30*NUMB); window.end();
198 shape_window sw(10,10,window.w()-20,window.h()-30*NUMB-20);
199 #if HAVE_GL
200 sw.mode(FL_RGB);
201 #endif
203 Fl_Window *w;
204 if (twowindow) { // make it's own window
205 sw.resizable(&sw);
206 w = &sw;
207 window.set_modal(); // makes controls stay on top when fullscreen pushed
208 argc--;
209 sw.show();
210 } else { // otherwise make a subwindow
211 window.add(sw);
212 window.resizable(&sw);
213 w = &window;
216 window.begin();
218 int y = window.h()-30*NUMB-5;
219 Fl_Hor_Slider slider(50,y,window.w()-60,30,"Sides:");
220 slider.align(FL_ALIGN_LEFT);
221 slider.callback(sides_cb,&sw);
222 slider.value(sw.sides);
223 slider.step(1);
224 slider.bounds(3,40);
225 y+=30;
227 Fl_Toggle_Light_Button b1(50,y,window.w()-60,30,"Double Buffered");
228 b1.callback(double_cb,&sw);
229 y+=30;
231 Fl_Toggle_Light_Button b2(50,y,window.w()-60,30,"Border");
232 b2.callback(border_cb,w);
233 b2.set();
234 border_button = &b2;
235 y+=30;
237 Fl_Toggle_Light_Button b3(50,y,window.w()-60,30,"FullScreen");
238 b3.callback(fullscreen_cb,w);
239 y+=30;
241 Fl_Button eb(50,y,window.w()-60,30,"Exit");
242 eb.callback(exit_cb);
243 y+=30;
245 if (initfull) {b3.set(); b3.do_callback();}
247 window.end();
248 window.show(argc,argv);
250 return Fl::run();
254 // End of "$Id: fullscreen.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".