2 // "$Id: fullscreen.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $"
4 // Fullscreen test program for the Fast Light Tool Kit (FLTK).
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
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
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
54 // Please report all bugs and problems on the following page:
56 // http://www.fltk.org/str.php
61 #include <FL/Fl_Single_Window.H>
62 #include <FL/Fl_Hor_Slider.H>
63 #include <FL/Fl_Toggle_Light_Button.H>
69 #include <FL/Fl_Gl_Window.H>
71 class shape_window
: public Fl_Gl_Window
{
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
) {
83 void shape_window::draw() {
84 printf("drawing size %d %d\n",w(),h());
89 glViewport(0,0,w(),h());
91 glClear(GL_COLOR_BUFFER_BIT
);
94 for (int j
= 0; j
< sides
; j
++) {
95 double ang
= j
*2*M_PI
/sides
;
96 glVertex3f(cos(ang
),sin(ang
),0);
103 #include <FL/fl_draw.H>
105 class shape_window
: public Fl_Window
{
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
) {
117 void shape_window::draw() {
119 fl_rectf(0,0,w(),h());
122 fl_draw("This requires GL",0,0,w(),h(),FL_ALIGN_CENTER
);
127 void sides_cb(Fl_Widget
*o
, void *p
) {
128 shape_window
*sw
= (shape_window
*)p
;
129 sw
->sides
= int(((Fl_Slider
*)o
)->value());
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
);
140 void double_cb(Fl_Widget
*, void *) {}
143 void border_cb(Fl_Widget
*o
, void *p
) {
144 Fl_Window
*w
= (Fl_Window
*)p
;
145 int d
= ((Fl_Button
*)o
)->value();
147 #if defined(WIN32) || defined(__APPLE__)
148 int wx
= w
->x(), wy
= w
->y();
149 w
->hide(); w
->show();
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();
164 #ifndef WIN32//necessary because fullscreen removes border
165 border_button
->value(0);
166 border_button
->do_callback();
170 w
->fullscreen_off(px
,py
,pw
,ph
);
176 void exit_cb(Fl_Widget
*, void *) {
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;}
190 int main(int argc
, char **argv
) {
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);
204 if (twowindow
) { // make it's own window
207 window
.set_modal(); // makes controls stay on top when fullscreen pushed
210 } else { // otherwise make a subwindow
212 window
.resizable(&sw
);
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
);
227 Fl_Toggle_Light_Button
b1(50,y
,window
.w()-60,30,"Double Buffered");
228 b1
.callback(double_cb
,&sw
);
231 Fl_Toggle_Light_Button
b2(50,y
,window
.w()-60,30,"Border");
232 b2
.callback(border_cb
,w
);
237 Fl_Toggle_Light_Button
b3(50,y
,window
.w()-60,30,"FullScreen");
238 b3
.callback(fullscreen_cb
,w
);
241 Fl_Button
eb(50,y
,window
.w()-60,30,"Exit");
242 eb
.callback(exit_cb
);
245 if (initfull
) {b3
.set(); b3
.do_callback();}
248 window
.show(argc
,argv
);
254 // End of "$Id: fullscreen.cxx 8033 2010-12-15 12:11:16Z AlbrechtS $".