Change tabs to spaces.

svn path=/trunk/; revision=13910
This commit is contained in:
Steven Edwards 2005-03-10 16:08:08 +00:00
parent 60f02a7882
commit 33c313a6ff
14 changed files with 3216 additions and 3219 deletions

View file

@ -1,8 +1,8 @@
//
// CardLib - Card bitmap support
// CardLib - Card bitmap support
//
// Freeware
// Copyright J Brown 2001
// Freeware
// Copyright J Brown 2001
//
#include <windows.h>
#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;
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;
if(i < 52) val = (i % 4) * 13 + (i/4);
else val = i;
hBitmap = LoadBitmap(hCardDll, MAKEINTRESOURCE(val + 1));
GetObject(hBitmap, sizeof(bmp), &bmp);
hBitmap = LoadBitmap(hCardDll, MAKEINTRESOURCE(val + 1));
GetObject(hBitmap, sizeof(bmp), &bmp);
width = bmp.bmWidth;
height = bmp.bmHeight;
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);
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);
hdcCard = CreateCompatibleDC(0);
ReleaseDC(0, hdc);
}
ReleaseDC(0, hdc);
}
hOld = SelectObject(hdcCard, hBitmap);
BitBlt(__hdcCardBitmaps, i*width, 0, width, height, hdcCard, 0, 0, SRCCOPY);
SelectObject(hdcCard, hOld);
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);
//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);
}
DeleteObject(hBitmap);
}
DeleteDC(hdcCard);
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;
}
if(hCardDll == 0)
{
MessageBox(0, "Error loading cards.dll (32bit)", "Shed", MB_OK | MB_ICONEXCLAMATION);
PostQuitMessage(0);
return;
}
LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight);
LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight);
FreeLibrary(hCardDll);
}
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);
fgold = SetTextColor(hdc, fg);
bgold = SetBkColor(hdc, bg);
PatBlt(hdc, rect->left, rect->top,
rect->right - rect->left,
rect->bottom - rect->top,
PATCOPY);
PatBlt(hdc, rect->left, rect->top,
rect->right - rect->left,
rect->bottom - rect->top,
PATCOPY);
SetBkColor(hdc, bgold);
SetTextColor(hdc, fgold);
SetBkColor(hdc, bgold);
SetTextColor(hdc, fgold);
SelectObject(hdc, hbrold);
DeleteObject(hbr);
DeleteObject(hbmp);
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);
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);
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);
//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);
//(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 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;
}

View file

@ -1,8 +1,8 @@
//
// CardLib - CardButton class
// CardLib - CardButton class
//
// Freeware
// Copyright J Brown 2001
// Freeware
// Copyright J Brown 2001
//
#include <windows.h>
#include <tchar.h>
@ -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);
crText = RGB(255,255,255);
crBack = RGB(0, 128, 0);
xadjust = 0;
yadjust = 0;
xjustify = 0;
yjustify = 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);
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;
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);
SetRect(&fill, x+1, y+1, x+width-1, y+height-1);
int one = 1;
int one = 1;
if(!fNormal)
{
x += width;
y += height;
width = -width;
height = -height;
one = -1;
OffsetRect(&fill, 1, 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);
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;
if(fVisible == false) return;
ExcludeClipRect(hdc, rect.left, rect.top, rect.right, rect.bottom);
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);
if(hFont == 0)
SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));
else
SelectObject(hdc, hFont);
GetTextExtentPoint32(hdc, szText, lstrlen(szText), &textsize);
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;
}
}
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;
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;
//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
//
//
// Calc icon pos
//
if(hIcon)
{
ExcludeClipRect(hdc, ix, iy, ix + 32, iy + 32);
}
if(hIcon)
{
ExcludeClipRect(hdc, ix, iy, ix + 32, iy + 32);
}
if(uStyle & CB_PUSHBUTTON)
{
DrawRect(hdc, &rect, fNormal);
if(uStyle & CB_PUSHBUTTON)
{
DrawRect(hdc, &rect, fNormal);
SetBkColor(hdc, MAKE_PALETTERGB(crBack));
SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText));
SetBkColor(hdc, MAKE_PALETTERGB(crBack));
SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText));
SelectClipRgn(hdc, 0);
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);
}
//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;
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;
POINT pt;
pt.x = x;
pt.y = y;
pt.x = x;
pt.y = y;
if(PtInRect(&rect, pt))
fButtonDown = true;
else
fButtonDown = false;
if(PtInRect(&rect, pt))
fButtonDown = true;
else
fButtonDown = false;
if(fButtonDown != fOldButtonDown)
Redraw();
}
if(fButtonDown != fOldButtonDown)
Redraw();
}
return 0;
return 0;
}
int CardButton::OnLButtonUp(HWND hwnd, int x, int y)
{
if(fMouseDown)
{
fMouseDown = false;
fButtonDown = false;
if(fMouseDown)
{
fMouseDown = false;
fButtonDown = false;
if(uStyle & CB_PUSHBUTTON)
{
Redraw();
ReleaseCapture();
}
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 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));
}
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;
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);
Draw(hdc, !fButtonDown);
RestorePalette(hdc, hOldPal);
RestorePalette(hdc, hOldPal);
ReleaseDC((HWND)parentWnd, hdc);
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 = GetHighlight(cr);
crShadow = GetShadow(cr);
//crHighlight = ScaleLumRGB(cr, +0.25);
//crShadow = ScaleLumRGB(cr, -0.25);
//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;
hIcon = hicon;
if(fRedraw)
Redraw();
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;
}

