diff --git a/rosapps/games/solitaire/cardlib/cardbitmaps.cpp b/rosapps/games/solitaire/cardlib/cardbitmaps.cpp index 530f6517721..9c5b4da81ad 100644 --- a/rosapps/games/solitaire/cardlib/cardbitmaps.cpp +++ b/rosapps/games/solitaire/cardlib/cardbitmaps.cpp @@ -1,8 +1,8 @@ // -// CardLib - Card bitmap support +// CardLib - Card bitmap support // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include #include "globals.h" @@ -12,7 +12,7 @@ #pragma comment( lib, "..\\CardLib\\cards16.lib" ) extern "C" HINSTANCE WINAPI LoadLibrary16( PSTR ); -extern "C" void WINAPI FreeLibrary16( HINSTANCE ); +extern "C" void WINAPI FreeLibrary16( HINSTANCE ); #endif #define NUMCARDBITMAPS (52+16) @@ -21,261 +21,261 @@ void PaintRect(HDC hdc, RECT *rect, COLORREF col); void LoadCardBitmapsFromLibrary(HINSTANCE hCardDll, int *pwidth, int *pheight) { - HBITMAP hBitmap; - HDC hdcCard; - HANDLE hOld; - int i, xpos; - int width, height; - BITMAP bmp; + HBITMAP hBitmap; + HDC hdcCard; + HANDLE hOld; + int i, xpos; + int width, height; + BITMAP bmp; - for(i = 0; i < NUMCARDBITMAPS; i++) - { - //convert into the range used by the cdt_xxx functions - int val; - - if(i < 52) val = (i % 4) * 13 + (i/4); - else val = i; - - hBitmap = LoadBitmap(hCardDll, MAKEINTRESOURCE(val + 1)); - GetObject(hBitmap, sizeof(bmp), &bmp); - - width = bmp.bmWidth; - height = bmp.bmHeight; - - if(i == 0) //if first time through, create BIG bitmap.. - { - HDC hdc = GetDC(0); - __hdcCardBitmaps = CreateCompatibleDC(hdc); - __hbmCardBitmaps = CreateCompatibleBitmap(hdc, width * NUMCARDBITMAPS, height); - SelectObject(__hdcCardBitmaps, __hbmCardBitmaps); - - hdcCard = CreateCompatibleDC(0); - - ReleaseDC(0, hdc); - } - - hOld = SelectObject(hdcCard, hBitmap); - BitBlt(__hdcCardBitmaps, i*width, 0, width, height, hdcCard, 0, 0, SRCCOPY); - SelectObject(hdcCard, hOld); - - //Now draw a black border around each card... - xpos = i*width; - MoveToEx(__hdcCardBitmaps, xpos+2, 0, 0); - LineTo(__hdcCardBitmaps, xpos+width - 3, 0); - LineTo(__hdcCardBitmaps, xpos+width - 1, 2); - LineTo(__hdcCardBitmaps, xpos+width - 1, height - 3); //vertical - LineTo(__hdcCardBitmaps, xpos+width - 3, height - 1); - LineTo(__hdcCardBitmaps, xpos+2, height - 1); - LineTo(__hdcCardBitmaps, xpos+0, height - 3); - LineTo(__hdcCardBitmaps, xpos+0, 2); - LineTo(__hdcCardBitmaps, xpos+2, 0); - - DeleteObject(hBitmap); - } - - DeleteDC(hdcCard); + for(i = 0; i < NUMCARDBITMAPS; i++) + { + //convert into the range used by the cdt_xxx functions + int val; + + if(i < 52) val = (i % 4) * 13 + (i/4); + else val = i; + + hBitmap = LoadBitmap(hCardDll, MAKEINTRESOURCE(val + 1)); + GetObject(hBitmap, sizeof(bmp), &bmp); + + width = bmp.bmWidth; + height = bmp.bmHeight; + + if(i == 0) //if first time through, create BIG bitmap.. + { + HDC hdc = GetDC(0); + __hdcCardBitmaps = CreateCompatibleDC(hdc); + __hbmCardBitmaps = CreateCompatibleBitmap(hdc, width * NUMCARDBITMAPS, height); + SelectObject(__hdcCardBitmaps, __hbmCardBitmaps); + + hdcCard = CreateCompatibleDC(0); + + ReleaseDC(0, hdc); + } + + hOld = SelectObject(hdcCard, hBitmap); + BitBlt(__hdcCardBitmaps, i*width, 0, width, height, hdcCard, 0, 0, SRCCOPY); + SelectObject(hdcCard, hOld); + + //Now draw a black border around each card... + xpos = i*width; + MoveToEx(__hdcCardBitmaps, xpos+2, 0, 0); + LineTo(__hdcCardBitmaps, xpos+width - 3, 0); + LineTo(__hdcCardBitmaps, xpos+width - 1, 2); + LineTo(__hdcCardBitmaps, xpos+width - 1, height - 3); //vertical + LineTo(__hdcCardBitmaps, xpos+width - 3, height - 1); + LineTo(__hdcCardBitmaps, xpos+2, height - 1); + LineTo(__hdcCardBitmaps, xpos+0, height - 3); + LineTo(__hdcCardBitmaps, xpos+0, 2); + LineTo(__hdcCardBitmaps, xpos+2, 0); + + DeleteObject(hBitmap); + } + + DeleteDC(hdcCard); - *pwidth = width; - *pheight = height; - + *pwidth = width; + *pheight = height; + } void LoadCardBitmaps(void) { - HINSTANCE hCardDll; - + HINSTANCE hCardDll; + - //If Windows NT/2000/XP - if(GetVersion() < 0x80000000) - { - hCardDll = LoadLibrary("cards.dll"); + //If Windows NT/2000/XP + if(GetVersion() < 0x80000000) + { + hCardDll = LoadLibrary("cards.dll"); - if(hCardDll == 0) - { - MessageBox(0, "Error loading cards.dll (32bit)", "Shed", MB_OK | MB_ICONEXCLAMATION); - PostQuitMessage(0); - return; - } - - LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight); - - FreeLibrary(hCardDll); - } + if(hCardDll == 0) + { + MessageBox(0, "Error loading cards.dll (32bit)", "Shed", MB_OK | MB_ICONEXCLAMATION); + PostQuitMessage(0); + return; + } + + LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight); + + FreeLibrary(hCardDll); + } #ifndef __REACTOS__ - //Else, Win9X - else - { - hCardDll = LoadLibrary16("cards.dll"); + //Else, Win9X + else + { + hCardDll = LoadLibrary16("cards.dll"); - if(hCardDll == 0) - { - MessageBox(0, "Error loading cards.dll (16bit)", "Shed", MB_OK | MB_ICONEXCLAMATION); - PostQuitMessage(0); - return; - } + if(hCardDll == 0) + { + MessageBox(0, "Error loading cards.dll (16bit)", "Shed", MB_OK | MB_ICONEXCLAMATION); + PostQuitMessage(0); + return; + } - LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight); + LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight); - FreeLibrary16(hCardDll); - } + FreeLibrary16(hCardDll); + } #endif } void FreeCardBitmaps() { - DeleteObject (__hbmCardBitmaps); - DeleteDC (__hdcCardBitmaps); + DeleteObject (__hbmCardBitmaps); + DeleteDC (__hdcCardBitmaps); } // -// Paint a checkered rectangle, with each alternate -// pixel being assigned a different colour +// Paint a checkered rectangle, with each alternate +// pixel being assigned a different colour // static void DrawCheckedRect(HDC hdc, RECT *rect, COLORREF fg, COLORREF bg) { - static WORD wCheckPat[8] = - { - 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555 - }; + static WORD wCheckPat[8] = + { + 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555 + }; - HBITMAP hbmp; - HBRUSH hbr, hbrold; - COLORREF fgold, bgold; + HBITMAP hbmp; + HBRUSH hbr, hbrold; + COLORREF fgold, bgold; - hbmp = CreateBitmap(8, 8, 1, 1, wCheckPat); - hbr = CreatePatternBrush(hbmp); + hbmp = CreateBitmap(8, 8, 1, 1, wCheckPat); + hbr = CreatePatternBrush(hbmp); - //UnrealizeObject(hbr); + //UnrealizeObject(hbr); - SetBrushOrgEx(hdc, rect->left, rect->top, 0); + SetBrushOrgEx(hdc, rect->left, rect->top, 0); - hbrold = (HBRUSH)SelectObject(hdc, hbr); + hbrold = (HBRUSH)SelectObject(hdc, hbr); - fgold = SetTextColor(hdc, fg); - bgold = SetBkColor(hdc, bg); - - PatBlt(hdc, rect->left, rect->top, - rect->right - rect->left, - rect->bottom - rect->top, - PATCOPY); - - SetBkColor(hdc, bgold); - SetTextColor(hdc, fgold); - - SelectObject(hdc, hbrold); - DeleteObject(hbr); - DeleteObject(hbmp); + fgold = SetTextColor(hdc, fg); + bgold = SetBkColor(hdc, bg); + + PatBlt(hdc, rect->left, rect->top, + rect->right - rect->left, + rect->bottom - rect->top, + PATCOPY); + + SetBkColor(hdc, bgold); + SetTextColor(hdc, fgold); + + SelectObject(hdc, hbrold); + DeleteObject(hbr); + DeleteObject(hbmp); } void GetSinkCols(COLORREF crBase, COLORREF *fg, COLORREF *bg, COLORREF *sh1, COLORREF *sh2) { - if(bg) *bg = crBase; - if(fg) *fg = ColorScaleRGB(crBase, RGB(255,255,255), 0.2);//RGB(49, 99, 140); - if(sh1) *sh1 = ColorScaleRGB(crBase, RGB(0,0,0), 0.4); - if(sh2) *sh2 = ColorScaleRGB(crBase, RGB(0,0,0), 0.2); + if(bg) *bg = crBase; + if(fg) *fg = ColorScaleRGB(crBase, RGB(255,255,255), 0.2);//RGB(49, 99, 140); + if(sh1) *sh1 = ColorScaleRGB(crBase, RGB(0,0,0), 0.4); + if(sh2) *sh2 = ColorScaleRGB(crBase, RGB(0,0,0), 0.2); } HBITMAP CreateSinkBmp(HDC hdcCompat, HDC hdc, COLORREF col, int width, int height) { - HANDLE hold, hpold; - HBITMAP hbm = CreateCompatibleBitmap(hdcCompat, width, height); + HANDLE hold, hpold; + HBITMAP hbm = CreateCompatibleBitmap(hdcCompat, width, height); - HPEN hpfg, hpbg, hpsh, hpsh2; + HPEN hpfg, hpbg, hpsh, hpsh2; - RECT rect; - COLORREF fg, bg, shadow, shadow2; + RECT rect; + COLORREF fg, bg, shadow, shadow2; - GetSinkCols(col, &fg, &bg, &shadow, &shadow2); + GetSinkCols(col, &fg, &bg, &shadow, &shadow2); - hold = SelectObject(hdc, hbm); + hold = SelectObject(hdc, hbm); - //fill with a solid base colour - SetRect(&rect, 0,0,width,height); - PaintRect(hdc, &rect, MAKE_PALETTERGB(bg)); + //fill with a solid base colour + SetRect(&rect, 0,0,width,height); + PaintRect(hdc, &rect, MAKE_PALETTERGB(bg)); - //draw the outline - hpfg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(fg)); - hpbg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(bg)); - hpsh = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow)); - hpsh2= CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow2)); + //draw the outline + hpfg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(fg)); + hpbg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(bg)); + hpsh = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow)); + hpsh2= CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow2)); - hpold = SelectObject(hdc, hpsh); - MoveToEx(hdc, 2, 0, NULL); - LineTo (hdc, width-3,0); - LineTo (hdc, width-1, 2); - - SelectObject(hdc, hpold); - hpold = SelectObject(hdc, hpsh2); - LineTo (hdc, width-1, height-3); //vertical - LineTo (hdc, width-3, height-1); - LineTo (hdc, 2, height-1); - LineTo (hdc, 0, height-3); - SelectObject(hdc, hpold); - hpold = SelectObject(hdc, hpsh); + hpold = SelectObject(hdc, hpsh); + MoveToEx(hdc, 2, 0, NULL); + LineTo (hdc, width-3,0); + LineTo (hdc, width-1, 2); + + SelectObject(hdc, hpold); + hpold = SelectObject(hdc, hpsh2); + LineTo (hdc, width-1, height-3); //vertical + LineTo (hdc, width-3, height-1); + LineTo (hdc, 2, height-1); + LineTo (hdc, 0, height-3); + SelectObject(hdc, hpold); + hpold = SelectObject(hdc, hpsh); - //MoveToEx( hdc, 0, height-3,0); - LineTo (hdc, 0, 2); - LineTo (hdc, 2, 0); + //MoveToEx( hdc, 0, height-3,0); + LineTo (hdc, 0, 2); + LineTo (hdc, 2, 0); - SelectObject(hdc, hpold); + SelectObject(hdc, hpold); - //draw the highlight (vertical) - hpold = SelectObject(hdc, hpfg); - MoveToEx(hdc, width - 2, 3, NULL); - LineTo (hdc, width - 2, height - 2); - - //(horz) - MoveToEx(hdc, width - 3, height-2, NULL); - LineTo (hdc, 3, height-2); - SelectObject(hdc, hpold); - - //draw the background - InflateRect(&rect, -2, -2); - DrawCheckedRect(hdc, &rect, MAKE_PALETTERGB(bg), MAKE_PALETTERGB(fg)); + //draw the highlight (vertical) + hpold = SelectObject(hdc, hpfg); + MoveToEx(hdc, width - 2, 3, NULL); + LineTo (hdc, width - 2, height - 2); + + //(horz) + MoveToEx(hdc, width - 3, height-2, NULL); + LineTo (hdc, 3, height-2); + SelectObject(hdc, hpold); + + //draw the background + InflateRect(&rect, -2, -2); + DrawCheckedRect(hdc, &rect, MAKE_PALETTERGB(bg), MAKE_PALETTERGB(fg)); - //overwrite the top-left background pixel - SetPixel(hdc, 2, 2, MAKE_PALETTERGB(bg)); + //overwrite the top-left background pixel + SetPixel(hdc, 2, 2, MAKE_PALETTERGB(bg)); - DeleteObject(hpsh); - DeleteObject(hpsh2); - DeleteObject(hpfg); - DeleteObject(hpbg); + DeleteObject(hpsh); + DeleteObject(hpsh2); + DeleteObject(hpfg); + DeleteObject(hpbg); - - return hbm; + + return hbm; } void CopyColor(PALETTEENTRY *pe, COLORREF col) { - pe->peBlue = GetBValue(col); - pe->peGreen = GetGValue(col); - pe->peRed = GetRValue(col); - pe->peFlags = 0; + pe->peBlue = GetBValue(col); + pe->peGreen = GetGValue(col); + pe->peRed = GetRValue(col); + pe->peFlags = 0; } HPALETTE MakePaletteFromCols(COLORREF cols[], int nNumColours) { - LOGPALETTE *lp; - HPALETTE hPalette; + LOGPALETTE *lp; + HPALETTE hPalette; - // Allocate memory for the logical palette - lp = (LOGPALETTE *)HeapAlloc( - GetProcessHeap(), 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nNumColours); + // Allocate memory for the logical palette + lp = (LOGPALETTE *)HeapAlloc( + GetProcessHeap(), 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nNumColours); - lp->palNumEntries = nNumColours; - lp->palVersion = 0x300; + lp->palNumEntries = nNumColours; + lp->palVersion = 0x300; - //copy the colours into the logical palette format - for(int i = 0; i < nNumColours; i++) - { - CopyColor(&lp->palPalEntry[i], cols[i]); - } + //copy the colours into the logical palette format + for(int i = 0; i < nNumColours; i++) + { + CopyColor(&lp->palPalEntry[i], cols[i]); + } - // create palette! - hPalette = CreatePalette(lp); + // create palette! + hPalette = CreatePalette(lp); - HeapFree(GetProcessHeap(), 0, lp); + HeapFree(GetProcessHeap(), 0, lp); - return hPalette; + return hPalette; } diff --git a/rosapps/games/solitaire/cardlib/cardbutton.cpp b/rosapps/games/solitaire/cardlib/cardbutton.cpp index 6c7ff8d8003..bfdfcf91218 100644 --- a/rosapps/games/solitaire/cardlib/cardbutton.cpp +++ b/rosapps/games/solitaire/cardlib/cardbutton.cpp @@ -1,8 +1,8 @@ // -// CardLib - CardButton class +// CardLib - CardButton class // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include #include @@ -13,477 +13,477 @@ #include "cardcolor.h" HPALETTE UseNicePalette(HDC, HPALETTE); -void RestorePalette(HDC, HPALETTE); +void RestorePalette(HDC, HPALETTE); void PaintRect(HDC hdc, RECT *rect, COLORREF colour); CardButton::CardButton(CardWindow &parent, int Id, TCHAR *szText, UINT Style, bool visible, - int x, int y, int width, int height) + int x, int y, int width, int height) : parentWnd(parent), id(Id), uStyle(Style), fVisible(visible), ButtonCallback(0) { - crText = RGB(255,255,255); - crBack = RGB(0, 128, 0); - - xadjust = 0; - yadjust = 0; - xjustify = 0; - yjustify = 0; + crText = RGB(255,255,255); + crBack = RGB(0, 128, 0); + + xadjust = 0; + yadjust = 0; + xjustify = 0; + yjustify = 0; - fMouseDown = false; - fButtonDown = false; + fMouseDown = false; + fButtonDown = false; - hIcon = 0; + hIcon = 0; - SetText(szText); - Move(x, y, width, height); + SetText(szText); + Move(x, y, width, height); - mxlock = CreateMutex(0, FALSE, 0); + mxlock = CreateMutex(0, FALSE, 0); - hFont = 0; + hFont = 0; } CardButton::~CardButton() { - CloseHandle(mxlock); + CloseHandle(mxlock); } void CardButton::DrawRect(HDC hdc, RECT *rect, bool fNormal) { - RECT fill; + RECT fill; - HANDLE hOld; + HANDLE hOld; - HPEN hhi = CreatePen(0, 0, MAKE_PALETTERGB(crHighlight)); - HPEN hsh = CreatePen(0, 0, MAKE_PALETTERGB(crShadow)); - HPEN hbl = (HPEN)GetStockObject(BLACK_PEN); - - int x = rect->left; - int y = rect->top; - int width = rect->right-rect->left - 1; - int height = rect->bottom-rect->top - 1; - - SetRect(&fill, x+1, y+1, x+width-1, y+height-1); + HPEN hhi = CreatePen(0, 0, MAKE_PALETTERGB(crHighlight)); + HPEN hsh = CreatePen(0, 0, MAKE_PALETTERGB(crShadow)); + HPEN hbl = (HPEN)GetStockObject(BLACK_PEN); + + int x = rect->left; + int y = rect->top; + int width = rect->right-rect->left - 1; + int height = rect->bottom-rect->top - 1; + + SetRect(&fill, x+1, y+1, x+width-1, y+height-1); - int one = 1; - - if(!fNormal) - { - x += width; - y += height; - width = -width; - height = -height; - one = -1; - OffsetRect(&fill, 1, 1); - } - - if(fNormal) - hOld = SelectObject(hdc, hhi); - else - hOld = SelectObject(hdc, hhi); + int one = 1; + + if(!fNormal) + { + x += width; + y += height; + width = -width; + height = -height; + one = -1; + OffsetRect(&fill, 1, 1); + } + + if(fNormal) + hOld = SelectObject(hdc, hhi); + else + hOld = SelectObject(hdc, hhi); - MoveToEx(hdc, x, y+height, 0); - LineTo(hdc, x, y); - LineTo(hdc, x+width, y); - SelectObject(hdc, hOld); + MoveToEx(hdc, x, y+height, 0); + LineTo(hdc, x, y); + LineTo(hdc, x+width, y); + SelectObject(hdc, hOld); - hOld = SelectObject(hdc, hbl); - LineTo(hdc, x+width, y+height); - LineTo(hdc, x-one, y+height); - SelectObject(hdc, hOld); + hOld = SelectObject(hdc, hbl); + LineTo(hdc, x+width, y+height); + LineTo(hdc, x-one, y+height); + SelectObject(hdc, hOld); - hOld = SelectObject(hdc, hsh); - MoveToEx(hdc, x+one, y+height-one, 0); - LineTo(hdc, x+width-one, y+height-one); - LineTo(hdc, x+width-one, y); - SelectObject(hdc, hOld); + hOld = SelectObject(hdc, hsh); + MoveToEx(hdc, x+one, y+height-one, 0); + LineTo(hdc, x+width-one, y+height-one); + LineTo(hdc, x+width-one, y); + SelectObject(hdc, hOld); - PaintRect(hdc, &fill, MAKE_PALETTERGB(crBack)); + PaintRect(hdc, &fill, MAKE_PALETTERGB(crBack)); - DeleteObject(hhi); - DeleteObject(hsh); + DeleteObject(hhi); + DeleteObject(hsh); } void CardButton::Clip(HDC hdc) { - if(fVisible == false) return; - - ExcludeClipRect(hdc, rect.left, rect.top, rect.right, rect.bottom); + if(fVisible == false) return; + + ExcludeClipRect(hdc, rect.left, rect.top, rect.right, rect.bottom); } void CardButton::Draw(HDC hdc, bool fNormal) { - SIZE textsize; - int x, y; //text x, y - int ix, iy; //icon x, y - int iconwidth = 0; + SIZE textsize; + int x, y; //text x, y + int ix, iy; //icon x, y + int iconwidth = 0; - RECT cliprect; + RECT cliprect; - if(fVisible == 0) return; + if(fVisible == 0) return; - if(hFont == 0) - SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)); - else - SelectObject(hdc, hFont); - - GetTextExtentPoint32(hdc, szText, lstrlen(szText), &textsize); - - if(hIcon) - { - x = rect.left + 32 + 8; - } - else - { - if(uStyle & CB_ALIGN_LEFT) - { - x = rect.left + iconwidth; - } - else if(uStyle & CB_ALIGN_RIGHT) - { - x = rect.left + (rect.right-rect.left-iconwidth-textsize.cx); - } - else //centered - { - x = rect.right - rect.left - iconwidth; - x = (x - textsize.cx) / 2; - x += rect.left + iconwidth; - } - } - - y = rect.bottom - rect.top; - y = (y - textsize.cy) / 2; - y += rect.top; - - //calc icon position.. - ix = rect.left + 4; - iy = rect.top + (rect.bottom-rect.top-32) / 2; + if(hFont == 0) + SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)); + else + SelectObject(hdc, hFont); + + GetTextExtentPoint32(hdc, szText, lstrlen(szText), &textsize); + + if(hIcon) + { + x = rect.left + 32 + 8; + } + else + { + if(uStyle & CB_ALIGN_LEFT) + { + x = rect.left + iconwidth; + } + else if(uStyle & CB_ALIGN_RIGHT) + { + x = rect.left + (rect.right-rect.left-iconwidth-textsize.cx); + } + else //centered + { + x = rect.right - rect.left - iconwidth; + x = (x - textsize.cx) / 2; + x += rect.left + iconwidth; + } + } + + y = rect.bottom - rect.top; + y = (y - textsize.cy) / 2; + y += rect.top; + + //calc icon position.. + ix = rect.left + 4; + iy = rect.top + (rect.bottom-rect.top-32) / 2; - //if button is pressed, then shift text - if(fNormal == false && (uStyle & CB_PUSHBUTTON)) - { - x += 1; - y += 1; - ix += 1; - iy += 1; - } + //if button is pressed, then shift text + if(fNormal == false && (uStyle & CB_PUSHBUTTON)) + { + x += 1; + y += 1; + ix += 1; + iy += 1; + } - SetRect(&cliprect, x, y, x+textsize.cx, y+textsize.cy); - ExcludeClipRect(hdc, x, y, x+textsize.cx, y+textsize.cy); + SetRect(&cliprect, x, y, x+textsize.cx, y+textsize.cy); + ExcludeClipRect(hdc, x, y, x+textsize.cx, y+textsize.cy); - // - // Calc icon pos - // - - if(hIcon) - { - ExcludeClipRect(hdc, ix, iy, ix + 32, iy + 32); - } - - if(uStyle & CB_PUSHBUTTON) - { - DrawRect(hdc, &rect, fNormal); + // + // Calc icon pos + // + + if(hIcon) + { + ExcludeClipRect(hdc, ix, iy, ix + 32, iy + 32); + } + + if(uStyle & CB_PUSHBUTTON) + { + DrawRect(hdc, &rect, fNormal); - SetBkColor(hdc, MAKE_PALETTERGB(crBack)); - SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); - - SelectClipRgn(hdc, 0); + SetBkColor(hdc, MAKE_PALETTERGB(crBack)); + SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); + + SelectClipRgn(hdc, 0); - ExtTextOut(hdc, x, y, ETO_OPAQUE, &cliprect, szText, lstrlen(szText), 0); - } - else - { - SetBkColor(hdc, MAKE_PALETTERGB(crBack)); - SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); + ExtTextOut(hdc, x, y, ETO_OPAQUE, &cliprect, szText, lstrlen(szText), 0); + } + else + { + SetBkColor(hdc, MAKE_PALETTERGB(crBack)); + SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); - SelectClipRgn(hdc, 0); + SelectClipRgn(hdc, 0); - ExtTextOut(hdc, x, y, ETO_OPAQUE, &rect, szText, lstrlen(szText), 0); - } + ExtTextOut(hdc, x, y, ETO_OPAQUE, &rect, szText, lstrlen(szText), 0); + } - if(hIcon) - { - HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBack)); - DrawIconEx(hdc, ix, iy, hIcon, 32, 32, 0, hbr, 0); - DeleteObject(hbr); - } + if(hIcon) + { + HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBack)); + DrawIconEx(hdc, ix, iy, hIcon, 32, 32, 0, hbr, 0); + DeleteObject(hbr); + } } void CardButton::AdjustPosition(int winwidth, int winheight) { - int width = rect.right-rect.left; - int height = rect.bottom-rect.top; + int width = rect.right-rect.left; + int height = rect.bottom-rect.top; - width = width & ~0x1; + width = width & ~0x1; - switch(xjustify) - { - case CS_XJUST_NONE: - break; + switch(xjustify) + { + case CS_XJUST_NONE: + break; - case CS_XJUST_CENTER: //centered - rect.left = (winwidth - (width)) / 2; - rect.left += xadjust; - rect.right = rect.left+width; - break; + case CS_XJUST_CENTER: //centered + rect.left = (winwidth - (width)) / 2; + rect.left += xadjust; + rect.right = rect.left+width; + break; - case CS_XJUST_RIGHT: //right-aligned - rect.left = winwidth - width; - rect.left += xadjust; - rect.right = rect.left+width; - break; - } + case CS_XJUST_RIGHT: //right-aligned + rect.left = winwidth - width; + rect.left += xadjust; + rect.right = rect.left+width; + break; + } - switch(yjustify) - { - case CS_YJUST_NONE: - break; + switch(yjustify) + { + case CS_YJUST_NONE: + break; - case CS_YJUST_CENTER: //centered - rect.top = (winheight - (height)) / 2; - rect.top += yadjust; - rect.bottom = rect.top+height; - break; + case CS_YJUST_CENTER: //centered + rect.top = (winheight - (height)) / 2; + rect.top += yadjust; + rect.bottom = rect.top+height; + break; - case CS_YJUST_BOTTOM: //right-aligned - rect.top = winheight - height; - rect.top += yadjust; - rect.bottom = rect.top+height; - break; - } + case CS_YJUST_BOTTOM: //right-aligned + rect.top = winheight - height; + rect.top += yadjust; + rect.bottom = rect.top+height; + break; + } } int CardButton::OnLButtonDown(HWND hwnd, int x, int y) { - if((uStyle & CB_PUSHBUTTON) == 0) - return 0; + if((uStyle & CB_PUSHBUTTON) == 0) + return 0; - //make sure that the user is allowed to do something - if(WaitForSingleObject(mxlock, 0) != WAIT_OBJECT_0) - { - return 0; - } - else - { - ReleaseMutex(mxlock); - } - - fMouseDown = true; - fButtonDown = true; + //make sure that the user is allowed to do something + if(WaitForSingleObject(mxlock, 0) != WAIT_OBJECT_0) + { + return 0; + } + else + { + ReleaseMutex(mxlock); + } + + fMouseDown = true; + fButtonDown = true; - Redraw(); + Redraw(); - SetCapture(hwnd); + SetCapture(hwnd); - return 1; + return 1; } int CardButton::OnMouseMove(HWND hwnd, int x, int y) { - if(fMouseDown) - { - bool fOldButtonDown = fButtonDown; + if(fMouseDown) + { + bool fOldButtonDown = fButtonDown; - POINT pt; - - pt.x = x; - pt.y = y; - - if(PtInRect(&rect, pt)) - fButtonDown = true; - else - fButtonDown = false; - - if(fButtonDown != fOldButtonDown) - Redraw(); - } - - return 0; + POINT pt; + + pt.x = x; + pt.y = y; + + if(PtInRect(&rect, pt)) + fButtonDown = true; + else + fButtonDown = false; + + if(fButtonDown != fOldButtonDown) + Redraw(); + } + + return 0; } int CardButton::OnLButtonUp(HWND hwnd, int x, int y) { - if(fMouseDown) - { - fMouseDown = false; - fButtonDown = false; - - if(uStyle & CB_PUSHBUTTON) - { - Redraw(); - ReleaseCapture(); - } - - //if have clicked the button - if(parentWnd.CardButtonFromPoint(x, y) == this) - { - if(ButtonCallback) - { - ButtonCallback(*this); - } - else - { - HWND hwnd = (HWND)parentWnd; - SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, BN_CLICKED), (LONG)hwnd); - } - } - } + if(fMouseDown) + { + fMouseDown = false; + fButtonDown = false; + + if(uStyle & CB_PUSHBUTTON) + { + Redraw(); + ReleaseCapture(); + } + + //if have clicked the button + if(parentWnd.CardButtonFromPoint(x, y) == this) + { + if(ButtonCallback) + { + ButtonCallback(*this); + } + else + { + HWND hwnd = (HWND)parentWnd; + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, BN_CLICKED), (LONG)hwnd); + } + } + } - return 0; + return 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) { - CardButton *cb; + CardButton *cb; - if(nNumButtons == MAXBUTTONS) - return 0; + if(nNumButtons == MAXBUTTONS) + return 0; - cb = new CardButton(*this, id, szText, uStyle, fVisible, x, y, width, height); - Buttons[nNumButtons++] = cb; + cb = new CardButton(*this, id, szText, uStyle, fVisible, x, y, width, height); + Buttons[nNumButtons++] = cb; - if(uStyle & CB_PUSHBUTTON) - { - cb->SetBackColor(CardButton::GetFace(crBackgnd)); - //cb->SetBackColor(ScaleLumRGB(crBackgnd, 0.1)); - cb->SetForeColor(RGB(255,255,255)); - } - else - { - cb->SetBackColor(crBackgnd); - cb->SetForeColor(RGB(255,255,255)); - } - - return cb; + if(uStyle & CB_PUSHBUTTON) + { + cb->SetBackColor(CardButton::GetFace(crBackgnd)); + //cb->SetBackColor(ScaleLumRGB(crBackgnd, 0.1)); + cb->SetForeColor(RGB(255,255,255)); + } + else + { + cb->SetBackColor(crBackgnd); + cb->SetForeColor(RGB(255,255,255)); + } + + return cb; } void CardButton::SetText(TCHAR *lpszFormat, ...) { - int count; + int count; - va_list args; - va_start(args, lpszFormat); + va_list args; + va_start(args, lpszFormat); - count = wvsprintf(szText, lpszFormat, args); - va_end(args); + count = wvsprintf(szText, lpszFormat, args); + va_end(args); } int CardButton::Id() { - return id; + return id; } void CardButton::Show(bool fShow) { - fVisible = fShow; + fVisible = fShow; } void CardButton::Move(int x, int y, int width, int height) { - SetRect(&rect, x, y, x+width, y+height); + SetRect(&rect, x, y, x+width, y+height); } void CardButton::Redraw() { - HDC hdc = GetDC((HWND)parentWnd); + HDC hdc = GetDC((HWND)parentWnd); - HPALETTE hOldPal = UseNicePalette(hdc, __hPalette); + HPALETTE hOldPal = UseNicePalette(hdc, __hPalette); - Draw(hdc, !fButtonDown); - - RestorePalette(hdc, hOldPal); - - ReleaseDC((HWND)parentWnd, hdc); + Draw(hdc, !fButtonDown); + + RestorePalette(hdc, hOldPal); + + ReleaseDC((HWND)parentWnd, hdc); } void CardButton::SetForeColor(COLORREF cr) { - crText = cr; + crText = cr; } void CardButton::SetBackColor(COLORREF cr) { - crBack = cr; + crBack = cr; - crHighlight = GetHighlight(cr); - crShadow = GetShadow(cr); - - //crHighlight = ScaleLumRGB(cr, +0.25); - //crShadow = ScaleLumRGB(cr, -0.25); + crHighlight = GetHighlight(cr); + crShadow = GetShadow(cr); + + //crHighlight = ScaleLumRGB(cr, +0.25); + //crShadow = ScaleLumRGB(cr, -0.25); } -// Static member +// Static member COLORREF CardButton::GetHighlight(COLORREF crBase) { - return ColorScaleRGB(crBase, RGB(255,255,255), 0.25); + return ColorScaleRGB(crBase, RGB(255,255,255), 0.25); } -// Static member +// Static member COLORREF CardButton::GetShadow(COLORREF crBase) { - return ColorScaleRGB(crBase, RGB(0, 0, 0), 0.25); + return ColorScaleRGB(crBase, RGB(0, 0, 0), 0.25); } COLORREF CardButton::GetFace(COLORREF crBase) { - return ColorScaleRGB(crBase, RGB(255,255,255), 0.1); + return ColorScaleRGB(crBase, RGB(255,255,255), 0.1); } void CardButton::SetPlacement(UINT xJustify, UINT yJustify, int xAdjust, int yAdjust) { - xadjust = xAdjust; - yadjust = yAdjust; - xjustify = xJustify; - yjustify = yJustify; + xadjust = xAdjust; + yadjust = yAdjust; + xjustify = xJustify; + yjustify = yJustify; } void CardButton::SetIcon(HICON hicon, bool fRedraw) { - hIcon = hicon; - - if(fRedraw) - Redraw(); + hIcon = hicon; + + if(fRedraw) + Redraw(); } void CardButton::SetFont(HFONT font) { - //don't delete the existing font.. - hFont = font; + //don't delete the existing font.. + hFont = font; } void CardButton::SetButtonProc(pButtonProc proc) { - ButtonCallback = proc; + ButtonCallback = proc; } bool CardButton::Lock() { - DWORD dw = WaitForSingleObject(mxlock, 0); + DWORD dw = WaitForSingleObject(mxlock, 0); - if(dw == WAIT_OBJECT_0) - return true; - else - return false; + if(dw == WAIT_OBJECT_0) + return true; + else + return false; } bool CardButton::UnLock() { - if(ReleaseMutex(mxlock)) - return true; - else - return false; + if(ReleaseMutex(mxlock)) + return true; + else + return false; } void CardButton::SetStyle(UINT style) { - uStyle = style; + uStyle = style; } UINT CardButton::GetStyle() { - return uStyle; + return uStyle; } diff --git a/rosapps/games/solitaire/cardlib/cardcolor.cpp b/rosapps/games/solitaire/cardlib/cardcolor.cpp index 6d0e0089df4..1d3348a81c1 100644 --- a/rosapps/games/solitaire/cardlib/cardcolor.cpp +++ b/rosapps/games/solitaire/cardlib/cardcolor.cpp @@ -1,5 +1,5 @@ // -// Colour support +// Colour support // #include @@ -10,16 +10,16 @@ inline double fMax(double a, double b) { - return a < b ? b : a; + return a < b ? b : a; } inline double fMin(double a, double b) { - return a < b ? a : b; + return a < b ? a : b; } /****************************************************************************** FUNCTION: RGBtoHLS - PURPOSE: Convert from RGB to HLS + PURPOSE: Convert from RGB to HLS IN: RGB color (0xBBGGRR) OUT: Hue, Saturation, Luminance from 0 to 1 COPYRIGHT:1995-1997 Robert Mashlan @@ -27,175 +27,175 @@ inline double fMin(double a, double b) ******************************************************************************/ void RGBtoHLS(const COLORREF rgb, double *H, double *L, double *S ) { - double delta; - double r = (double)((rgb )&0xFF)/255; - double g = (double)((rgb>> 8)&0xFF)/255; - double b = (double)((rgb>>16)&0xFF)/255; - double cmax = MAX3(r,g,b); - double cmin = MIN3(r,g,b); - *L=(cmax+cmin)/2.0; - - if(cmax == cmin) - { - *S = *H = 0; // it's really undefined - } - else - { - if(*L < 0.5) *S = (cmax-cmin)/(cmax+cmin); - else *S = (cmax-cmin)/(2.0-cmax-cmin); - - delta = cmax - cmin; - - if(r == cmax) - { - *H = (g - b) / delta; - } - else - { - if(g == cmax) *H = 2.0 + (b-r) / delta; - else *H = 4.0 + (r-g) / delta; - } - *H /= 6.0; - if (*H < 0.0) *H += 1; - } + double delta; + double r = (double)((rgb )&0xFF)/255; + double g = (double)((rgb>> 8)&0xFF)/255; + double b = (double)((rgb>>16)&0xFF)/255; + double cmax = MAX3(r,g,b); + double cmin = MIN3(r,g,b); + *L=(cmax+cmin)/2.0; + + if(cmax == cmin) + { + *S = *H = 0; // it's really undefined + } + else + { + if(*L < 0.5) *S = (cmax-cmin)/(cmax+cmin); + else *S = (cmax-cmin)/(2.0-cmax-cmin); + + delta = cmax - cmin; + + if(r == cmax) + { + *H = (g - b) / delta; + } + else + { + if(g == cmax) *H = 2.0 + (b-r) / delta; + else *H = 4.0 + (r-g) / delta; + } + *H /= 6.0; + if (*H < 0.0) *H += 1; + } } /****************************************************************************** FUNCTION: HueToRGB - PURPOSE: Convert a hue (color) to RGB + PURPOSE: Convert a hue (color) to RGB COPYRIGHT:1995-1997 Robert Mashlan Modified for LabWindows/CVI, 1999 Guillaume Dargaud ******************************************************************************/ double HueToRGB(const double m1, const double m2, double h ) { - if (h<0) h+=1.0; - if (h>1) h-=1.0; - if (6.0*h < 1 ) return (m1+(m2-m1)*h*6.0); - if (2.0*h < 1 ) return m2; - if (3.0*h < 2.0) return (m1+(m2-m1)*((2.0/3.0)-h)*6.0); - return m1; + if (h<0) h+=1.0; + if (h>1) h-=1.0; + if (6.0*h < 1 ) return (m1+(m2-m1)*h*6.0); + if (2.0*h < 1 ) return m2; + if (3.0*h < 2.0) return (m1+(m2-m1)*((2.0/3.0)-h)*6.0); + return m1; } /****************************************************************************** FUNCTION: HLStoRGB - PURPOSE: Convert from HSL to RGB - IN: Hue, Saturation, Luminance from 0 to 1 - RETURN: RGB color (0xBBGGRR) + PURPOSE: Convert from HSL to RGB + IN: Hue, Saturation, Luminance from 0 to 1 + RETURN: RGB color (0xBBGGRR) COPYRIGHT:1995-1997 Robert Mashlan Modified for LabWindows/CVI, 1999 Guillaume Dargaud ******************************************************************************/ COLORREF HLStoRGB(const double H, const double L, const double S ) { - double r,g,b; - double m1, m2; + double r,g,b; + double m1, m2; - if(S == 0) - { - r = g = b = L; - } - else - { - if (L <= 0.5) - m2 = L * (1.0 + S); - else - m2 = L + S - L * S; + if(S == 0) + { + r = g = b = L; + } + else + { + if (L <= 0.5) + m2 = L * (1.0 + S); + else + m2 = L + S - L * S; - m1 = 2.0 * L - m2; + m1 = 2.0 * L - m2; - r = HueToRGB(m1,m2,H+1.0/3.0); - g = HueToRGB(m1,m2,H); - b = HueToRGB(m1,m2,H-1.0/3.0); - } + r = HueToRGB(m1,m2,H+1.0/3.0); + g = HueToRGB(m1,m2,H); + b = HueToRGB(m1,m2,H-1.0/3.0); + } - return RGB(r*255, g*255, b*255); + return RGB(r*255, g*255, b*255); } /****************************************************************************** FUNCTION: ColorScaleHSL - PURPOSE: Returns the HSL linear interpolated color between 2 colors - (more natural looking than RGB interpolation) - For instance if the luminance is the same in Col1 and Col2, - then the luminance of the result will be the same - If Ratio=0, you get Col1, - If Ratio=1, you get Col2 + PURPOSE: Returns the HSL linear interpolated color between 2 colors + (more natural looking than RGB interpolation) + For instance if the luminance is the same in Col1 and Col2, + then the luminance of the result will be the same + If Ratio=0, you get Col1, + If Ratio=1, you get Col2 IN: Col1: low color in hex 0xBBGGRR format - Col2: high color in hex 0xBBGGRR format - Ratio: 0 for low color, 1 for high color, or in between + Col2: high color in hex 0xBBGGRR format + Ratio: 0 for low color, 1 for high color, or in between EXAMPLE: Col1=0, Col2=0xFF00FF, Ratio=0.5 returns 0x1F5F3F ******************************************************************************/ -COLORREF ColorScaleHSL( const COLORREF Col1, const COLORREF Col2, const double Ratio) +COLORREF ColorScaleHSL( const COLORREF Col1, const COLORREF Col2, const double Ratio) { - static double H1, H2, S1, S2, L1, L2; - - if (Ratio<=0) return Col1; // Ratio parameter must be between 0 and 1 - else if (Ratio>=1) return Col2; + static double H1, H2, S1, S2, L1, L2; + + if (Ratio<=0) return Col1; // Ratio parameter must be between 0 and 1 + else if (Ratio>=1) return Col2; - RGBtoHLS( Col1, &H1, &L1, &S1); - RGBtoHLS( Col2, &H2, &L2, &S2); - return HLStoRGB( H1+(H2-H1)*Ratio, L1+(L2-L1)*Ratio, S1+(S2-S1)*Ratio ); + RGBtoHLS( Col1, &H1, &L1, &S1); + RGBtoHLS( Col2, &H2, &L2, &S2); + return HLStoRGB( H1+(H2-H1)*Ratio, L1+(L2-L1)*Ratio, S1+(S2-S1)*Ratio ); } /****************************************************************************** FUNCTION: ColorScaleRGB - PURPOSE: Returns the RGB linear interpolated color between 2 colors - If Ratio=0, you get Col1, - If Ratio=1, you get Col2 + PURPOSE: Returns the RGB linear interpolated color between 2 colors + If Ratio=0, you get Col1, + If Ratio=1, you get Col2 IN: Col1: low color in hex 0xBBGGRR format - Col2: high color in hex 0xBBGGRR format - Ratio: 0 for low color, 1 for high color, or in between + Col2: high color in hex 0xBBGGRR format + Ratio: 0 for low color, 1 for high color, or in between EXAMPLE: Col1=0, Col2=0xFF00FF, Ratio=0.5 returns 0x800080 ******************************************************************************/ -COLORREF ColorScaleRGB( const COLORREF Col1, - const COLORREF Col2, - const double Ratio) { - int R1=(Col1)&0xFF, G1=(Col1>>8)&0xFF, B1=(Col1>>16)&0xFF; - int R2=(Col2)&0xFF, G2=(Col2>>8)&0xFF, B2=(Col2>>16)&0xFF; +COLORREF ColorScaleRGB( const COLORREF Col1, + const COLORREF Col2, + const double Ratio) { + int R1=(Col1)&0xFF, G1=(Col1>>8)&0xFF, B1=(Col1>>16)&0xFF; + int R2=(Col2)&0xFF, G2=(Col2>>8)&0xFF, B2=(Col2>>16)&0xFF; - if (Ratio<=0) return Col1; // Ratio parameter must be between 0 and 1 - else if (Ratio>=1) return Col2; + if (Ratio<=0) return Col1; // Ratio parameter must be between 0 and 1 + else if (Ratio>=1) return Col2; -/* return RGB( - (R1 + (R2 - R1) * (Ratio + 0.02) + 0.5), // rounding - (G1 + (G2 - G1) * (Ratio - 0.00) + 0.5), - (B1 + (B2 - B1) * (Ratio + 0.05) + 0.5) - );*/ +/* return RGB( + (R1 + (R2 - R1) * (Ratio + 0.02) + 0.5), // rounding + (G1 + (G2 - G1) * (Ratio - 0.00) + 0.5), + (B1 + (B2 - B1) * (Ratio + 0.05) + 0.5) + );*/ - /*double r = Ratio; - if(Col2 == 0) - r = 1-Ratio; - else - r = 1+Ratio; - R1 = (int)(double(R1) * r + 0.5); - G1 = (int)(double(G1) * r + 0.5); - B1 = (int)(double(B1) * r + 0.5); - return RGB(R1,G1,B1);*/ + /*double r = Ratio; + if(Col2 == 0) + r = 1-Ratio; + else + r = 1+Ratio; + R1 = (int)(double(R1) * r + 0.5); + G1 = (int)(double(G1) * r + 0.5); + B1 = (int)(double(B1) * r + 0.5); + return RGB(R1,G1,B1);*/ - return RGB( - (R1 + (R2 - R1) * (Ratio + 0.02) + 0.5), // rounding - (G1 + (G2 - G1) * (Ratio - 0.00) + 0.5), - (B1 + (B2 - B1) * (Ratio + 0.05) + 0.5) - ); + return RGB( + (R1 + (R2 - R1) * (Ratio + 0.02) + 0.5), // rounding + (G1 + (G2 - G1) * (Ratio - 0.00) + 0.5), + (B1 + (B2 - B1) * (Ratio + 0.05) + 0.5) + ); } COLORREF ColorDarker(COLORREF col, double ratio) { - return ColorScaleHSL(col, RGB(0,0,0), ratio); + return ColorScaleHSL(col, RGB(0,0,0), ratio); } COLORREF ColorLighter(COLORREF col, double ratio) { - return ColorScaleHSL(col, RGB(255,255,255), ratio); + return ColorScaleHSL(col, RGB(255,255,255), ratio); } // -// Experimental!!! +// Experimental!!! // #if 0 @@ -203,135 +203,135 @@ typedef enum { Red, Green, Blue }; void RGBtoHLS(COLORREF rgb, double *Hue, double *Lum, double *Sat) { - double mn, mx; - int major; + double mn, mx; + int major; - BYTE red, green, blue; + BYTE red, green, blue; - red = GetRValue(rgb); - green = GetGValue(rgb); - blue = GetBValue(rgb); + red = GetRValue(rgb); + green = GetGValue(rgb); + blue = GetBValue(rgb); - if(red < green) - { - mn = red; mx = green; major = Green; - } - else - { - mn = green; mx = red; major = Red; - } + if(red < green) + { + mn = red; mx = green; major = Green; + } + else + { + mn = green; mx = red; major = Red; + } - if(blue < mn) - { - mn = blue; - } - else if(blue > mx) - { - mx = blue; major = Blue; - } + if(blue < mn) + { + mn = blue; + } + else if(blue > mx) + { + mx = blue; major = Blue; + } - if(mn == mx) - { - *Lum = mn / 255; - *Sat = 0; - *Hue = 0; - } - else - { - *Lum = (mx + mn) / 510; + if(mn == mx) + { + *Lum = mn / 255; + *Sat = 0; + *Hue = 0; + } + else + { + *Lum = (mx + mn) / 510; - if(*Lum <= 0.5) - *Sat = (mx-mn) / (mn+mx); - else - *Sat = (mx-mn) / (510-mn-mx); + if(*Lum <= 0.5) + *Sat = (mx-mn) / (mn+mx); + else + *Sat = (mx-mn) / (510-mn-mx); - switch(major) - { - case Red: *Hue = (green-blue) * 60.0 / (mx-mn) + 360.0; - break; + switch(major) + { + case Red: *Hue = (green-blue) * 60.0 / (mx-mn) + 360.0; + break; - case Green: *Hue = (blue-red) * 60.0 / (mx-mn) + 120.0; - break; + case Green: *Hue = (blue-red) * 60.0 / (mx-mn) + 120.0; + break; - case Blue: *Hue = (red-green) * 60.0 / (mx-mn) + 240.0; - break; + case Blue: *Hue = (red-green) * 60.0 / (mx-mn) + 240.0; + break; - } + } - if(*Hue > 360.0) - *Hue -= 360.0; - } + if(*Hue > 360.0) + *Hue -= 360.0; + } } static BYTE Value(double m1, double m2, double hue) { - if(hue > 360) hue -= 360; - else if(hue < 0) hue += 360; + if(hue > 360) hue -= 360; + else if(hue < 0) hue += 360; - if(hue < 60) - m1 = m1 + (m2 - m1) * hue / 60; - else if(hue < 180) - m1 = m2; - else if(hue < 240) - m1 = m1 + (m2 - m1) * (240 - hue) / 60; + if(hue < 60) + m1 = m1 + (m2 - m1) * hue / 60; + else if(hue < 180) + m1 = m2; + else if(hue < 240) + m1 = m1 + (m2 - m1) * (240 - hue) / 60; - return (BYTE)(m1 * 255); + return (BYTE)(m1 * 255); } COLORREF HLStoRGB(const double Hue, const double Lum, const double Sat) { - BYTE red, green, blue; + BYTE red, green, blue; - if(Sat == 0) - { - red = green = blue = (BYTE)(Lum * 255); - } - else - { - double m1, m2; + if(Sat == 0) + { + red = green = blue = (BYTE)(Lum * 255); + } + else + { + double m1, m2; - if(Lum <= 0.5) - m2 = Lum + Lum * Sat; - else - m2 = Lum + Sat - Lum * Sat; + if(Lum <= 0.5) + m2 = Lum + Lum * Sat; + else + m2 = Lum + Sat - Lum * Sat; - m1 = 2 * Lum - m2; + m1 = 2 * Lum - m2; - red = Value(m1, m2, Hue + 120); - green = Value(m1, m2, Hue); - blue = Value(m1, m2, Hue - 120); - } + red = Value(m1, m2, Hue + 120); + green = Value(m1, m2, Hue); + blue = Value(m1, m2, Hue - 120); + } - return RGB(red, green, blue); + return RGB(red, green, blue); } COLORREF ScaleLumRGB(COLORREF col1, double ratio) { - double H1, L1, S1; + double H1, L1, S1; - RGBtoHLS(col1, &H1, &L1, &S1); + RGBtoHLS(col1, &H1, &L1, &S1); - L1 += L1 * ratio; + L1 += L1 * ratio; - return HLStoRGB(H1, L1, S1); + return HLStoRGB(H1, L1, S1); } COLORREF ColorScaleHSL(const COLORREF Col1, const COLORREF Col2, const double Ratio) { - static double H1, H2, S1, S2, L1, L2; - - if(Ratio <= 0) return Col1; // Ratio parameter must be between 0 and 1 - else if(Ratio >= 1) return Col2; + static double H1, H2, S1, S2, L1, L2; + + if(Ratio <= 0) return Col1; // Ratio parameter must be between 0 and 1 + else if(Ratio >= 1) return Col2; - RGBtoHLS( Col1, &H1, &L1, &S1); - RGBtoHLS( Col2, &H2, &L2, &S2); + RGBtoHLS( Col1, &H1, &L1, &S1); + RGBtoHLS( Col2, &H2, &L2, &S2); - return HLStoRGB( H1 /*+ (H2 - H1 ) * Ratio*/, L1 + (L2 - L1) * Ratio, S1 + (S2 - S1) * Ratio * 2); + return HLStoRGB( H1 /*+ (H2 - H1 ) * Ratio*/, L1 + (L2 - L1) * Ratio, S1 + (S2 - S1) * Ratio * 2); } COLORREF ColorScaleRGB(const COLORREF Col1, const COLORREF Col2, const double Ratio) { - return ColorScaleHSL(Col1, Col2, Ratio); + return ColorScaleHSL(Col1, Col2, Ratio); } #endif diff --git a/rosapps/games/solitaire/cardlib/cardcount.cpp b/rosapps/games/solitaire/cardlib/cardcount.cpp index d8ab036ab55..7321858abd0 100644 --- a/rosapps/games/solitaire/cardlib/cardcount.cpp +++ b/rosapps/games/solitaire/cardlib/cardcount.cpp @@ -1,90 +1,90 @@ // -// CardCount is a helper library for CardStacks. -// -// When you initialize a CardCount object with a +// CardCount is a helper library for CardStacks. +// +// When you initialize a CardCount object with a // cardstack, it keeps track of the number of cards -// the stack contains. +// the stack contains. // -// e.g. CardCount count(cardstack); +// e.g. CardCount count(cardstack); // -// Then you can do: -// -// int num_fives = count[5] -// -// count.Add(cardstack2); - combine with another stack +// Then you can do: +// +// int num_fives = count[5] +// +// count.Add(cardstack2); - combine with another stack // -// int num_aces = count[1] - aces low -// int num_aces = count[14] - aces high +// int num_aces = count[1] - aces low +// int num_aces = count[14] - aces high // -// count.Clear(); +// count.Clear(); // #include "cardcount.h" CardCount::CardCount() { - Clear(); + Clear(); } CardCount::CardCount(const CardStack &cs) { - Init(cs); + Init(cs); } void CardCount::Clear() { - for(int i = 0; i < 13; i++) - count[i] = 0; + for(int i = 0; i < 13; i++) + count[i] = 0; } void CardCount::Add(const CardStack &cs) { - for(int i = 0; i < cs.NumCards(); i++) - { - Card card = cs[i]; + for(int i = 0; i < cs.NumCards(); i++) + { + Card card = cs[i]; - int val = card.LoVal(); - count[val - 1]++; - } + int val = card.LoVal(); + count[val - 1]++; + } } void CardCount::Sub(const CardStack &cs) { - for(int i = 0; i < cs.NumCards(); i++) - { - Card card = cs[i]; - int val = card.LoVal(); - - if(count[val - 1] > 0) - count[val - 1]--; - } + for(int i = 0; i < cs.NumCards(); i++) + { + Card card = cs[i]; + int val = card.LoVal(); + + if(count[val - 1] > 0) + count[val - 1]--; + } } void CardCount::Init(const CardStack &cs) { - Clear(); - Add(cs); + Clear(); + Add(cs); } int CardCount::operator [] (size_t index) const { - if(index < 1) return 0; - else if(index > 14) return 0; //if out of range - else if(index == 14) index = 1; //if a "ace-high" + if(index < 1) return 0; + else if(index > 14) return 0; //if out of range + else if(index == 14) index = 1; //if a "ace-high" - return count[index - 1]; + return count[index - 1]; } // -// Decrement specified item by one +// Decrement specified item by one // void CardCount::Dec(size_t index) { - if(index < 1) return; - else if(index > 14) return; //if out of range - else if(index == 14) index = 1; //if a "ace-high" + if(index < 1) return; + else if(index > 14) return; //if out of range + else if(index == 14) index = 1; //if a "ace-high" - index -= 1; + index -= 1; - if(count[index] > 0) - count[index]--; + if(count[index] > 0) + count[index]--; } diff --git a/rosapps/games/solitaire/cardlib/cardlib.cpp b/rosapps/games/solitaire/cardlib/cardlib.cpp index 6006c9ef546..acd37c0c92c 100644 --- a/rosapps/games/solitaire/cardlib/cardlib.cpp +++ b/rosapps/games/solitaire/cardlib/cardlib.cpp @@ -1,8 +1,8 @@ // -// CardLib - not much of interest in here +// CardLib - not much of interest in here // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include #include "cardlib.h" @@ -14,27 +14,27 @@ void LoadCardBitmaps(void); extern double __CARDZOOMSPEED; // -// Global variables! +// Global variables! // HDC __hdcCardBitmaps; HBITMAP __hbmCardBitmaps; -HDC __hdcPlaceHolder; -HBITMAP __hbmPlaceHolder; +HDC __hdcPlaceHolder; +HBITMAP __hbmPlaceHolder; HPALETTE __holdplacepal; -int __cardwidth; -int __cardheight; +int __cardwidth; +int __cardheight; HPALETTE __hPalette; // -// Cardlib global functions! +// Cardlib global functions! // void CardLib_SetZoomSpeed(int speed) { - __CARDZOOMSPEED = (double)speed; + __CARDZOOMSPEED = (double)speed; } /* @@ -44,10 +44,10 @@ void CardLib_SetZoomSpeed(int speed) would have unpredicted side-effects. e.g. Card card(Hearts, 4); - if(card == 4) - how does 4 get converted?? - It uses the Card(int uval) constructor, - which results in a 2 of clubs... - not what was expected + if(card == 4) - how does 4 get converted?? + It uses the Card(int uval) constructor, + which results in a 2 of clubs... + not what was expected */ /* void CardLib_SetAcesHigh(bool fHigh); @@ -62,55 +62,55 @@ bool operator >= (const Card &lhs, const Card &rhs); /* void CardLib_SetAcesHigh(bool fHigh) { - __CARDLIB_ACES_HIGH = fHigh; + __CARDLIB_ACES_HIGH = fHigh; } bool operator == (const Card &lhs, const Card &rhs) { - if(__CARDLIB_ACES_HIGH) - return lhs.HiVal() == rhs.HiVal(); - else - return lhs.LoVal() == rhs.LoVal(); + if(__CARDLIB_ACES_HIGH) + return lhs.HiVal() == rhs.HiVal(); + else + return lhs.LoVal() == rhs.LoVal(); } bool operator != (const Card &lhs, const Card &rhs) { - if(__CARDLIB_ACES_HIGH) - return lhs.HiVal() != rhs.HiVal(); - else - return lhs.LoVal() != rhs.LoVal(); + if(__CARDLIB_ACES_HIGH) + return lhs.HiVal() != rhs.HiVal(); + else + return lhs.LoVal() != rhs.LoVal(); } bool operator > (const Card &lhs, const Card &rhs) { - if(__CARDLIB_ACES_HIGH) - return lhs.HiVal() > rhs.HiVal(); - else - return lhs.LoVal() > rhs.LoVal(); + if(__CARDLIB_ACES_HIGH) + return lhs.HiVal() > rhs.HiVal(); + else + return lhs.LoVal() > rhs.LoVal(); } bool operator >= (const Card &lhs, const Card &rhs) { - if(__CARDLIB_ACES_HIGH) - return lhs.HiVal() >= rhs.HiVal(); - else - return lhs.LoVal() >= rhs.LoVal(); + if(__CARDLIB_ACES_HIGH) + return lhs.HiVal() >= rhs.HiVal(); + else + return lhs.LoVal() >= rhs.LoVal(); } bool operator < (const Card &lhs, const Card &rhs) { - if(__CARDLIB_ACES_HIGH) - return lhs.HiVal() < rhs.HiVal(); - else - return lhs.LoVal() < rhs.LoVal(); + if(__CARDLIB_ACES_HIGH) + return lhs.HiVal() < rhs.HiVal(); + else + return lhs.LoVal() < rhs.LoVal(); } bool operator <= (const Card &lhs, const Card &rhs) { - if(__CARDLIB_ACES_HIGH) - return lhs.HiVal() <= rhs.HiVal(); - else - return lhs.LoVal() <= rhs.LoVal(); + if(__CARDLIB_ACES_HIGH) + return lhs.HiVal() <= rhs.HiVal(); + else + return lhs.LoVal() <= rhs.LoVal(); } */ diff --git a/rosapps/games/solitaire/cardlib/cardregion.cpp b/rosapps/games/solitaire/cardlib/cardregion.cpp index 8ecf4be2263..5eb1c3f4a34 100644 --- a/rosapps/games/solitaire/cardlib/cardregion.cpp +++ b/rosapps/games/solitaire/cardlib/cardregion.cpp @@ -1,8 +1,8 @@ // -// CardLib - CardRegion class +// CardLib - CardRegion class // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include @@ -18,641 +18,641 @@ void PaintRect(HDC hdc, RECT *rect, COLORREF colour); CardRegion::CardRegion(CardWindow &parent, int Id, bool visible, int x, int y, int xOffset, int yOffset) : id(Id), parentWnd(parent), xpos(x), ypos(y), xoffset(xOffset), yoffset(yOffset), fVisible(visible) { - width = __cardwidth; - height = __cardheight; + width = __cardwidth; + height = __cardheight; - crBackgnd = RGB(0, 64, 100); + crBackgnd = RGB(0, 64, 100); - uFaceDirType = CS_FACE_UP; - nFaceDirOption = 0; - uEmptyImage = CS_EI_SUNK; + uFaceDirType = CS_FACE_UP; + nFaceDirOption = 0; + uEmptyImage = CS_EI_SUNK; - fVisible = visible; + fVisible = visible; - nThreedCount = 1; - nBackCardIdx = 53; + nThreedCount = 1; + nBackCardIdx = 53; - Update(); //Update this stack's size+card count + Update(); //Update this stack's size+card count - hdcBackGnd = 0; - hbmBackGnd = 0; - hdcDragCard = 0; - hbmDragCard = 0; + hdcBackGnd = 0; + hbmBackGnd = 0; + hdcDragCard = 0; + hbmDragCard = 0; - nDragCardWidth = 0; - nDragCardHeight = 0; - - CanDragCallback = 0; - CanDropCallback = 0; - AddCallback = 0; - RemoveCallback = 0; - ClickCallback = 0; - DblClickCallback = 0; + nDragCardWidth = 0; + nDragCardHeight = 0; + + CanDragCallback = 0; + CanDropCallback = 0; + AddCallback = 0; + RemoveCallback = 0; + ClickCallback = 0; + DblClickCallback = 0; - uDragRule = CS_DRAG_ALL; - uDropRule = CS_DROP_ALL; + uDragRule = CS_DRAG_ALL; + uDropRule = CS_DROP_ALL; - xjustify = yjustify = xadjust = yadjust = 0; + xjustify = yjustify = xadjust = yadjust = 0; - nFlashCount = 0; - fFlashVisible = false; - uFlashTimer = (UINT)-1; + nFlashCount = 0; + fFlashVisible = false; + uFlashTimer = (UINT)-1; - fMouseDragging = false; + fMouseDragging = false; - mxlock = CreateMutex(0, FALSE, 0); + mxlock = CreateMutex(0, FALSE, 0); } CardRegion::~CardRegion() { - CloseHandle(mxlock); + CloseHandle(mxlock); } void CardRegion::SetBackColor(COLORREF cr) { - crBackgnd = cr; + crBackgnd = cr; } int CardRegion::CalcApparentCards(int realnum) { - return ((realnum + nThreedCount - 1) - (realnum + nThreedCount - 1) % nThreedCount) / nThreedCount; + return ((realnum + nThreedCount - 1) - (realnum + nThreedCount - 1) % nThreedCount) / nThreedCount; } void CardRegion::CalcApparentCards() { - nNumApparentCards = CalcApparentCards(cardstack.NumCards()); + nNumApparentCards = CalcApparentCards(cardstack.NumCards()); } void CardRegion::UpdateSize(void) { - if(cardstack.NumCards() > 0) - { - if(xoffset > 0) - width = (nNumApparentCards - 1) * xoffset + __cardwidth; - else - width = (nNumApparentCards - 1) * -xoffset + __cardwidth; + if(cardstack.NumCards() > 0) + { + if(xoffset > 0) + width = (nNumApparentCards - 1) * xoffset + __cardwidth; + else + width = (nNumApparentCards - 1) * -xoffset + __cardwidth; - if(yoffset > 0) - height = (nNumApparentCards - 1) * yoffset + __cardheight; - else - height = (nNumApparentCards - 1) * -yoffset + __cardheight; - } - else - { - width = __cardwidth; - height = __cardheight; - } + if(yoffset > 0) + height = (nNumApparentCards - 1) * yoffset + __cardheight; + else + height = (nNumApparentCards - 1) * -yoffset + __cardheight; + } + else + { + width = __cardwidth; + height = __cardheight; + } } CardRegion *CardWindow::CreateRegion(int id, bool fVisible, int x, int y, int xoffset, int yoffset) { - CardRegion *cr; + CardRegion *cr; - if(nNumCardRegions == MAXCARDSTACKS) - return FALSE; + if(nNumCardRegions == MAXCARDSTACKS) + return FALSE; - cr = new CardRegion(*this, id, fVisible, x, y, xoffset, yoffset); - cr->SetBackColor(crBackgnd); - cr->SetBackCardIdx(nBackCardIdx); + cr = new CardRegion(*this, id, fVisible, x, y, xoffset, yoffset); + cr->SetBackColor(crBackgnd); + cr->SetBackCardIdx(nBackCardIdx); - Regions[nNumCardRegions++] = cr; - - return cr; + Regions[nNumCardRegions++] = cr; + + return cr; } int CardRegion::GetOverlapRatio(int x, int y, int w, int h) { - RECT me, him; - RECT inter; - SetRect(&him, x, y, x+w, y+h); - SetRect(&me, xpos, ypos, xpos+width, ypos+height); + RECT me, him; + RECT inter; + SetRect(&him, x, y, x+w, y+h); + SetRect(&me, xpos, ypos, xpos+width, ypos+height); - //see if the specified rectangle overlaps us - if(IntersectRect(&inter, &me, &him)) - { - int wi = inter.right - inter.left; - int hi = inter.bottom - inter.top; + //see if the specified rectangle overlaps us + if(IntersectRect(&inter, &me, &him)) + { + int wi = inter.right - inter.left; + int hi = inter.bottom - inter.top; - int overlap = wi * hi; - int total = width * height; + int overlap = wi * hi; + int total = width * height; - int percent = (overlap << 16) / total; - return (percent * 100) >> 16; - } - //do not overlap - else - { - return 0; - } + int percent = (overlap << 16) / total; + return (percent * 100) >> 16; + } + //do not overlap + else + { + return 0; + } } bool CardRegion::SetDragRule(UINT uDragType, pCanDragProc proc) { - switch(uDragType) - { - case CS_DRAG_NONE: case CS_DRAG_ALL: case CS_DRAG_TOP: - uDragRule = uDragType; - return true; + switch(uDragType) + { + case CS_DRAG_NONE: case CS_DRAG_ALL: case CS_DRAG_TOP: + uDragRule = uDragType; + return true; - case CS_DRAG_CALLBACK: - uDragRule = uDragType; - CanDragCallback = proc; - return true; + case CS_DRAG_CALLBACK: + uDragRule = uDragType; + CanDragCallback = proc; + return true; - default: - return false; - } + default: + return false; + } } bool CardRegion::SetDropRule(UINT uDropType, pCanDropProc proc) { - switch(uDropType) - { - case CS_DROP_NONE: case CS_DROP_ALL: - uDropRule = uDropType; - return true; + switch(uDropType) + { + case CS_DROP_NONE: case CS_DROP_ALL: + uDropRule = uDropType; + return true; - case CS_DROP_CALLBACK: - uDropRule = uDropType; - CanDropCallback = proc; - return true; + case CS_DROP_CALLBACK: + uDropRule = uDropType; + CanDropCallback = proc; + return true; - default: - return false; - } + default: + return false; + } } void CardRegion::SetClickProc(pClickProc proc) { - ClickCallback = proc; + ClickCallback = proc; } void CardRegion::SetDblClickProc(pClickProc proc) { - DblClickCallback = proc; + DblClickCallback = proc; } void CardRegion::SetAddCardProc(pAddProc proc) { - AddCallback = proc; + AddCallback = proc; } void CardRegion::SetRemoveCardProc(pRemoveProc proc) { - RemoveCallback = proc; + RemoveCallback = proc; } void CardRegion::Update() { - CalcApparentCards(); - UpdateSize(); - UpdateFaceDir(cardstack); + CalcApparentCards(); + UpdateSize(); + UpdateFaceDir(cardstack); } bool CardRegion::SetThreedCount(int count) { - if(count < 1) - { - return false; - } - else - { - nThreedCount = count; - return true; - } + if(count < 1) + { + return false; + } + else + { + nThreedCount = count; + return true; + } } void CardRegion::SetOffsets(int x, int y) { - xoffset = x; - yoffset = y; + xoffset = x; + yoffset = y; } void CardRegion::SetPos(int x, int y) { - xpos = x; - ypos = y; + xpos = x; + ypos = y; } void CardRegion::Show(bool fShow) { - fVisible = fShow; + fVisible = fShow; } bool CardRegion::IsVisible() { - return fVisible; + return fVisible; } void CardRegion::SetPlacement(UINT xJustify, UINT yJustify, int xAdjust, int yAdjust) { - xjustify = xJustify; - yjustify = yJustify; - xadjust = xAdjust; - yadjust = yAdjust; + xjustify = xJustify; + yjustify = yJustify; + xadjust = xAdjust; + yadjust = yAdjust; } void CardRegion::SetFaceDirection(UINT uDirType, int nOption) { - switch(uDirType) - { - case CS_FACE_UP: case CS_FACE_DOWN: case CS_FACE_DOWNUP: - case CS_FACE_UPDOWN: case CS_FACE_ANY: - uFaceDirType = uDirType; - nFaceDirOption = nOption; + switch(uDirType) + { + case CS_FACE_UP: case CS_FACE_DOWN: case CS_FACE_DOWNUP: + case CS_FACE_UPDOWN: case CS_FACE_ANY: + uFaceDirType = uDirType; + nFaceDirOption = nOption; - UpdateFaceDir(cardstack); + UpdateFaceDir(cardstack); - break; - } + break; + } } UINT CardRegion::GetFaceDirection(int *pnOption) { - if(pnOption) - *pnOption = nFaceDirOption; + if(pnOption) + *pnOption = nFaceDirOption; - return uFaceDirType; + return uFaceDirType; } void CardRegion::AdjustPosition(int winwidth, int winheight) { - Update(); //Update this stack's card count + size + Update(); //Update this stack's card count + size - switch(xjustify) - { - default: case CS_XJUST_NONE: break; - - case CS_XJUST_CENTER: //centered - xpos = (winwidth - (width & ~0x1)) / 2; - xpos += xadjust; + switch(xjustify) + { + default: case CS_XJUST_NONE: break; + + case CS_XJUST_CENTER: //centered + xpos = (winwidth - (width & ~0x1)) / 2; + xpos += xadjust; - if(xoffset < 0) xpos += (width - __cardwidth); - - break; + if(xoffset < 0) xpos += (width - __cardwidth); + + break; - case CS_XJUST_RIGHT: //right-aligned - xpos = winwidth - __cardwidth;//width - 20; - xpos += xadjust; - break; - } + case CS_XJUST_RIGHT: //right-aligned + xpos = winwidth - __cardwidth;//width - 20; + xpos += xadjust; + break; + } - switch(yjustify) - { - default: case CS_YJUST_NONE: break; - - case CS_YJUST_CENTER: //centered - ypos = (winheight - height) / 2; - ypos += yadjust; - if(yoffset < 0) ypos += (height - __cardheight); - break; + switch(yjustify) + { + default: case CS_YJUST_NONE: break; + + case CS_YJUST_CENTER: //centered + ypos = (winheight - height) / 2; + ypos += yadjust; + if(yoffset < 0) ypos += (height - __cardheight); + break; - case CS_YJUST_BOTTOM: //bottom-aligned - ypos = winheight - __cardheight;//height - 20; - ypos += yadjust; - break; - } + case CS_YJUST_BOTTOM: //bottom-aligned + ypos = winheight - __cardheight;//height - 20; + ypos += yadjust; + break; + } } void CardRegion::Flash(int count, int milliseconds) { - if(count <= 0) return; + if(count <= 0) return; - nFlashCount = count; - fFlashVisible = false; - uFlashTimer = SetTimer((HWND)parentWnd, (WPARAM)this, milliseconds, 0); - - parentWnd.Redraw(); + nFlashCount = count; + fFlashVisible = false; + uFlashTimer = SetTimer((HWND)parentWnd, (WPARAM)this, milliseconds, 0); + + parentWnd.Redraw(); } void CardRegion::StopFlash() { - if(uFlashTimer != (UINT)-1) - { - KillTimer((HWND)parentWnd, uFlashTimer); - nFlashCount = 0; - uFlashTimer = (UINT)-1; - fFlashVisible = true; - } + if(uFlashTimer != (UINT)-1) + { + KillTimer((HWND)parentWnd, uFlashTimer); + nFlashCount = 0; + uFlashTimer = (UINT)-1; + fFlashVisible = true; + } } void CardRegion::DoFlash() { - if(uFlashTimer != (UINT)-1) - { - fFlashVisible = !fFlashVisible; + if(uFlashTimer != (UINT)-1) + { + fFlashVisible = !fFlashVisible; - if(--nFlashCount == 0) - { - KillTimer((HWND)parentWnd, uFlashTimer); - uFlashTimer = (UINT)-1; - fFlashVisible = true; - } - - parentWnd.Redraw(); - } + if(--nFlashCount == 0) + { + KillTimer((HWND)parentWnd, uFlashTimer); + uFlashTimer = (UINT)-1; + fFlashVisible = true; + } + + parentWnd.Redraw(); + } } int CardRegion::Id() { - return id; + return id; } void CardRegion::SetEmptyImage(UINT uImage) { - switch(uImage) - { - case CS_EI_NONE: case CS_EI_SUNK: - uEmptyImage = uImage; - break; + switch(uImage) + { + case CS_EI_NONE: case CS_EI_SUNK: + uEmptyImage = uImage; + break; - default: - uEmptyImage = CS_EI_NONE; - break; - } - + default: + uEmptyImage = CS_EI_NONE; + break; + } + } void CardRegion::SetBackCardIdx(UINT uBackIdx) { - if(uBackIdx >= 52 && uBackIdx <= 68) - nBackCardIdx = uBackIdx; + if(uBackIdx >= 52 && uBackIdx <= 68) + nBackCardIdx = uBackIdx; } void CardRegion::SetCardStack(const CardStack &cs) { - //make a complete copy of the specified stack.. - cardstack = cs; + //make a complete copy of the specified stack.. + cardstack = cs; - // Update the face-direction and stack-size - Update(); + // Update the face-direction and stack-size + Update(); } const CardStack & CardRegion::GetCardStack() { - //return reference to our internal stack - return cardstack; + //return reference to our internal stack + return cardstack; } // -// Update specified card-stack using THIS stack's +// Update specified card-stack using THIS stack's // face direction rules! // void CardRegion::UpdateFaceDir(CardStack &cards) { - int i, n, num; + int i, n, num; - num = cards.NumCards(); + num = cards.NumCards(); - //Now apply the face direction rules.. - switch(uFaceDirType) - { - case CS_FACE_UP: + //Now apply the face direction rules.. + switch(uFaceDirType) + { + case CS_FACE_UP: - for(i = 0; i < num; i++) - { - cards[i].SetFaceUp(true); - } + for(i = 0; i < num; i++) + { + cards[i].SetFaceUp(true); + } - break; + break; - case CS_FACE_DOWN: + case CS_FACE_DOWN: - for(i = 0; i < num; i++) - { - cards[i].SetFaceUp(false); - } + for(i = 0; i < num; i++) + { + cards[i].SetFaceUp(false); + } - break; + break; - case CS_FACE_DOWNUP: + case CS_FACE_DOWNUP: - num = cardstack.NumCards(); - n = min(nFaceDirOption, num); + num = cardstack.NumCards(); + n = min(nFaceDirOption, num); - //bottom n cards.. - for(i = 0; i < n; i++) - { - cards[num - i - 1].SetFaceUp(false); - } + //bottom n cards.. + for(i = 0; i < n; i++) + { + cards[num - i - 1].SetFaceUp(false); + } - for(i = n; i < num; i++) - { - cards[num - i - 1].SetFaceUp(true); - } + for(i = n; i < num; i++) + { + cards[num - i - 1].SetFaceUp(true); + } - break; + break; - case CS_FACE_UPDOWN: + case CS_FACE_UPDOWN: - num = cardstack.NumCards(); - n = min(nFaceDirOption, num); + num = cardstack.NumCards(); + n = min(nFaceDirOption, num); - for(i = 0; i < n; i++) - { - cards[num - i - 1].SetFaceUp(true); - } + for(i = 0; i < n; i++) + { + cards[num - i - 1].SetFaceUp(true); + } - for(i = n; i < num; i++) - { - cards[num - i - 1].SetFaceUp(false); - } + for(i = n; i < num; i++) + { + cards[num - i - 1].SetFaceUp(false); + } - break; + break; - case CS_FACE_ANY: //cards can be any orientation - default: - break; - } + case CS_FACE_ANY: //cards can be any orientation + default: + break; + } } bool CardRegion::MoveCard(CardRegion *pDestStack, int nNumCards, bool fAnimate) { - HDC hdc; + HDC hdc; - int x, y; + int x, y; - if(pDestStack == 0) return false; //{ forcedfacedir = -1 ;return 0; } + if(pDestStack == 0) return false; //{ forcedfacedir = -1 ;return 0; } - if(nNumCards < 0 || nNumCards > cardstack.NumCards()) - return false; + if(nNumCards < 0 || nNumCards > cardstack.NumCards()) + return false; - x = xpos + xoffset * (nNumApparentCards - nNumCards); - y = ypos + yoffset * (nNumApparentCards - nNumCards); + x = xpos + xoffset * (nNumApparentCards - nNumCards); + y = ypos + yoffset * (nNumApparentCards - nNumCards); - oldx = x; - oldy = y; - - dragstack = cardstack.Pop(nNumCards); + oldx = x; + oldy = y; + + dragstack = cardstack.Pop(nNumCards); - //Alter the drag-stack so that it's cards are the same way up - //as the destination. Use the destination's drag-rules - //instead of this ones!! - CardStack temp; - temp.Push(pDestStack->GetCardStack()); - temp.Push(dragstack); + //Alter the drag-stack so that it's cards are the same way up + //as the destination. Use the destination's drag-rules + //instead of this ones!! + CardStack temp; + temp.Push(pDestStack->GetCardStack()); + temp.Push(dragstack); - pDestStack->UpdateFaceDir(temp); + pDestStack->UpdateFaceDir(temp); - dragstack = temp.Pop(nNumCards); + dragstack = temp.Pop(nNumCards); - if(fAnimate) - { - iNumDragCards = nNumCards; - PrepareDragBitmaps(nNumCards); - } + if(fAnimate) + { + iNumDragCards = nNumCards; + PrepareDragBitmaps(nNumCards); + } - Update(); //Update this stack's size+card count + Update(); //Update this stack's size+card count - if(fAnimate) - { - hdc = GetDC((HWND)parentWnd); + if(fAnimate) + { + hdc = GetDC((HWND)parentWnd); - ZoomCard(hdc, x, y, pDestStack); - - ReleaseDC((HWND)parentWnd, hdc); - ReleaseDragBitmaps(); - } + ZoomCard(hdc, x, y, pDestStack); + + ReleaseDC((HWND)parentWnd, hdc); + ReleaseDragBitmaps(); + } - // Get a copy of the cardstack - CardStack cs = pDestStack->GetCardStack(); - cs.Push(dragstack); - - pDestStack->SetCardStack(cs); - - //cs = pDestStack->GetCardStack(); - //pDestStack->Update(); - //pDestStack->UpdateFaceDir(cs); + // Get a copy of the cardstack + CardStack cs = pDestStack->GetCardStack(); + cs.Push(dragstack); + + pDestStack->SetCardStack(cs); + + //cs = pDestStack->GetCardStack(); + //pDestStack->Update(); + //pDestStack->UpdateFaceDir(cs); - RedrawIfNotDim(pDestStack, false); + RedrawIfNotDim(pDestStack, false); - //forcedfacedir = -1; - return true; + //forcedfacedir = -1; + return true; } // -// Simple wrappers +// Simple wrappers // int CardRegion::NumCards() const { - if(fMouseDragging) - return cardstack.NumCards() + dragstack.NumCards(); - else - return cardstack.NumCards(); + if(fMouseDragging) + return cardstack.NumCards() + dragstack.NumCards(); + else + return cardstack.NumCards(); } bool CardRegion::Lock() { - DWORD dw = WaitForSingleObject(mxlock, 0); + DWORD dw = WaitForSingleObject(mxlock, 0); - if(dw == WAIT_OBJECT_0) - { - //TRACE("LockStack succeeded\n"); - return true; - } - else - { - //TRACE("LockStack failed\n"); - return false; - } - return false; + if(dw == WAIT_OBJECT_0) + { + //TRACE("LockStack succeeded\n"); + return true; + } + else + { + //TRACE("LockStack failed\n"); + return false; + } + return false; } bool CardRegion::UnLock() { - if(ReleaseMutex(mxlock)) - { - //TRACE("Unlocking stack\n"); - return true; - } - else - { - //TRACE("Unlocking stack failed\n"); - return false; - } + if(ReleaseMutex(mxlock)) + { + //TRACE("Unlocking stack\n"); + return true; + } + else + { + //TRACE("Unlocking stack failed\n"); + return false; + } } bool CardRegion::PlayCard(CardRegion *pDestStack, int value, int num) { - //search the stack for the specified card value... - while(num--) - { - for(int i = 0; i < cardstack.NumCards(); i++) - { - if(cardstack[i].HiVal() == value) - { - //swap the card with one at top pos... - Card card = cardstack.RemoveCard(i); - cardstack.Push(card); + //search the stack for the specified card value... + while(num--) + { + for(int i = 0; i < cardstack.NumCards(); i++) + { + if(cardstack[i].HiVal() == value) + { + //swap the card with one at top pos... + Card card = cardstack.RemoveCard(i); + cardstack.Push(card); - Redraw(); + Redraw(); - MoveCard(pDestStack, 1, true); - break; - } - } - } + MoveCard(pDestStack, 1, true); + break; + } + } + } - return true; + return true; } // -// Redraw the current stack if it has a different -// layout than the comparison stack. +// Redraw the current stack if it has a different +// layout than the comparison stack. // void CardRegion::RedrawIfNotDim(CardRegion *pCompare, bool fFullRedraw) { - // - // - // - if( pCompare->xoffset != xoffset || - pCompare->yoffset != yoffset || - pCompare->nThreedCount != nThreedCount || - pCompare->uFaceDirType != uFaceDirType || - pCompare->uFaceDirType != CS_FACE_ANY - ) - { - if(fFullRedraw) - parentWnd.Redraw(); - else - pCompare->Redraw(); - } - + // + // + // + if( pCompare->xoffset != xoffset || + pCompare->yoffset != yoffset || + pCompare->nThreedCount != nThreedCount || + pCompare->uFaceDirType != uFaceDirType || + pCompare->uFaceDirType != CS_FACE_ANY + ) + { + if(fFullRedraw) + parentWnd.Redraw(); + else + pCompare->Redraw(); + } + } // -// SimulateDrag mimicks the complete drag+drop process. +// SimulateDrag mimicks the complete drag+drop process. // It basically just a MoveCard(..), but it calls the // event callbacks as well. // bool CardRegion::SimulateDrag(CardRegion *pDestStack, int iNumDragCards, bool fAnimate) { - if(pDestStack == 0) - return false; + if(pDestStack == 0) + return false; - if(CanDragCards(iNumDragCards) != false) + if(CanDragCards(iNumDragCards) != false) { - //make a list of the cards that would be in the drag list - CardStack tempstack = cardstack.Top(iNumDragCards); + //make a list of the cards that would be in the drag list + CardStack tempstack = cardstack.Top(iNumDragCards); - if(pDestStack->CanDropCards(tempstack)) - { - MoveCard(pDestStack, iNumDragCards, fAnimate); - - if(RemoveCallback) - RemoveCallback(*this, iNumDragCards); + if(pDestStack->CanDropCards(tempstack)) + { + MoveCard(pDestStack, iNumDragCards, fAnimate); + + if(RemoveCallback) + RemoveCallback(*this, iNumDragCards); - if(pDestStack->AddCallback) - pDestStack->AddCallback(*pDestStack, pDestStack->cardstack); - - RedrawIfNotDim(pDestStack, true); - } + if(pDestStack->AddCallback) + pDestStack->AddCallback(*pDestStack, pDestStack->cardstack); + + RedrawIfNotDim(pDestStack, true); + } - } + } - return true; + return true; } diff --git a/rosapps/games/solitaire/cardlib/cardrgndraw.cpp b/rosapps/games/solitaire/cardlib/cardrgndraw.cpp index 32d8bbf7cfa..a5da84d8921 100644 --- a/rosapps/games/solitaire/cardlib/cardrgndraw.cpp +++ b/rosapps/games/solitaire/cardlib/cardrgndraw.cpp @@ -1,8 +1,8 @@ // -// CardLib - CardRegion drawing support +// CardLib - CardRegion drawing support // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include #include "cardlib.h" @@ -15,33 +15,33 @@ void CardBlt(HDC hdc, int x, int y, int nCardNum); void DrawCard(HDC hdc, int x, int y, HDC hdcSource, int width, int height); // -// Draw specified card at position x, y -// xoff - source offset from left of card -// yoff - source offset from top of card -// width - width to draw -// height - height to draw +// Draw specified card at position x, y +// xoff - source offset from left of card +// yoff - source offset from top of card +// width - width to draw +// height - height to draw // void CardBlt(HDC hdc, int x, int y, int nCardNum)//, int xoff, int yoff, int width, int height) { - int sx = nCardNum * __cardwidth; - int sy = 0; - int width = __cardwidth; - int height = __cardheight; + int sx = nCardNum * __cardwidth; + int sy = 0; + int width = __cardwidth; + int height = __cardheight; - //draw main center band - BitBlt(hdc, x+2, y, width - 4, height, __hdcCardBitmaps, sx+2, sy+0, SRCCOPY); + //draw main center band + BitBlt(hdc, x+2, y, width - 4, height, __hdcCardBitmaps, sx+2, sy+0, SRCCOPY); - //draw the two bits to the left - BitBlt(hdc, x, y+2, 1, height - 4, __hdcCardBitmaps, sx+0, sy+2, SRCCOPY); - BitBlt(hdc, x+1, y+1, 1, height - 2, __hdcCardBitmaps, sx+1, sy+1, SRCCOPY); + //draw the two bits to the left + BitBlt(hdc, x, y+2, 1, height - 4, __hdcCardBitmaps, sx+0, sy+2, SRCCOPY); + BitBlt(hdc, x+1, y+1, 1, height - 2, __hdcCardBitmaps, sx+1, sy+1, SRCCOPY); - //draw the two bits to the right - BitBlt(hdc, x+width-2, y+1, 1, height - 2, __hdcCardBitmaps, sx+width-2, sy+1, SRCCOPY); - BitBlt(hdc, x+width-1, y+2, 1, height - 4, __hdcCardBitmaps, sx+width-1, sy+2, SRCCOPY); + //draw the two bits to the right + BitBlt(hdc, x+width-2, y+1, 1, height - 2, __hdcCardBitmaps, sx+width-2, sy+1, SRCCOPY); + BitBlt(hdc, x+width-1, y+2, 1, height - 4, __hdcCardBitmaps, sx+width-1, sy+2, SRCCOPY); } // -// Draw a shape this this: +// Draw a shape this this: // // ++++++++++++ // ++++++++++++++ @@ -49,44 +49,44 @@ void CardBlt(HDC hdc, int x, int y, int nCardNum)//, int xoff, int yoff, int wid // void DrawHorzCardStrip(HDC hdc, int x, int y, int nCardNum, int height, BOOL fDrawTips) { - int sx = nCardNum * __cardwidth; - int sy = 0; - int one = 1; - int two = 2; - BOOL tips = fDrawTips ? FALSE : TRUE; + int sx = nCardNum * __cardwidth; + int sy = 0; + int one = 1; + int two = 2; + BOOL tips = fDrawTips ? FALSE : TRUE; - if(height == 0) return; + if(height == 0) return; - if(height < 0) - { - sy = sy + __cardheight; - y -= height; - one = -one; - two = -two; - } + if(height < 0) + { + sy = sy + __cardheight; + y -= height; + one = -one; + two = -two; + } - // draw the main vertical band - // - BitBlt(hdc, x + 2, y, __cardwidth - 4, height, __hdcCardBitmaps, sx+2, sy, SRCCOPY); + // draw the main vertical band + // + BitBlt(hdc, x + 2, y, __cardwidth - 4, height, __hdcCardBitmaps, sx+2, sy, SRCCOPY); - //if(height <= 1) return; + //if(height <= 1) return; - // draw the "lips" at the left and right - BitBlt(hdc, x+1, y+one, 1, height-one*tips, __hdcCardBitmaps, sx+1, sy+one, SRCCOPY); - BitBlt(hdc, x+__cardwidth-2, y+one, 1, height-one*tips, __hdcCardBitmaps, sx+__cardwidth-2, sy+one, SRCCOPY); + // draw the "lips" at the left and right + BitBlt(hdc, x+1, y+one, 1, height-one*tips, __hdcCardBitmaps, sx+1, sy+one, SRCCOPY); + BitBlt(hdc, x+__cardwidth-2, y+one, 1, height-one*tips, __hdcCardBitmaps, sx+__cardwidth-2, sy+one, SRCCOPY); - //if(height <= 2) return; + //if(height <= 2) return; - // draw the outer-most lips - BitBlt(hdc, x, y+two, 1, height-two*tips, __hdcCardBitmaps, sx, sy+two, SRCCOPY); - BitBlt(hdc, x+__cardwidth-1, y+two, 1, height-two*tips, __hdcCardBitmaps, sx+__cardwidth-1, sy+two, SRCCOPY); + // draw the outer-most lips + BitBlt(hdc, x, y+two, 1, height-two*tips, __hdcCardBitmaps, sx, sy+two, SRCCOPY); + BitBlt(hdc, x+__cardwidth-1, y+two, 1, height-two*tips, __hdcCardBitmaps, sx+__cardwidth-1, sy+two, SRCCOPY); } // -// Draw a shape like this: +// Draw a shape like this: // // +++ -// +++ +// +++ // +++ // +++ // +++ @@ -99,515 +99,515 @@ void DrawHorzCardStrip(HDC hdc, int x, int y, int nCardNum, int height, BOOL fDr // void DrawVertCardStrip(HDC hdc, int x, int y, int nCardNum, int width, BOOL fDrawTips) { - int sx = nCardNum * __cardwidth; - int sy = 0; - int one = 1; - int two = 2; - BOOL tips = fDrawTips ? FALSE : TRUE; + int sx = nCardNum * __cardwidth; + int sy = 0; + int one = 1; + int two = 2; + BOOL tips = fDrawTips ? FALSE : TRUE; - if(width == 0) return; - + if(width == 0) return; + - if(width < 0) - { - sx = sx + __cardwidth; - x -= width; - one = -1; - two = -2; - } + if(width < 0) + { + sx = sx + __cardwidth; + x -= width; + one = -1; + two = -2; + } - // draw the main vertical band - // - BitBlt(hdc, x, y + 2, width, __cardheight - 4, __hdcCardBitmaps, sx, sy+2, SRCCOPY); + // draw the main vertical band + // + BitBlt(hdc, x, y + 2, width, __cardheight - 4, __hdcCardBitmaps, sx, sy+2, SRCCOPY); - //if(width <= 1) return; + //if(width <= 1) return; - // draw the "lips" at the top and bottom - BitBlt(hdc, x+one, y+1, width-one*tips, 1, __hdcCardBitmaps, sx+one, sy + 1, SRCCOPY); - BitBlt(hdc, x+one, y+__cardheight-2, width-one*tips, 1, __hdcCardBitmaps, sx+one, sy + __cardheight-2, SRCCOPY); + // draw the "lips" at the top and bottom + BitBlt(hdc, x+one, y+1, width-one*tips, 1, __hdcCardBitmaps, sx+one, sy + 1, SRCCOPY); + BitBlt(hdc, x+one, y+__cardheight-2, width-one*tips, 1, __hdcCardBitmaps, sx+one, sy + __cardheight-2, SRCCOPY); - //if(width <= 2) return; + //if(width <= 2) return; - // draw the outer-most lips - BitBlt(hdc, x+two, y, width-two*tips, 1, __hdcCardBitmaps, sx+two, sy, SRCCOPY); - BitBlt(hdc, x+two, y+__cardheight-1, width-two*tips, 1, __hdcCardBitmaps, sx+two, sy + __cardheight-1, SRCCOPY); + // draw the outer-most lips + BitBlt(hdc, x+two, y, width-two*tips, 1, __hdcCardBitmaps, sx+two, sy, SRCCOPY); + BitBlt(hdc, x+two, y+__cardheight-1, width-two*tips, 1, __hdcCardBitmaps, sx+two, sy + __cardheight-1, SRCCOPY); } // -// xdir - <0 or >0 -// ydir - <0 or >0 +// xdir - <0 or >0 +// ydir - <0 or >0 // void DrawCardCorner(HDC hdc, int x, int y, int cardval, int xdir, int ydir) { - int sx = cardval * __cardwidth; - int sy = 0; + int sx = cardval * __cardwidth; + int sy = 0; - HDC hdcSource = __hdcCardBitmaps; + HDC hdcSource = __hdcCardBitmaps; - if(xdir < 0) - { - x += __cardwidth + xdir - 1; - sx += __cardwidth + xdir - 1; - } - else - { - x += xdir; - sx += xdir; - } + if(xdir < 0) + { + x += __cardwidth + xdir - 1; + sx += __cardwidth + xdir - 1; + } + else + { + x += xdir; + sx += xdir; + } - if(ydir < 0) - { - y += __cardheight + ydir - 1; - sy += __cardheight + ydir - 1; - } - else - { - y += ydir; - sy += ydir; - } + if(ydir < 0) + { + y += __cardheight + ydir - 1; + sy += __cardheight + ydir - 1; + } + else + { + y += ydir; + sy += ydir; + } - //convert x,y directions to -1, +1 - xdir = xdir < 0 ? -1 : 1; - ydir = ydir < 0 ? -1 : 1; + //convert x,y directions to -1, +1 + xdir = xdir < 0 ? -1 : 1; + ydir = ydir < 0 ? -1 : 1; - SetPixel(hdc, x+xdir, y , GetPixel(hdcSource, sx+xdir, sy)); - SetPixel(hdc, x, y, GetPixel(hdcSource, sx, sy)); - SetPixel(hdc, x, y+ydir, GetPixel(hdcSource, sx, sy+ydir)); + SetPixel(hdc, x+xdir, y , GetPixel(hdcSource, sx+xdir, sy)); + SetPixel(hdc, x, y, GetPixel(hdcSource, sx, sy)); + SetPixel(hdc, x, y+ydir, GetPixel(hdcSource, sx, sy+ydir)); } // -// Draw a card (i.e. miss out the corners) +// Draw a card (i.e. miss out the corners) // void DrawCard(HDC hdc, int x, int y, HDC hdcDragCard, int width, int height) { - //draw main center band - BitBlt(hdc, x+2, y, width - 4, height, hdcDragCard, 2, 0, SRCCOPY); + //draw main center band + BitBlt(hdc, x+2, y, width - 4, height, hdcDragCard, 2, 0, SRCCOPY); - //draw the two bits to the left - BitBlt(hdc, x, y+2, 1, height - 4, hdcDragCard, 0, 2, SRCCOPY); - BitBlt(hdc, x+1, y+1, 1, height - 2, hdcDragCard, 1, 1, SRCCOPY); + //draw the two bits to the left + BitBlt(hdc, x, y+2, 1, height - 4, hdcDragCard, 0, 2, SRCCOPY); + BitBlt(hdc, x+1, y+1, 1, height - 2, hdcDragCard, 1, 1, SRCCOPY); - //draw the two bits to the right - BitBlt(hdc, x+width-2, y+1, 1, height - 2, hdcDragCard, width-2, 1, SRCCOPY); - BitBlt(hdc, x+width-1, y+2, 1, height - 4, hdcDragCard, width-1, 2, SRCCOPY); + //draw the two bits to the right + BitBlt(hdc, x+width-2, y+1, 1, height - 2, hdcDragCard, width-2, 1, SRCCOPY); + BitBlt(hdc, x+width-1, y+2, 1, height - 4, hdcDragCard, width-1, 2, SRCCOPY); } // -// Clip a card SHAPE - basically any rectangle +// Clip a card SHAPE - basically any rectangle // with rounded corners // int ClipCard(HDC hdc, int x, int y, int width, int height) { - ExcludeClipRect(hdc, x+2, y, x+2+width-4, y+ height); - ExcludeClipRect(hdc, x, y+2, x+1, y+2+height-4); - ExcludeClipRect(hdc, x+1, y+1, x+2, y+1+height-2); - ExcludeClipRect(hdc, x+width-2, y+1, x+width-2+1, y+1+height-2); - ExcludeClipRect(hdc, x+width-1, y+2, x+width-1+1, y+2+height-4); - return 0; + ExcludeClipRect(hdc, x+2, y, x+2+width-4, y+ height); + ExcludeClipRect(hdc, x, y+2, x+1, y+2+height-4); + ExcludeClipRect(hdc, x+1, y+1, x+2, y+1+height-2); + ExcludeClipRect(hdc, x+width-2, y+1, x+width-2+1, y+1+height-2); + ExcludeClipRect(hdc, x+width-1, y+2, x+width-1+1, y+2+height-4); + return 0; } void CardRegion::Clip(HDC hdc) { - int numtoclip; + int numtoclip; - if(fVisible == false) - return; + if(fVisible == false) + return; - Update(); //Update this stack's size+card count - numtoclip = nNumApparentCards; + Update(); //Update this stack's size+card count + numtoclip = nNumApparentCards; - //if we are making this stack flash on/off, then only - //clip the stack for drawing if the flash is in its ON state - if(nFlashCount != 0) - { - if(fFlashVisible == FALSE) - numtoclip = 0; - } + //if we are making this stack flash on/off, then only + //clip the stack for drawing if the flash is in its ON state + if(nFlashCount != 0) + { + if(fFlashVisible == FALSE) + numtoclip = 0; + } - //if offset along a diagonal - if(xoffset != 0 && yoffset != 0 && cardstack.NumCards() != 0) - { - for(int j = 0; j < numtoclip; j ++) - { - ClipCard(hdc, xpos + xoffset * j, ypos + yoffset * j, __cardwidth, __cardheight); - } - } - //otherwise if just offset along a horizontal/vertical axis - else - { - if(yoffset < 0 && numtoclip > 0) - { - ClipCard(hdc, xpos, ypos-((numtoclip-1)*-yoffset), width, height); - } - else if(xoffset < 0 && numtoclip > 0) - { - ClipCard(hdc, xpos-((numtoclip-1)*-xoffset), ypos, width, height); - } - else - { - ClipCard(hdc, xpos, ypos, width, height); - } - } + //if offset along a diagonal + if(xoffset != 0 && yoffset != 0 && cardstack.NumCards() != 0) + { + for(int j = 0; j < numtoclip; j ++) + { + ClipCard(hdc, xpos + xoffset * j, ypos + yoffset * j, __cardwidth, __cardheight); + } + } + //otherwise if just offset along a horizontal/vertical axis + else + { + if(yoffset < 0 && numtoclip > 0) + { + ClipCard(hdc, xpos, ypos-((numtoclip-1)*-yoffset), width, height); + } + else if(xoffset < 0 && numtoclip > 0) + { + ClipCard(hdc, xpos-((numtoclip-1)*-xoffset), ypos, width, height); + } + else + { + ClipCard(hdc, xpos, ypos, width, height); + } + } } void CardRegion::Render(HDC hdc) { - int cardnum = 0; - int numtodraw; - BOOL fDrawTips; - - Update(); //Update this stack's card count + size + int cardnum = 0; + int numtodraw; + BOOL fDrawTips; + + Update(); //Update this stack's card count + size - numtodraw = nNumApparentCards; + numtodraw = nNumApparentCards; - if(nFlashCount != 0) - { - if(fFlashVisible == false) - numtodraw = 0; - } + if(nFlashCount != 0) + { + if(fFlashVisible == false) + numtodraw = 0; + } - if(fVisible == 0) return; - - cardnum = cardstack.NumCards() - numtodraw; - int counter; + if(fVisible == 0) return; + + cardnum = cardstack.NumCards() - numtodraw; + int counter; - for(counter = 0; counter < numtodraw; counter++) - { - int cardval; - - int x = xoffset * counter + xpos; - int y = yoffset * counter + ypos; + for(counter = 0; counter < numtodraw; counter++) + { + int cardval; + + int x = xoffset * counter + xpos; + int y = yoffset * counter + ypos; - //if about to draw last card, then actually draw the top card - if(counter == numtodraw - 1) cardnum = cardstack.NumCards() - 1; - - Card card = cardstack.cardlist[cardnum]; - cardval = card.Idx(); - - if(card.FaceDown()) - cardval = nBackCardIdx; //card-back - - //only draw the visible part of the card - if(counter < numtodraw - 1) - { - if(yoffset != 0 && xoffset != 0) - fDrawTips = FALSE; - else - fDrawTips = TRUE; + //if about to draw last card, then actually draw the top card + if(counter == numtodraw - 1) cardnum = cardstack.NumCards() - 1; + + Card card = cardstack.cardlist[cardnum]; + cardval = card.Idx(); + + if(card.FaceDown()) + cardval = nBackCardIdx; //card-back + + //only draw the visible part of the card + if(counter < numtodraw - 1) + { + if(yoffset != 0 && xoffset != 0) + fDrawTips = FALSE; + else + fDrawTips = TRUE; - if(yoffset != 0 && abs(xoffset) == 1 || xoffset != 0 && abs(yoffset) == 1) - fDrawTips = TRUE; + if(yoffset != 0 && abs(xoffset) == 1 || xoffset != 0 && abs(yoffset) == 1) + fDrawTips = TRUE; - //draw horizontal strips - if(yoffset > 0) - { - DrawHorzCardStrip(hdc, x, y, cardval, yoffset, fDrawTips); - } - else if(yoffset < 0) - { - DrawHorzCardStrip(hdc, x, y+__cardheight+yoffset, cardval, yoffset, fDrawTips); - } + //draw horizontal strips + if(yoffset > 0) + { + DrawHorzCardStrip(hdc, x, y, cardval, yoffset, fDrawTips); + } + else if(yoffset < 0) + { + DrawHorzCardStrip(hdc, x, y+__cardheight+yoffset, cardval, yoffset, fDrawTips); + } - //draw some vertical bars - if(xoffset > 0) - { - DrawVertCardStrip(hdc, x, y, cardval, xoffset, fDrawTips); - } - else if(xoffset < 0) - { - DrawVertCardStrip(hdc, x+__cardwidth+xoffset, y, cardval, xoffset, fDrawTips); - } + //draw some vertical bars + if(xoffset > 0) + { + DrawVertCardStrip(hdc, x, y, cardval, xoffset, fDrawTips); + } + else if(xoffset < 0) + { + DrawVertCardStrip(hdc, x+__cardwidth+xoffset, y, cardval, xoffset, fDrawTips); + } - if(yoffset != 0 && xoffset != 0)//fDrawTips == FALSE) - { - //if we didn't draw any tips, then this is a 2-dim stack - //(i.e, it goes at a diagonal). - //in this case, we need to fill in the small triangle in - //each corner! - DrawCardCorner(hdc, x, y, cardval, xoffset, yoffset); - } - } - //if the top card, draw the whole thing - else - { - CardBlt(hdc, x, y, cardval); - } + if(yoffset != 0 && xoffset != 0)//fDrawTips == FALSE) + { + //if we didn't draw any tips, then this is a 2-dim stack + //(i.e, it goes at a diagonal). + //in this case, we need to fill in the small triangle in + //each corner! + DrawCardCorner(hdc, x, y, cardval, xoffset, yoffset); + } + } + //if the top card, draw the whole thing + else + { + CardBlt(hdc, x, y, cardval); + } - cardnum ++; + cardnum ++; - } //end of index - - if(counter == 0) //if the cardstack is empty, then draw it that way - { - int x = xpos; - int y = ypos; - - switch(uEmptyImage) - { - default: case CS_EI_NONE: - //this wipes the RECT variable, so watch out! - //SetRect(&rect, x, y, x+__cardwidth, y+__cardheight); - //PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); - parentWnd.PaintCardRgn(hdc, x, y, __cardwidth, __cardheight, x, y); - break; - - case CS_EI_SUNK: //case CS_EI_CIRC: case CS_EI_X: - DrawCard(hdc, x, y, __hdcPlaceHolder, __cardwidth, __cardheight); - break; - } - - } + } //end of index + + if(counter == 0) //if the cardstack is empty, then draw it that way + { + int x = xpos; + int y = ypos; + + switch(uEmptyImage) + { + default: case CS_EI_NONE: + //this wipes the RECT variable, so watch out! + //SetRect(&rect, x, y, x+__cardwidth, y+__cardheight); + //PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); + parentWnd.PaintCardRgn(hdc, x, y, __cardwidth, __cardheight, x, y); + break; + + case CS_EI_SUNK: //case CS_EI_CIRC: case CS_EI_X: + DrawCard(hdc, x, y, __hdcPlaceHolder, __cardwidth, __cardheight); + break; + } + + } - return; + return; } int calc_offset(int offset, int numcards, int numtodrag, int realvisible) { - if(offset >= 0) - return -offset * numcards; - else - return -offset * (numtodrag) + - -offset * (realvisible - 1); + if(offset >= 0) + return -offset * numcards; + else + return -offset * (numtodrag) + + -offset * (realvisible - 1); } void CardRegion::PrepareDragBitmaps(int numtodrag) { - RECT rect; - HDC hdc; - int icard; - int numcards = cardstack.NumCards(); - int xoff, yoff; + RECT rect; + HDC hdc; + int icard; + int numcards = cardstack.NumCards(); + int xoff, yoff; - if(nThreedCount > 1) - { - PrepareDragBitmapsThreed(numtodrag); - return; - } + if(nThreedCount > 1) + { + PrepareDragBitmapsThreed(numtodrag); + return; + } - //work out how big the bitmaps need to be - nDragCardWidth = (numtodrag - 1) * abs(xoffset) + __cardwidth; - nDragCardHeight = (numtodrag - 1) * abs(yoffset) + __cardheight; + //work out how big the bitmaps need to be + nDragCardWidth = (numtodrag - 1) * abs(xoffset) + __cardwidth; + nDragCardHeight = (numtodrag - 1) * abs(yoffset) + __cardheight; - //Create bitmap for the back-buffer - hdc = GetDC(NULL); - hdcBackGnd = CreateCompatibleDC(hdc); - hbmBackGnd = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); - SelectObject(hdcBackGnd, hbmBackGnd); + //Create bitmap for the back-buffer + hdc = GetDC(NULL); + hdcBackGnd = CreateCompatibleDC(hdc); + hbmBackGnd = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); + SelectObject(hdcBackGnd, hbmBackGnd); - //Create bitmap for the drag-image - hdcDragCard = CreateCompatibleDC(hdc); - hbmDragCard = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); - SelectObject(hdcDragCard, hbmDragCard); - ReleaseDC(NULL, hdc); + //Create bitmap for the drag-image + hdcDragCard = CreateCompatibleDC(hdc); + hbmDragCard = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); + SelectObject(hdcDragCard, hbmDragCard); + ReleaseDC(NULL, hdc); - UseNicePalette(hdcBackGnd, __hPalette); - UseNicePalette(hdcDragCard, __hPalette); + UseNicePalette(hdcBackGnd, __hPalette); + UseNicePalette(hdcDragCard, __hPalette); - int realvisible = numcards / nThreedCount; + int realvisible = numcards / nThreedCount; - //if(numcards > 0 && realvisible == 0) realvisible = 1; - int iwhichcard = numcards - 1; - if(nThreedCount == 1) iwhichcard = 0; + //if(numcards > 0 && realvisible == 0) realvisible = 1; + int iwhichcard = numcards - 1; + if(nThreedCount == 1) iwhichcard = 0; - //grab the first bit of background so we can prep the back buffer; do this by - //rendering the card stack (minus the card we are dragging) to the temporary - //background buffer, so it appears if we have lifted the card from the stack - //PaintRect(hdcBackGnd, &rect, crBackgnd); - SetRect(&rect, 0, 0, nDragCardWidth, nDragCardHeight); + //grab the first bit of background so we can prep the back buffer; do this by + //rendering the card stack (minus the card we are dragging) to the temporary + //background buffer, so it appears if we have lifted the card from the stack + //PaintRect(hdcBackGnd, &rect, crBackgnd); + SetRect(&rect, 0, 0, nDragCardWidth, nDragCardHeight); - xoff = calc_offset(xoffset, numcards, numtodrag, realvisible); - yoff = calc_offset(yoffset, numcards, numtodrag, realvisible); - - parentWnd.PaintCardRgn(hdcBackGnd, 0, 0, nDragCardWidth, nDragCardHeight, xpos - xoff, ypos - yoff); + xoff = calc_offset(xoffset, numcards, numtodrag, realvisible); + yoff = calc_offset(yoffset, numcards, numtodrag, realvisible); + + parentWnd.PaintCardRgn(hdcBackGnd, 0, 0, nDragCardWidth, nDragCardHeight, xpos - xoff, ypos - yoff); - // - // Render the cardstack into the back-buffer. The stack - // has already had the dragcards removed, so just draw - // what is left - // - for(icard = 0; icard < realvisible; icard++) - { - Card card = cardstack.cardlist[iwhichcard]; - int nCardVal; - - nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; + // + // Render the cardstack into the back-buffer. The stack + // has already had the dragcards removed, so just draw + // what is left + // + for(icard = 0; icard < realvisible; icard++) + { + Card card = cardstack.cardlist[iwhichcard]; + int nCardVal; + + nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; - xoff = xoffset * icard + calc_offset(xoffset, numcards, numtodrag, realvisible);//- xoffset * ((numcards+numtodrag) / nThreedCount - numtodrag); - yoff = yoffset * icard + calc_offset(yoffset, numcards, numtodrag, realvisible);//- yoffset * ((numcards+numtodrag) / nThreedCount - numtodrag); + xoff = xoffset * icard + calc_offset(xoffset, numcards, numtodrag, realvisible);//- xoffset * ((numcards+numtodrag) / nThreedCount - numtodrag); + yoff = yoffset * icard + calc_offset(yoffset, numcards, numtodrag, realvisible);//- yoffset * ((numcards+numtodrag) / nThreedCount - numtodrag); - CardBlt(hdcBackGnd, xoff, yoff, nCardVal); - iwhichcard++; - } - - // - // If there are no cards under this one, just draw the place holder - // - if(numcards == 0) - { - int xoff = 0, yoff = 0; + CardBlt(hdcBackGnd, xoff, yoff, nCardVal); + iwhichcard++; + } + + // + // If there are no cards under this one, just draw the place holder + // + if(numcards == 0) + { + int xoff = 0, yoff = 0; - if(xoffset < 0) xoff = nDragCardWidth - __cardwidth; - if(yoffset < 0) yoff = nDragCardHeight - __cardheight; + if(xoffset < 0) xoff = nDragCardWidth - __cardwidth; + if(yoffset < 0) yoff = nDragCardHeight - __cardheight; - switch(uEmptyImage) - { - case CS_EI_NONE: - //No need to draw anything: We already cleared the - //back-buffer before the main loop.. + switch(uEmptyImage) + { + case CS_EI_NONE: + //No need to draw anything: We already cleared the + //back-buffer before the main loop.. - //SetRect(&rc, xoff, yoff, xoff+ __cardwidth, yoff + __cardheight); - //PaintRect(hdcBackGnd, &rc, MAKE_PALETTERGB(crBackgnd)); - //parentWnd.PaintCardRgn(hdcBackGnd, xoff, yoff, __cardwidth, __cardheight, xpos, ypos);// + xoff, ypos + yoff); - break; + //SetRect(&rc, xoff, yoff, xoff+ __cardwidth, yoff + __cardheight); + //PaintRect(hdcBackGnd, &rc, MAKE_PALETTERGB(crBackgnd)); + //parentWnd.PaintCardRgn(hdcBackGnd, xoff, yoff, __cardwidth, __cardheight, xpos, ypos);// + xoff, ypos + yoff); + break; - case CS_EI_SUNK: - DrawCard(hdcBackGnd, xoff, yoff, __hdcPlaceHolder, __cardwidth, __cardheight); - break; - } - } + case CS_EI_SUNK: + DrawCard(hdcBackGnd, xoff, yoff, __hdcPlaceHolder, __cardwidth, __cardheight); + break; + } + } - // - // now render the drag-cards into the dragcard image - // - PaintRect(hdcDragCard, &rect, crBackgnd); + // + // now render the drag-cards into the dragcard image + // + PaintRect(hdcDragCard, &rect, crBackgnd); - for(icard = 0; icard < numtodrag; icard++) - { - int nCardVal; + for(icard = 0; icard < numtodrag; icard++) + { + int nCardVal; - if(xoffset >= 0) xoff = xoffset * icard; - else xoff = -xoffset * (numtodrag - icard - 1); - - if(yoffset >= 0) yoff = yoffset * icard; - else yoff = -yoffset * (numtodrag - icard - 1); + if(xoffset >= 0) xoff = xoffset * icard; + else xoff = -xoffset * (numtodrag - icard - 1); + + if(yoffset >= 0) yoff = yoffset * icard; + else yoff = -yoffset * (numtodrag - icard - 1); - Card card = dragstack.cardlist[icard]; - - nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; + Card card = dragstack.cardlist[icard]; + + nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; - CardBlt(hdcDragCard, xoff, yoff, nCardVal); - } + CardBlt(hdcDragCard, xoff, yoff, nCardVal); + } } void CardRegion::PrepareDragBitmapsThreed(int numtodrag) { - RECT rect; - HDC hdc; - int icard; - int numunder = 0; - int iwhichcard; + RECT rect; + HDC hdc; + int icard; + int numunder = 0; + int iwhichcard; - int numcards = cardstack.NumCards(); + int numcards = cardstack.NumCards(); - //work out how big the bitmaps need to be - nDragCardWidth = (numtodrag - 1) * abs(xoffset) + __cardwidth; - nDragCardHeight = (numtodrag - 1) * abs(yoffset) + __cardheight; + //work out how big the bitmaps need to be + nDragCardWidth = (numtodrag - 1) * abs(xoffset) + __cardwidth; + nDragCardHeight = (numtodrag - 1) * abs(yoffset) + __cardheight; - //Create bitmap for the back-buffer - hdc = GetDC(NULL); - hdcBackGnd = CreateCompatibleDC(hdc); - hbmBackGnd = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); - SelectObject(hdcBackGnd, hbmBackGnd); + //Create bitmap for the back-buffer + hdc = GetDC(NULL); + hdcBackGnd = CreateCompatibleDC(hdc); + hbmBackGnd = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); + SelectObject(hdcBackGnd, hbmBackGnd); - //create bitmap for the drag-image - hdcDragCard = CreateCompatibleDC(hdc); - hbmDragCard = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); - SelectObject(hdcDragCard, hbmDragCard); - ReleaseDC(NULL, hdc); + //create bitmap for the drag-image + hdcDragCard = CreateCompatibleDC(hdc); + hbmDragCard = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); + SelectObject(hdcDragCard, hbmDragCard); + ReleaseDC(NULL, hdc); - UseNicePalette(hdcBackGnd, __hPalette); - UseNicePalette(hdcDragCard, __hPalette); + UseNicePalette(hdcBackGnd, __hPalette); + UseNicePalette(hdcDragCard, __hPalette); - //grab the first bit of background so we can prep the back buffer; do this by - //rendering the card stack (minus the card we are dragging) to the temporary - //background buffer, so it appears if we have lifted the card from the stack - //--SetRect(&rect, 0, 0, nDragCardWidth, nDragCardHeight); - //--PaintRect(hdcBackGnd, &rect, crBackgnd); + //grab the first bit of background so we can prep the back buffer; do this by + //rendering the card stack (minus the card we are dragging) to the temporary + //background buffer, so it appears if we have lifted the card from the stack + //--SetRect(&rect, 0, 0, nDragCardWidth, nDragCardHeight); + //--PaintRect(hdcBackGnd, &rect, crBackgnd); - int threedadjust = numcards % nThreedCount == 0; - - numunder = CalcApparentCards(numcards); - iwhichcard = (numcards+numtodrag) - numunder - 1; - if(nThreedCount == 1) iwhichcard = 0; - - int xoff = calc_offset(xoffset, numunder, numtodrag, numunder); - int yoff = calc_offset(yoffset, numunder, numtodrag, numunder); + int threedadjust = numcards % nThreedCount == 0; + + numunder = CalcApparentCards(numcards); + iwhichcard = (numcards+numtodrag) - numunder - 1; + if(nThreedCount == 1) iwhichcard = 0; + + int xoff = calc_offset(xoffset, numunder, numtodrag, numunder); + int yoff = calc_offset(yoffset, numunder, numtodrag, numunder); - parentWnd.PaintCardRgn(hdcBackGnd, 0,0, nDragCardWidth,nDragCardHeight, xpos - xoff,ypos - yoff); + parentWnd.PaintCardRgn(hdcBackGnd, 0,0, nDragCardWidth,nDragCardHeight, xpos - xoff,ypos - yoff); - // - // Render the cardstack into the back-buffer. The stack - // has already had the dragcards removed, so just draw - // what is left - // - for(icard = 0; icard < numunder; icard++) - { - Card card = cardstack.cardlist[iwhichcard]; - int nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; + // + // Render the cardstack into the back-buffer. The stack + // has already had the dragcards removed, so just draw + // what is left + // + for(icard = 0; icard < numunder; icard++) + { + Card card = cardstack.cardlist[iwhichcard]; + int nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; - CardBlt(hdcBackGnd, - xoffset * icard - xoffset*(numunder-numtodrag+threedadjust), - yoffset * icard - yoffset*(numunder-numtodrag+threedadjust), - nCardVal); + CardBlt(hdcBackGnd, + xoffset * icard - xoffset*(numunder-numtodrag+threedadjust), + yoffset * icard - yoffset*(numunder-numtodrag+threedadjust), + nCardVal); - iwhichcard++; - } - - // - // If there are no cards under this one, just draw the place holder - // - if(numcards == 0) - { - switch(uEmptyImage) - { - case CS_EI_NONE: - //no need! we've already cleared the whole - //back-buffer before the main loop! - //SetRect(&rect, 0, 0, __cardwidth, __cardheight); - //PaintRect(hdcBackGnd, &rect, MAKE_PALETTERGB(crBackgnd)); - break; + iwhichcard++; + } + + // + // If there are no cards under this one, just draw the place holder + // + if(numcards == 0) + { + switch(uEmptyImage) + { + case CS_EI_NONE: + //no need! we've already cleared the whole + //back-buffer before the main loop! + //SetRect(&rect, 0, 0, __cardwidth, __cardheight); + //PaintRect(hdcBackGnd, &rect, MAKE_PALETTERGB(crBackgnd)); + break; - case CS_EI_SUNK: - DrawCard(hdcBackGnd, 0, 0, __hdcPlaceHolder, __cardwidth, __cardheight); - break; - - } - } + case CS_EI_SUNK: + DrawCard(hdcBackGnd, 0, 0, __hdcPlaceHolder, __cardwidth, __cardheight); + break; + + } + } - // - // now render the drag-cards into the dragcard image - // - PaintRect(hdcDragCard, &rect, crBackgnd); - - for(icard = 0; icard < numtodrag; icard++) - { - Card card = dragstack.cardlist[icard]; - int nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; + // + // now render the drag-cards into the dragcard image + // + PaintRect(hdcDragCard, &rect, crBackgnd); + + for(icard = 0; icard < numtodrag; icard++) + { + Card card = dragstack.cardlist[icard]; + int nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; - CardBlt(hdcDragCard, xoffset * icard, yoffset * icard, nCardVal); - } + CardBlt(hdcDragCard, xoffset * icard, yoffset * icard, nCardVal); + } } void CardRegion::ReleaseDragBitmaps(void) { - //SelectObject(hdcBackGnd, hOld1); - DeleteObject(hbmBackGnd); - DeleteDC(hdcBackGnd); + //SelectObject(hdcBackGnd, hOld1); + DeleteObject(hbmBackGnd); + DeleteDC(hdcBackGnd); - //SelectObject(hdcDragCard, hOld2); - DeleteObject(hbmDragCard); - DeleteDC(hdcDragCard); + //SelectObject(hdcDragCard, hOld2); + DeleteObject(hbmDragCard); + DeleteDC(hdcDragCard); } void CardRegion::Redraw() { - HDC hdc = GetDC((HWND)parentWnd); + HDC hdc = GetDC((HWND)parentWnd); - Update(); - Render(hdc); + Update(); + Render(hdc); - ReleaseDC((HWND)parentWnd, hdc); + ReleaseDC((HWND)parentWnd, hdc); } diff --git a/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp b/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp index 4e9bd5259ae..317986acdce 100644 --- a/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp +++ b/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp @@ -1,8 +1,8 @@ // -// CardLib - CardRegion mouse-related stuff +// CardLib - CardRegion mouse-related stuff // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include #include @@ -29,454 +29,454 @@ static pDebugClickProc DebugStackClickProc = 0; void CardLib_SetStackClickProc(pDebugClickProc proc) { - DebugStackClickProc = proc; + DebugStackClickProc = proc; } #endif CardRegion *CardWindow::GetBestStack(int x, int y, int w, int h) { - int maxoverlap = 0; - int maxoverlapidx = -1; + int maxoverlap = 0; + int maxoverlapidx = -1; - //find the stack which is most covered by the dropped - //cards. Only include those which allow drops. - // - for(int i = 0; i < nNumCardRegions; i++) - { - int percent = Regions[i]->GetOverlapRatio(x, y, w, h); + //find the stack which is most covered by the dropped + //cards. Only include those which allow drops. + // + for(int i = 0; i < nNumCardRegions; i++) + { + int percent = Regions[i]->GetOverlapRatio(x, y, w, h); - //if this stack has the biggest coverage yet - if(percent > maxoverlap && Regions[i]->IsVisible()) - { - maxoverlap = percent; - maxoverlapidx = i; - } - } - - //if we found a stack to drop onto - if(maxoverlapidx != -1) - { - return Regions[maxoverlapidx]; - } - else - { - return 0; - } + //if this stack has the biggest coverage yet + if(percent > maxoverlap && Regions[i]->IsVisible()) + { + maxoverlap = percent; + maxoverlapidx = i; + } + } + + //if we found a stack to drop onto + if(maxoverlapidx != -1) + { + return Regions[maxoverlapidx]; + } + else + { + return 0; + } } bool CardRegion::IsPointInStack(int x, int y) { - int axpos = xoffset < 0 ? xpos + (nNumApparentCards-1)*xoffset : xpos; - int aypos = yoffset < 0 ? ypos + (nNumApparentCards-1)*yoffset : ypos; - - if(x >= axpos && x < axpos + width && y >= aypos && y < aypos + height && fVisible) - return true; - else - return false; + int axpos = xoffset < 0 ? xpos + (nNumApparentCards-1)*xoffset : xpos; + int aypos = yoffset < 0 ? ypos + (nNumApparentCards-1)*yoffset : ypos; + + if(x >= axpos && x < axpos + width && y >= aypos && y < aypos + height && fVisible) + return true; + else + return false; } int CardRegion::GetNumDragCards(int x, int y) { - int cardindex = 0; //index from stack start - int maxidx; + int cardindex = 0; //index from stack start + int maxidx; - //make x,y relative to the stack's upper left corner - x -= xpos + (xoffset < 0 ? (nNumApparentCards/*cardstack.NumCards()*/ - 1) * xoffset : 0); - y -= ypos + (yoffset < 0 ? (nNumApparentCards/*cardstack.NumCards()*/ - 1) * yoffset : 0); - - //if stack is empty, cannot drag any cards from it - if(cardstack.NumCards() <= 0) - return 0; + //make x,y relative to the stack's upper left corner + x -= xpos + (xoffset < 0 ? (nNumApparentCards/*cardstack.NumCards()*/ - 1) * xoffset : 0); + y -= ypos + (yoffset < 0 ? (nNumApparentCards/*cardstack.NumCards()*/ - 1) * yoffset : 0); + + //if stack is empty, cannot drag any cards from it + if(cardstack.NumCards() <= 0) + return 0; - //see which card in the stack has been clicked on - //top-bottom ordering - if(yoffset > 0) - { - if(y < height - __cardheight) - cardindex = y / yoffset; - else - cardindex = cardstack.NumCards() - 1; - } - else if(yoffset < 0) - { - if(y < __cardheight) - cardindex = cardstack.NumCards() - 1; - else - cardindex = cardstack.NumCards() - ((y - __cardheight) / -yoffset) - 2; - } - else //yoffset == 0 - { - cardindex = cardstack.NumCards() - 1; - } + //see which card in the stack has been clicked on + //top-bottom ordering + if(yoffset > 0) + { + if(y < height - __cardheight) + cardindex = y / yoffset; + else + cardindex = cardstack.NumCards() - 1; + } + else if(yoffset < 0) + { + if(y < __cardheight) + cardindex = cardstack.NumCards() - 1; + else + cardindex = cardstack.NumCards() - ((y - __cardheight) / -yoffset) - 2; + } + else //yoffset == 0 + { + cardindex = cardstack.NumCards() - 1; + } - maxidx = cardindex; + maxidx = cardindex; - //if left-right - if(xoffset > 0) - { - if(x < width - __cardwidth) - cardindex = x / xoffset; - else - cardindex = cardstack.NumCards() - 1; - } - else if(xoffset < 0) - { - if(x < __cardwidth) - cardindex = cardstack.NumCards() - 1; - else - cardindex = cardstack.NumCards() - ((x - __cardwidth) / -xoffset) - 2; - } - else - { - cardindex = cardstack.NumCards() - 1; - } + //if left-right + if(xoffset > 0) + { + if(x < width - __cardwidth) + cardindex = x / xoffset; + else + cardindex = cardstack.NumCards() - 1; + } + else if(xoffset < 0) + { + if(x < __cardwidth) + cardindex = cardstack.NumCards() - 1; + else + cardindex = cardstack.NumCards() - ((x - __cardwidth) / -xoffset) - 2; + } + else + { + cardindex = cardstack.NumCards() - 1; + } - if(cardindex > maxidx) cardindex = maxidx; + if(cardindex > maxidx) cardindex = maxidx; - if(cardindex > cardstack.NumCards()) - cardindex = 1; + if(cardindex > cardstack.NumCards()) + cardindex = 1; - //if are trying to drag too many cards at once - return cardstack.NumCards() - cardindex; + //if are trying to drag too many cards at once + return cardstack.NumCards() - cardindex; } bool CardRegion::CanDragCards(int iNumCards) { - if(iNumCards <= 0) return false; - if(nThreedCount > 1 && iNumCards > 1) return false; + if(iNumCards <= 0) return false; + if(nThreedCount > 1 && iNumCards > 1) return false; - if(WaitForSingleObject(mxlock, 0) != WAIT_OBJECT_0) - { -// TRACE("Failed to gain access to card stack\n"); - return false; - } + if(WaitForSingleObject(mxlock, 0) != WAIT_OBJECT_0) + { +// TRACE("Failed to gain access to card stack\n"); + return false; + } - ReleaseMutex(mxlock); + ReleaseMutex(mxlock); - switch(uDragRule) - { - case CS_DRAG_ALL: - return true; - - case CS_DRAG_TOP: + switch(uDragRule) + { + case CS_DRAG_ALL: + return true; + + case CS_DRAG_TOP: - if(iNumCards == 1) - return true; - else - return false; - - case CS_DRAG_NONE: - return false; - - case CS_DRAG_CALLBACK: - - if(CanDragCallback) - { - return CanDragCallback(*this, iNumCards); - } - else - { - return false; - } - - default: - return false; - } + if(iNumCards == 1) + return true; + else + return false; + + case CS_DRAG_NONE: + return false; + + case CS_DRAG_CALLBACK: + + if(CanDragCallback) + { + return CanDragCallback(*this, iNumCards); + } + else + { + return false; + } + + default: + return false; + } } bool CardRegion::CanDropCards(CardStack &cards) { - if(WaitForSingleObject(mxlock, 0) != WAIT_OBJECT_0) - { - return false; - } + if(WaitForSingleObject(mxlock, 0) != WAIT_OBJECT_0) + { + return false; + } - ReleaseMutex(mxlock); + ReleaseMutex(mxlock); - switch(uDropRule) - { - case CS_DROP_ALL: - return true; + switch(uDropRule) + { + case CS_DROP_ALL: + return true; - case CS_DROP_NONE: - return false; + case CS_DROP_NONE: + return false; - case CS_DROP_CALLBACK: - - if(CanDropCallback) - { - return CanDropCallback(*this, cards); - } - else - { - return false; - } + case CS_DROP_CALLBACK: + + if(CanDropCallback) + { + return CanDropCallback(*this, cards); + } + else + { + return false; + } - default: - return false; - } + default: + return false; + } } bool CardRegion::OnLButtonDblClk(int x, int y) { - iNumDragCards = GetNumDragCards(x, y); + iNumDragCards = GetNumDragCards(x, y); - if(DblClickCallback) - DblClickCallback(*this, iNumDragCards); + if(DblClickCallback) + DblClickCallback(*this, iNumDragCards); - return true; + return true; } bool CardRegion::OnLButtonDown(int x, int y) { - iNumDragCards = GetNumDragCards(x, y); + iNumDragCards = GetNumDragCards(x, y); #ifdef _DEBUG - if(DebugStackClickProc) - { - if(!DebugStackClickProc(*this)) - return false; - } + if(DebugStackClickProc) + { + if(!DebugStackClickProc(*this)) + return false; + } #endif - if(ClickCallback) - ClickCallback(*this, iNumDragCards); + if(ClickCallback) + ClickCallback(*this, iNumDragCards); - if(CanDragCards(iNumDragCards) != false) + if(CanDragCards(iNumDragCards) != false) { - //offset of the mouse cursor relative to the top-left corner - //of the cards that are being dragged - mousexoffset = x - xpos - xoffset * (nNumApparentCards - iNumDragCards); - mouseyoffset = y - ypos - yoffset * (nNumApparentCards - iNumDragCards); - - if(xoffset < 0) - mousexoffset += -xoffset * (iNumDragCards - 1); + //offset of the mouse cursor relative to the top-left corner + //of the cards that are being dragged + mousexoffset = x - xpos - xoffset * (nNumApparentCards - iNumDragCards); + mouseyoffset = y - ypos - yoffset * (nNumApparentCards - iNumDragCards); + + if(xoffset < 0) + mousexoffset += -xoffset * (iNumDragCards - 1); - if(yoffset < 0) - mouseyoffset += -yoffset * (iNumDragCards - 1); - - //remove the cards from the source stack - dragstack = cardstack.Pop(iNumDragCards); + if(yoffset < 0) + mouseyoffset += -yoffset * (iNumDragCards - 1); + + //remove the cards from the source stack + dragstack = cardstack.Pop(iNumDragCards); - //prepare the back buffer, and the drag image - PrepareDragBitmaps(iNumDragCards); + //prepare the back buffer, and the drag image + PrepareDragBitmaps(iNumDragCards); - oldx = x - mousexoffset; - oldy = y - mouseyoffset; - - Update(); //Update this stack's card count + size + oldx = x - mousexoffset; + oldy = y - mouseyoffset; + + Update(); //Update this stack's card count + size - SetCapture((HWND)parentWnd); + SetCapture((HWND)parentWnd); - //set AFTER settings the dragstack... - fMouseDragging = true; + //set AFTER settings the dragstack... + fMouseDragging = true; - return true; - } + return true; + } - return false; + return false; } bool CardRegion::OnLButtonUp(int x, int y) { - CardRegion *pDestStack = 0; - HDC hdc; - int dropstackid = CS_DROPZONE_NODROP; - - RECT dragrect; - DropZone *dropzone; + CardRegion *pDestStack = 0; + HDC hdc; + int dropstackid = CS_DROPZONE_NODROP; + + RECT dragrect; + DropZone *dropzone; - fMouseDragging = false; + fMouseDragging = false; - //first of all, see if any drop zones have been registered - SetRect(&dragrect, x-mousexoffset, y-mouseyoffset, x-mousexoffset+nDragCardWidth, y-mouseyoffset+nDragCardHeight); + //first of all, see if any drop zones have been registered + SetRect(&dragrect, x-mousexoffset, y-mouseyoffset, x-mousexoffset+nDragCardWidth, y-mouseyoffset+nDragCardHeight); - dropzone = parentWnd.GetDropZoneFromRect(&dragrect); + dropzone = parentWnd.GetDropZoneFromRect(&dragrect); - if(dropzone) - { - dropstackid = dropzone->DropCards(dragstack); - - if(dropstackid != CS_DROPZONE_NODROP) - pDestStack = parentWnd.CardRegionFromId(dropstackid); - else - pDestStack = 0; - } - else - { - pDestStack = parentWnd.GetBestStack(x - mousexoffset, y - mouseyoffset, nDragCardWidth, nDragCardHeight); - } - - // If have found a stack to drop onto - // - TRACE ( "can I drop card?\n" ); - if(pDestStack && pDestStack->CanDropCards(dragstack)) - { - TRACE ( "yes, dropping card\n" ); - hdc = GetDC((HWND)parentWnd); - // UseNicePalette(hdc); - ZoomCard(hdc, x - mousexoffset, y - mouseyoffset, pDestStack); - ReleaseDC((HWND)parentWnd, hdc); - - // - //add the cards to the destination stack - // - CardStack temp = pDestStack->GetCardStack(); - temp.Push(dragstack); - - pDestStack->SetCardStack(temp); -// pDestStack->Update(); //Update this stack's card count + size -// pDestStack->UpdateFaceDir(temp); - - // Call the remove callback on THIS stack, if one is specified - // - if(RemoveCallback) - RemoveCallback(*this, iNumDragCards); + if(dropzone) + { + dropstackid = dropzone->DropCards(dragstack); + + if(dropstackid != CS_DROPZONE_NODROP) + pDestStack = parentWnd.CardRegionFromId(dropstackid); + else + pDestStack = 0; + } + else + { + pDestStack = parentWnd.GetBestStack(x - mousexoffset, y - mouseyoffset, nDragCardWidth, nDragCardHeight); + } + + // If have found a stack to drop onto + // + TRACE ( "can I drop card?\n" ); + if(pDestStack && pDestStack->CanDropCards(dragstack)) + { + TRACE ( "yes, dropping card\n" ); + hdc = GetDC((HWND)parentWnd); + // UseNicePalette(hdc); + ZoomCard(hdc, x - mousexoffset, y - mouseyoffset, pDestStack); + ReleaseDC((HWND)parentWnd, hdc); + + // + //add the cards to the destination stack + // + CardStack temp = pDestStack->GetCardStack(); + temp.Push(dragstack); + + pDestStack->SetCardStack(temp); +// pDestStack->Update(); //Update this stack's card count + size +// pDestStack->UpdateFaceDir(temp); + + // Call the remove callback on THIS stack, if one is specified + // + if(RemoveCallback) + RemoveCallback(*this, iNumDragCards); - // Call the add callback, if one is specified - // - if(pDestStack->AddCallback) - pDestStack->AddCallback(*pDestStack, pDestStack->cardstack);//index, deststack->numcards); - - RedrawIfNotDim(pDestStack, true); - TRACE ( "done dropping card\n" ); - } + // Call the add callback, if one is specified + // + if(pDestStack->AddCallback) + pDestStack->AddCallback(*pDestStack, pDestStack->cardstack);//index, deststack->numcards); + + RedrawIfNotDim(pDestStack, true); + TRACE ( "done dropping card\n" ); + } - // - // Otherwise, let the cards snap back onto this stack - // - else - { - TRACE ( "no, putting card back\n" ); - hdc = GetDC((HWND)parentWnd); - TRACE ( "calling ZoomCard()\n" ); - ZoomCard(hdc, x - mousexoffset, y - mouseyoffset, this); - TRACE ( "cardstack += dragstack\n" ); - cardstack += dragstack; - TRACE ( "calling ReleaseDC()\n" ); - ReleaseDC((HWND)parentWnd, hdc); + // + // Otherwise, let the cards snap back onto this stack + // + else + { + TRACE ( "no, putting card back\n" ); + hdc = GetDC((HWND)parentWnd); + TRACE ( "calling ZoomCard()\n" ); + ZoomCard(hdc, x - mousexoffset, y - mouseyoffset, this); + TRACE ( "cardstack += dragstack\n" ); + cardstack += dragstack; + TRACE ( "calling ReleaseDC()\n" ); + ReleaseDC((HWND)parentWnd, hdc); - TRACE ( "calling Update()\n" ); - Update(); //Update this stack's card count + size - TRACE ( "done putting card back\n" ); - } - - ReleaseDragBitmaps(); - ReleaseCapture(); - - TRACE ( "OnLButtonUp() done\n" ); - return true; + TRACE ( "calling Update()\n" ); + Update(); //Update this stack's card count + size + TRACE ( "done putting card back\n" ); + } + + ReleaseDragBitmaps(); + ReleaseCapture(); + + TRACE ( "OnLButtonUp() done\n" ); + return true; } bool CardRegion::OnMouseMove(int x, int y) { - HDC hdc; + HDC hdc; - hdc = GetDC((HWND)parentWnd); - - x -= mousexoffset; - y -= mouseyoffset; - - MoveDragCardTo(hdc, x, y); + hdc = GetDC((HWND)parentWnd); + + x -= mousexoffset; + y -= mouseyoffset; + + MoveDragCardTo(hdc, x, y); - //BitBlt(hdc, nDragCardWidth+10, 0, nDragCardWidth, nDragCardHeight, hdcBackGnd, 0, 0, SRCCOPY); - //BitBlt(hdc, 0, 0, nDragCardWidth, nDragCardHeight, hdcDragCard, 0, 0, SRCCOPY); - - ReleaseDC((HWND)parentWnd, hdc); - - oldx = x; - oldy = y; - - return true; + //BitBlt(hdc, nDragCardWidth+10, 0, nDragCardWidth, nDragCardHeight, hdcBackGnd, 0, 0, SRCCOPY); + //BitBlt(hdc, 0, 0, nDragCardWidth, nDragCardHeight, hdcDragCard, 0, 0, SRCCOPY); + + ReleaseDC((HWND)parentWnd, hdc); + + oldx = x; + oldy = y; + + return true; } // -// There is a bug in BitBlt when the source x,y -// become < 0. So this wrapper function simply adjusts -// the coords so that we never try to blt in from this range +// There is a bug in BitBlt when the source x,y +// become < 0. So this wrapper function simply adjusts +// the coords so that we never try to blt in from this range // BOOL ClippedBitBlt(HDC hdcDest, int x, int y, int width, int height, HDC hdcSrc, int srcx, int srcy, DWORD dwROP) { - if(srcx < 0) - { - x = 0 - srcx; - width = width + srcx; - srcx = 0; - } + if(srcx < 0) + { + x = 0 - srcx; + width = width + srcx; + srcx = 0; + } - if(srcy < 0) - { - y = 0 - srcy; - height = height + srcy; - srcy = 0; - } + if(srcy < 0) + { + y = 0 - srcy; + height = height + srcy; + srcy = 0; + } - return BitBlt(hdcDest, x, y, width, height, hdcSrc, srcx, srcy, dwROP); + return BitBlt(hdcDest, x, y, width, height, hdcSrc, srcx, srcy, dwROP); } void CardRegion::MoveDragCardTo(HDC hdc, int x, int y) { - RECT inter, rect1, rect2; + RECT inter, rect1, rect2; - //mask off the new position of the drag-card, so - //that it will not be painted over - ClipCard(hdc, x, y, nDragCardWidth, nDragCardHeight); - - //restore the area covered by the card at its previous position - BitBlt(hdc, oldx, oldy, nDragCardWidth, nDragCardHeight, hdcBackGnd, 0, 0, SRCCOPY); + //mask off the new position of the drag-card, so + //that it will not be painted over + ClipCard(hdc, x, y, nDragCardWidth, nDragCardHeight); + + //restore the area covered by the card at its previous position + BitBlt(hdc, oldx, oldy, nDragCardWidth, nDragCardHeight, hdcBackGnd, 0, 0, SRCCOPY); - //remove clipping so we can draw the card at its new place - SelectClipRgn(hdc, NULL); - - //if the card's old and new positions overlap, then we - //need some funky code to update the "saved background" image, - SetRect(&rect1, oldx, oldy, oldx+nDragCardWidth, oldy+nDragCardHeight); - SetRect(&rect2, x, y, x+nDragCardWidth, y+nDragCardHeight); - - if(IntersectRect(&inter, &rect1, &rect2)) - { - int interwidth = inter.right-inter.left; - int interheight = inter.bottom-inter.top; - int destx, desty, srcx, srcy; - - if(rect2.left > rect1.left) - { - destx = 0; srcx = nDragCardWidth - interwidth; - } - else - { - destx = nDragCardWidth - interwidth; srcx = 0; - } - - if(rect2.top > rect1.top) - { - desty = 0; srcy = nDragCardHeight - interheight; - } - else - { - desty = nDragCardHeight - interheight; srcy = 0; - } - - //shift the bit we didn't use for the restore (due to the clipping) - //into the opposite corner - BitBlt(hdcBackGnd, destx,desty, interwidth, interheight, hdcBackGnd, srcx, srcy, SRCCOPY); - - ExcludeClipRect(hdcBackGnd, destx, desty, destx+interwidth, desty+interheight); - - //this bit requires us to clip the BitBlt (from screen to background) - //as BitBlt is a bit buggy it seems - ClippedBitBlt(hdcBackGnd, 0,0, nDragCardWidth, nDragCardHeight, hdc, x, y, SRCCOPY); - SelectClipRgn(hdcBackGnd, NULL); - } - else - { - BitBlt(hdcBackGnd, 0,0, nDragCardWidth, nDragCardHeight, hdc, x, y, SRCCOPY); - } - - //finally draw the card to the screen - DrawCard(hdc, x, y, hdcDragCard, nDragCardWidth, nDragCardHeight); + //remove clipping so we can draw the card at its new place + SelectClipRgn(hdc, NULL); + + //if the card's old and new positions overlap, then we + //need some funky code to update the "saved background" image, + SetRect(&rect1, oldx, oldy, oldx+nDragCardWidth, oldy+nDragCardHeight); + SetRect(&rect2, x, y, x+nDragCardWidth, y+nDragCardHeight); + + if(IntersectRect(&inter, &rect1, &rect2)) + { + int interwidth = inter.right-inter.left; + int interheight = inter.bottom-inter.top; + int destx, desty, srcx, srcy; + + if(rect2.left > rect1.left) + { + destx = 0; srcx = nDragCardWidth - interwidth; + } + else + { + destx = nDragCardWidth - interwidth; srcx = 0; + } + + if(rect2.top > rect1.top) + { + desty = 0; srcy = nDragCardHeight - interheight; + } + else + { + desty = nDragCardHeight - interheight; srcy = 0; + } + + //shift the bit we didn't use for the restore (due to the clipping) + //into the opposite corner + BitBlt(hdcBackGnd, destx,desty, interwidth, interheight, hdcBackGnd, srcx, srcy, SRCCOPY); + + ExcludeClipRect(hdcBackGnd, destx, desty, destx+interwidth, desty+interheight); + + //this bit requires us to clip the BitBlt (from screen to background) + //as BitBlt is a bit buggy it seems + ClippedBitBlt(hdcBackGnd, 0,0, nDragCardWidth, nDragCardHeight, hdc, x, y, SRCCOPY); + SelectClipRgn(hdcBackGnd, NULL); + } + else + { + BitBlt(hdcBackGnd, 0,0, nDragCardWidth, nDragCardHeight, hdc, x, y, SRCCOPY); + } + + //finally draw the card to the screen + DrawCard(hdc, x, y, hdcDragCard, nDragCardWidth, nDragCardHeight); } @@ -484,159 +484,159 @@ void CardRegion::MoveDragCardTo(HDC hdc, int x, int y) //extern "C" int _ftol(void) { return 0; } // -// Better do this in fixed-point, to stop -// VC from linking in floatingpoint-long conversions +// Better do this in fixed-point, to stop +// VC from linking in floatingpoint-long conversions // //#define FIXED_PREC_MOVE #ifdef FIXED_PREC_MOVE #define PRECISION 12 void ZoomCard(HDC hdc, int xpos, int ypos, CARDSTACK *dest) { - long dx, dy, x , y; + long dx, dy, x , y; - - int apparentcards; - x = xpos << PRECISION; y = ypos << PRECISION; + + int apparentcards; + x = xpos << PRECISION; y = ypos << PRECISION; - oldx = (int)xpos; - oldy = (int)ypos; + oldx = (int)xpos; + oldy = (int)ypos; - apparentcards=dest->numcards/dest->threedcount; + apparentcards=dest->numcards/dest->threedcount; - int idestx = dest->xpos + dest->xoffset * (apparentcards);// - iNumDragCards); - int idesty = dest->ypos + dest->yoffset * (apparentcards);// - iNumDragCards); + int idestx = dest->xpos + dest->xoffset * (apparentcards);// - iNumDragCards); + int idesty = dest->ypos + dest->yoffset * (apparentcards);// - iNumDragCards); - //normalise the motion vector - dx = (idestx<>PRECISION; - iy = (int)y>>PRECISION; - if(dx < 0 && ix < idestx) ix = idestx; - else if(dx > 0 && ix > idestx) ix = idestx; + ix = (int)x>>PRECISION; + iy = (int)y>>PRECISION; + if(dx < 0 && ix < idestx) ix = idestx; + else if(dx > 0 && ix > idestx) ix = idestx; - if(dy < 0 && iy < idesty) iy = idesty; - else if(dy > 0 && iy > idesty) iy = idesty; + if(dy < 0 && iy < idesty) iy = idesty; + else if(dy > 0 && iy > idesty) iy = idesty; - MoveDragCardTo(hdc, ix, iy); + MoveDragCardTo(hdc, ix, iy); - if(ix == idestx && iy == idesty) - break; + if(ix == idestx && iy == idesty) + break; - oldx = (int)x >> PRECISION; - oldy = (int)y >> PRECISION; + oldx = (int)x >> PRECISION; + oldy = (int)y >> PRECISION; - //dx *= 1.2; - //dy *= 1.2; + //dx *= 1.2; + //dy *= 1.2; - Sleep(10); - } + Sleep(10); + } } #else void CardRegion::ZoomCard(HDC hdc, int xpos, int ypos, CardRegion *pDestStack) { - TRACE ( "ENTER ZoomCard()\n" ); - double dx, dy, x ,y; - int apparentcards; - x = (double)xpos; y = (double)ypos; + TRACE ( "ENTER ZoomCard()\n" ); + double dx, dy, x ,y; + int apparentcards; + x = (double)xpos; y = (double)ypos; - oldx = (int)x; - oldy = (int)y; + oldx = (int)x; + oldy = (int)y; - apparentcards = pDestStack->cardstack.NumCards() / pDestStack->nThreedCount; + apparentcards = pDestStack->cardstack.NumCards() / pDestStack->nThreedCount; - int idestx = pDestStack->xpos + pDestStack->xoffset * (apparentcards); - int idesty = pDestStack->ypos + pDestStack->yoffset * (apparentcards); + int idestx = pDestStack->xpos + pDestStack->xoffset * (apparentcards); + int idesty = pDestStack->ypos + pDestStack->yoffset * (apparentcards); - if(pDestStack->yoffset < 0) - idesty += pDestStack->yoffset * (iNumDragCards-1); + if(pDestStack->yoffset < 0) + idesty += pDestStack->yoffset * (iNumDragCards-1); - if(pDestStack->xoffset < 0) - idestx += pDestStack->xoffset * (iNumDragCards-1); + if(pDestStack->xoffset < 0) + idestx += pDestStack->xoffset * (iNumDragCards-1); - //normalise the motion vector - dx = idestx - x; - dy = idesty - y; - if ( fabs(dx) + fabs(dy) < 0.001f ) - { - MoveDragCardTo(hdc, idestx, idesty); - return; - } - double recip = 1.0 / sqrt(dx*dx + dy*dy); - dx *= recip * __CARDZOOMSPEED; dy *= recip * __CARDZOOMSPEED; + //normalise the motion vector + dx = idestx - x; + dy = idesty - y; + if ( fabs(dx) + fabs(dy) < 0.001f ) + { + MoveDragCardTo(hdc, idestx, idesty); + return; + } + double recip = 1.0 / sqrt(dx*dx + dy*dy); + dx *= recip * __CARDZOOMSPEED; dy *= recip * __CARDZOOMSPEED; - //if(dx < 0) dxinc = 1.001; else + //if(dx < 0) dxinc = 1.001; else - for(;;) - { - bool attarget = true; - int ix, iy; - x += dx; - y += dy; + for(;;) + { + bool attarget = true; + int ix, iy; + x += dx; + y += dy; - ix = (int)x; - iy = (int)y; + ix = (int)x; + iy = (int)y; - if(dx < 0.0 && ix < idestx) ix = idestx; - else if(dx > 0.0 && ix > idestx) ix = idestx; - else attarget = false; + if(dx < 0.0 && ix < idestx) ix = idestx; + else if(dx > 0.0 && ix > idestx) ix = idestx; + else attarget = false; - if(dy < 0.0 && iy < idesty) iy = idesty; - else if(dy > 0.0 && iy > idesty) iy = idesty; - else attarget = false; + if(dy < 0.0 && iy < idesty) iy = idesty; + else if(dy > 0.0 && iy > idesty) iy = idesty; + else attarget = false; - //if the target stack wants the drag cards drawn differently - //to how they are, then redraw the drag card image just before - //the cards land - /*if(attarget == true) - { - for(int i = 0; i < iNumDragCards; i++) - { - int xdraw = pDestStack->xoffset*i; - int ydraw = pDestStack->yoffset*i; + //if the target stack wants the drag cards drawn differently + //to how they are, then redraw the drag card image just before + //the cards land + /*if(attarget == true) + { + for(int i = 0; i < iNumDragCards; i++) + { + int xdraw = pDestStack->xoffset*i; + int ydraw = pDestStack->yoffset*i; - if(pDestStack->yoffset < 0) - ydraw = -pDestStack->yoffset * (iNumDragCards-i-1); - if(pDestStack->xoffset < 0) - xdraw = -pDestStack->xoffset * (iNumDragCards-i-1); + if(pDestStack->yoffset < 0) + ydraw = -pDestStack->yoffset * (iNumDragCards-i-1); + if(pDestStack->xoffset < 0) + xdraw = -pDestStack->xoffset * (iNumDragCards-i-1); - if(pDestStack->facedirection == CS_FACEUP && - pDestStack->numcards+i >= dest->numfacedown) - { - //cdtDraw(hdcDragCard, xdraw, ydraw, iDragCards[i], ectFACES, 0); - } - else - { - //cdtDraw(hdcDragCard, xdraw, ydraw, CARDSTACK::backcard, ectBACKS, 0); - } - } - }*/ + if(pDestStack->facedirection == CS_FACEUP && + pDestStack->numcards+i >= dest->numfacedown) + { + //cdtDraw(hdcDragCard, xdraw, ydraw, iDragCards[i], ectFACES, 0); + } + else + { + //cdtDraw(hdcDragCard, xdraw, ydraw, CARDSTACK::backcard, ectBACKS, 0); + } + } + }*/ - MoveDragCardTo(hdc, ix, iy); + MoveDragCardTo(hdc, ix, iy); - if(attarget || ix == idestx && iy == idesty) - break; + if(attarget || ix == idestx && iy == idesty) + break; - oldx = (int)x; - oldy = (int)y; + oldx = (int)x; + oldy = (int)y; - //dx *= 1.2; - //dy *= 1.2; + //dx *= 1.2; + //dy *= 1.2; - Sleep(10); - } - TRACE ( "EXIT ZoomCard()\n" ); + Sleep(10); + } + TRACE ( "EXIT ZoomCard()\n" ); } #endif diff --git a/rosapps/games/solitaire/cardlib/cardstack.cpp b/rosapps/games/solitaire/cardlib/cardstack.cpp index 147c0962588..06b9f2583d4 100644 --- a/rosapps/games/solitaire/cardlib/cardstack.cpp +++ b/rosapps/games/solitaire/cardlib/cardstack.cpp @@ -1,8 +1,8 @@ // -// CardLib - CardStack class +// CardLib - CardStack class // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include #include @@ -11,227 +11,227 @@ Card &CardStack::operator[] (size_t index) { - if(index >= (size_t)nNumCards) index = nNumCards - 1; - return cardlist[nNumCards - index - 1]; + if(index >= (size_t)nNumCards) index = nNumCards - 1; + return cardlist[nNumCards - index - 1]; } const Card &CardStack::operator[] (size_t index) const { - if(index >= (size_t)nNumCards) index = nNumCards - 1; - return cardlist[nNumCards - index - 1]; + if(index >= (size_t)nNumCards) index = nNumCards - 1; + return cardlist[nNumCards - index - 1]; } -// Subscripting operator for a constant sequence +// Subscripting operator for a constant sequence // /*Card CardStack::operator[] (size_t index) const { - return cardlist[index]; + return cardlist[index]; }*/ // -// Subscripting operator for a non-const sequence +// Subscripting operator for a non-const sequence // /*CardStack::ref CardStack::operator[] (size_t index) { - return ref(this, index); + return ref(this, index); }*/ void CardStack::Clear() { - nNumCards = 0; + nNumCards = 0; } void CardStack::NewDeck() { - nNumCards = 52; + nNumCards = 52; - for(int i = 0; i < 52; i++) - cardlist[i].nValue = i; + for(int i = 0; i < 52; i++) + cardlist[i].nValue = i; } void CardStack::Shuffle() { - int src, dest; - Card temp; + int src, dest; + Card temp; - //shuffle 8 times.. - for(int i = 0; i < 8; i++) - for(dest = nNumCards - 1; dest > 0; dest--) - { - //want to do this: - // bad: src = rand() % (dest + 1) - // good: src = rand() / (RAND_MAX / (dest+1) + 1) - - //positions from 0 to dest - src = rand() / (RAND_MAX / (dest+1) + 1); - - //swap the cards - temp = cardlist[src]; - cardlist[src] = cardlist[dest]; - cardlist[dest] = temp; - } + //shuffle 8 times.. + for(int i = 0; i < 8; i++) + for(dest = nNumCards - 1; dest > 0; dest--) + { + //want to do this: + // bad: src = rand() % (dest + 1) + // good: src = rand() / (RAND_MAX / (dest+1) + 1) + + //positions from 0 to dest + src = rand() / (RAND_MAX / (dest+1) + 1); + + //swap the cards + temp = cardlist[src]; + cardlist[src] = cardlist[dest]; + cardlist[dest] = temp; + } } void CardStack::Reverse() { - for(int i = 0; i < nNumCards / 2; i++) - { - Card temp = cardlist[i]; - cardlist[i] = cardlist[nNumCards - i - 1]; - cardlist[nNumCards - i - 1] = temp; - } + for(int i = 0; i < nNumCards / 2; i++) + { + Card temp = cardlist[i]; + cardlist[i] = cardlist[nNumCards - i - 1]; + cardlist[nNumCards - i - 1] = temp; + } } void CardStack::Push(const Card card) { - if(nNumCards < MAX_CARDSTACK_SIZE) - cardlist[nNumCards++] = card; + if(nNumCards < MAX_CARDSTACK_SIZE) + cardlist[nNumCards++] = card; } void CardStack::Push(const CardStack &cardstack) { - if(nNumCards + cardstack.nNumCards < MAX_CARDSTACK_SIZE) - { - int num = cardstack.NumCards(); - - for(int i = 0; i < num; i++) - cardlist[nNumCards++] = cardstack.cardlist[i]; - } + if(nNumCards + cardstack.nNumCards < MAX_CARDSTACK_SIZE) + { + int num = cardstack.NumCards(); + + for(int i = 0; i < num; i++) + cardlist[nNumCards++] = cardstack.cardlist[i]; + } } CardStack& CardStack::operator += (Card card) { - Push(card); - return *this; + Push(card); + return *this; } CardStack& CardStack::operator += (CardStack &cs) { - Push(cs); - return *this; + Push(cs); + return *this; } CardStack CardStack::operator + (Card card) { - CardStack poo = *this; - poo.Push(card); - return poo; + CardStack poo = *this; + poo.Push(card); + return poo; } CardStack CardStack::operator + (CardStack &cs) { - CardStack poo = *this; - poo.Push(cs); - return poo; + CardStack poo = *this; + poo.Push(cs); + return poo; } Card CardStack::Pop() { - if(nNumCards > 0) - return cardlist[--nNumCards]; - else - return 0; + if(nNumCards > 0) + return cardlist[--nNumCards]; + else + return 0; } CardStack CardStack::Pop(int items) { - if(items <= nNumCards && nNumCards > 0) - { - CardStack cs(*this, nNumCards - items); + if(items <= nNumCards && nNumCards > 0) + { + CardStack cs(*this, nNumCards - items); - nNumCards -= items; + nNumCards -= items; - return cs; - } - else - { - return CardStack(); - } + return cs; + } + else + { + return CardStack(); + } } Card CardStack::Top() { - if(nNumCards > 0) - return cardlist[nNumCards - 1]; - else - return 0; + if(nNumCards > 0) + return cardlist[nNumCards - 1]; + else + return 0; } CardStack CardStack::Top(int items) { - if(items <= nNumCards && nNumCards > 0) - { - return CardStack (*this, nNumCards - items); - } - else - { - return CardStack(); - } + if(items <= nNumCards && nNumCards > 0) + { + return CardStack (*this, nNumCards - items); + } + else + { + return CardStack(); + } } Card CardStack::RemoveCard(size_t index) { - if(nNumCards == 0 || index >= (size_t)nNumCards) - return 0; + if(nNumCards == 0 || index >= (size_t)nNumCards) + return 0; - //put index into reverse range.. - index = nNumCards - index - 1; + //put index into reverse range.. + index = nNumCards - index - 1; - Card temp = cardlist[index]; + Card temp = cardlist[index]; - nNumCards--; + nNumCards--; - for(size_t i = index; i < (size_t)nNumCards; i++) - { - cardlist[i] = cardlist[i+1]; - } + for(size_t i = index; i < (size_t)nNumCards; i++) + { + cardlist[i] = cardlist[i+1]; + } - return temp; + return temp; } void CardStack::InsertCard(size_t index, Card card) { - if(nNumCards == MAX_CARDSTACK_SIZE) - return; + if(nNumCards == MAX_CARDSTACK_SIZE) + return; - if(index > (size_t)nNumCards) - return; + if(index > (size_t)nNumCards) + return; - if((size_t)nNumCards == index) - { - cardlist[nNumCards] = card; - nNumCards++; - return; - } + if((size_t)nNumCards == index) + { + cardlist[nNumCards] = card; + nNumCards++; + return; + } - //put index into reverse range.. - index = nNumCards - index - 1; + //put index into reverse range.. + index = nNumCards - index - 1; - nNumCards++; + nNumCards++; - //make room for the card - for(size_t i = nNumCards; i > index; i--) - { - cardlist[i] = cardlist[i - 1]; - } + //make room for the card + for(size_t i = nNumCards; i > index; i--) + { + cardlist[i] = cardlist[i - 1]; + } - cardlist[index] = card; + cardlist[index] = card; } void CardStack::Print() { -// for(int i = 0; i < nNumCards; i++) -// cout << cardlist[i].HiVal() << " "; +// for(int i = 0; i < nNumCards; i++) +// cout << cardlist[i].HiVal() << " "; } CardStack::CardStack(CardStack ©this, size_t fromindex) { - nNumCards = copythis.nNumCards - fromindex; + nNumCards = copythis.nNumCards - fromindex; - for(int i = 0; i < nNumCards; i++) - cardlist[i] = copythis.cardlist[fromindex + i]; + for(int i = 0; i < nNumCards; i++) + cardlist[i] = copythis.cardlist[fromindex + i]; } diff --git a/rosapps/games/solitaire/cardlib/cardwindow.cpp b/rosapps/games/solitaire/cardlib/cardwindow.cpp index 1f27c136c93..44550867509 100644 --- a/rosapps/games/solitaire/cardlib/cardwindow.cpp +++ b/rosapps/games/solitaire/cardlib/cardwindow.cpp @@ -1,8 +1,8 @@ // -// CardLib - CardWindow class +// CardLib - CardWindow class // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include #include @@ -18,26 +18,26 @@ extern HPALETTE __holdplacepal; HPALETTE UseNicePalette(HDC hdc, HPALETTE hPalette) { - HPALETTE hOld; + HPALETTE hOld; - hOld = SelectPalette(hdc, hPalette, FALSE); - RealizePalette(hdc); + hOld = SelectPalette(hdc, hPalette, FALSE); + RealizePalette(hdc); - return hOld; + return hOld; } void RestorePalette(HDC hdc, HPALETTE hOldPal) { - SelectPalette(hdc, hOldPal, TRUE); + SelectPalette(hdc, hOldPal, TRUE); } HPALETTE MakePaletteFromCols(COLORREF cols[], int nNumColours); -void PaintRect(HDC hdc, RECT *rect, COLORREF colour); +void PaintRect(HDC hdc, RECT *rect, COLORREF colour); HBITMAP CreateSinkBmp(HDC hdcCompat, HDC hdc, COLORREF col, int width, int height); void GetSinkCols(COLORREF crBase, COLORREF *fg, COLORREF *bg, COLORREF *sh1, COLORREF *sh2); -void LoadCardBitmaps(); -void FreeCardBitmaps(); +void LoadCardBitmaps(); +void FreeCardBitmaps(); static TCHAR szCardName[] = _T("CardWnd32"); static bool fRegistered = false; @@ -46,296 +46,296 @@ static LONG uCardBitmapRef = 0; void RegisterCardWindow() { - WNDCLASSEX wc; + WNDCLASSEX wc; - //Window class for the main application parent window - wc.cbSize = sizeof(wc); - wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; - wc.lpfnWndProc = CardWindow::CardWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = sizeof(CardWindow *); - wc.hInstance = GetModuleHandle(0); - wc.hIcon = 0; - wc.hCursor = LoadCursor (NULL, IDC_ARROW); - wc.hbrBackground = 0; - wc.lpszMenuName = 0; - wc.lpszClassName = szCardName; - wc.hIconSm = 0; + //Window class for the main application parent window + wc.cbSize = sizeof(wc); + wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; + wc.lpfnWndProc = CardWindow::CardWndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = sizeof(CardWindow *); + wc.hInstance = GetModuleHandle(0); + wc.hIcon = 0; + wc.hCursor = LoadCursor (NULL, IDC_ARROW); + wc.hbrBackground = 0; + wc.lpszMenuName = 0; + wc.lpszClassName = szCardName; + wc.hIconSm = 0; - RegisterClassEx(&wc); + RegisterClassEx(&wc); } CardWindow::CardWindow() : m_hWnd(0) { - HDC hdc = GetDC(0); + HDC hdc = GetDC(0); - nNumButtons = 0; - nNumCardRegions = 0; - nNumDropZones = 0; - nBackCardIdx = 53; + nNumButtons = 0; + nNumCardRegions = 0; + nNumDropZones = 0; + nBackCardIdx = 53; - ResizeWndCallback = 0; - hbmBackImage = 0; - hdcBackImage = 0; + ResizeWndCallback = 0; + hbmBackImage = 0; + hdcBackImage = 0; - srand((unsigned)GetTickCount()); + srand((unsigned)GetTickCount()); - //All colours (buttons, highlights, decks) - //are calculated off this single base colour - crBackgnd = PALETTERGB(0,80,0);//PALETTERGB(0,64,100); + //All colours (buttons, highlights, decks) + //are calculated off this single base colour + crBackgnd = PALETTERGB(0,80,0);//PALETTERGB(0,64,100); - // If uCardBitmapRef was previously zero, then - // load the card bitmaps - if(1 == InterlockedIncrement(&uCardBitmapRef)) - { - LoadCardBitmaps(); + // If uCardBitmapRef was previously zero, then + // load the card bitmaps + if(1 == InterlockedIncrement(&uCardBitmapRef)) + { + LoadCardBitmaps(); - __hPalette = CreateCardPalette(); + __hPalette = CreateCardPalette(); - __hdcPlaceHolder = CreateCompatibleDC(hdc); - - __holdplacepal = UseNicePalette(__hdcPlaceHolder, __hPalette); + __hdcPlaceHolder = CreateCompatibleDC(hdc); + + __holdplacepal = UseNicePalette(__hdcPlaceHolder, __hPalette); - __hbmPlaceHolder = CreateSinkBmp(hdc, __hdcPlaceHolder, crBackgnd, __cardwidth, __cardheight); + __hbmPlaceHolder = CreateSinkBmp(hdc, __hdcPlaceHolder, crBackgnd, __cardwidth, __cardheight); - } + } - ReleaseDC(0, hdc); + ReleaseDC(0, hdc); - //register the window class if necessary - if(!fRegistered) - { - fRegistered = true; - RegisterCardWindow(); - } + //register the window class if necessary + if(!fRegistered) + { + fRegistered = true; + RegisterCardWindow(); + } } BOOL CardWindow::Create(HWND hwndParent, DWORD dwExStyle, DWORD dwStyle, int x, int y, int width, int height) { - if(m_hWnd) - return FALSE; + if(m_hWnd) + return FALSE; - //Create the window associated with this object - m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, szCardName, 0, - WS_CHILD | WS_VISIBLE, - 0,0,100,100, - hwndParent, 0, GetModuleHandle(0), this); + //Create the window associated with this object + m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, szCardName, 0, + WS_CHILD | WS_VISIBLE, + 0,0,100,100, + hwndParent, 0, GetModuleHandle(0), this); - return TRUE; + return TRUE; } BOOL CardWindow::Destroy() { - DestroyWindow(m_hWnd); - m_hWnd = 0; + DestroyWindow(m_hWnd); + m_hWnd = 0; - return TRUE; + return TRUE; } CardWindow::~CardWindow() { - if(m_hWnd) - DestroyWindow(m_hWnd); + if(m_hWnd) + DestroyWindow(m_hWnd); - DeleteAll(); + DeleteAll(); - if(0 == InterlockedDecrement(&uCardBitmapRef)) - { - FreeCardBitmaps(); + if(0 == InterlockedDecrement(&uCardBitmapRef)) + { + FreeCardBitmaps(); - DeleteObject(__hbmPlaceHolder); - DeleteDC (__hdcPlaceHolder); + DeleteObject(__hbmPlaceHolder); + DeleteDC (__hdcPlaceHolder); - RestorePalette(__hdcPlaceHolder, __holdplacepal); + RestorePalette(__hdcPlaceHolder, __holdplacepal); - if(__hPalette) - DeleteObject(__hPalette); - } + if(__hPalette) + DeleteObject(__hPalette); + } } bool CardWindow::DeleteAll() { - int i; + int i; - for(i = 0; i < nNumCardRegions; i++) - { - delete Regions[i]; - } + for(i = 0; i < nNumCardRegions; i++) + { + delete Regions[i]; + } - for(i = 0; i < nNumButtons; i++) - { - delete Buttons[i]; - } + for(i = 0; i < nNumButtons; i++) + { + delete Buttons[i]; + } - for(i = 0; i < nNumDropZones; i++) - { - delete dropzone[i]; - } + for(i = 0; i < nNumDropZones; i++) + { + delete dropzone[i]; + } - nNumCardRegions = nNumButtons = nNumDropZones = 0; + nNumCardRegions = nNumButtons = nNumDropZones = 0; - return true; + return true; } void CardWindow::SetBackColor(COLORREF cr) { - crBackgnd = cr; - int i; - - // - // Create the exact palette we need to render the buttons/stacks - // - RestorePalette(__hdcPlaceHolder, __holdplacepal); + crBackgnd = cr; + int i; + + // + // Create the exact palette we need to render the buttons/stacks + // + RestorePalette(__hdcPlaceHolder, __holdplacepal); - if(__hPalette) - DeleteObject(__hPalette); + if(__hPalette) + DeleteObject(__hPalette); - __hPalette = CreateCardPalette(); + __hPalette = CreateCardPalette(); - // - // re-create the place-holder! - HDC hdc = GetDC(m_hWnd); + // + // re-create the place-holder! + HDC hdc = GetDC(m_hWnd); - DeleteObject(__hbmPlaceHolder); + DeleteObject(__hbmPlaceHolder); - __holdplacepal = UseNicePalette(__hdcPlaceHolder, __hPalette); + __holdplacepal = UseNicePalette(__hdcPlaceHolder, __hPalette); - __hbmPlaceHolder = CreateSinkBmp(hdc, __hdcPlaceHolder, crBackgnd, __cardwidth, __cardheight); - //SelectObject(__hdcPlaceHolder, __hbmPlaceHolder); + __hbmPlaceHolder = CreateSinkBmp(hdc, __hdcPlaceHolder, crBackgnd, __cardwidth, __cardheight); + //SelectObject(__hdcPlaceHolder, __hbmPlaceHolder); - //reset all buttons to same colour - for(i = 0; i < nNumButtons; i++) - { - if(Buttons[i]->GetStyle() & CB_PUSHBUTTON) - { - Buttons[i]->SetBackColor(ColorScaleRGB(crBackgnd, RGB(255,255,255), 0.1)); - } - else - { - Buttons[i]->SetBackColor(crBackgnd); - } - } + //reset all buttons to same colour + for(i = 0; i < nNumButtons; i++) + { + if(Buttons[i]->GetStyle() & CB_PUSHBUTTON) + { + Buttons[i]->SetBackColor(ColorScaleRGB(crBackgnd, RGB(255,255,255), 0.1)); + } + else + { + Buttons[i]->SetBackColor(crBackgnd); + } + } - for(i = 0; i < nNumCardRegions; i++) - { - Regions[i]->SetBackColor(crBackgnd); - } + for(i = 0; i < nNumCardRegions; i++) + { + Regions[i]->SetBackColor(crBackgnd); + } - ReleaseDC(m_hWnd, hdc); + ReleaseDC(m_hWnd, hdc); } COLORREF CardWindow::GetBackColor() { - return crBackgnd; + return crBackgnd; } CardButton* CardWindow::CardButtonFromPoint(int x, int y) { - CardButton *bptr = 0; + CardButton *bptr = 0; - POINT pt; - pt.x = x; - pt.y = y; + POINT pt; + pt.x = x; + pt.y = y; - //Search BACKWARDS...to reflect the implicit Z-order that - //the button creation provided - for(int i = nNumButtons - 1; i >= 0; i--) - { - bptr = Buttons[i]; - if(PtInRect(&bptr->rect, pt) && bptr->fVisible) - return bptr; - } + //Search BACKWARDS...to reflect the implicit Z-order that + //the button creation provided + for(int i = nNumButtons - 1; i >= 0; i--) + { + bptr = Buttons[i]; + if(PtInRect(&bptr->rect, pt) && bptr->fVisible) + return bptr; + } - return 0; + return 0; } CardRegion* CardWindow::CardRegionFromPoint(int x, int y) { - POINT pt; - pt.x = x; - pt.y = y; + POINT pt; + pt.x = x; + pt.y = y; - //Search BACKWARDS...to reflect the implicit Z-order that - //the stack creation provided - for(int i = nNumCardRegions - 1; i >= 0; i--) - { - if(Regions[i]->IsPointInStack(x, y)) - return Regions[i]; - } + //Search BACKWARDS...to reflect the implicit Z-order that + //the stack creation provided + for(int i = nNumCardRegions - 1; i >= 0; i--) + { + if(Regions[i]->IsPointInStack(x, y)) + return Regions[i]; + } - return 0; + return 0; } // -// Forward all window messages onto the appropriate +// Forward all window messages onto the appropriate // class instance // LRESULT CALLBACK CardWindow::CardWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { - CardWindow *cw = (CardWindow *)GetWindowLong(hwnd, 0); - return cw->WndProc(hwnd, iMsg, wParam, lParam); + CardWindow *cw = (CardWindow *)GetWindowLong(hwnd, 0); + return cw->WndProc(hwnd, iMsg, wParam, lParam); } void CardWindow::Paint(HDC hdc) { - int i; - RECT rect; - HPALETTE hOldPal; + int i; + RECT rect; + HPALETTE hOldPal; - hOldPal = UseNicePalette(hdc, __hPalette); + hOldPal = UseNicePalette(hdc, __hPalette); - // - // Clip the card stacks so that they won't - // get painted over - // - for(i = 0; i < nNumCardRegions; i++) - { - Regions[i]->Clip(hdc); - } + // + // Clip the card stacks so that they won't + // get painted over + // + for(i = 0; i < nNumCardRegions; i++) + { + Regions[i]->Clip(hdc); + } - // - // Clip the buttons - // - for(i = 0; i < nNumButtons; i++) - { - Buttons[i]->Clip(hdc); - } + // + // Clip the buttons + // + for(i = 0; i < nNumButtons; i++) + { + Buttons[i]->Clip(hdc); + } - // Now paint the whole screen with background colour, - // - GetClientRect(m_hWnd, &rect); - - //PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); - PaintCardRgn(hdc, 0, 0, rect.right, rect.bottom, 0, 0); - SelectClipRgn(hdc, NULL); + // Now paint the whole screen with background colour, + // + GetClientRect(m_hWnd, &rect); + + //PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); + PaintCardRgn(hdc, 0, 0, rect.right, rect.bottom, 0, 0); + SelectClipRgn(hdc, NULL); - // Don't let cards draw over buttons, so clip buttons again - // - for(i = 0; i < nNumButtons; i++) - { - Buttons[i]->Clip(hdc); - } + // Don't let cards draw over buttons, so clip buttons again + // + for(i = 0; i < nNumButtons; i++) + { + Buttons[i]->Clip(hdc); + } - // Paint each card stack in turn - // - for(i = 0; i < nNumCardRegions; i++) - { - Regions[i]->Render(hdc); - } - - // Paint each button now - // - SelectClipRgn(hdc, NULL); + // Paint each card stack in turn + // + for(i = 0; i < nNumCardRegions; i++) + { + Regions[i]->Render(hdc); + } + + // Paint each button now + // + SelectClipRgn(hdc, NULL); - for(i = 0; i < nNumButtons; i++) - { - Buttons[i]->Redraw(); - } + for(i = 0; i < nNumButtons; i++) + { + Buttons[i]->Redraw(); + } - RestorePalette(hdc, hOldPal); + RestorePalette(hdc, hOldPal); } @@ -343,469 +343,469 @@ void CardWindow::Paint(HDC hdc) LRESULT CALLBACK CardWindow::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { - HDC hdc; - PAINTSTRUCT ps; + HDC hdc; + PAINTSTRUCT ps; - CREATESTRUCT *cs; + CREATESTRUCT *cs; - static CardButton *buttonptr = 0; - static CardRegion *stackptr = 0; + static CardButton *buttonptr = 0; + static CardRegion *stackptr = 0; - int x, y, i; + int x, y, i; - switch(iMsg) - { - case WM_NCCREATE: + switch(iMsg) + { + case WM_NCCREATE: - // When we created this window, we passed in the - // pointer to the class object (CardWindow *) in the - // call to CreateWindow. - cs = (CREATESTRUCT *)lParam; + // When we created this window, we passed in the + // pointer to the class object (CardWindow *) in the + // call to CreateWindow. + cs = (CREATESTRUCT *)lParam; - // - // associate this class with the window - // - SetWindowLong(hwnd, 0, (LONG)cs->lpCreateParams); + // + // associate this class with the window + // + SetWindowLong(hwnd, 0, (LONG)cs->lpCreateParams); - return 1; + return 1; - case WM_NCDESTROY: - // Don't delete anything here.. - break; + case WM_NCDESTROY: + // Don't delete anything here.. + break; - case WM_SIZE: - nWidth = LOWORD(lParam); - nHeight = HIWORD(lParam); - - // - // reposition all the stacks and buttons - // in case any of them are centered, right-justified etc - // - for(i = 0; i < nNumCardRegions; i++) - { - Regions[i]->AdjustPosition(nWidth, nHeight); - } - - for(i = 0; i < nNumButtons; i++) - { - Buttons[i]->AdjustPosition(nWidth, nHeight); - } + case WM_SIZE: + nWidth = LOWORD(lParam); + nHeight = HIWORD(lParam); + + // + // reposition all the stacks and buttons + // in case any of them are centered, right-justified etc + // + for(i = 0; i < nNumCardRegions; i++) + { + Regions[i]->AdjustPosition(nWidth, nHeight); + } + + for(i = 0; i < nNumButtons; i++) + { + Buttons[i]->AdjustPosition(nWidth, nHeight); + } - // - // Call the user-defined resize proc AFTER all the stacks - // have been positioned - // - if(ResizeWndCallback) - ResizeWndCallback(nWidth, nHeight); + // + // Call the user-defined resize proc AFTER all the stacks + // have been positioned + // + if(ResizeWndCallback) + ResizeWndCallback(nWidth, nHeight); - return 0; + return 0; - case WM_PAINT: + case WM_PAINT: - hdc = BeginPaint(hwnd, &ps); + hdc = BeginPaint(hwnd, &ps); - Paint(hdc); + Paint(hdc); - EndPaint(hwnd, &ps); - return 0; + EndPaint(hwnd, &ps); + return 0; - case WM_TIMER: - - //find the timer object in the registered funcs - /*if(wParam >= 0x10000) - { - for(i = 0; i < nRegFuncs; i++) - { - if(RegFuncs[i].id == wParam) - { - KillTimer(hwnd, wParam); - - //call the registered function!! - RegFuncs[i].func(RegFuncs[i].dwParam); - - RegFuncs[i] = RegFuncs[nRegFuncs-1]; - nRegFuncs--; - } - } - } - else*/ - { - //find the cardstack - CardRegion *stackobj = (CardRegion *)wParam;//CardStackFromId(wParam); - stackobj->DoFlash(); - } + case WM_TIMER: + + //find the timer object in the registered funcs + /*if(wParam >= 0x10000) + { + for(i = 0; i < nRegFuncs; i++) + { + if(RegFuncs[i].id == wParam) + { + KillTimer(hwnd, wParam); + + //call the registered function!! + RegFuncs[i].func(RegFuncs[i].dwParam); + + RegFuncs[i] = RegFuncs[nRegFuncs-1]; + nRegFuncs--; + } + } + } + else*/ + { + //find the cardstack + CardRegion *stackobj = (CardRegion *)wParam;//CardStackFromId(wParam); + stackobj->DoFlash(); + } - return 0; + return 0; - case WM_LBUTTONDBLCLK: + case WM_LBUTTONDBLCLK: - x = (short)LOWORD(lParam); - y = (short)HIWORD(lParam); + x = (short)LOWORD(lParam); + y = (short)HIWORD(lParam); - if((buttonptr = CardButtonFromPoint(x, y)) != 0) - { - buttonptr->OnLButtonDown(hwnd, x, y); - return 0; - } + if((buttonptr = CardButtonFromPoint(x, y)) != 0) + { + buttonptr->OnLButtonDown(hwnd, x, y); + return 0; + } - if((stackptr = CardRegionFromPoint(x, y)) != 0) - { - stackptr->OnLButtonDblClk(x, y); - stackptr = 0; - } + if((stackptr = CardRegionFromPoint(x, y)) != 0) + { + stackptr->OnLButtonDblClk(x, y); + stackptr = 0; + } - return 0; + return 0; - case WM_LBUTTONDOWN: + case WM_LBUTTONDOWN: - x = (short)LOWORD(lParam); - y = (short)HIWORD(lParam); + x = (short)LOWORD(lParam); + y = (short)HIWORD(lParam); - //if clicked on a button - if((buttonptr = CardButtonFromPoint(x, y)) != 0) - { - if(buttonptr->OnLButtonDown(hwnd, x, y) == 0) - buttonptr = 0; + //if clicked on a button + if((buttonptr = CardButtonFromPoint(x, y)) != 0) + { + if(buttonptr->OnLButtonDown(hwnd, x, y) == 0) + buttonptr = 0; - return 0; - } + return 0; + } - if((stackptr = CardRegionFromPoint(x, y)) != 0) - { - if(!stackptr->OnLButtonDown(x, y)) - stackptr = 0; - } - - return 0; + if((stackptr = CardRegionFromPoint(x, y)) != 0) + { + if(!stackptr->OnLButtonDown(x, y)) + stackptr = 0; + } + + return 0; - case WM_LBUTTONUP: - - x = (short)LOWORD(lParam); - y = (short)HIWORD(lParam); + case WM_LBUTTONUP: + + x = (short)LOWORD(lParam); + y = (short)HIWORD(lParam); - // - // if we were clicking a button - // - if(buttonptr != 0) - { - buttonptr->OnLButtonUp(hwnd, x, y); - buttonptr = 0; - return 0; - } - - if(stackptr != 0) - { - stackptr->OnLButtonUp(x, y); - stackptr = 0; - return 0; - } + // + // if we were clicking a button + // + if(buttonptr != 0) + { + buttonptr->OnLButtonUp(hwnd, x, y); + buttonptr = 0; + return 0; + } + + if(stackptr != 0) + { + stackptr->OnLButtonUp(x, y); + stackptr = 0; + return 0; + } - return 0; + return 0; - case WM_MOUSEMOVE: - - x = (short)LOWORD(lParam); - y = (short)HIWORD(lParam); + case WM_MOUSEMOVE: + + x = (short)LOWORD(lParam); + y = (short)HIWORD(lParam); - // if we were clicking a button - if(buttonptr != 0) - { - buttonptr->OnMouseMove(hwnd, x, y); - return 0; - } + // if we were clicking a button + if(buttonptr != 0) + { + buttonptr->OnMouseMove(hwnd, x, y); + return 0; + } - if(stackptr != 0) - { - return stackptr->OnMouseMove(x, y); - } - - return 0; + if(stackptr != 0) + { + return stackptr->OnMouseMove(x, y); + } + + return 0; - } + } - return DefWindowProc (hwnd, iMsg, wParam, lParam); + return DefWindowProc (hwnd, iMsg, wParam, lParam); } CardRegion* CardWindow::CardRegionFromId(int id) { - for(int i = 0; i < nNumCardRegions; i++) - { - if(Regions[i]->id == id) - return Regions[i]; - } + for(int i = 0; i < nNumCardRegions; i++) + { + if(Regions[i]->id == id) + return Regions[i]; + } - return 0; + return 0; } CardButton* CardWindow::CardButtonFromId(int id) { - for(int i = 0; i < nNumButtons; i++) - { - if(Buttons[i]->id == id) - return Buttons[i]; - } + for(int i = 0; i < nNumButtons; i++) + { + if(Buttons[i]->id == id) + return Buttons[i]; + } - return 0; + return 0; } void CardWindow::Redraw() { - InvalidateRect(m_hWnd, 0, 0); - UpdateWindow(m_hWnd); + InvalidateRect(m_hWnd, 0, 0); + UpdateWindow(m_hWnd); } bool CardWindow::DeleteButton(CardButton *pButton) { - for(int i = 0; i < nNumButtons; i++) - { - if(Buttons[i] == pButton) - { - CardButton *cb = Buttons[i]; - - //shift any after this one backwards - for(int j = i; j < nNumButtons - 1; j++) - { - Buttons[j] = Buttons[j + 1]; - } + for(int i = 0; i < nNumButtons; i++) + { + if(Buttons[i] == pButton) + { + CardButton *cb = Buttons[i]; + + //shift any after this one backwards + for(int j = i; j < nNumButtons - 1; j++) + { + Buttons[j] = Buttons[j + 1]; + } - delete cb; - nNumButtons--; - - return true; - } - } + delete cb; + nNumButtons--; + + return true; + } + } - return false; + return false; } bool CardWindow::DeleteRegion(CardRegion *pRegion) { - for(int i = 0; i < nNumCardRegions; i++) - { - if(Regions[i] == pRegion) - { - CardRegion *cr = Regions[i]; - - //shift any after this one backwards - for(int j = i; j < nNumCardRegions - 1; j++) - { - Regions[j] = Regions[j + 1]; - } + for(int i = 0; i < nNumCardRegions; i++) + { + if(Regions[i] == pRegion) + { + CardRegion *cr = Regions[i]; + + //shift any after this one backwards + for(int j = i; j < nNumCardRegions - 1; j++) + { + Regions[j] = Regions[j + 1]; + } - delete cr; - nNumCardRegions--; + delete cr; + nNumCardRegions--; - return true; - } - } + return true; + } + } - return false; + return false; } void CardWindow::EmptyStacks(void) { - for(int i = 0; i < nNumCardRegions; i++) - { - Regions[i]->Clear(); - Regions[i]->Update(); - } + for(int i = 0; i < nNumCardRegions; i++) + { + Regions[i]->Clear(); + Regions[i]->Update(); + } - Redraw(); + Redraw(); } bool CardWindow::DistributeStacks(int nIdFrom, int nNumStacks, UINT xJustify, int xSpacing, int nStartX) { - int numvisiblestacks = 0; - int curx = nStartX; - int startindex = -1; - int i; + int numvisiblestacks = 0; + int curx = nStartX; + int startindex = -1; + int i; - //find the stack which starts with our ID - for(i = 0; i < nNumCardRegions; i++) - { - if(Regions[i]->Id() == nIdFrom) - { - startindex = i; - break; - } - } + //find the stack which starts with our ID + for(i = 0; i < nNumCardRegions; i++) + { + if(Regions[i]->Id() == nIdFrom) + { + startindex = i; + break; + } + } - //if didn't find, return - if(i == nNumCardRegions) return false; + //if didn't find, return + if(i == nNumCardRegions) return false; - //count the stacks that are visible - for(i = startindex; i < startindex + nNumStacks; i++) - { - if(Regions[i]->IsVisible()) - numvisiblestacks++; - } - - if(xJustify == CS_XJUST_CENTER) - { - //startx -= ((numvisiblestacks + spacing) * cardwidth - spacing) / 2; - int viswidth; - viswidth = numvisiblestacks * __cardwidth; - viswidth += xSpacing * (numvisiblestacks - 1); - curx = -(viswidth - __cardwidth) / 2; + //count the stacks that are visible + for(i = startindex; i < startindex + nNumStacks; i++) + { + if(Regions[i]->IsVisible()) + numvisiblestacks++; + } + + if(xJustify == CS_XJUST_CENTER) + { + //startx -= ((numvisiblestacks + spacing) * cardwidth - spacing) / 2; + int viswidth; + viswidth = numvisiblestacks * __cardwidth; + viswidth += xSpacing * (numvisiblestacks - 1); + curx = -(viswidth - __cardwidth) / 2; - for(i = startindex; i < startindex + nNumStacks; i++) - { - if(Regions[i]->IsVisible()) - { - Regions[i]->xadjust = curx; - Regions[i]->xjustify = CS_XJUST_CENTER; - curx += Regions[i]->width + xSpacing; - } - - } - } + for(i = startindex; i < startindex + nNumStacks; i++) + { + if(Regions[i]->IsVisible()) + { + Regions[i]->xadjust = curx; + Regions[i]->xjustify = CS_XJUST_CENTER; + curx += Regions[i]->width + xSpacing; + } + + } + } - if(xJustify == CS_XJUST_RIGHT) - { - nStartX -= ((numvisiblestacks + xSpacing) * __cardwidth - xSpacing); - } - - if(xJustify == CS_XJUST_NONE) - { - for(i = startindex; i < startindex + nNumStacks; i++) - { - if(Regions[i]->IsVisible()) - { - Regions[i]->xpos = curx; - curx += Regions[i]->width + xSpacing; - Regions[i]->UpdateSize(); - } - - } - } + if(xJustify == CS_XJUST_RIGHT) + { + nStartX -= ((numvisiblestacks + xSpacing) * __cardwidth - xSpacing); + } + + if(xJustify == CS_XJUST_NONE) + { + for(i = startindex; i < startindex + nNumStacks; i++) + { + if(Regions[i]->IsVisible()) + { + Regions[i]->xpos = curx; + curx += Regions[i]->width + xSpacing; + Regions[i]->UpdateSize(); + } + + } + } - return 0; + return 0; } void CardWindow::Update() { - for(int i = 0; i < nNumCardRegions; i++) - { - Regions[i]->AdjustPosition(nWidth, nHeight); - } + for(int i = 0; i < nNumCardRegions; i++) + { + Regions[i]->AdjustPosition(nWidth, nHeight); + } } void CardWindow::SetResizeProc(pResizeWndProc proc) { - ResizeWndCallback = proc; + ResizeWndCallback = proc; } HPALETTE CardWindow::CreateCardPalette() { - COLORREF cols[10]; - int nNumCols; + COLORREF cols[10]; + int nNumCols; - //include button text colours - cols[0] = RGB(0, 0, 0); - cols[1] = RGB(255, 255, 255); + //include button text colours + cols[0] = RGB(0, 0, 0); + cols[1] = RGB(255, 255, 255); - //include the base background colour - cols[1] = crBackgnd; + //include the base background colour + cols[1] = crBackgnd; - //include the standard button colours... - cols[3] = CardButton::GetHighlight(crBackgnd); - cols[4] = CardButton::GetShadow(crBackgnd); - cols[5] = CardButton::GetFace(crBackgnd); + //include the standard button colours... + cols[3] = CardButton::GetHighlight(crBackgnd); + cols[4] = CardButton::GetShadow(crBackgnd); + cols[5] = CardButton::GetFace(crBackgnd); - //include the sunken image bitmap colours... - GetSinkCols(crBackgnd, &cols[6], &cols[7], &cols[8], &cols[9]); + //include the sunken image bitmap colours... + GetSinkCols(crBackgnd, &cols[6], &cols[7], &cols[8], &cols[9]); - nNumCols = 10; + nNumCols = 10; - return MakePaletteFromCols(cols, nNumCols); + return MakePaletteFromCols(cols, nNumCols); } void CardWindow::SetBackCardIdx(UINT uBackIdx) { - if(uBackIdx >= 52 && uBackIdx <= 68) - nBackCardIdx = uBackIdx; + if(uBackIdx >= 52 && uBackIdx <= 68) + nBackCardIdx = uBackIdx; - for(int i = 0; i < nNumCardRegions; i++) - Regions[i]->SetBackCardIdx(uBackIdx); + for(int i = 0; i < nNumCardRegions; i++) + Regions[i]->SetBackCardIdx(uBackIdx); } void CardWindow::PaintCardRgn(HDC hdc, int dx, int dy, int width, int height, int sx, int sy) { - RECT rect; + RECT rect; - //if just a solid background colour - if(hbmBackImage == 0) - { - SetRect(&rect, dx, dy, dx+width, dy+height); - - /*if(GetVersion() < 0x80000000) - { - PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); - } - else*/ - { - HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBackgnd)); - FillRect(hdc, &rect, hbr); - DeleteObject(hbr); - } - } - //otherwise, paint using the bitmap - else - { - // Draw whatever part of background we can - BitBlt(hdc, dx, dy, width, height, hdcBackImage, sx, sy, SRCCOPY); + //if just a solid background colour + if(hbmBackImage == 0) + { + SetRect(&rect, dx, dy, dx+width, dy+height); + + /*if(GetVersion() < 0x80000000) + { + PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); + } + else*/ + { + HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBackgnd)); + FillRect(hdc, &rect, hbr); + DeleteObject(hbr); + } + } + //otherwise, paint using the bitmap + else + { + // Draw whatever part of background we can + BitBlt(hdc, dx, dy, width, height, hdcBackImage, sx, sy, SRCCOPY); - // Now we need to paint any area outside the bitmap, - // just in case the bitmap is too small to fill whole window - if(0)//sx + width > bm.bmWidth || sy + height > bm.bmHeight) - { - // Find out size of bitmap - BITMAP bm; - GetObject(hbmBackImage, sizeof(bm), &bm); + // Now we need to paint any area outside the bitmap, + // just in case the bitmap is too small to fill whole window + if(0)//sx + width > bm.bmWidth || sy + height > bm.bmHeight) + { + // Find out size of bitmap + BITMAP bm; + GetObject(hbmBackImage, sizeof(bm), &bm); - HRGN hr1 = CreateRectRgn(sx, sy, sx+width, sy+height); - HRGN hr2 = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight); - HRGN hr3 = CreateRectRgn(0,0, 1, 1); - HRGN hr4 = CreateRectRgn(0,0, 1, 1); - - CombineRgn(hr3, hr1, hr2, RGN_DIFF); - - GetClipRgn(hdc, hr4); - - CombineRgn(hr3, hr4, hr3, RGN_AND); - SelectClipRgn(hdc, hr3); - - // Fill remaining space not filled with bitmap - HBRUSH hbr = CreateSolidBrush(crBackgnd); - FillRgn(hdc, hr3, hbr); - DeleteObject(hbr); + HRGN hr1 = CreateRectRgn(sx, sy, sx+width, sy+height); + HRGN hr2 = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight); + HRGN hr3 = CreateRectRgn(0,0, 1, 1); + HRGN hr4 = CreateRectRgn(0,0, 1, 1); + + CombineRgn(hr3, hr1, hr2, RGN_DIFF); + + GetClipRgn(hdc, hr4); + + CombineRgn(hr3, hr4, hr3, RGN_AND); + SelectClipRgn(hdc, hr3); + + // Fill remaining space not filled with bitmap + HBRUSH hbr = CreateSolidBrush(crBackgnd); + FillRgn(hdc, hr3, hbr); + DeleteObject(hbr); - // Clean up - SelectClipRgn(hdc, hr4); - - DeleteObject(hr1); - DeleteObject(hr2); - DeleteObject(hr3); - DeleteObject(hr4); - } - } + // Clean up + SelectClipRgn(hdc, hr4); + + DeleteObject(hr1); + DeleteObject(hr2); + DeleteObject(hr3); + DeleteObject(hr4); + } + } } void CardWindow::SetBackImage(HBITMAP hBitmap) { - //delete current image?? NO! - if(hdcBackImage == 0) - { - hdcBackImage = CreateCompatibleDC(0); - } + //delete current image?? NO! + if(hdcBackImage == 0) + { + hdcBackImage = CreateCompatibleDC(0); + } - hbmBackImage = hBitmap; + hbmBackImage = hBitmap; - if(hBitmap) - SelectObject(hdcBackImage, hBitmap); + if(hBitmap) + SelectObject(hdcBackImage, hBitmap); } diff --git a/rosapps/games/solitaire/cardlib/dropzone.cpp b/rosapps/games/solitaire/cardlib/dropzone.cpp index dfa6dcc2636..63a4af5caab 100644 --- a/rosapps/games/solitaire/cardlib/dropzone.cpp +++ b/rosapps/games/solitaire/cardlib/dropzone.cpp @@ -1,8 +1,8 @@ // -// CardLib - DropZone class +// CardLib - DropZone class // -// Freeware -// Copyright J Brown 2001 +// Freeware +// Copyright J Brown 2001 // #include @@ -12,58 +12,58 @@ bool CardWindow::RegisterDropZone(int id, RECT *rect, pDropZoneProc proc) { - if(nNumDropZones == MAXDROPZONES) - return false; + if(nNumDropZones == MAXDROPZONES) + return false; - DropZone *dz = new DropZone(id, rect, proc); - - dropzone[nNumDropZones++] = dz; + DropZone *dz = new DropZone(id, rect, proc); + + dropzone[nNumDropZones++] = dz; - return false; + return false; } DropZone *CardWindow::GetDropZoneFromRect(RECT *rect) { - for(int i = 0; i < nNumDropZones; i++) - { - RECT inter; - RECT zone; - - //if any part of the drag rectangle falls within a drop zone, - //let that take priority over any other card stack. - dropzone[i]->GetZone(&zone); + for(int i = 0; i < nNumDropZones; i++) + { + RECT inter; + RECT zone; + + //if any part of the drag rectangle falls within a drop zone, + //let that take priority over any other card stack. + dropzone[i]->GetZone(&zone); - if(IntersectRect(&inter, rect, &zone)) - { - //see if the callback wants us to drop a card on - //a particular stack - return dropzone[i]; - } - } + if(IntersectRect(&inter, rect, &zone)) + { + //see if the callback wants us to drop a card on + //a particular stack + return dropzone[i]; + } + } - return 0; + return 0; } bool CardWindow::DeleteDropZone(int id) { - for(int i = 0; i < nNumDropZones; i++) - { - if(dropzone[i]->id == id) - { - DropZone *dz = dropzone[i]; - - //shift any after this one backwards - for(int j = i; j < nNumDropZones - 1; j++) - { - dropzone[j] = dropzone[j + 1]; - } + for(int i = 0; i < nNumDropZones; i++) + { + if(dropzone[i]->id == id) + { + DropZone *dz = dropzone[i]; + + //shift any after this one backwards + for(int j = i; j < nNumDropZones - 1; j++) + { + dropzone[j] = dropzone[j + 1]; + } - delete dz; - nNumDropZones--; - return true; - } - } + delete dz; + nNumDropZones--; + return true; + } + } - return false; + return false; } diff --git a/rosapps/games/solitaire/solcreate.cpp b/rosapps/games/solitaire/solcreate.cpp index 9f2facbc87e..0efb23a9520 100644 --- a/rosapps/games/solitaire/solcreate.cpp +++ b/rosapps/games/solitaire/solcreate.cpp @@ -18,70 +18,67 @@ CardRegion *pRowStack[NUM_ROW_STACKS]; extern CardStack activepile; HBITMAP hbmBitmap; -HDC hdcBitmap; +HDC hdcBitmap; void CreateSol() { - int i; + int i; -// hbmBitmap = (HBITMAP)LoadImage(0,"test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE); -// SolWnd.SetBackImage(hbmBitmap); +// hbmBitmap = (HBITMAP)LoadImage(0,"test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE); +// SolWnd.SetBackImage(hbmBitmap); - activepile.Clear(); + activepile.Clear(); - pDeck = SolWnd.CreateRegion(DECK_ID, true, xBorder, yBorder, 2, 1); - pDeck->SetEmptyImage(CS_EI_SUNK); - pDeck->SetThreedCount(6); - pDeck->SetDragRule(CS_DRAG_NONE, 0); - pDeck->SetDropRule(CS_DROP_NONE, 0); - pDeck->SetClickProc(DeckClickProc); - pDeck->SetDblClickProc(DeckClickProc); - pDeck->SetFaceDirection(CS_FACE_DOWN, 0); + pDeck = SolWnd.CreateRegion(DECK_ID, true, xBorder, yBorder, 2, 1); + pDeck->SetEmptyImage(CS_EI_SUNK); + pDeck->SetThreedCount(6); + pDeck->SetDragRule(CS_DRAG_NONE, 0); + pDeck->SetDropRule(CS_DROP_NONE, 0); + pDeck->SetClickProc(DeckClickProc); + pDeck->SetDblClickProc(DeckClickProc); + pDeck->SetFaceDirection(CS_FACE_DOWN, 0); - pPile = SolWnd.CreateRegion(PILE_ID, true, 110, yBorder, CS_DEFXOFF, 1); - pPile->SetEmptyImage(CS_EI_NONE); - pPile->SetDragRule(CS_DRAG_TOP, 0); - pPile->SetDropRule(CS_DROP_NONE, 0); - pPile->SetDblClickProc(PileDblClickProc); - pPile->SetRemoveCardProc(PileRemoveProc); + pPile = SolWnd.CreateRegion(PILE_ID, true, 110, yBorder, CS_DEFXOFF, 1); + pPile->SetEmptyImage(CS_EI_NONE); + pPile->SetDragRule(CS_DRAG_TOP, 0); + pPile->SetDropRule(CS_DROP_NONE, 0); + pPile->SetDblClickProc(PileDblClickProc); + pPile->SetRemoveCardProc(PileRemoveProc); - // - // Create the suit stacks - // - for(i = 0; i < 4; i++) - { - pSuitStack[i] = SolWnd.CreateRegion(SUIT_ID+i, true, 0, yBorder, 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); + // + // Create the suit stacks + // + for(i = 0; i < 4; i++) + { + pSuitStack[i] = SolWnd.CreateRegion(SUIT_ID+i, true, 0, yBorder, 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]->SetDropRule(CS_DROP_CALLBACK, SuitStackDropProc); - pSuitStack[i]->SetDragRule(CS_DRAG_TOP); + pSuitStack[i]->SetDropRule(CS_DROP_CALLBACK, SuitStackDropProc); + pSuitStack[i]->SetDragRule(CS_DRAG_TOP); - pSuitStack[i]->SetAddCardProc(SuitStackAddProc); - } - - // - // Create the row stacks - // - for(i = 0; i < NUM_ROW_STACKS; i++) - { - pRowStack[i] = SolWnd.CreateRegion(ROW_ID+i, true, 0, yRowStacks, 0, 14); - 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); - - pRowStack[i]->SetEmptyImage(CS_EI_NONE); - - pRowStack[i]->SetDragRule(CS_DRAG_CALLBACK, RowStackDragProc); - pRowStack[i]->SetDropRule(CS_DROP_CALLBACK, RowStackDropProc); - pRowStack[i]->SetClickProc(RowStackClickProc); - pRowStack[i]->SetDblClickProc(RowStackDblClickProc); - } + pSuitStack[i]->SetAddCardProc(SuitStackAddProc); + } + // + // Create the row stacks + // + for(i = 0; i < NUM_ROW_STACKS; i++) + { + pRowStack[i] = SolWnd.CreateRegion(ROW_ID+i, true, 0, yRowStacks, 0, 14); + 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); + pRowStack[i]->SetEmptyImage(CS_EI_NONE); + pRowStack[i]->SetDragRule(CS_DRAG_CALLBACK, RowStackDragProc); + pRowStack[i]->SetDropRule(CS_DROP_CALLBACK, RowStackDropProc); + pRowStack[i]->SetClickProc(RowStackClickProc); + pRowStack[i]->SetDblClickProc(RowStackDblClickProc); + } } diff --git a/rosapps/games/solitaire/solgame.cpp b/rosapps/games/solitaire/solgame.cpp index 7a12e09943b..35bb9653ab9 100644 --- a/rosapps/games/solitaire/solgame.cpp +++ b/rosapps/games/solitaire/solgame.cpp @@ -18,343 +18,343 @@ bool fGameStarted = false; void NewGame(void) { - TRACE("ENTER NewGame()\n"); - int i, j; + TRACE("ENTER NewGame()\n"); + int i, j; - SolWnd.EmptyStacks(); - - //create a new card-stack - CardStack deck; - deck.NewDeck(); - deck.Shuffle(); - activepile.Clear(); + SolWnd.EmptyStacks(); + + //create a new card-stack + CardStack deck; + deck.NewDeck(); + deck.Shuffle(); + activepile.Clear(); - //deal to each row stack.. - for(i = 0; i < NUM_ROW_STACKS; i++) - { - CardStack temp; - temp.Clear(); + //deal to each row stack.. + for(i = 0; i < NUM_ROW_STACKS; i++) + { + CardStack temp; + temp.Clear(); - pRowStack[i]->SetFaceDirection(CS_FACE_DOWNUP, i); + pRowStack[i]->SetFaceDirection(CS_FACE_DOWNUP, i); - for(j = 0; j <= i; j++) - { - temp.Push(deck.Pop()); - } + for(j = 0; j <= i; j++) + { + temp.Push(deck.Pop()); + } - pRowStack[i]->SetCardStack(temp); - } + pRowStack[i]->SetCardStack(temp); + } - //put the other cards onto the deck - pDeck->SetCardStack(deck); - pDeck->Update(); - - SolWnd.Redraw(); + //put the other cards onto the deck + pDeck->SetCardStack(deck); + pDeck->Update(); + + SolWnd.Redraw(); - fGameStarted = false; - TRACE("EXIT NewGame()\n"); + fGameStarted = false; + TRACE("EXIT NewGame()\n"); } // -// Now follow the stack callback functions. This is where we +// Now follow the stack callback functions. This is where we // provide the game functionality and rules // // -// Can only drag face-up cards +// Can only drag face-up cards // bool CARDLIBPROC RowStackDragProc(CardRegion &stackobj, int iNumDragCards) { - TRACE("ENTER RowStackDragProc()\n"); - int numfacedown; - int numcards; + TRACE("ENTER RowStackDragProc()\n"); + int numfacedown; + int numcards; - stackobj.GetFaceDirection(&numfacedown); + stackobj.GetFaceDirection(&numfacedown); - numcards = stackobj.NumCards(); + numcards = stackobj.NumCards(); - TRACE("EXIT RowStackDragProc()\n"); - if(iNumDragCards <= numcards-numfacedown) - return true; - else - return false; + TRACE("EXIT RowStackDragProc()\n"); + if(iNumDragCards <= numcards-numfacedown) + return true; + else + return false; } // -// Row a row-stack, we can only drop cards -// that are lower / different colour +// Row a row-stack, we can only drop cards +// that are lower / different colour // bool CARDLIBPROC RowStackDropProc(CardRegion &stackobj, const CardStack &dragcards) { - TRACE("ENTER RowStackDropProc()\n"); - Card dragcard = dragcards[dragcards.NumCards() - 1]; + TRACE("ENTER RowStackDropProc()\n"); + Card dragcard = dragcards[dragcards.NumCards() - 1]; - //if we are empty, can only drop a stack with a King at bottom - if(stackobj.NumCards() == 0) - { - if(dragcard.LoVal() != 13) - { - TRACE("EXIT RowStackDropProc(false)\n"); - return false; - } - } - else - { - const CardStack &mystack = stackobj.GetCardStack(); - - //can only drop if card is 1 less - if(mystack[0].LoVal() != dragcard.LoVal() + 1) - { - TRACE("EXIT RowStackDropProc(false)\n"); - return false; - } + //if we are empty, can only drop a stack with a King at bottom + if(stackobj.NumCards() == 0) + { + if(dragcard.LoVal() != 13) + { + TRACE("EXIT RowStackDropProc(false)\n"); + return false; + } + } + else + { + const CardStack &mystack = stackobj.GetCardStack(); + + //can only drop if card is 1 less + if(mystack[0].LoVal() != dragcard.LoVal() + 1) + { + TRACE("EXIT RowStackDropProc(false)\n"); + return false; + } - //can only drop if card is different colour - if( mystack[0].IsBlack() && !dragcard.IsRed() || - !mystack[0].IsBlack() && dragcard.IsRed() ) - { - TRACE("EXIT RowStackDropProc(false)\n"); - return false; - } - } + //can only drop if card is different colour + if( mystack[0].IsBlack() && !dragcard.IsRed() || + !mystack[0].IsBlack() && dragcard.IsRed() ) + { + TRACE("EXIT RowStackDropProc(false)\n"); + return false; + } + } - TRACE("EXIT RowStackDropProc(true)\n"); - return true; + TRACE("EXIT RowStackDropProc(true)\n"); + return true; } // -// Can only drop a card onto a suit-stack if the +// Can only drop a card onto a suit-stack if the // card is 1 higher, and is the same suit // bool CanDrop(CardRegion &stackobj, Card card) { - TRACE("ENTER CanDrop()\n"); - int topval; + TRACE("ENTER CanDrop()\n"); + int topval; - const CardStack &cardstack = stackobj.GetCardStack(); + const CardStack &cardstack = stackobj.GetCardStack(); - if(cardstack.NumCards() > 0) - { - if(card.Suit() != cardstack[0].Suit()) - { - TRACE("EXIT CanDrop()\n"); - return false; - } + if(cardstack.NumCards() > 0) + { + if(card.Suit() != cardstack[0].Suit()) + { + TRACE("EXIT CanDrop()\n"); + return false; + } - topval = cardstack[0].LoVal(); - } - else - { - topval = 0; - } + topval = cardstack[0].LoVal(); + } + else + { + topval = 0; + } - //make sure 1 higher - if(card.LoVal() != (topval + 1)) - { - TRACE("EXIT CanDrop()\n"); - return false; - } + //make sure 1 higher + if(card.LoVal() != (topval + 1)) + { + TRACE("EXIT CanDrop()\n"); + return false; + } - TRACE("EXIT CanDrop()\n"); - return true; + TRACE("EXIT CanDrop()\n"); + return true; } // -// Can only drop a card onto suit stack if it is same suit, and 1 higher +// Can only drop a card onto suit stack if it is same suit, and 1 higher // bool CARDLIBPROC SuitStackDropProc(CardRegion &stackobj, const CardStack &dragcards) { - TRACE("ENTER SuitStackDropProc()\n"); - //only drop 1 card at a time - if(dragcards.NumCards() != 1) - { - TRACE("EXIT SuitStackDropProc()\n"); - return false; - } + TRACE("ENTER SuitStackDropProc()\n"); + //only drop 1 card at a time + if(dragcards.NumCards() != 1) + { + TRACE("EXIT SuitStackDropProc()\n"); + return false; + } - bool b = CanDrop(stackobj, dragcards[0]); - TRACE("EXIT SuitStackDropProc()\n"); - return b; + bool b = CanDrop(stackobj, dragcards[0]); + TRACE("EXIT SuitStackDropProc()\n"); + return b; } // -// Single-click on one of the row-stacks -// Turn the top-card over if they are all face-down +// Single-click on one of the row-stacks +// Turn the top-card over if they are all face-down // void CARDLIBPROC RowStackClickProc(CardRegion &stackobj, int iNumClicked) { - TRACE("ENTER RowStackClickProc()\n"); - int numfacedown; - - stackobj.GetFaceDirection(&numfacedown); + TRACE("ENTER RowStackClickProc()\n"); + int numfacedown; + + stackobj.GetFaceDirection(&numfacedown); - //if all face-down, then make top card face-up - if(stackobj.NumCards() == numfacedown) - { - if(numfacedown > 0) numfacedown--; - stackobj.SetFaceDirection(CS_FACE_DOWNUP, numfacedown); - stackobj.Redraw(); - } - TRACE("EXIT RowStackClickProc()\n"); + //if all face-down, then make top card face-up + if(stackobj.NumCards() == numfacedown) + { + if(numfacedown > 0) numfacedown--; + stackobj.SetFaceDirection(CS_FACE_DOWNUP, numfacedown); + stackobj.Redraw(); + } + TRACE("EXIT RowStackClickProc()\n"); } // -// Find the suit-stack that can accept the specified card +// Find the suit-stack that can accept the specified card // CardRegion *FindSuitStackFromCard(Card card) { - TRACE("ENTER FindSuitStackFromCard()\n"); - for(int i = 0; i < 4; i++) - { - if(CanDrop(*pSuitStack[i], card)) - { - TRACE("EXIT FindSuitStackFromCard()\n"); - return pSuitStack[i]; - } - } + TRACE("ENTER FindSuitStackFromCard()\n"); + for(int i = 0; i < 4; i++) + { + if(CanDrop(*pSuitStack[i], card)) + { + TRACE("EXIT FindSuitStackFromCard()\n"); + return pSuitStack[i]; + } + } - TRACE("EXIT FindSuitStackFromCard()\n"); - return 0; + TRACE("EXIT FindSuitStackFromCard()\n"); + return 0; } // -// What happens when we add a card to one of the suit stacks? +// What happens when we add a card to one of the suit stacks? // Well, nothing (it is already added), but we need to // check all four stacks (not just this one) to see if // the game has finished. // void CARDLIBPROC SuitStackAddProc(CardRegion &stackobj, const CardStack &added) { - TRACE("ENTER SuitStackAddProc()\n"); - bool fGameOver = true; + TRACE("ENTER SuitStackAddProc()\n"); + bool fGameOver = true; - for(int i = 0; i < 4; i++) - { - if(pSuitStack[i]->NumCards() != 13) - { - fGameOver = false; - break; - } - } + for(int i = 0; i < 4; i++) + { + if(pSuitStack[i]->NumCards() != 13) + { + fGameOver = false; + break; + } + } - if(fGameOver) - { - MessageBox(SolWnd, _T("Congratulations, you win!!"), szAppName, MB_OK | MB_ICONINFORMATION); - - for(int i = 0; i < 4; i++) - { - pSuitStack[i]->Flash(11, 100); - } - } - TRACE("EXIT SuitStackAddProc()\n"); + if(fGameOver) + { + MessageBox(SolWnd, _T("Congratulations, you win!!"), szAppName, MB_OK | MB_ICONINFORMATION); + + for(int i = 0; i < 4; i++) + { + pSuitStack[i]->Flash(11, 100); + } + } + TRACE("EXIT SuitStackAddProc()\n"); } // -// Double-click on one of the row stacks -// The aim is to find a suit-stack to move the +// Double-click on one of the row stacks +// The aim is to find a suit-stack to move the // double-clicked card to. // void CARDLIBPROC RowStackDblClickProc(CardRegion &stackobj, int iNumClicked) { - TRACE("ENTER RowStackDblClickProc()\n"); - //can only move 1 card at a time - if(iNumClicked != 1) - { - TRACE("EXIT RowStackDblClickProc()\n"); - return; - } + TRACE("ENTER RowStackDblClickProc()\n"); + //can only move 1 card at a time + if(iNumClicked != 1) + { + TRACE("EXIT RowStackDblClickProc()\n"); + return; + } - //find a suit-stack to move the card to... - const CardStack &cardstack = stackobj.GetCardStack(); - CardRegion *pDest = FindSuitStackFromCard(cardstack[0]); - - if(pDest != 0) - { - //stackobj.MoveCards(pDest, 1, true); - //use the SimulateDrag funcion, because we get the - //AddProc callbacks called for us on the destination stacks... - stackobj.SimulateDrag(pDest, 1, true); - } - TRACE("EXIT RowStackDblClickProc()\n"); + //find a suit-stack to move the card to... + const CardStack &cardstack = stackobj.GetCardStack(); + CardRegion *pDest = FindSuitStackFromCard(cardstack[0]); + + if(pDest != 0) + { + //stackobj.MoveCards(pDest, 1, true); + //use the SimulateDrag funcion, because we get the + //AddProc callbacks called for us on the destination stacks... + stackobj.SimulateDrag(pDest, 1, true); + } + TRACE("EXIT RowStackDblClickProc()\n"); } // -// Face-up pile double-click +// Face-up pile double-click // void CARDLIBPROC PileDblClickProc(CardRegion &stackobj, int iNumClicked) { - TRACE("ENTER PileDblClickProc()\n"); - RowStackDblClickProc(stackobj, iNumClicked); - TRACE("EXIT PileDblClickProc()\n"); + TRACE("ENTER PileDblClickProc()\n"); + RowStackDblClickProc(stackobj, iNumClicked); + TRACE("EXIT PileDblClickProc()\n"); } // -// What happens when a card is removed from face-up pile? +// What happens when a card is removed from face-up pile? // void CARDLIBPROC PileRemoveProc(CardRegion &stackobj, int iItems) { - TRACE("ENTER PileRemoveProc()\n"); - //modify our "virtual" pile by removing the same card - //that was removed from the physical card stack - activepile.Pop(iItems); + TRACE("ENTER PileRemoveProc()\n"); + //modify our "virtual" pile by removing the same card + //that was removed from the physical card stack + activepile.Pop(iItems); - //if there is just 1 card left, then modify the - //stack to contain ALL the face-up cards..the effect - //will be, the next time a card is dragged, all the - //previous card-triplets will be available underneath - if(stackobj.NumCards() == 1) - { - stackobj.SetOffsets(0,0); - stackobj.SetCardStack(activepile); - } - TRACE("EXIT PileRemoveProc()\n"); + //if there is just 1 card left, then modify the + //stack to contain ALL the face-up cards..the effect + //will be, the next time a card is dragged, all the + //previous card-triplets will be available underneath + if(stackobj.NumCards() == 1) + { + stackobj.SetOffsets(0,0); + stackobj.SetCardStack(activepile); + } + TRACE("EXIT PileRemoveProc()\n"); } // -// Double-click on the deck -// Move 3 cards to the face-up pile +// Double-click on the deck +// Move 3 cards to the face-up pile // void CARDLIBPROC DeckClickProc(CardRegion &stackobj, int iNumClicked) { - TRACE("ENTER DeckClickProc()\n"); - CardStack cardstack = stackobj.GetCardStack(); - CardStack pile = pPile->GetCardStack(); + TRACE("ENTER DeckClickProc()\n"); + CardStack cardstack = stackobj.GetCardStack(); + CardStack pile = pPile->GetCardStack(); - fGameStarted = true; + fGameStarted = true; - //reset the face-up pile to represent 3 cards - pPile->SetOffsets(CS_DEFXOFF, 1); + //reset the face-up pile to represent 3 cards + pPile->SetOffsets(CS_DEFXOFF, 1); - if(cardstack.NumCards() == 0) - { - pile.Clear(); + if(cardstack.NumCards() == 0) + { + pile.Clear(); - activepile.Reverse(); - cardstack.Push(activepile); - activepile.Clear(); - } - else - { - int numcards = min(3, cardstack.NumCards()); - - //make a "visible" copy of these cards - CardStack temp; - temp = cardstack.Pop(numcards); - temp.Reverse(); + activepile.Reverse(); + cardstack.Push(activepile); + activepile.Clear(); + } + else + { + int numcards = min(3, cardstack.NumCards()); + + //make a "visible" copy of these cards + CardStack temp; + temp = cardstack.Pop(numcards); + temp.Reverse(); - pile.Clear(); - pile.Push(temp); + pile.Clear(); + pile.Push(temp); - //remove the top 3 from deck - activepile.Push(temp); - } + //remove the top 3 from deck + activepile.Push(temp); + } - activepile.Print(); + activepile.Print(); - pDeck->SetCardStack(cardstack); - pPile->SetCardStack(pile); + pDeck->SetCardStack(cardstack); + pPile->SetCardStack(pile); - SolWnd.Redraw(); - TRACE("EXIT DeckClickProc()\n"); + SolWnd.Redraw(); + TRACE("EXIT DeckClickProc()\n"); } diff --git a/rosapps/games/solitaire/solitaire.cpp b/rosapps/games/solitaire/solitaire.cpp index e7e12a7ac95..dc2faf80fcb 100644 --- a/rosapps/games/solitaire/solitaire.cpp +++ b/rosapps/games/solitaire/solitaire.cpp @@ -8,10 +8,10 @@ TCHAR szHelpPath[MAX_PATH]; -DWORD dwAppStartTime; -HWND hwndMain; -HWND hwndStatus; -HINSTANCE hInstance; +DWORD dwAppStartTime; +HWND hwndMain; +HWND hwndStatus; +HINSTANCE hInstance; TCHAR szAppName[] = _T("Solitaire"); @@ -21,202 +21,202 @@ LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); void MakePath(TCHAR *szDest, UINT nDestLen, TCHAR *szExt) { - TCHAR *ptr; - - ptr = szDest + GetModuleFileName(GetModuleHandle(0), szDest, nDestLen) - 1; - while(*ptr-- != '.'); - lstrcpy(ptr + 1, szExt); + TCHAR *ptr; + + ptr = szDest + GetModuleFileName(GetModuleHandle(0), szDest, nDestLen) - 1; + while(*ptr-- != '.'); + lstrcpy(ptr + 1, szExt); } int main ( int argc, char** argv ) { - return WinMain ( NULL, NULL, NULL, SW_SHOW ); + return WinMain ( NULL, NULL, NULL, SW_SHOW ); } // -// Main entry point +// Main entry point // int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, PSTR szCmdLine, int iCmdShow) { - HWND hwnd; - MSG msg; - WNDCLASSEX wndclass; - INITCOMMONCONTROLSEX ice; - HACCEL hAccelTable; + HWND hwnd; + MSG msg; + WNDCLASSEX wndclass; + INITCOMMONCONTROLSEX ice; + HACCEL hAccelTable; - hInstance = hInst; + hInstance = hInst; - //Window class for the main application parent window - wndclass.cbSize = sizeof(wndclass); - wndclass.style = 0;//CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = hInst; - wndclass.hIcon = LoadIcon (hInst, MAKEINTRESOURCE(IDI_ICON1)); - wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); - wndclass.hbrBackground = (HBRUSH)NULL; - wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); - wndclass.lpszClassName = szAppName; - wndclass.hIconSm = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0); + //Window class for the main application parent window + wndclass.cbSize = sizeof(wndclass); + wndclass.style = 0;//CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = WndProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInst; + wndclass.hIcon = LoadIcon (hInst, MAKEINTRESOURCE(IDI_ICON1)); + wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); + wndclass.hbrBackground = (HBRUSH)NULL; + wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); + wndclass.lpszClassName = szAppName; + wndclass.hIconSm = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0); - RegisterClassEx(&wndclass); + RegisterClassEx(&wndclass); - ice.dwSize = sizeof(ice); - ice.dwICC = ICC_BAR_CLASSES; - InitCommonControlsEx(&ice); + ice.dwSize = sizeof(ice); + ice.dwICC = ICC_BAR_CLASSES; + InitCommonControlsEx(&ice); - srand((unsigned)GetTickCount());//timeGetTime()); + srand((unsigned)GetTickCount());//timeGetTime()); -// InitCardLib(); +// InitCardLib(); -// LoadSettings(); +// LoadSettings(); - //Construct the path to our help file - MakePath(szHelpPath, MAX_PATH, _T(".hlp")); - - hwnd = CreateWindow(szAppName, // window class name - szAppName, // window caption - WS_OVERLAPPEDWINDOW - ,//|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 - hInst, // program instance handle - NULL); // creation parameters + //Construct the path to our help file + MakePath(szHelpPath, MAX_PATH, _T(".hlp")); + + hwnd = CreateWindow(szAppName, // window class name + szAppName, // window caption + WS_OVERLAPPEDWINDOW + ,//|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 + hInst, // program instance handle + NULL); // creation parameters - hwndMain = hwnd; + hwndMain = hwnd; - ShowWindow(hwnd, iCmdShow); - UpdateWindow(hwnd); + ShowWindow(hwnd, iCmdShow); + UpdateWindow(hwnd); - hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1)); + hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1)); - while(GetMessage(&msg, NULL,0,0)) - { - if(!TranslateAccelerator(hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } + while(GetMessage(&msg, NULL,0,0)) + { + if(!TranslateAccelerator(hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } -// SaveSettings(); +// SaveSettings(); - return msg.wParam; + return msg.wParam; } //----------------------------------------------------------------------------- LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { - static int nWidth, nHeight; - int nStatusHeight = 0;//20; - int parts[] = { 100, -1 }; - UINT ret; + static int nWidth, nHeight; + int nStatusHeight = 0;//20; + int parts[] = { 100, -1 }; + UINT ret; - MINMAXINFO *mmi; + MINMAXINFO *mmi; - switch(iMsg) - { - case WM_CREATE: - hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, "Ready", hwnd, 0); - - //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0); + switch(iMsg) + { + case WM_CREATE: + hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, "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)""); + SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts); + SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)""); - ShowWindow(hwndStatus, SW_HIDE); + ShowWindow(hwndStatus, SW_HIDE); - SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0); + SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0); - CreateSol(); + CreateSol(); - NewGame(); + NewGame(); - dwAppStartTime = GetTickCount(); + dwAppStartTime = GetTickCount(); - return 0; + return 0; - case WM_DESTROY: - PostQuitMessage(0); - return 0; + case WM_DESTROY: + PostQuitMessage(0); + return 0; - case WM_SIZE: - nWidth = LOWORD(lParam); - nHeight = HIWORD(lParam); + case WM_SIZE: + nWidth = LOWORD(lParam); + nHeight = HIWORD(lParam); - MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE); - //MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE); - //parts[0] = nWidth - 256; - //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts); + MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE); + //MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE); + //parts[0] = nWidth - 256; + //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts); - return 0; + return 0; - case WM_GETMINMAXINFO: - mmi = (MINMAXINFO *)lParam; - mmi->ptMinTrackSize.x = 600; - mmi->ptMinTrackSize.y = 400; + case WM_GETMINMAXINFO: + mmi = (MINMAXINFO *)lParam; + mmi->ptMinTrackSize.x = 600; + mmi->ptMinTrackSize.y = 400; - 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 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_DECK: + //ShowDeckOptionsDlg(hwnd); + return 0; - case IDM_GAME_OPTIONS: - //ShowGameOptionsDlg(hwnd); - return 0; + case IDM_GAME_OPTIONS: + //ShowGameOptionsDlg(hwnd); + return 0; - case IDM_HELP_CONTENTS: + case IDM_HELP_CONTENTS: - WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play"); - - return 0; + WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play"); + + return 0; - case IDM_HELP_ABOUT: - MessageBox(hwnd, _T("Solitare by J Brown\r\n\r\nCardLib version 1.0."), szAppName, MB_OK|MB_ICONINFORMATION); + case IDM_HELP_ABOUT: + MessageBox(hwnd, _T("Solitare by J Brown\r\n\r\nCardLib version 1.0."), szAppName, MB_OK|MB_ICONINFORMATION); - return 0; + return 0; - case IDM_GAME_EXIT: - PostMessage(hwnd, WM_CLOSE, 0, 0); - return 0; - } + case IDM_GAME_EXIT: + PostMessage(hwnd, WM_CLOSE, 0, 0); + return 0; + } - return 0; + return 0; - case WM_CLOSE: - - ret = IDOK; + case WM_CLOSE: + + ret = IDOK; - if(fGameStarted) - { - ret = MessageBox(hwnd, _T("Quit the current game?"), szAppName, MB_OKCANCEL|MB_ICONQUESTION); - } + if(fGameStarted) + { + ret = MessageBox(hwnd, _T("Quit the current game?"), szAppName, MB_OKCANCEL|MB_ICONQUESTION); + } - if(ret == IDOK) - { - WinHelp(hwnd, szHelpPath, HELP_QUIT, 0); - DestroyWindow(hwnd); - } + if(ret == IDOK) + { + WinHelp(hwnd, szHelpPath, HELP_QUIT, 0); + DestroyWindow(hwnd); + } - return 0; - } + return 0; + } - return DefWindowProc (hwnd, iMsg, wParam, lParam); + return DefWindowProc (hwnd, iMsg, wParam, lParam); }