eliminate warnings, fix bug that locked up game when single-clicking a card

svn path=/trunk/; revision=13907
This commit is contained in:
Royce Mitchell III 2005-03-10 04:58:40 +00:00
parent 26676ade4c
commit 60f02a7882
11 changed files with 102 additions and 36 deletions

View file

@ -20,7 +20,7 @@ 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)
: parentWnd(parent), id(Id), fVisible(visible), uStyle(Style), ButtonCallback(0)
: parentWnd(parent), id(Id), uStyle(Style), fVisible(visible), ButtonCallback(0)
{
crText = RGB(255,255,255);
crBack = RGB(0, 128, 0);

View file

@ -186,28 +186,12 @@ COLORREF ColorScaleRGB( const COLORREF Col1,
COLORREF ColorDarker(COLORREF col, double ratio)
{
static double Hue, Lum, Sat;
//RGBtoHLS(col, &Hue, &Lum, &Sat);
//col = HLStoRGB(Hue, fMax(0.0,Lum-ratio), Sat);
return ColorScaleHSL(col, RGB(0,0,0), ratio);
//return col;
}
COLORREF ColorLighter(COLORREF col, double ratio)
{
static double Hue, Lum, Sat;
//RGBtoHLS(col, &Hue, &Lum, &Sat);
//col = HLStoRGB(Hue, fMin(1.0,Lum+ratio), Sat);
return ColorScaleHSL(col, RGB(255,255,255), ratio);
//return col;
}
//

View file

@ -10,7 +10,7 @@
void LoadCardBitmaps(void);
static bool __CARDLIB_ACES_HIGH = false;
//static bool __CARDLIB_ACES_HIGH = false;
extern double __CARDZOOMSPEED;
//

View file

@ -16,7 +16,7 @@ HBITMAP CreateSinkBmp(HDC hdcCompat, HDC hdc, int width, int height);
void PaintRect(HDC hdc, RECT *rect, COLORREF colour);
CardRegion::CardRegion(CardWindow &parent, int Id, bool visible, int x, int y, int xOffset, int yOffset)
: parentWnd(parent), id(Id), fVisible(visible), xpos(x), ypos(y), xoffset(xOffset), yoffset(yOffset)
: id(Id), parentWnd(parent), xpos(x), ypos(y), xoffset(xOffset), yoffset(yOffset), fVisible(visible)
{
width = __cardwidth;
height = __cardheight;
@ -56,7 +56,7 @@ CardRegion::CardRegion(CardWindow &parent, int Id, bool visible, int x, int y, i
nFlashCount = 0;
fFlashVisible = false;
uFlashTimer = -1;
uFlashTimer = (UINT)-1;
fMouseDragging = false;
@ -331,25 +331,25 @@ void CardRegion::Flash(int count, int milliseconds)
void CardRegion::StopFlash()
{
if(uFlashTimer != -1)
if(uFlashTimer != (UINT)-1)
{
KillTimer((HWND)parentWnd, uFlashTimer);
nFlashCount = 0;
uFlashTimer = -1;
uFlashTimer = (UINT)-1;
fFlashVisible = true;
}
}
void CardRegion::DoFlash()
{
if(uFlashTimer != -1)
if(uFlashTimer != (UINT)-1)
{
fFlashVisible = !fFlashVisible;
if(--nFlashCount == 0)
{
KillTimer((HWND)parentWnd, uFlashTimer);
uFlashTimer = -1;
uFlashTimer = (UINT)-1;
fFlashVisible = true;
}

View file

@ -147,12 +147,12 @@ private:
bool fMouseDragging;
int xoffset; //direction that cards take
int yoffset;
int xpos; //coordinates of stack
int ypos;
int xoffset; //direction that cards take
int yoffset;
int width; //stack-size of all cards
int height;

View file

@ -6,11 +6,18 @@
//
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include "cardlib.h"
#include "cardwindow.h"
#include "cardregion.h"
#if 1
#define TRACE(s)
#else
#define TRACE(s) printf("%s(%i): %s",__FILE__,__LINE__,s)
#endif
double __CARDZOOMSPEED = 32;
int ClipCard(HDC hdc, int x, int y, int width, int height);
@ -304,8 +311,10 @@ bool CardRegion::OnLButtonUp(int x, int y)
// 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);
@ -332,6 +341,7 @@ bool CardRegion::OnLButtonUp(int x, int y)
pDestStack->AddCallback(*pDestStack, pDestStack->cardstack);//index, deststack->numcards);
RedrawIfNotDim(pDestStack, true);
TRACE ( "done dropping card\n" );
}
//
@ -339,18 +349,24 @@ bool CardRegion::OnLButtonUp(int x, int y)
//
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;
}
@ -531,6 +547,7 @@ void ZoomCard(HDC hdc, int xpos, int ypos, CARDSTACK *dest)
#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;
@ -552,6 +569,11 @@ void CardRegion::ZoomCard(HDC hdc, int xpos, int ypos, CardRegion *pDestStack)
//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;
@ -566,6 +588,7 @@ void CardRegion::ZoomCard(HDC hdc, int xpos, int ypos, CardRegion *pDestStack)
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;
@ -614,5 +637,6 @@ void CardRegion::ZoomCard(HDC hdc, int xpos, int ypos, CardRegion *pDestStack)
Sleep(10);
}
TRACE ( "EXIT ZoomCard()\n" );
}
#endif

View file

@ -282,7 +282,6 @@ void CardWindow::Paint(HDC hdc)
{
int i;
RECT rect;
int xpos = 10;
HPALETTE hOldPal;
hOldPal = UseNicePalette(hdc, __hPalette);

View file

@ -4,6 +4,8 @@ PATH_TO_TOP = ../../../reactos
TARGET_TYPE = program
TARGET_APPTYPE = windows
# change to console for debugging purposes...
#TARGET_APPTYPE = console
TARGET_INSTALLDIR = system32

View file

@ -1,16 +1,24 @@
#include <windows.h>
#include <commctrl.h>
#include <tchar.h>
#include <stdio.h>
#include "resource.h"
#include "cardlib/cardlib.h"
//#include "../catch22lib/trace.h"
#include "solitaire.h"
#if 1
#define TRACE(s)
#else
#define TRACE(s) printf("%s(%i): %s",__FILE__,__LINE__,s)
#endif
CardStack activepile;
bool fGameStarted = false;
void NewGame(void)
{
TRACE("ENTER NewGame()\n");
int i, j;
SolWnd.EmptyStacks();
@ -44,6 +52,7 @@ void NewGame(void)
SolWnd.Redraw();
fGameStarted = false;
TRACE("EXIT NewGame()\n");
}
//
@ -56,6 +65,7 @@ void NewGame(void)
//
bool CARDLIBPROC RowStackDragProc(CardRegion &stackobj, int iNumDragCards)
{
TRACE("ENTER RowStackDragProc()\n");
int numfacedown;
int numcards;
@ -63,6 +73,7 @@ bool CARDLIBPROC RowStackDragProc(CardRegion &stackobj, int iNumDragCards)
numcards = stackobj.NumCards();
TRACE("EXIT RowStackDragProc()\n");
if(iNumDragCards <= numcards-numfacedown)
return true;
else
@ -76,13 +87,17 @@ bool CARDLIBPROC RowStackDragProc(CardRegion &stackobj, int iNumDragCards)
//
bool CARDLIBPROC RowStackDropProc(CardRegion &stackobj, const CardStack &dragcards)
{
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
{
@ -90,14 +105,21 @@ bool CARDLIBPROC RowStackDropProc(CardRegion &stackobj, const CardStack &dragca
//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;
}
}
TRACE("EXIT RowStackDropProc(true)\n");
return true;
}
@ -107,6 +129,7 @@ bool CARDLIBPROC RowStackDropProc(CardRegion &stackobj, const CardStack &dragca
//
bool CanDrop(CardRegion &stackobj, Card card)
{
TRACE("ENTER CanDrop()\n");
int topval;
const CardStack &cardstack = stackobj.GetCardStack();
@ -115,6 +138,7 @@ bool CanDrop(CardRegion &stackobj, Card card)
{
if(card.Suit() != cardstack[0].Suit())
{
TRACE("EXIT CanDrop()\n");
return false;
}
@ -127,8 +151,12 @@ bool CanDrop(CardRegion &stackobj, Card card)
//make sure 1 higher
if(card.LoVal() != (topval + 1))
{
TRACE("EXIT CanDrop()\n");
return false;
}
TRACE("EXIT CanDrop()\n");
return true;
}
@ -137,13 +165,17 @@ bool CanDrop(CardRegion &stackobj, Card card)
//
bool CARDLIBPROC SuitStackDropProc(CardRegion &stackobj, const CardStack &dragcards)
{
int topval = 0;
TRACE("ENTER SuitStackDropProc()\n");
//only drop 1 card at a time
if(dragcards.NumCards() != 1)
{
TRACE("EXIT SuitStackDropProc()\n");
return false;
}
return CanDrop(stackobj, dragcards[0]);
bool b = CanDrop(stackobj, dragcards[0]);
TRACE("EXIT SuitStackDropProc()\n");
return b;
}
//
@ -152,6 +184,7 @@ bool CARDLIBPROC SuitStackDropProc(CardRegion &stackobj, const CardStack &dragca
//
void CARDLIBPROC RowStackClickProc(CardRegion &stackobj, int iNumClicked)
{
TRACE("ENTER RowStackClickProc()\n");
int numfacedown;
stackobj.GetFaceDirection(&numfacedown);
@ -163,6 +196,7 @@ void CARDLIBPROC RowStackClickProc(CardRegion &stackobj, int iNumClicked)
stackobj.SetFaceDirection(CS_FACE_DOWNUP, numfacedown);
stackobj.Redraw();
}
TRACE("EXIT RowStackClickProc()\n");
}
//
@ -170,12 +204,17 @@ void CARDLIBPROC RowStackClickProc(CardRegion &stackobj, int iNumClicked)
//
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("EXIT FindSuitStackFromCard()\n");
return 0;
}
@ -187,6 +226,7 @@ CardRegion *FindSuitStackFromCard(Card card)
//
void CARDLIBPROC SuitStackAddProc(CardRegion &stackobj, const CardStack &added)
{
TRACE("ENTER SuitStackAddProc()\n");
bool fGameOver = true;
for(int i = 0; i < 4; i++)
@ -207,6 +247,7 @@ void CARDLIBPROC SuitStackAddProc(CardRegion &stackobj, const CardStack &added)
pSuitStack[i]->Flash(11, 100);
}
}
TRACE("EXIT SuitStackAddProc()\n");
}
//
@ -216,9 +257,13 @@ void CARDLIBPROC SuitStackAddProc(CardRegion &stackobj, const CardStack &added)
//
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;
}
//find a suit-stack to move the card to...
const CardStack &cardstack = stackobj.GetCardStack();
@ -231,6 +276,7 @@ void CARDLIBPROC RowStackDblClickProc(CardRegion &stackobj, int iNumClicked)
//AddProc callbacks called for us on the destination stacks...
stackobj.SimulateDrag(pDest, 1, true);
}
TRACE("EXIT RowStackDblClickProc()\n");
}
//
@ -238,7 +284,9 @@ void CARDLIBPROC RowStackDblClickProc(CardRegion &stackobj, int iNumClicked)
//
void CARDLIBPROC PileDblClickProc(CardRegion &stackobj, int iNumClicked)
{
TRACE("ENTER PileDblClickProc()\n");
RowStackDblClickProc(stackobj, iNumClicked);
TRACE("EXIT PileDblClickProc()\n");
}
//
@ -246,6 +294,7 @@ void CARDLIBPROC PileDblClickProc(CardRegion &stackobj, int iNumClicked)
//
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);
@ -259,6 +308,7 @@ void CARDLIBPROC PileRemoveProc(CardRegion &stackobj, int iItems)
stackobj.SetOffsets(0,0);
stackobj.SetCardStack(activepile);
}
TRACE("EXIT PileRemoveProc()\n");
}
//
@ -267,6 +317,7 @@ void CARDLIBPROC PileRemoveProc(CardRegion &stackobj, int iItems)
//
void CARDLIBPROC DeckClickProc(CardRegion &stackobj, int iNumClicked)
{
TRACE("ENTER DeckClickProc()\n");
CardStack cardstack = stackobj.GetCardStack();
CardStack pile = pPile->GetCardStack();
@ -305,4 +356,5 @@ void CARDLIBPROC DeckClickProc(CardRegion &stackobj, int iNumClicked)
pPile->SetCardStack(pile);
SolWnd.Redraw();
TRACE("EXIT DeckClickProc()\n");
}

View file

@ -28,6 +28,11 @@ void MakePath(TCHAR *szDest, UINT nDestLen, TCHAR *szExt)
lstrcpy(ptr + 1, szExt);
}
int main ( int argc, char** argv )
{
return WinMain ( NULL, NULL, NULL, SW_SHOW );
}
//
// Main entry point
//