glutGet(GLUT_WINDOW_X) and glutGet(GLUT_WINDOW_Y) on a child window now
return top-left of child w.r.t. parent's client area resizer demo now also has child window button 'c'. doesn't work with fullscreen for some reason.... git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1367 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
b5664b39e7
commit
8fb0c5d924
@ -2,21 +2,26 @@
|
|||||||
|
|
||||||
#include <GL/freeglut.h>
|
#include <GL/freeglut.h>
|
||||||
|
|
||||||
int nWindow;
|
int nWindow, nChildWindow = -1;
|
||||||
int nLoopMain = 0;
|
int nLoopMain = 0;
|
||||||
|
|
||||||
int nPosX, nPosY;
|
int nPosX, nPosY;
|
||||||
int nWidth, nHeight;
|
int nWidth, nHeight;
|
||||||
|
|
||||||
|
GLboolean bChildPosDone = GL_FALSE, bChildSizeDone = GL_FALSE;
|
||||||
|
|
||||||
void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY );
|
void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY );
|
||||||
void Redisplay();
|
void Redisplay();
|
||||||
|
void Reshape(int x, int y);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DrawQuad()
|
void DrawQuad()
|
||||||
{
|
{
|
||||||
|
nWidth = glutGet(GLUT_WINDOW_WIDTH);
|
||||||
|
nHeight = glutGet(GLUT_WINDOW_HEIGHT);
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex2d(nWidth*.25, nHeight*.75);
|
glVertex2d(nWidth*.25, nHeight*.75);
|
||||||
glVertex2d(nWidth*.75, nHeight*.75);
|
glVertex2d(nWidth*.75, nHeight*.75);
|
||||||
@ -27,25 +32,62 @@ void DrawQuad()
|
|||||||
|
|
||||||
void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
|
void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
|
||||||
{
|
{
|
||||||
if (cChar == 27)
|
switch (cChar)
|
||||||
|
{
|
||||||
|
case 27:
|
||||||
glutLeaveMainLoop();
|
glutLeaveMainLoop();
|
||||||
|
|
||||||
else if (cChar=='f')
|
break;
|
||||||
{
|
|
||||||
printf("main window toggle fullscreen\n");
|
|
||||||
|
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
case 'F':
|
||||||
|
printf("main window toggle fullscreen\n");
|
||||||
glutFullScreenToggle();
|
glutFullScreenToggle();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
case 'R':
|
||||||
|
if (nChildWindow!=-1)
|
||||||
|
{
|
||||||
|
glutSetWindow(nChildWindow);
|
||||||
|
printf("child window resize\n");
|
||||||
|
if (!bChildSizeDone)
|
||||||
|
glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)+50,glutGet(GLUT_WINDOW_HEIGHT)+50);
|
||||||
|
else
|
||||||
|
glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)-50,glutGet(GLUT_WINDOW_HEIGHT)-50);
|
||||||
|
bChildSizeDone = !bChildSizeDone;
|
||||||
}
|
}
|
||||||
else if (cChar=='r')
|
else
|
||||||
{
|
{
|
||||||
printf("main window resize\n");
|
printf("main window resize\n");
|
||||||
|
|
||||||
if (nWidth<400)
|
if (nWidth<400)
|
||||||
glutReshapeWindow(600,300);
|
glutReshapeWindow(600,300);
|
||||||
else
|
else
|
||||||
glutReshapeWindow(300,300);
|
glutReshapeWindow(300,300);
|
||||||
}
|
}
|
||||||
else if (cChar=='m')
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
case 'M':
|
||||||
|
if (nChildWindow!=-1)
|
||||||
|
{
|
||||||
|
glutSetWindow(nChildWindow);
|
||||||
|
|
||||||
|
/* The window position you request is relative to the top-left
|
||||||
|
* corner of the client area of the parent window.
|
||||||
|
*/
|
||||||
|
if (!bChildPosDone)
|
||||||
|
glutPositionWindow(glutGet(GLUT_WINDOW_X)+50,glutGet(GLUT_WINDOW_Y)+50);
|
||||||
|
else
|
||||||
|
glutPositionWindow(glutGet(GLUT_WINDOW_X)-50,glutGet(GLUT_WINDOW_Y)-50);
|
||||||
|
bChildPosDone = !bChildPosDone;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
printf("main window position\n");
|
printf("main window position\n");
|
||||||
|
|
||||||
@ -58,6 +100,40 @@ void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
|
|||||||
else
|
else
|
||||||
glutPositionWindow(300,300);
|
glutPositionWindow(300,300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case 'c':
|
||||||
|
case 'C':
|
||||||
|
if (nChildWindow==-1)
|
||||||
|
{
|
||||||
|
/* open child window */
|
||||||
|
printf("open child window\n");
|
||||||
|
nWidth = glutGet(GLUT_WINDOW_WIDTH);
|
||||||
|
nHeight = glutGet(GLUT_WINDOW_HEIGHT);
|
||||||
|
|
||||||
|
nChildWindow = glutCreateSubWindow(nWindow,(int)(nWidth*.35),(int)(nHeight*.35),(int)(nWidth*.3),(int)(nHeight*.3));
|
||||||
|
glutKeyboardFunc( SampleKeyboard );
|
||||||
|
glutDisplayFunc( Redisplay );
|
||||||
|
glutReshapeFunc( Reshape );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* close child window */
|
||||||
|
printf("close child window\n");
|
||||||
|
glutSetWindow(nWindow);
|
||||||
|
glutDestroyWindow(nChildWindow);
|
||||||
|
nChildWindow = -1;
|
||||||
|
bChildSizeDone = GL_FALSE;
|
||||||
|
bChildPosDone = GL_FALSE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Idle(void)
|
void Idle(void)
|
||||||
@ -67,18 +143,32 @@ void Idle(void)
|
|||||||
|
|
||||||
void Reshape(int x, int y)
|
void Reshape(int x, int y)
|
||||||
{
|
{
|
||||||
|
int win = glutGetWindow();
|
||||||
|
|
||||||
nWidth = glutGet(GLUT_WINDOW_WIDTH);
|
nWidth = glutGet(GLUT_WINDOW_WIDTH);
|
||||||
nHeight = glutGet(GLUT_WINDOW_HEIGHT);
|
nHeight = glutGet(GLUT_WINDOW_HEIGHT);
|
||||||
|
printf("reshape %s, %dx%d\n",win==nWindow?"main":"child",
|
||||||
|
nWidth, nHeight);
|
||||||
|
|
||||||
glViewport(0,0,nWidth,nHeight);
|
glViewport(0,0,nWidth,nHeight);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluOrtho2D(0,nWidth,0,nHeight);
|
gluOrtho2D(0,nWidth,0,nHeight);
|
||||||
|
|
||||||
|
if (win==nWindow && nChildWindow!=-1)
|
||||||
|
{
|
||||||
|
glutSetWindow(nChildWindow);
|
||||||
|
glutPositionWindow((int)(nWidth*.35),(int)(nHeight*.35));
|
||||||
|
glutReshapeWindow((int)(nWidth*.3),(int)(nHeight*.3));
|
||||||
|
glutSetWindow(nWindow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Redisplay(void)
|
void Redisplay(void)
|
||||||
{
|
{
|
||||||
if (nLoopMain++%6==0)
|
int win = glutGetWindow();
|
||||||
|
|
||||||
|
if (nLoopMain++%20==0)
|
||||||
{
|
{
|
||||||
int border, caption;
|
int border, caption;
|
||||||
|
|
||||||
@ -96,20 +186,35 @@ void Redisplay(void)
|
|||||||
* or simply when maximized--try pressing the maximize button).
|
* or simply when maximized--try pressing the maximize button).
|
||||||
* the returned size is the size of the client area
|
* the returned size is the size of the client area
|
||||||
*/
|
*/
|
||||||
printf("window now %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n",
|
if (win==nWindow)
|
||||||
|
printf("main window %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n",
|
||||||
nWidth, nHeight,
|
nWidth, nHeight,
|
||||||
nPosX ,nPosY,
|
nPosX ,nPosY,
|
||||||
nPosX-border,
|
nPosX-border,
|
||||||
nPosY-border-caption);
|
nPosY-border-caption);
|
||||||
|
else
|
||||||
|
printf("child window %dx%d, top-left of client at: (%d,%d), relative to parent\n",
|
||||||
|
nWidth, nHeight,
|
||||||
|
nPosX ,nPosY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (win==nWindow)
|
||||||
|
{
|
||||||
glClearColor(.2f,0.f,0.f,0.f);
|
glClearColor(.2f,0.f,0.f,0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
glColor3f(1,1,1);
|
glColor3f(1,1,1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* child window */
|
||||||
|
glClearColor(.0f,.2f,0.f,0.f);
|
||||||
|
glColor3f(.5,.5,.5);
|
||||||
|
glutPostWindowRedisplay(nWindow);
|
||||||
|
}
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
DrawQuad();
|
DrawQuad();
|
||||||
|
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
glutPostRedisplay();
|
glutPostWindowRedisplay(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,5 +241,5 @@ int main(int argc, char* argv[])
|
|||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
printf("glutMainLoop returned\n");
|
printf("glutMainLoop returned\n");
|
||||||
|
|
||||||
return 1;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
@ -183,6 +183,19 @@ int fgPlatformGlutGet ( GLenum eWhat )
|
|||||||
GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
|
GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
|
||||||
#else
|
#else
|
||||||
winRect = fghGetClientArea(fgStructure.CurrentWindow, FALSE);
|
winRect = fghGetClientArea(fgStructure.CurrentWindow, FALSE);
|
||||||
|
if (fgStructure.CurrentWindow->Parent && (eWhat==GLUT_WINDOW_X || eWhat==GLUT_WINDOW_Y))
|
||||||
|
{
|
||||||
|
/* For child window, we should return relative to upper-left
|
||||||
|
* of parent's client area.
|
||||||
|
*/
|
||||||
|
POINT topleft;
|
||||||
|
topleft.x = winRect.left;
|
||||||
|
topleft.y = winRect.top;
|
||||||
|
|
||||||
|
ScreenToClient(fgStructure.CurrentWindow->Parent->Window.Handle,&topleft);
|
||||||
|
winRect.left = topleft.x;
|
||||||
|
winRect.top = topleft.y;
|
||||||
|
}
|
||||||
#endif /* defined(_WIN32_WCE) */
|
#endif /* defined(_WIN32_WCE) */
|
||||||
|
|
||||||
switch( eWhat )
|
switch( eWhat )
|
||||||
|
Reference in New Issue
Block a user