implemented position callback on windows and some other minor edits
authorDiederick Niehorster <dcnieho@gmail.com>
Fri, 23 Nov 2012 07:41:39 +0000 (07:41 +0000)
committerDiederick Niehorster <dcnieho@gmail.com>
Fri, 23 Nov 2012 07:41:39 +0000 (07:41 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1477 7f0cb862-5218-0410-a997-914c9d46530a

progs/demos/CallbackMaker/CallbackMaker.c
progs/demos/Resizer/Resizer.cpp
src/fg_ext.c
src/mswin/fg_main_mswin.c
src/mswin/fg_state_mswin.c

index ec93516..5027ca5 100644 (file)
@@ -207,7 +207,7 @@ Position(int left, int top)
 {
   int 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 ) ;
   position_called[winIdx] = 1 ;
   position_left[winIdx] = left ;
index 60d76fe..58c0552 100644 (file)
@@ -141,29 +141,35 @@ void Idle(void)
     glutPostRedisplay();\r
 }\r
 \r
-void Reshape(int x, int y)\r
+void Reshape(int width, int height)\r
 {\r
     int win = glutGetWindow();\r
 \r
-    nWidth  = glutGet(GLUT_WINDOW_WIDTH);\r
-    nHeight = glutGet(GLUT_WINDOW_HEIGHT);\r
     printf("reshape %s, %dx%d\n",win==nWindow?"main":"child",\r
-        nWidth, nHeight);\r
+        width, height);\r
 \r
-    glViewport(0,0,nWidth,nHeight);\r
+    glViewport(0,0,width,height);\r
     glMatrixMode(GL_PROJECTION);\r
     glLoadIdentity();\r
-    gluOrtho2D(0,nWidth,0,nHeight);\r
+    gluOrtho2D(0,width,0,height);\r
 \r
     if (win==nWindow && nChildWindow!=-1)\r
     {\r
         glutSetWindow(nChildWindow);\r
-        glutPositionWindow((int)(nWidth*.35),(int)(nHeight*.35));\r
-        glutReshapeWindow((int)(nWidth*.3),(int)(nHeight*.3));\r
+        glutPositionWindow((int)(width*.35),(int)(height*.35));\r
+        glutReshapeWindow((int)(width*.3),(int)(height*.3));\r
         glutSetWindow(nWindow);\r
     }\r
 }\r
 \r
+void Position(int x, int y)\r
+{\r
+    int win = glutGetWindow();\r
+\r
+    printf("position %s, %dx%d\n",win==nWindow?"main":"child",\r
+        x, y);\r
+}\r
+\r
 void Redisplay(void)\r
 {\r
     int win = glutGetWindow();\r
@@ -246,6 +252,7 @@ int main(int argc, char* argv[])
     glutKeyboardFunc( SampleKeyboard );\r
     glutDisplayFunc( Redisplay );\r
     glutReshapeFunc( Reshape );\r
+    glutPositionFunc( Position );\r
 \r
     glutMainLoop();\r
     printf("glutMainLoop returned\n");\r
index beadca3..6e1784b 100644 (file)
@@ -86,6 +86,7 @@ static GLUTproc fghGetGLUTProcAddress( const char* procName )
     CHECK_NAME(glutDetachMenu);
     CHECK_NAME(glutDisplayFunc);
     CHECK_NAME(glutReshapeFunc);
+    CHECK_NAME(glutPositionFunc);
     CHECK_NAME(glutKeyboardFunc);
     CHECK_NAME(glutMouseFunc);
     CHECK_NAME(glutMultiEntryFunc);
index 59b2530..981acad 100644 (file)
@@ -427,6 +427,17 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
 
         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:
 /*        printf("WM_SETFOCUS: %p\n", window ); */
 
index 9df5211..bea609e 100644 (file)
@@ -187,11 +187,9 @@ int fgPlatformGlutGet ( GLenum eWhat )
         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.
+             * of parent's client area.
              */
-            POINT topleft;
-            topleft.x = winRect.left;
-            topleft.y = winRect.top;
+            POINT topleft = {winRect.left,winRect.top};
 
             ScreenToClient(fgStructure.CurrentWindow->Parent->Window.Handle,&topleft);
             winRect.left = topleft.x;