/*
FLTK_GL.C - Test resizable FLTK 1.3.0 windows forced to be square.
set FLTK_DIR = $HOME/fltk-1.3.0
Windows:
set CCFLAGS = '-mwindows -DUSE_OPENGL32'
set LFLAGS = '-lglu32 -lopengl32 -lpthread -ldl -lole32 -luuid -lcomctl32'
Mac:
set CCFLAGS = '-arch ppc -arch i686 -arch x86_64'
set LFLAGS = "-framework AGL -framework Cocoa -framework OpenGL \
-framework ApplicationServices -lpthread"
g++ $CCFLAGS -o FLTK_GL FLTK_GL.C -I$FLTK_DIR -L$FLTK_DIR/lib -lfltk -lfltk_gl
$LFLAGS
./FLTK_GL
Drag lower-left corner to resize and note the 'blank area margin' that shows
when width != height.
Ian's hack-around: when the user lets go of the corner,
momentarily hide then show the window to cause the native window manager to
re-create the now square window without the 'blank area margin'.
Q1. Can Ian's hack-around be made to work on Windows?
When I run this program on Windows, the timeout occurs starting from
mouse-down rather than mouse-up - which causes the user to 'drop' the
window corner too soon.
Q2. How does this program behave on Linux?
Is Ian's hack-around not needed - i.e., size_range() suffices?
Or if used, does it work (like on Mac) or not work (like Windows)?
Q3. Is there a better solution?
E.g., can FLTK be amended so size_range() suffices on all platforms?
2012-07-27, plessel dot todd at epa dot gov
*/
#include <iostream>
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
// HACK to cause window to be trimmed to a square
// after interactive reshaping.
// Based on MacArthur, Ian (SELEX GALILEO, UK)
// http://www.mail-archive.com/[email protected]/msg09047.html
static void hide_show_window(void *v) {
Fl_Gl_Window* const window = (Fl_Gl_Window*) v;
window->hide();
window->show();
std::cout << "hide_show_window" << std::endl;
Fl::remove_timeout( hide_show_window );
}
// Based on http://seriss.com/people/erco/fltk/#OpenGlSimple
// Simple resizable 2D GL window erco 10/08/05
class MyGlWindow : public Fl_Gl_Window {
int size; // Window size in screen pixels.
// FLTK draw callback:
// (w,h) is upper right, (-w,-h) is lower left, (0,0) is center
void draw() {
int w = this->w();
int h = this->h();
std::cout << "draw: w = " << w << " h = " << h << std::endl;
w = w < h ? w : h; h = w; // Enforce square window.
// First time? init viewport, etc.
if (!valid()) {
valid(1);
glLoadIdentity();
glViewport(0,0,w,h);
glOrtho(-w,w,-h,h,-1,1);
}
// Clear screen
glClear(GL_COLOR_BUFFER_BIT);
// Draw white 'X'
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP); glVertex2f(w, h); glVertex2f(-w,-h); glEnd();
glBegin(GL_LINE_STRIP); glVertex2f(w,-h); glVertex2f(-w, h); glEnd();
}
// FLTK resize callback.
// If window reshaped, need to readjust viewport/ortho
void resize(int X,int Y,int W,int H) {
std::cout << "resize: W = " << W << " H = " << H << std::endl;
if ( W != size || H != size ) { // Resized and/or reshaped.
W = W < H ? W : H; H = W;// Enforce square window.
size = W;
std::cout << " size = " << size << std::endl;
Fl_Gl_Window::resize(X,Y,size,size);
glLoadIdentity();
glViewport(0,0,size,size);
glOrtho(-size,size,-size,size,-1,1);
redraw();
Fl::add_timeout(0.1, hide_show_window, (void *)this); // HACK.
}
}
public:
// CONSTRUCTOR
MyGlWindow(int X,int Y,int W,int H,const char*L=0)
: Fl_Gl_Window(X,Y,W < H ? W : H,W < H ? W : H,L) {
size = W < H ? W : H;
resizable(this);
size_range(100, 100, 2000, 2000, 1, 1, 1); // Enforce square window.
end();
show();
}
};
int main() {
MyGlWindow mygl(100, 100, 500, 500, "OpenGL Square Window");
return(Fl::run());
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs