Author: gedmurphy
Date: Fri Aug 3 16:47:40 2007
New Revision: 28129
URL:
http://svn.reactos.org/svn/reactos?rev=28129&view=rev
Log:
- add a dialog to allow users to change the card backs
- highlights a few drawing bugs in ros
Modified:
trunk/reactos/base/applications/games/solitaire/cardlib/cardbitmaps.cpp
trunk/reactos/base/applications/games/solitaire/cardlib/cardbutton.cpp
trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.cpp
trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.h
trunk/reactos/base/applications/games/solitaire/lang/en-US.rc
trunk/reactos/base/applications/games/solitaire/resource.h
trunk/reactos/base/applications/games/solitaire/solitaire.cpp
trunk/reactos/base/applications/games/solitaire/solitaire.h
Modified: trunk/reactos/base/applications/games/solitaire/cardlib/cardbitmaps.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/cardlib/cardbitmaps.cpp (original)
+++ trunk/reactos/base/applications/games/solitaire/cardlib/cardbitmaps.cpp Fri Aug 3
16:47:40 2007
@@ -263,7 +263,7 @@
lp = (LOGPALETTE *)HeapAlloc(
GetProcessHeap(), 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nNumColours);
- lp->palNumEntries = nNumColours;
+ lp->palNumEntries = (WORD)nNumColours;
lp->palVersion = 0x300;
//copy the colours into the logical palette format
Modified: trunk/reactos/base/applications/games/solitaire/cardlib/cardbutton.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/cardlib/cardbutton.cpp (original)
+++ trunk/reactos/base/applications/games/solitaire/cardlib/cardbutton.cpp Fri Aug 3
16:47:40 2007
@@ -334,7 +334,7 @@
return 0;
}
-#define _countof(array) (sizeof(array)/sizeof(array[0]))
+//#define _countof(array) (sizeof(array)/sizeof(array[0]))
CardButton *CardWindow::CreateButton(int id, TCHAR *szText, UINT uStyle, bool fVisible,
int x, int y, int width, int height)
{
Modified: trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.cpp (original)
+++ trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.cpp Fri Aug 3
16:47:40 2007
@@ -735,6 +735,11 @@
}
+UINT CardWindow::GetBackCardIdx()
+{
+ return nBackCardIdx;
+}
+
void CardWindow::PaintCardRgn(HDC hdc, int dx, int dy, int width, int height, int sx, int
sy)
{
RECT rect;
Modified: trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.h (original)
+++ trunk/reactos/base/applications/games/solitaire/cardlib/cardwindow.h Fri Aug 3
16:47:40 2007
@@ -46,6 +46,7 @@
void SetBackColor(COLORREF cr);
COLORREF GetBackColor();
void SetBackCardIdx(UINT uBackIdx);
+ UINT GetBackCardIdx();
void SetBackImage(HBITMAP hBitmap);
void EmptyStacks(void);
Modified: trunk/reactos/base/applications/games/solitaire/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/lang/en-US.rc (original)
+++ trunk/reactos/base/applications/games/solitaire/lang/en-US.rc Fri Aug 3 16:47:40
2007
@@ -29,6 +29,20 @@
END
+IDD_CARDBACK DIALOGEX 6, 6, 221, 96
+CAPTION "Select Card Back"
+FONT 8, "MS Shell Dlg"
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_SHELLFONT
+BEGIN
+ CONTROL "", IDC_CARDBACK1, "Static", SS_NOTIFY, 4, 7, 50,
61
+ CONTROL "", IDC_CARDBACK2, "Static", SS_NOTIFY, 58, 7, 50,
61
+ CONTROL "", IDC_CARDBACK3, "Static", SS_NOTIFY, 112, 7, 50,
61
+ CONTROL "", IDC_CARDBACK4, "Static", SS_NOTIFY, 166, 7, 50,
61
+ DEFPUSHBUTTON "OK", IDOK, 104, 77, 54, 13
+ PUSHBUTTON "Cancel", IDCANCEL, 162, 77, 54, 13
+END
+
+
/* Strings */
STRINGTABLE
@@ -48,7 +62,7 @@
BEGIN
MENUITEM "&Deal\tF2", IDM_GAME_NEW
MENUITEM SEPARATOR
- MENUITEM "De&ck...", IDM_GAME_DECK, GRAYED
+ MENUITEM "De&ck...", IDM_GAME_DECK
MENUITEM "&Options...", IDM_GAME_OPTIONS
MENUITEM SEPARATOR
MENUITEM "&Exit", IDM_GAME_EXIT
Modified: trunk/reactos/base/applications/games/solitaire/resource.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/resource.h (original)
+++ trunk/reactos/base/applications/games/solitaire/resource.h Fri Aug 3 16:47:40 2007
@@ -20,6 +20,11 @@
#define IDC_OPT_DRAWTHREE 1202
#define IDC_OPT_SHOWTIME 1203
#define IDC_OPT_STATUSBAR 1204
+#define IDD_CARDBACK 1250
+#define IDC_CARDBACK1 1251
+#define IDC_CARDBACK2 1252
+#define IDC_CARDBACK3 1253
+#define IDC_CARDBACK4 1254
/* Strings */
#define IDS_SOL_NAME 1300
Modified: trunk/reactos/base/applications/games/solitaire/solitaire.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/solitaire.cpp (original)
+++ trunk/reactos/base/applications/games/solitaire/solitaire.cpp Fri Aug 3 16:47:40
2007
@@ -23,6 +23,15 @@
CardWindow SolWnd;
+typedef struct _CardBack
+{
+ HWND hSelf;
+ WNDPROC hOldProc;
+ INT hdcNum;
+ INT imgNum;
+ BOOL bSelected;
+} CARDBACK, *PCARDBACK;
+
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
void MakePath(TCHAR *szDest, UINT nDestLen, const TCHAR *szExt)
@@ -38,10 +47,11 @@
{
DWORD dwDisposition;
DWORD dwSize;
+ DWORD dwBack;
HKEY hKey;
if (RegCreateKeyEx(HKEY_CURRENT_USER,
-
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Solitaire"),
+ _T("Software\\ReactOS\\Solitaire"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
@@ -59,16 +69,26 @@
(LPBYTE)&dwOptions,
&dwSize);
+ dwSize = sizeof(DWORD);
+ RegQueryValueEx(hKey,
+ _T("Back"),
+ NULL,
+ NULL,
+ (LPBYTE)&dwBack,
+ &dwSize);
+ SolWnd.SetBackCardIdx(dwBack);
+
RegCloseKey(hKey);
}
VOID SaveSettings(VOID)
{
DWORD dwDisposition;
+ DWORD dwBack;
HKEY hKey;
if (RegCreateKeyEx(HKEY_CURRENT_USER,
-
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Solitaire"),
+ _T("Software\\ReactOS\\Solitaire"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
@@ -83,6 +103,14 @@
0,
REG_DWORD,
(CONST BYTE *)&dwOptions,
+ sizeof(DWORD));
+
+ dwBack = SolWnd.GetBackCardIdx();
+ RegSetValueEx(hKey,
+ _T("Back"),
+ 0,
+ REG_DWORD,
+ (CONST BYTE *)&dwBack,
sizeof(DWORD));
RegCloseKey(hKey);
@@ -138,13 +166,13 @@
hwnd = CreateWindow(szAppName, // window class name
szAppName, // window caption
WS_OVERLAPPEDWINDOW
- ,//|WS_CLIPCHILDREN, // window style
+ ,//|WS_CLIPCHILDREN, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
- CW_USEDEFAULT, // initial x size
- CW_USEDEFAULT, // initial y size
- NULL, // parent window handle
- NULL, // use window class menu
+ 600, // initial x size
+ 450, // initial y size
+ NULL, // parent window handle
+ NULL, // use window class menu
hInst, // program instance handle
NULL); // creation parameters
@@ -208,6 +236,176 @@
{
if ((dwOldOptions & OPTION_THREE_CARDS) != (dwOptions &
OPTION_THREE_CARDS))
NewGame();
+ }
+}
+
+
+LRESULT CALLBACK
+CardImageWndProc(HWND hwnd,
+ UINT msg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ PCARDBACK pCardBack = (PCARDBACK)GetWindowLongPtr(hwnd,
+ GWL_USERDATA);
+ static WNDPROC hOldProc = NULL;
+
+ if (!hOldProc && pCardBack)
+ hOldProc = pCardBack->hOldProc;
+
+ switch (msg)
+ {
+ case WM_PAINT:
+ {
+ HDC hdc;
+ PAINTSTRUCT ps;
+ HPEN hPen, hOldPen;
+ HBRUSH hBrush, hOldBrush;
+ RECT rc;
+
+ hdc = BeginPaint(hwnd, &ps);
+
+ if (pCardBack->bSelected)
+ {
+ hPen = CreatePen(PS_SOLID, 2, RGB(0,0,0));
+ }
+ else
+ {
+ DWORD Face = GetSysColor(COLOR_3DFACE);
+ hPen = CreatePen(PS_SOLID, 2, Face);
+ }
+
+ GetClientRect(hwnd, &rc);
+ hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
+ hOldPen = (HPEN)SelectObject(hdc, hPen);
+ hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);
+
+ Rectangle(hdc,
+ rc.left+1,
+ rc.top+1,
+ rc.right,
+ rc.bottom);
+
+ BitBlt(hdc,
+ 2,
+ 2,
+ __cardwidth,
+ __cardheight,
+ __hdcCardBitmaps,
+ pCardBack->hdcNum * __cardwidth,
+ 0,
+ SRCCOPY);
+
+ SelectObject(hdc, hOldPen);
+ SelectObject(hdc, hOldBrush);
+
+ EndPaint(hwnd, &ps);
+
+ break;
+ }
+
+ case WM_LBUTTONDOWN:
+ pCardBack->bSelected = pCardBack->bSelected ? FALSE : TRUE;
+ break;
+ }
+
+ return CallWindowProc(hOldProc,
+ hwnd,
+ msg,
+ wParam,
+ lParam);
+}
+
+
+BOOL CALLBACK CardBackDlgProc(HWND hDlg,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ static PCARDBACK pCardBacks = NULL;
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ {
+ INT i, c;
+ SIZE_T size = sizeof(CARDBACK) * NUM_CARDBACKS;
+
+ pCardBacks = (PCARDBACK)HeapAlloc(GetProcessHeap(),
+ 0,
+ size);
+
+ for (i = 0, c = CARDBACK_START; c <= CARDBACK_END; i++, c++)
+ {
+ pCardBacks[i].hSelf = GetDlgItem(hDlg, c);
+ pCardBacks[i].bSelected = FALSE;
+ pCardBacks[i].hdcNum = CARDBACK_RES_START + i;
+ pCardBacks[i].imgNum = i + 1;
+ pCardBacks[i].hOldProc = (WNDPROC)SetWindowLongPtr(pCardBacks[i].hSelf,
+ GWLP_WNDPROC,
+
(LONG_PTR)CardImageWndProc);
+
+ SetWindowLongPtr(pCardBacks[i].hSelf,
+ GWL_USERDATA,
+ (LONG_PTR)&pCardBacks[i]);
+ }
+
+ return TRUE;
+ }
+
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
+ {
+ INT i, num = 0;
+ for (i = 0; i < NUM_CARDBACKS; i++)
+ {
+ if (pCardBacks[i].bSelected)
+ {
+ num = pCardBacks[i].imgNum;
+ }
+ }
+
+ EndDialog(hDlg, LOWORD(wParam) == IDOK ? num : FALSE);
+ HeapFree(GetProcessHeap(), 0, pCardBacks);
+ return TRUE;
+ }
+
+ if (HIWORD(wParam) == STN_CLICKED)
+ {
+ INT i;
+ RECT rc;
+ for (i = 0; i < NUM_CARDBACKS; i++)
+ {
+ if (pCardBacks[i].hSelf == (HWND)lParam)
+ {
+ pCardBacks[i].bSelected = TRUE;
+ }
+ else
+ pCardBacks[i].bSelected = FALSE;
+
+ GetClientRect(pCardBacks[i].hSelf, &rc);
+ InvalidateRect(pCardBacks[i].hSelf, &rc, TRUE);
+ }
+
+ break;
+ }
+ }
+
+ return FALSE;
+}
+
+
+VOID ShowDeckOptionsDlg(HWND hwnd)
+{
+ INT cardBack;
+
+ if ((cardBack = DialogBox(hInstance,
+ MAKEINTRESOURCE(IDD_CARDBACK),
+ hwnd,
+ CardBackDlgProc)))
+ {
+ SolWnd.SetBackCardIdx(CARDBACK_RES_START + (cardBack - 1));
+ SolWnd.Redraw();
}
}
@@ -272,7 +470,7 @@
return 0;
case IDM_GAME_DECK:
- //ShowDeckOptionsDlg(hwnd);
+ ShowDeckOptionsDlg(hwnd);
return 0;
case IDM_GAME_OPTIONS:
Modified: trunk/reactos/base/applications/games/solitaire/solitaire.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/games/so…
==============================================================================
--- trunk/reactos/base/applications/games/solitaire/solitaire.h (original)
+++ trunk/reactos/base/applications/games/solitaire/solitaire.h Fri Aug 3 16:47:40 2007
@@ -6,6 +6,10 @@
extern bool fGameStarted;
#define OPTION_THREE_CARDS 8
+#define CARDBACK_START IDC_CARDBACK1
+#define CARDBACK_END IDC_CARDBACK4
+#define NUM_CARDBACKS (CARDBACK_END - CARDBACK_START + 1)
+#define CARDBACK_RES_START 53
extern DWORD dwOptions;