Exemplo n.º 1
0
void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
{
    RECT windowRect;

    /*
     * For windowed mode, get the current position of the
     * window and resize taking the size of the frame
     * decorations into account.
     */

    /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
    GetWindowRect( window->Window.Handle, &windowRect );

    /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */
    windowRect.right    = windowRect.left+width;
    windowRect.bottom   = windowRect.top+height;

    if (window->Parent == NULL)
        /* get the window rect from this to feed to SetWindowPos, correct for window decorations */
        fghComputeWindowRectFromClientArea_QueryWindow(window,&windowRect,TRUE);
    else
    {
        /* correct rect for position client area of parent window
         * (SetWindowPos input for child windows is in coordinates
         * relative to the parent's client area).
         * Child windows don't have decoration, so no need to correct
         * for them.
         */
        RECT parentRect;
        parentRect = fghGetClientArea( window->Parent, FALSE );
        windowRect.left   -= parentRect.left;
        windowRect.right  -= parentRect.left;
        windowRect.top    -= parentRect.top;
        windowRect.bottom -= parentRect.top;
    }
    
    /* Do the actual resizing */
    SetWindowPos( window->Window.Handle,
                  HWND_TOP,
                  windowRect.left, windowRect.top,
                  windowRect.right - windowRect.left,
                  windowRect.bottom- windowRect.top,
                  SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
                  SWP_NOZORDER
    );
}
Exemplo n.º 2
0
void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
{
    RECT windowRect;

    /*
     * HACK HACK HACK:
     * Before we do anything else, check if this is a newly created window
     * that did not have its windowStatus/visibility func called yet
     * we do that on first paint, but because I want to keep the paint
     * operation as lean as possible, we do it here. The first paint
     * goes together with a first resize call before the display callback
     * is called, so this is just in time. Shitty place to do it, but this
     * is the only reliable way I can think of to call the callback upon
     * first draw of the window.
     * More broadly speaking, I know this is an ugly hack, but I'm not sure
     * what else to do about it.  Depending on WM_ACTIVATE would not work
     * as not all windows get this when you are opening multiple before the
     * mainloop starts. WM_SHOWWINDOW looked like an interesting candidate,
     * but it is generated and processed before glutCreate(Sub)Window
     * returns, so no callback can yet be set on the window.
     */
    /* Check windowStatus/visibility func has been notified that window is visible (deferred from creation time to give user opportunity to register callbacks) */
    if (!window->State.pWState.WindowFuncCalled)
    {
        fghNotifyWindowStatus(window);
        window->State.pWState.WindowFuncCalled = GL_TRUE;
    }

    /*
     * For windowed mode, get the current position of the
     * window and resize taking the size of the frame
     * decorations into account.
     *
     * Note on maximizing behavior of Windows: the resize borders are off
     * the screen such that the client area extends all the way from the
     * leftmost corner to the rightmost corner to maximize screen real
     * estate. A caption is still shown however to allow interaction with
     * the window controls. This is default behavior of Windows that
     * FreeGLUT sticks with. To alter, one would have to check if
     * WS_MAXIMIZE style is set when a resize event is triggered, and
     * then manually correct the windowRect to put the borders back on
     * screen.
     */

    /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
    GetWindowRect( window->Window.Handle, &windowRect );

    /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */
    windowRect.right    = windowRect.left+width;
    windowRect.bottom   = windowRect.top+height;

    if (window->Parent == NULL)
        /* get the window rect from this to feed to SetWindowPos, correct for window decorations */
        fghComputeWindowRectFromClientArea_QueryWindow(&windowRect,window,TRUE);
    else
    {
        /* correct rect for position client area of parent window
         * (SetWindowPos input for child windows is in coordinates
         * relative to the parent's client area).
         * Child windows don't have decoration, so no need to correct
         * for them.
         */
        RECT parentRect;
        fghGetClientArea( &parentRect, window->Parent );
        OffsetRect(&windowRect,-parentRect.left,-parentRect.top);
    }
    
    /* Do the actual resizing */
    SetWindowPos( window->Window.Handle,
                  HWND_TOP,
                  windowRect.left, windowRect.top,
                  windowRect.right - windowRect.left,
                  windowRect.bottom- windowRect.top,
                  SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
                  SWP_NOZORDER
    );

    /* Set new width and height so we can test for that in WM_SIZE message handler and don't do anything if not needed */
    window->State.Width  = width;
    window->State.Height = height;
}