Author: cfinck Date: Sun Oct 14 22:21:27 2007 New Revision: 29570
URL: http://svn.reactos.org/svn/reactos?rev=29570&view=rev Log: - Use #define's for setting the borders between elements. - 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
Modified: trunk/reactos/base/applications/games/solitaire/solcreate.cpp trunk/reactos/base/applications/games/solitaire/solitaire.cpp trunk/reactos/base/applications/games/solitaire/solitaire.h
Modified: trunk/reactos/base/applications/games/solitaire/solcreate.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/sol... ============================================================================== --- trunk/reactos/base/applications/games/solitaire/solcreate.cpp (original) +++ trunk/reactos/base/applications/games/solitaire/solcreate.cpp Sun Oct 14 22:21:27 2007 @@ -5,10 +5,6 @@ #include "cardlib/cardlib.h"
#include "solitaire.h" - -const int yBorder = 20; -const int xBorder = 20; -const int yRowStacks = yBorder + 128;
CardRegion *pDeck; CardRegion *pPile; @@ -18,7 +14,7 @@ extern CardStack activepile;
HBITMAP hbmBitmap; -HDC hdcBitmap; +HDC hdcBitmap;
void CreateSol() { @@ -30,7 +26,7 @@ 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 @@ 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 @@ // 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 @@ // 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);
Modified: trunk/reactos/base/applications/games/solitaire/solitaire.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/sol... ============================================================================== --- trunk/reactos/base/applications/games/solitaire/solitaire.cpp (original) +++ trunk/reactos/base/applications/games/solitaire/solitaire.cpp Sun Oct 14 22:21:27 2007 @@ -169,8 +169,8 @@ ,//|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 @@
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 @@ //----------------------------------------------------------------------------- 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(); - - dwAppStartTime = GetTickCount(); - - return 0; - - case WM_DESTROY: - PostQuitMessage(0); - return 0; - - case WM_SIZE: - nWidth = LOWORD(lParam); - nHeight = HIWORD(lParam); - - 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; - - case WM_GETMINMAXINFO: - mmi = (MINMAXINFO *)lParam; - mmi->ptMinTrackSize.x = 600; - mmi->ptMinTrackSize.y = 400; - return 0; - - case WM_COMMAND: - switch(LOWORD(wParam)) - { - case IDM_GAME_NEW: - //simulate a button click on the new button.. + case WM_CREATE: + { + int parts[] = { 100, -1 }; + RECT rcStatus; + + 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)""); + + // 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); + + SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0); + + CreateSol(); + NewGame(); + + dwAppStartTime = GetTickCount(); + return 0; - - case IDM_GAME_DECK: - ShowDeckOptionsDlg(hwnd); + } + + case WM_DESTROY: + PostQuitMessage(0); return 0;
- case IDM_GAME_OPTIONS: - ShowGameOptionsDlg(hwnd); + 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_HELP_CONTENTS: - WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play"); + 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; - - case IDM_HELP_ABOUT: - MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION); + } + + 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; + } + return 0;
- case IDM_GAME_EXIT: - PostMessage(hwnd, WM_CLOSE, 0, 0); + case WM_CLOSE: + if (fGameStarted == false) + { + DestroyWindow(hwnd); + 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 0; - - case WM_CLOSE: - if (fGameStarted == false) - { - DestroyWindow(hwnd); - return 0; - } - else - { - 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);
Modified: trunk/reactos/base/applications/games/solitaire/solitaire.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/sol... ============================================================================== --- trunk/reactos/base/applications/games/solitaire/solitaire.h (original) +++ trunk/reactos/base/applications/games/solitaire/solitaire.h Sun Oct 14 22:21:27 2007 @@ -17,11 +17,20 @@ 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;