View file

@ -1,5 +1,5 @@
//
// Colour support
// Colour support
//
#include <windows.h>
@ -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;
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);
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;
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;
}
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;
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;
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;
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;
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

View file

@ -1,90 +1,90 @@
//
// CardCount is a helper library for CardStacks.
// CardCount is a helper library for CardStacks.
//
// When you initialize a CardCount object with a
// 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:
// Then you can do:
//
// int num_fives = count[5]
// int num_fives = count[5]
//
// count.Add(cardstack2); - combine with another stack
// 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();
for(int i = 0; i < cs.NumCards(); i++)
{
Card card = cs[i];
int val = card.LoVal();
if(count[val - 1] > 0)
count[val - 1]--;
}
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]--;
}

View file

@ -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 <windows.h>
#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();
}
*/

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
//
// CardLib - CardStack class
// CardLib - CardStack class
//
// Freeware
// Copyright J Brown 2001
// Freeware
// Copyright J Brown 2001
//
#include <windows.h>
#include <stdlib.h>
@ -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)
//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);
//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;
}
//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();
if(nNumCards + cardstack.nNumCards < MAX_CARDSTACK_SIZE)
{
int num = cardstack.NumCards();
for(int i = 0; i < num; i++)
cardlist[nNumCards++] = cardstack.cardlist[i];
}
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 &copythis, 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];
}

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
//
// CardLib - DropZone class
// CardLib - DropZone class
//
// Freeware
// Copyright J Brown 2001
// Freeware
// Copyright J Brown 2001
//
#include <windows.h>
@ -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 *dz = new DropZone(id, rect, proc);
dropzone[nNumDropZones++] = dz;
dropzone[nNumDropZones++] = dz;
return false;
return false;
}
DropZone *CardWindow::GetDropZoneFromRect(RECT *rect)
{
for(int i = 0; i < nNumDropZones; i++)
{
RECT inter;
RECT 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 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];
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];
}
//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;
}

View file

@ -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);
}
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);
}
//
// 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);
}
}

View file

@ -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();
SolWnd.EmptyStacks();
//create a new card-stack
CardStack deck;
deck.NewDeck();
deck.Shuffle();
activepile.Clear();
//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();
//put the other cards onto the deck
pDeck->SetCardStack(deck);
pDeck->Update();
SolWnd.Redraw();
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();
//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 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;
TRACE("ENTER RowStackClickProc()\n");
int numfacedown;
stackobj.GetFaceDirection(&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);
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");
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]);
//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");
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());
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();
//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");
}

View file

@ -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;
TCHAR *ptr;
ptr = szDest + GetModuleFileName(GetModuleHandle(0), szDest, nDestLen) - 1;
while(*ptr-- != '.');
lstrcpy(ptr + 1, szExt);
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"));
//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
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);
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_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:
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_GAME_NEW:
//simulate a button click on the new button..
NewGame();
return 0;
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");
WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
return 0;
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:
case WM_CLOSE:
ret = IDOK;
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);
}