+ 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);
+ }
+ else
+ {
+ *xBorderWidth = 0;
+ *yBorderWidth = 0;
+ }
+}
+
+#if(WINVER >= 0x500)
+typedef struct
+{
+ int *x;
+ int *y;
+ const char *name;
+} m_proc_t;
+
+static BOOL CALLBACK m_proc(HMONITOR mon,
+ HDC hdc,
+ LPRECT rect,
+ LPARAM data)
+{
+ m_proc_t *dp=(m_proc_t *)data;
+ MONITORINFOEX info;
+ BOOL res;
+ info.cbSize=sizeof(info);
+ res=GetMonitorInfo(mon,(LPMONITORINFO)&info);
+ if( res )
+ {
+ if( strcmp(dp->name,info.szDevice)==0 )
+ {
+ *(dp->x)=info.rcMonitor.left;
+ *(dp->y)=info.rcMonitor.top;
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+/*
+ * this function returns the origin of the screen identified by
+ * fgDisplay.DisplayName, and 0 otherwise.
+ * This is used in fgOpenWindow to open the gamemode window on the screen
+ * identified by the -display command line argument. The function should
+ * not be called otherwise.
+ */
+
+static void get_display_origin(int *xp,int *yp)
+{
+ *xp = 0;
+ *yp = 0;
+
+ if( fgDisplay.DisplayName )
+ {
+ m_proc_t st;
+ st.x=xp;
+ st.y=yp;
+ st.name=fgDisplay.DisplayName;
+ EnumDisplayMonitors(0,0,m_proc,(LPARAM)&st);
+ }
+}
+#else
+#pragma message( "-display parameter only works if compiled with WINVER >= 0x0500")
+
+static void get_display_origin(int *xp,int *yp)
+{
+ *xp = 0;
+ *yp = 0;
+
+ if( fgDisplay.DisplayName )
+ {
+ fgWarning( "for working -display support FreeGLUT must be compiled with WINVER >= 0x0500");
+ }
+}