From 60f02a7882db6c29857bc31c8d6fd1d544f7ce98 Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Thu, 10 Mar 2005 04:58:40 +0000 Subject: [PATCH] eliminate warnings, fix bug that locked up game when single-clicking a card svn path=/trunk/; revision=13907 --- .../games/solitaire/cardlib/cardbutton.cpp | 2 +- rosapps/games/solitaire/cardlib/cardcolor.cpp | 16 ----- rosapps/games/solitaire/cardlib/cardcount.cpp | 2 +- rosapps/games/solitaire/cardlib/cardlib.cpp | 2 +- .../games/solitaire/cardlib/cardregion.cpp | 14 ++--- rosapps/games/solitaire/cardlib/cardregion.h | 6 +- .../games/solitaire/cardlib/cardrgnmouse.cpp | 30 +++++++++- .../games/solitaire/cardlib/cardwindow.cpp | 1 - rosapps/games/solitaire/makefile | 2 + rosapps/games/solitaire/solgame.cpp | 58 ++++++++++++++++++- rosapps/games/solitaire/solitaire.cpp | 5 ++ 11 files changed, 102 insertions(+), 36 deletions(-) diff --git a/rosapps/games/solitaire/cardlib/cardbutton.cpp b/rosapps/games/solitaire/cardlib/cardbutton.cpp index a0a2b3a9f6c..6c7ff8d8003 100644 --- a/rosapps/games/solitaire/cardlib/cardbutton.cpp +++ b/rosapps/games/solitaire/cardlib/cardbutton.cpp @@ -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); diff --git a/rosapps/games/solitaire/cardlib/cardcolor.cpp b/rosapps/games/solitaire/cardlib/cardcolor.cpp index f82c9fa77a1..6d0e0089df4 100644 --- a/rosapps/games/solitaire/cardlib/cardcolor.cpp +++ b/rosapps/games/solitaire/cardlib/cardcolor.cpp @@ -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; } // diff --git a/rosapps/games/solitaire/cardlib/cardcount.cpp b/rosapps/games/solitaire/cardlib/cardcount.cpp index e14777afbbb..d8ab036ab55 100644 --- a/rosapps/games/solitaire/cardlib/cardcount.cpp +++ b/rosapps/games/solitaire/cardlib/cardcount.cpp @@ -87,4 +87,4 @@ void CardCount::Dec(size_t index) if(count[index] > 0) count[index]--; -} \ No newline at end of file +} diff --git a/rosapps/games/solitaire/cardlib/cardlib.cpp b/rosapps/games/solitaire/cardlib/cardlib.cpp index 07cd4eec73b..6006c9ef546 100644 --- a/rosapps/games/solitaire/cardlib/cardlib.cpp +++ b/rosapps/games/solitaire/cardlib/cardlib.cpp @@ -10,7 +10,7 @@ void LoadCardBitmaps(void); -static bool __CARDLIB_ACES_HIGH = false; +//static bool __CARDLIB_ACES_HIGH = false; extern double __CARDZOOMSPEED; // diff --git a/rosapps/games/solitaire/cardlib/cardregion.cpp b/rosapps/games/solitaire/cardlib/cardregion.cpp index 1a7e8ce19ce..8ecf4be2263 100644 --- a/rosapps/games/solitaire/cardlib/cardregion.cpp +++ b/rosapps/games/solitaire/cardlib/cardregion.cpp @@ -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; } @@ -655,4 +655,4 @@ bool CardRegion::SimulateDrag(CardRegion *pDestStack, int iNumDragCards, bool fA } return true; -} \ No newline at end of file +} diff --git a/rosapps/games/solitaire/cardlib/cardregion.h b/rosapps/games/solitaire/cardlib/cardregion.h index d2806a9c9b5..1dc9498492f 100644 --- a/rosapps/games/solitaire/cardlib/cardregion.h +++ b/rosapps/games/solitaire/cardlib/cardregion.h @@ -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; diff --git a/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp b/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp index a3bf6e771ea..4e9bd5259ae 100644 --- a/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp +++ b/rosapps/games/solitaire/cardlib/cardrgnmouse.cpp @@ -6,11 +6,18 @@ // #include #include +#include #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,25 +341,32 @@ bool CardRegion::OnLButtonUp(int x, int y) 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); + 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,7 +588,8 @@ 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; + + 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 diff --git a/rosapps/games/solitaire/cardlib/cardwindow.cpp b/rosapps/games/solitaire/cardlib/cardwindow.cpp index 748ac71e52b..1f27c136c93 100644 --- a/rosapps/games/solitaire/cardlib/cardwindow.cpp +++ b/rosapps/games/solitaire/cardlib/cardwindow.cpp @@ -282,7 +282,6 @@ void CardWindow::Paint(HDC hdc) { int i; RECT rect; - int xpos = 10; HPALETTE hOldPal; hOldPal = UseNicePalette(hdc, __hPalette); diff --git a/rosapps/games/solitaire/makefile b/rosapps/games/solitaire/makefile index 449a771e950..f05f1d68ce1 100644 --- a/rosapps/games/solitaire/makefile +++ b/rosapps/games/solitaire/makefile @@ -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 diff --git a/rosapps/games/solitaire/solgame.cpp b/rosapps/games/solitaire/solgame.cpp index b2ae928e583..7a12e09943b 100644 --- a/rosapps/games/solitaire/solgame.cpp +++ b/rosapps/games/solitaire/solgame.cpp @@ -1,16 +1,24 @@ #include #include #include +#include #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"); } diff --git a/rosapps/games/solitaire/solitaire.cpp b/rosapps/games/solitaire/solitaire.cpp index c8e3e66c148..e7e12a7ac95 100644 --- a/rosapps/games/solitaire/solitaire.cpp +++ b/rosapps/games/solitaire/solitaire.cpp @@ -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 //