+ clientRect->right += xBorderWidth * 2;
+ clientRect->bottom += yBorderWidth * 2;
+ }
+ else
+ {
+ clientRect->left -= xBorderWidth;
+ clientRect->right += xBorderWidth;
+ clientRect->top -= yBorderWidth;
+ clientRect->bottom += yBorderWidth;
+ }
+}
+
+/* Computes position of corners of window Rect (outer position including
+ * decorations) based on the provided client rect and based on the style
+ * of the window in question. If the window pointer or the window handle
+ * is NULL, a fully decorated window (caption and border) is assumed.
+ * Furthermore, if posIsOutside is set to true, the input client Rect is
+ * taken to follow freeGLUT's window specification convention in which the
+ * top-left corner is at the outside of the window, while the size
+ * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable
+ * area.
+*/
+void fghComputeWindowRectFromClientArea_QueryWindow( const SFG_Window *window, RECT *clientRect, BOOL posIsOutside )
+{
+ DWORD windowStyle = 0;
+
+ if (window && window->Window.Handle)
+ windowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
+ else
+ windowStyle = WS_OVERLAPPEDWINDOW;
+
+ fghComputeWindowRectFromClientArea_UseStyle(windowStyle, clientRect, posIsOutside);
+}
+
+/* Computes position of corners of client area (drawable area) of a window
+ * based on the provided window Rect (outer position including decorations)
+ * and based on the style of the window in question. If the window pointer
+ * or the window handle is NULL, a fully decorated window (caption and
+ * border) is assumed.
+ * Furthermore, if wantPosOutside is set to true, the output client Rect
+ * will follow freeGLUT's window specification convention in which the
+ * top-left corner is at the outside of the window, the size
+ * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable
+ * area.
+ */
+void fghComputeClientAreaFromWindowRect( const SFG_Window *window, RECT *windowRect, BOOL wantPosOutside )
+{
+ DWORD windowStyle = 0;
+ int xBorderWidth = 0, yBorderWidth = 0;
+
+ if (window && window->Window.Handle)
+ windowStyle = GetWindowLong(window->Window.Handle, GWL_STYLE);
+ else
+ windowStyle = WS_OVERLAPPEDWINDOW;
+
+ /* If window has title bar, correct rect for it */
+ if (windowStyle & WS_MAXIMIZEBOX) /* Need to query for WS_MAXIMIZEBOX to see if we have a title bar, the WS_CAPTION query is also true for a WS_DLGFRAME only... */
+ if (wantPosOutside)
+ windowRect->bottom -= GetSystemMetrics( SM_CYCAPTION );
+ else
+ windowRect->top += GetSystemMetrics( SM_CYCAPTION );
+
+ /* get width of window's borders (frame), correct rect for it.
+ * Note, borders can be of zero width if style does not specify borders
+ */
+ fghGetBorderWidth(windowStyle, &xBorderWidth, &yBorderWidth);
+ if (wantPosOutside)
+ {
+ windowRect->right -= xBorderWidth * 2;
+ windowRect->bottom -= yBorderWidth * 2;
+ }
+ else
+ {
+ windowRect->left += xBorderWidth;
+ windowRect->right -= xBorderWidth;
+ windowRect->top += yBorderWidth;
+ windowRect->bottom -= yBorderWidth;
+ }
+}
+
+/* Gets the rect describing the client area (drawable area) of the
+ * specified window.
+ * Returns an empty rect if window pointer or window handle is NULL.
+ * If wantPosOutside is set to true, the output client Rect
+ * will follow freeGLUT's window specification convention in which the
+ * top-left corner is at the outside of the window, while the size
+ * (rect.right-rect.left,rect.bottom-rect.top) is the size of the drawable
+ * area.
+ */
+RECT fghGetClientArea( const SFG_Window *window, BOOL wantPosOutside )
+{
+ RECT windowRect = {0,0,0,0};
+
+ freeglut_return_val_if_fail((window && window->Window.Handle),windowRect);
+
+ /*
+ * call GetWindowRect()
+ * (this returns the pixel coordinates of the outside of the window)
+ */
+ GetWindowRect( window->Window.Handle, &windowRect );
+
+ /* Then correct the results */
+ fghComputeClientAreaFromWindowRect(window, &windowRect, wantPosOutside);
+
+ return windowRect;
+}
+
+/* Returns the width of the window borders based on the window's style.
+ */
+void fghGetBorderWidth(const DWORD windowStyle, int* xBorderWidth, int* yBorderWidth)
+{
+ if (windowStyle & WS_THICKFRAME)
+ {
+ *xBorderWidth = GetSystemMetrics(SM_CXSIZEFRAME);
+ *yBorderWidth = GetSystemMetrics(SM_CYSIZEFRAME);
+ }
+ else if (windowStyle & WS_DLGFRAME)
+ {
+ *xBorderWidth = GetSystemMetrics(SM_CXFIXEDFRAME);
+ *yBorderWidth = GetSystemMetrics(SM_CYFIXEDFRAME);