Merge branch 'svn/trunk'

This commit is contained in:
Diederick Niehorster 2014-01-18 00:20:59 +08:00
commit 0b67500f5d
2 changed files with 71 additions and 3 deletions

View File

@ -22,6 +22,62 @@ float color[][3] = {
{0, 1, 1}, {0, 1, 1},
{1, 0, 1} {1, 0, 1}
}; };
int timerInts[] = {
250,
500,
1000
};
int timerSurroundInt = 1000, timerCenterInt = 1000;
/* menu IDs, creation/update funcs and callback */
int menuID, subMenuSurround, subMenuCenter;
void createMenuEntries(int which)
{
for (int i = 0; i < sizeof(timerInts) / sizeof(*timerInts); i++)
{
char temp[10] = {'\0'};
/* flag current value */
if ((which == 1 ? timerSurroundInt : timerCenterInt) == timerInts[i])
temp[0] = '+';
else
temp[0] = '-';
sprintf(temp + 1, " %4d ms", timerInts[i]);
glutAddMenuEntry(temp, timerInts[i]);
}
}
void updateMenuEntries(int which)
{
for (int i = 0; i < sizeof(timerInts) / sizeof(*timerInts); i++)
{
char temp[10] = { '\0' };
/* flag current value */
if ((which == 1 ? timerSurroundInt : timerCenterInt) == timerInts[i])
temp[0] = '+';
else
temp[0] = '-';
sprintf(temp + 1, " %4d ms", timerInts[i]);
glutChangeToMenuEntry(i+1, temp, timerInts[i]);
}
}
void MenuSurround(int timerInt)
{
timerSurroundInt = timerInt;
glutSetMenu(subMenuSurround);
updateMenuEntries(1);
}
void MenuCenter(int timerInt)
{
timerCenterInt = timerInt;
glutSetMenu(subMenuCenter);
updateMenuEntries(2);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -36,6 +92,18 @@ int main(int argc, char **argv)
glutTimerFunc(1000, timer_func, 1); glutTimerFunc(1000, timer_func, 1);
glutTimerFunc(500, timer_func, 2); glutTimerFunc(500, timer_func, 2);
/* menus for setting timing */
subMenuSurround = glutCreateMenu(MenuSurround);
createMenuEntries(1);
subMenuCenter = glutCreateMenu(MenuCenter);
createMenuEntries(2);
menuID = glutCreateMenu(MenuSurround); /* doesn't matter, no clickable entries in this menu */
glutAddSubMenu("Center", subMenuCenter);
glutAddSubMenu("Surround", subMenuSurround);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop(); glutMainLoop();
return 0; return 0;
} }
@ -69,6 +137,6 @@ void timer_func(int which)
glutPostRedisplay(); glutPostRedisplay();
/* (re)set the timer callback and ask glut to call it in 1 second */ /* (re)set the timer callback and ask glut to call it in x ms */
glutTimerFunc(1000, timer_func, which); glutTimerFunc(which == 1 ? timerSurroundInt:timerCenterInt, timer_func, which);
} }

View File

@ -607,7 +607,7 @@ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed,
fgSetWindow( parent_window ); fgSetWindow( parent_window );
fgStructure.CurrentMenu = active_menu; fgStructure.CurrentMenu = active_menu;
/* Deactivate menu and then call callback (we don't want menu to stay in view while callback is executing) */ /* Deactivate menu and then call callback (we don't want menu to stay in view while callback is executing, and user should be able to change menus in callback) */
fgDeactivateMenu( parent_window ); fgDeactivateMenu( parent_window );
active_menu->Callback( active_entry->ID ); active_menu->Callback( active_entry->ID );