Author: spitzak
Date: 2008-11-12 12:49:58 -0800 (Wed, 12 Nov 2008)
New Revision: 6521
Log:
Copied suggested patch by Ian MacArthur to fix glut idle callback.
I also fixed the glut popup menus.
Modified:
trunk/fltk/glut.h
trunk/glut/fractals.cxx
trunk/glut/glut_compatability.cxx
Modified: trunk/fltk/glut.h
===================================================================
--- trunk/fltk/glut.h 2008-11-12 17:18:06 UTC (rev 6520)
+++ trunk/fltk/glut.h 2008-11-12 20:49:58 UTC (rev 6521)
@@ -251,7 +251,7 @@
inline void glutVisibilityFunc(void (*f)(int s)) {glut_window->visibility=f;}
enum {GLUT_NOT_VISIBLE, GLUT_VISIBLE};
-inline void glutIdleFunc(void (*f)()) {fltk::set_idle(f);}
+FL_GLUT_API void glutIdleFunc(void (*f)());
// Warning: this cast may not work on all machines:
inline void glutTimerFunc(unsigned int msec, void (*f)(int), int value) {
Modified: trunk/glut/fractals.cxx
===================================================================
--- trunk/glut/fractals.cxx 2008-11-12 17:18:06 UTC (rev 6520)
+++ trunk/glut/fractals.cxx 2008-11-12 20:49:58 UTC (rev 6521)
@@ -750,6 +750,7 @@
// create fltk window:
Window window(512+20, 512+110);
window.resizable(window);
+ window.begin();
// create a bunch of buttons:
Group *g = new Group(50,50,400-110,30,"Level:");
@@ -770,14 +771,12 @@
g->end();
b = new Button(400,50,100,30,"New Fractal");
b->callback(handlemenu,(void*)MENU_RAND);
-
b = new RadioButton( 10,10,100,25,"Mountain");
b->callback(choosefract,(void*)MOUNTAIN);
b = new RadioButton(110,10,100,25,"Tree");
b->callback(choosefract,(void*)TREE);
b->set();
b = new RadioButton(210,10,100,25,"Island");
b->callback(choosefract,(void*)ISLAND);
b = new Button(400,10,100,30,"Quit");
b->callback(handlemenu,(void*)MENU_QUIT);
-
window.show(argc,argv); // glut will die unless parent window visible
window.begin(); // this will cause Glut window to be a child
glutInitWindowSize(512, 512);
Modified: trunk/glut/glut_compatability.cxx
===================================================================
--- trunk/glut/glut_compatability.cxx 2008-11-12 17:18:06 UTC (rev 6520)
+++ trunk/glut/glut_compatability.cxx 2008-11-12 20:49:58 UTC (rev 6521)
@@ -63,6 +63,7 @@
GlutWindow *glut_window;
int glut_menu;
+void (*glut_idle_function)();
void (*glut_menustate_function)(int);
void (*glut_menustatus_function)(int,int,int);
@@ -306,22 +307,22 @@
static Menu* menus[MAXMENUS+1];
static void item_cb(Widget* w, long v) {
- ItemGroup* m = (ItemGroup* )w;
- Item* i = (Item*)m->get_item();
- int num_item= (int) i->argument();
- ( (void(*)(int)) v) (num_item);
+ void* cb = w->parent()->user_data(); // get call passed to glutCreateMenu
+ // v should work but there is an fltk (mis)feature that if it is zero
+ // then the one from the menu is passed.
+ ( (void(*)(int)) cb) (int(w->argument()));
}
static void domenu(int n, int ex, int ey) {
glut_menu = n;
- if (glut_menustate_function)
+ if (glut_menustate_function)
glut_menustate_function(1);
- if (glut_menustatus_function)
+ if (glut_menustatus_function)
glut_menustatus_function(1,ex,ey);
menus[n]->popup(fltk::Rectangle(event_x(), event_y(),0,0), 0);
- if (glut_menustatus_function)
+ if (glut_menustatus_function)
glut_menustatus_function(0,ex,ey);
- if (glut_menustate_function)
+ if (glut_menustate_function)
glut_menustate_function(0);
}
@@ -333,7 +334,6 @@
Menu* m = new ItemGroup("menu");
// store the callback in the user_data, the child widgets will
// look here for it:
- m->callback(item_cb);
m->user_data((void*)cb);
menus[i] = m;
return glut_menu = i;
@@ -347,7 +347,7 @@
void glutAddMenuEntry(const char *label, int value) {
menus[glut_menu]->begin();
Item* m = new Item(label);
- m->callback( menus[glut_menu]->callback()/*item_cb*/,(void*)(long)value);
+ m->callback(item_cb,(long)value);
}
void glutAddSubMenu(const char *label, int submenu) {
@@ -373,6 +373,14 @@
delete m->child(item-1);
}
+void glutIdleFunc(void (*f)())
+{
+ if (glut_idle_function == f) return; // no change
+ if (glut_idle_function) fltk::remove_idle((void (*)(void
*))glut_idle_function);
+ if (f) fltk::add_idle((void (*)(void *))f);
+ glut_idle_function = f;
+}
+
////////////////////////////////////////////////////////////////
int glutGet(GLenum type) {
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit