- Use #define's for setting the borders between elements.
authorColin Finck <colin@reactos.org>
Sun, 14 Oct 2007 18:21:27 +0000 (18:21 +0000)
committerColin Finck <colin@reactos.org>
Sun, 14 Oct 2007 18:21:27 +0000 (18:21 +0000)
- Don't use some values, which are based on hardcoded card metrics. Compute them using the #define's for the borders and the card metrics instead.
  This way we can use the Bavarian cards.dll (cardsbav) now and theoretically cards in any size :-)
- Set the minimum window height and width by computing the size of all used elements using the new #define's and the card metrics.
- Some indentation changes

svn path=/trunk/; revision=29570

reactos/base/applications/games/solitaire/solcreate.cpp
reactos/base/applications/games/solitaire/solitaire.cpp
reactos/base/applications/games/solitaire/solitaire.h

index 622f2a6..e83a154 100644 (file)
@@ -6,10 +6,6 @@
 
 #include "solitaire.h"
 
-const int yBorder = 20;
-const int xBorder = 20;
-const int yRowStacks = yBorder + 128;
-
 CardRegion *pDeck;
 CardRegion *pPile;
 CardRegion *pSuitStack[4];
@@ -18,7 +14,7 @@ CardRegion *pRowStack[NUM_ROW_STACKS];
 extern CardStack activepile;
 
 HBITMAP hbmBitmap;
-HDC        hdcBitmap;
+HDC     hdcBitmap;
 
 void CreateSol()
 {
@@ -30,7 +26,7 @@ void CreateSol()
     activepile.Clear();
 
 
-    pDeck = SolWnd.CreateRegion(DECK_ID, true, xBorder, yBorder, 2, 1);
+    pDeck = SolWnd.CreateRegion(DECK_ID, true, X_BORDER, Y_BORDER, 2, 1);
     pDeck->SetEmptyImage(CS_EI_SUNK);
     pDeck->SetThreedCount(6);
     pDeck->SetDragRule(CS_DRAG_NONE, 0);
@@ -39,7 +35,7 @@ void CreateSol()
     pDeck->SetDblClickProc(DeckClickProc);
     pDeck->SetFaceDirection(CS_FACE_DOWN, 0);
 
-    pPile = SolWnd.CreateRegion(PILE_ID, true, 110, yBorder, CS_DEFXOFF, 1);
+    pPile = SolWnd.CreateRegion(PILE_ID, true, X_BORDER + __cardwidth + X_PILE_BORDER, Y_BORDER, CS_DEFXOFF, 1);
     pPile->SetEmptyImage(CS_EI_NONE);
     pPile->SetDragRule(CS_DRAG_TOP, 0);
     pPile->SetDropRule(CS_DROP_NONE, 0);
@@ -51,10 +47,9 @@ void CreateSol()
     //
     for(i = 0; i < 4; i++)
     {
-        pSuitStack[i] = SolWnd.CreateRegion(SUIT_ID+i, true, 0, yBorder, 0, 0);
+        pSuitStack[i] = SolWnd.CreateRegion(SUIT_ID+i, true, 0, Y_BORDER, 0, 0);
         pSuitStack[i]->SetEmptyImage(CS_EI_SUNK);
-        //pSuitStack[i]->SetPlacement(CS_XJUST_RIGHT, 0, -i * (__cardwidth + 4) - xBorder, 0);
-        pSuitStack[i]->SetPlacement(CS_XJUST_CENTER, 0, i * (__cardwidth + 10) , 0);
+        pSuitStack[i]->SetPlacement(CS_XJUST_CENTER, 0, i * (__cardwidth + X_SUITSTACK_BORDER) , 0);
 
         pSuitStack[i]->SetDropRule(CS_DROP_CALLBACK, SuitStackDropProc);
         pSuitStack[i]->SetDragRule(CS_DRAG_TOP);
@@ -67,12 +62,12 @@ void CreateSol()
     //
     for(i = 0; i < NUM_ROW_STACKS; i++)
     {
-        pRowStack[i] = SolWnd.CreateRegion(ROW_ID+i, true, 0, yRowStacks, 0, 14);
+        pRowStack[i] = SolWnd.CreateRegion(ROW_ID+i, true, 0, Y_BORDER + __cardheight + Y_ROWSTACK_BORDER, 0, Y_ROWSTACK_CARDOFFSET);
         pRowStack[i]->SetEmptyImage(CS_EI_SUNK);
         pRowStack[i]->SetFaceDirection(CS_FACE_DOWNUP, i);
         
         pRowStack[i]->SetPlacement(CS_XJUST_CENTER, 0, 
-            (i - NUM_ROW_STACKS/2) * (__cardwidth + 10),     0);
+            (i - NUM_ROW_STACKS/2) * (__cardwidth + X_ROWSTACK_BORDER),     0);
 
         pRowStack[i]->SetEmptyImage(CS_EI_NONE);
 
index 7a20862..d0cffa3 100644 (file)
@@ -169,8 +169,8 @@ int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int iCm
                 ,//|WS_CLIPCHILDREN,      // window style
                 CW_USEDEFAULT,            // initial x position
                 CW_USEDEFAULT,            // initial y position
-                600,                      // initial x size
-                450,                      // initial y size
+                0,                        // The real size will be computed in WndProc through WM_GETMINMAXINFO
+                0,                        // The real size will be computed in WndProc through WM_GETMINMAXINFO
                 NULL,                     // parent window handle
                 NULL,                     // use window class menu
                 hInst,                    // program instance handle
@@ -255,11 +255,17 @@ VOID ShowGameOptionsDlg(HWND hwnd)
 
             if (dwOptions & OPTION_SHOW_STATUS)
             {
+                RECT rc;
+
                 ShowWindow(hwndStatus, SW_SHOW);
                 GetWindowRect(hwndStatus, &rcStatus);
                 nStatusHeight = rcStatus.bottom - rcStatus.top;
                 MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE);
                 MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE);
+
+                // Force the window to process WM_GETMINMAXINFO again
+                GetWindowRect(hwndMain, &rc);
+                SetWindowPos(hwndMain, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER);
             }
             else
             {
@@ -443,110 +449,127 @@ VOID ShowDeckOptionsDlg(HWND hwnd)
 //-----------------------------------------------------------------------------
 LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
 {
-    static int nWidth, nHeight;
-    int parts[] = { 100, -1 };
-    int ret;
-    RECT rc;
-    int nStatusHeight = 0;
-
-    MINMAXINFO *mmi;
+    static int nWidth, nHeight, nStatusHeight;
 
     switch(iMsg)
     {
-    case WM_CREATE:
-        hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, _T("Ready"), hwnd, 0);
-
-        //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
-
-        SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts); 
-        SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"");
-
-        SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0);
-
-        CreateSol();
-
-        NewGame();
+        case WM_CREATE:
+        {
+            int parts[] = { 100, -1 };
+            RECT rcStatus;
 
-        dwAppStartTime = GetTickCount();
+            hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, _T("Ready"), hwnd, 0);
 
-        return 0;
+            //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
 
-    case WM_DESTROY:
-        PostQuitMessage(0);
-        return 0;
+            SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts); 
+            SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"");
 
-    case WM_SIZE:
-        nWidth  = LOWORD(lParam);
-        nHeight = HIWORD(lParam);
+            // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
+            // Force the window to process WM_GETMINMAXINFO again
+            GetWindowRect(hwndStatus, &rcStatus);
+            nStatusHeight = rcStatus.bottom - rcStatus.top;
+            SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER);
 
-        if (dwOptions & OPTION_SHOW_STATUS)
-        {
-            GetWindowRect(hwndStatus, &rc);
-            nStatusHeight = rc.bottom - rc.top;
-            MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE);
-            MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE);
-        }
-        else
-        {
-            MoveWindow(SolWnd, 0, 0, nWidth, nHeight, TRUE);
-        }
-        //parts[0] = nWidth - 256;
-        //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts); 
-        return 0;
+            SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0);
 
-    case WM_GETMINMAXINFO:
-        mmi = (MINMAXINFO *)lParam;
-        mmi->ptMinTrackSize.x = 600;
-        mmi->ptMinTrackSize.y = 400;
-        return 0;
+            CreateSol();
 
-    case WM_COMMAND:
-        switch(LOWORD(wParam))
-        {
-        case IDM_GAME_NEW:
-            //simulate a button click on the new button..
             NewGame();
-            return 0;
 
-        case IDM_GAME_DECK:
-            ShowDeckOptionsDlg(hwnd);
-            return 0;
+            dwAppStartTime = GetTickCount();
 
-        case IDM_GAME_OPTIONS:
-            ShowGameOptionsDlg(hwnd);
             return 0;
+        }
 
-        case IDM_HELP_CONTENTS:
-            WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
+        case WM_DESTROY:
+            PostQuitMessage(0);
             return 0;
 
-        case IDM_HELP_ABOUT:
-            MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION);
+        case WM_SIZE:
+            nWidth  = LOWORD(lParam);
+            nHeight = HIWORD(lParam);
+
+            if (dwOptions & OPTION_SHOW_STATUS)
+            {
+                MoveWindow(SolWnd, 0, 0, nWidth, nHeight - nStatusHeight, TRUE);
+                MoveWindow(hwndStatus, 0, nHeight - nStatusHeight, nWidth, nHeight, TRUE);
+            }
+            else
+            {
+                MoveWindow(SolWnd, 0, 0, nWidth, nHeight, TRUE);
+            }
+            //parts[0] = nWidth - 256;
+            //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts); 
             return 0;
 
-        case IDM_GAME_EXIT:
-            PostMessage(hwnd, WM_CLOSE, 0, 0);
+        case WM_GETMINMAXINFO:
+        {
+            MINMAXINFO *mmi;
+
+            mmi = (MINMAXINFO *)lParam;
+            mmi->ptMinTrackSize.x = X_BORDER + NUM_ROW_STACKS * (__cardwidth + X_ROWSTACK_BORDER) + X_BORDER;
+            mmi->ptMinTrackSize.y = GetSystemMetrics(SM_CYCAPTION) +
+                                    GetSystemMetrics(SM_CYMENU) +
+                                    Y_BORDER +
+                                    __cardheight +
+                                    Y_ROWSTACK_BORDER +
+                                    6 * Y_ROWSTACK_CARDOFFSET +
+                                    __cardheight +
+                                    Y_BORDER +
+                                    (dwOptions & OPTION_SHOW_STATUS ? nStatusHeight : 0);
             return 0;
         }
 
-        return 0;
+        case WM_COMMAND:
+            switch(LOWORD(wParam))
+            {
+            case IDM_GAME_NEW:
+                //simulate a button click on the new button..
+                NewGame();
+                return 0;
+
+            case IDM_GAME_DECK:
+                ShowDeckOptionsDlg(hwnd);
+                return 0;
+
+            case IDM_GAME_OPTIONS:
+                ShowGameOptionsDlg(hwnd);
+                return 0;
+
+            case IDM_HELP_CONTENTS:
+                WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
+                return 0;
+
+            case IDM_HELP_ABOUT:
+                MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION);
+                return 0;
+
+            case IDM_GAME_EXIT:
+                PostMessage(hwnd, WM_CLOSE, 0, 0);
+                return 0;
+            }
 
-    case WM_CLOSE:
-        if (fGameStarted == false)
-        {
-            DestroyWindow(hwnd);
             return 0;
-        }
-        else
-        {
-            ret = MessageBox(hwnd, MsgQuit, szAppName, MB_OKCANCEL|MB_ICONQUESTION);
-            if (ret == IDOK)
+
+        case WM_CLOSE:
+            if (fGameStarted == false)
             {
-                WinHelp(hwnd, szHelpPath, HELP_QUIT, 0);
                 DestroyWindow(hwnd);
+                return 0;
             }
-        }
-        return 0;
+            else
+            {
+                int ret;
+
+                ret = MessageBox(hwnd, MsgQuit, szAppName, MB_OKCANCEL|MB_ICONQUESTION);
+                if (ret == IDOK)
+                {
+                    WinHelp(hwnd, szHelpPath, HELP_QUIT, 0);
+                    DestroyWindow(hwnd);
+                }
+            }
+            return 0;
     }
 
     return DefWindowProc (hwnd, iMsg, wParam, lParam);
index 79b524c..f49799f 100644 (file)
@@ -17,11 +17,20 @@ extern DWORD dwOptions;
 void CreateSol();
 void NewGame(void);
 
-#define NUM_ROW_STACKS 7
-#define DECK_ID                        1
-#define PILE_ID                        2
-#define SUIT_ID                        4
-#define ROW_ID                 10
+#define NUM_ROW_STACKS     7
+#define DECK_ID            1
+#define PILE_ID            2
+#define SUIT_ID            4
+#define ROW_ID             10
+
+// Various metrics used for placing the objects and computing the minimum window size
+#define X_BORDER                 20
+#define X_PILE_BORDER            18
+#define X_ROWSTACK_BORDER        10
+#define X_SUITSTACK_BORDER       10
+#define Y_BORDER                 20
+#define Y_ROWSTACK_BORDER        32
+#define Y_ROWSTACK_CARDOFFSET    14
 
 extern CardRegion *pDeck;
 extern CardRegion *pPile;