implemented position callback on windows and some other minor edits

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1477 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2012-11-23 07:41:39 +00:00
parent a0b41213a5
commit aa38dc56b4
5 changed files with 30 additions and 13 deletions

View File

@ -207,7 +207,7 @@ Position(int left, int top)
{ {
int winIdx; int winIdx;
int window = getWindowAndIdx(&winIdx); int window = getWindowAndIdx(&winIdx);
printf ( "%6d Window %d Reshape Callback: %d %d\n", printf ( "%6d Window %d Position Callback: %d %d\n",
++sequence_number, window, left, top ) ; ++sequence_number, window, left, top ) ;
position_called[winIdx] = 1 ; position_called[winIdx] = 1 ;
position_left[winIdx] = left ; position_left[winIdx] = left ;

View File

@ -141,29 +141,35 @@ void Idle(void)
glutPostRedisplay(); glutPostRedisplay();
} }
void Reshape(int x, int y) void Reshape(int width, int height)
{ {
int win = glutGetWindow(); int win = glutGetWindow();
nWidth = glutGet(GLUT_WINDOW_WIDTH);
nHeight = glutGet(GLUT_WINDOW_HEIGHT);
printf("reshape %s, %dx%d\n",win==nWindow?"main":"child", 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); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluOrtho2D(0,nWidth,0,nHeight); gluOrtho2D(0,width,0,height);
if (win==nWindow && nChildWindow!=-1) if (win==nWindow && nChildWindow!=-1)
{ {
glutSetWindow(nChildWindow); glutSetWindow(nChildWindow);
glutPositionWindow((int)(nWidth*.35),(int)(nHeight*.35)); glutPositionWindow((int)(width*.35),(int)(height*.35));
glutReshapeWindow((int)(nWidth*.3),(int)(nHeight*.3)); glutReshapeWindow((int)(width*.3),(int)(height*.3));
glutSetWindow(nWindow); glutSetWindow(nWindow);
} }
} }
void Position(int x, int y)
{
int win = glutGetWindow();
printf("position %s, %dx%d\n",win==nWindow?"main":"child",
x, y);
}
void Redisplay(void) void Redisplay(void)
{ {
int win = glutGetWindow(); int win = glutGetWindow();
@ -246,6 +252,7 @@ int main(int argc, char* argv[])
glutKeyboardFunc( SampleKeyboard ); glutKeyboardFunc( SampleKeyboard );
glutDisplayFunc( Redisplay ); glutDisplayFunc( Redisplay );
glutReshapeFunc( Reshape ); glutReshapeFunc( Reshape );
glutPositionFunc( Position );
glutMainLoop(); glutMainLoop();
printf("glutMainLoop returned\n"); printf("glutMainLoop returned\n");

View File

@ -86,6 +86,7 @@ static GLUTproc fghGetGLUTProcAddress( const char* procName )
CHECK_NAME(glutDetachMenu); CHECK_NAME(glutDetachMenu);
CHECK_NAME(glutDisplayFunc); CHECK_NAME(glutDisplayFunc);
CHECK_NAME(glutReshapeFunc); CHECK_NAME(glutReshapeFunc);
CHECK_NAME(glutPositionFunc);
CHECK_NAME(glutKeyboardFunc); CHECK_NAME(glutKeyboardFunc);
CHECK_NAME(glutMouseFunc); CHECK_NAME(glutMouseFunc);
CHECK_NAME(glutMultiEntryFunc); CHECK_NAME(glutMultiEntryFunc);

View File

@ -427,6 +427,17 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
break; break;
case WM_MOVE:
{
SFG_Window* saved_window = fgStructure.CurrentWindow;
RECT windowRect;
GetWindowRect( window->Window.Handle, &windowRect );
INVOKE_WCB( *window, Position, ( windowRect.left, windowRect.top ) );
fgSetWindow(saved_window);
}
break;
case WM_SETFOCUS: case WM_SETFOCUS:
/* printf("WM_SETFOCUS: %p\n", window ); */ /* printf("WM_SETFOCUS: %p\n", window ); */

View File

@ -189,9 +189,7 @@ int fgPlatformGlutGet ( GLenum eWhat )
/* For child window, we should return relative to upper-left /* For child window, we should return relative to upper-left
* of parent's client area. * of parent's client area.
*/ */
POINT topleft; POINT topleft = {winRect.left,winRect.top};
topleft.x = winRect.left;
topleft.y = winRect.top;
ScreenToClient(fgStructure.CurrentWindow->Parent->Window.Handle,&topleft); ScreenToClient(fgStructure.CurrentWindow->Parent->Window.Handle,&topleft);
winRect.left = topleft.x; winRect.left = topleft.x;