Greg Ercolano wrote:
> Christian Convey wrote:
>> my menu hotkeys no longer seem to work.
>
> To bring sanity to an interface that has multiple widgets
> all on screen competing for the same keystrokes, focus is
> the way to control it.
> ..
> This would mean having your GL window accept and respond to
> focus events as per the docs on handling events, ie. handle()ing
> FL_FOCUS, FL_UNFOCUS, etc. by return()ing 1, and also return()ing
> 1 when you receive up/down arrow events, so that they aren't passed
> on to other widgets.
Example of the above suggestion:
---- snip
#include <stdio.h>
#include <FL/Fl.h>
#include <FL/Fl_Window.h>
#include <FL/Fl_Gl_Window.h>
#include <FL/Fl_Menu_Bar.h>
#include <FL/Fl_Input.h>
#include <FL/names.h>
//
// GL window taking focus for keyboard events it needs
//
void Callback(Fl_Widget*,void *s) {
fprintf(stderr, "CALLBACK '%s'\n", (const char*)s);
}
class MyGlWindow : public Fl_Gl_Window {
public:
MyGlWindow(int X,int Y,int W,int H,const char* L=0) :
Fl_Gl_Window(X,Y,W,H,L) {
}
void draw() {
//...whatever..//
}
int handle(int e) {
int ret = Fl_Gl_Window::handle(e);
switch ( e ) {
case FL_FOCUS:
case FL_UNFOCUS:
ret = 1; break; // respond to focus
case FL_KEYUP:
case FL_KEYDOWN: // handle certain keyboard events
switch ( Fl::event_key() ) {
case FL_Up: Callback(NULL, (void*)"GL WINDOW: Up" );
ret = 1; break;
case FL_Down: Callback(NULL, (void*)"GL WINDOW: Down" );
ret = 1; break;
case FL_Left: Callback(NULL, (void*)"GL WINDOW: Left" );
ret = 1; break;
case FL_Right: Callback(NULL, (void*)"GL WINDOW: Right");
ret = 1; break;
}
break;
}
return(ret);
}
};
int main(int argc, char *argv[]) {
Fl_Window win(720,486);
Fl_Menu_Bar bar(0,0,720,25);
bar.add("&File/Up", FL_Up, Callback, (void*)"UP");
bar.add("&File/Down", FL_Down, Callback, (void*)"DOWN");
bar.add("&File/&Quit", FL_ALT+'q', Callback, (void*)"QUIT");
Fl_Input a(140,50,200,25,"Input A");
Fl_Input b(140,80,200,25,"Input B");
MyGlWindow gl(10,120,720-20,200);
gl.end();
Fl::focus(&gl); // start with GL window in focus (comment out
if needed)
win.resizable(win);
win.show();
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk