X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FResizer%2FResizer.cpp;h=28350228ce10f77cb7b9f2a93fb45f400d03d880;hb=56cc35535901ef071bf8acab59ba176355ee3e0e;hp=76d55f77320adb3fdaccb337c849e7873aba501f;hpb=89dd359a930dae8ea53261279c57aae9387642ef;p=freeglut diff --git a/progs/demos/Resizer/Resizer.cpp b/progs/demos/Resizer/Resizer.cpp index 76d55f7..2835022 100644 --- a/progs/demos/Resizer/Resizer.cpp +++ b/progs/demos/Resizer/Resizer.cpp @@ -12,7 +12,9 @@ GLboolean bChildPosDone = GL_FALSE, bChildSizeDone = GL_FALSE; void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ); void Redisplay(); -void Reshape(int x, int y); +void Reshape(int width, int height); +void Position(int x, int y); +void WindowStatus(int state); @@ -30,6 +32,12 @@ void DrawQuad() glEnd(); } +void UnhideTimer(int window) +{ + glutSetWindow(window); + glutShowWindow(); +} + void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ) { switch (cChar) @@ -50,7 +58,7 @@ void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ) case 'r': case 'R': - if (nChildWindow!=-1) + if (nChildWindow!=-1 && cChar=='r') /* Capital R always resizes the main window*/ { glutSetWindow(nChildWindow); printf("child window resize\n"); @@ -62,6 +70,7 @@ void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ) } else { + glutSetWindow(nWindow); printf("main window resize\n"); if (nWidth<400) glutReshapeWindow(600,300); @@ -74,10 +83,9 @@ void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ) case 'm': case 'M': - if (nChildWindow!=-1) + if (nChildWindow!=-1 && cChar=='m') /* Capital M always moves the main window*/ { glutSetWindow(nChildWindow); - /* The window position you request is relative to the top-left * corner of the client area of the parent window. */ @@ -89,8 +97,8 @@ void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ) } else { + glutSetWindow(nWindow); printf("main window position\n"); - /* The window position you request is the outer top-left of the window, * the client area is at a different position if the window has borders * and/or a title bar. @@ -117,6 +125,8 @@ void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ) glutKeyboardFunc( SampleKeyboard ); glutDisplayFunc( Redisplay ); glutReshapeFunc( Reshape ); + glutPositionFunc( Position ); + glutWindowStatusFunc( WindowStatus ); } else { @@ -131,6 +141,26 @@ void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY ) break; + case 'i': + case 'I': + glutIconifyWindow(); + break; + + + case 'h': + case 'H': + if (nChildWindow!=-1 && cChar=='h') /* Capital H always hides the main window*/ + { + glutSetWindow(nChildWindow); + glutTimerFunc(2000, UnhideTimer, nChildWindow); + } + else + { + glutSetWindow(nWindow); + glutTimerFunc(2000, UnhideTimer, nWindow); + } + glutHideWindow(); + default: break; } @@ -141,62 +171,44 @@ void Idle(void) glutPostRedisplay(); } -void Reshape(int x, int y) +void Reshape(int width, int height) { int win = glutGetWindow(); - nWidth = glutGet(GLUT_WINDOW_WIDTH); - nHeight = glutGet(GLUT_WINDOW_HEIGHT); printf("reshape %s, %dx%d\n",win==nWindow?"main":"child", - nWidth, nHeight); + width, height); - glViewport(0,0,nWidth,nHeight); + glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluOrtho2D(0,nWidth,0,nHeight); + gluOrtho2D(0,width,0,height); if (win==nWindow && nChildWindow!=-1) { glutSetWindow(nChildWindow); - glutPositionWindow((int)(nWidth*.35),(int)(nHeight*.35)); - glutReshapeWindow((int)(nWidth*.3),(int)(nHeight*.3)); + glutPositionWindow((int)(width*.35),(int)(height*.35)); + glutReshapeWindow((int)(width*.3),(int)(height*.3)); glutSetWindow(nWindow); } } -void Redisplay(void) +void Position(int x, int y) { int win = glutGetWindow(); - if (nLoopMain++%20==0) - { - int border, caption; - - nPosX = glutGet(GLUT_WINDOW_X); - nPosY = glutGet(GLUT_WINDOW_Y); - nWidth = glutGet(GLUT_WINDOW_WIDTH); - nHeight = glutGet(GLUT_WINDOW_HEIGHT); - border = glutGet(GLUT_WINDOW_BORDER_WIDTH); - caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT); - /* returned position is top-left of client area, to get top-left of - * of window you'll need to add the size of the border and caption - * of the current window (can be 0). - * Note that the window position is not necessarily positive (e.g. - * when the window is on a monitor to the left of the primary monitor - * or simply when maximized--try pressing the maximize button). - * the returned size is the size of the client area - */ - if (win==nWindow) - printf("main window %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n", - nWidth, nHeight, - nPosX ,nPosY, - nPosX-border, - nPosY-border-caption); - else - printf("child window %dx%d, top-left of client at: (%d,%d), relative to parent\n", - nWidth, nHeight, - nPosX ,nPosY); - } + printf("position, %s: (%d,%d)\n",win==nWindow?"top-left of main":"top-left of child relative to parent", + x, y); +} + +void WindowStatus(int state) +{ + int win = glutGetWindow(); + printf("windowstatus (win %i): %i\n",win,state); +} + +void Redisplay(void) +{ + int win = glutGetWindow(); if (win==nWindow) { @@ -217,16 +229,59 @@ void Redisplay(void) glutPostWindowRedisplay(win); } +void Timer(int unused) +{ + int win = glutGetWindow(); + int border, caption; + + nPosX = glutGet(GLUT_WINDOW_X); + nPosY = glutGet(GLUT_WINDOW_Y); + nWidth = glutGet(GLUT_WINDOW_WIDTH); + nHeight = glutGet(GLUT_WINDOW_HEIGHT); + border = glutGet(GLUT_WINDOW_BORDER_WIDTH); + caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT); + /* returned position is top-left of client area, to get top-left of + * of window you'll need to add the size of the border and caption + * of the current window (can be 0). + * Note that the window position is not necessarily positive (e.g. + * when the window is on a monitor to the left of the primary monitor + * or simply when maximized--try pressing the maximize button). + * the returned size is the size of the client area + * Note that the top-left of a child window is relative to the + * top-left of the client area of the parent. + */ + /* printf("window border: %dpx, caption: %dpx\n",border,caption); */ + if (win==nWindow) + printf("main window %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n", + nWidth, nHeight, + nPosX ,nPosY, + nPosX-border, + nPosY-border-caption); + else + printf("child window %dx%d, top-left of client at: (%d,%d), relative to parent\n", + nWidth, nHeight, + nPosX ,nPosY); + + /* (re)set the timer callback and ask glut to call it in 500 ms */ + glutTimerFunc(500, Timer, 0); +} + int main(int argc, char* argv[]) { + int border, caption; glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE /*| GLUT_BORDERLESS*/); // do try as well with GLUT_BORDERLESS and GLUT_CAPTIONLESS glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); - - /* The window position you request is the outer top-left of the window, - * the client area is at a different position if the window has borders - * and/or a title bar. + + /* Get border and caption size of default window style */ + border = glutGet(GLUT_WINDOW_BORDER_WIDTH); + caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT); + printf("default window style border: %dpx, caption: %dpx\n",border,caption); + + /* NB: The window position you request is the outer top-left of the + * window, the client area is at a different position if the window has + * borders and/or a title bar. */ glutInitWindowPosition(150,250); glutInitWindowSize(200,200); @@ -237,6 +292,10 @@ int main(int argc, char* argv[]) glutKeyboardFunc( SampleKeyboard ); glutDisplayFunc( Redisplay ); glutReshapeFunc( Reshape ); + glutPositionFunc( Position ); + glutWindowStatusFunc( WindowStatus ); + + glutTimerFunc(300, Timer, 0); glutMainLoop(); printf("glutMainLoop returned\n");