2004-03-15 21:26:42 +01:00
|
|
|
/*
|
|
|
|
* Cards dll implementation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Sami Nopanen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-03-15 21:26:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
|
|
|
|
#include "cards.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(cards);
|
|
|
|
|
|
|
|
|
|
|
|
void WINAPI cdtTerm(void);
|
|
|
|
|
|
|
|
|
|
|
|
static HINSTANCE hInst;
|
|
|
|
static int cardWidth;
|
|
|
|
static int cardHeight;
|
|
|
|
static HBITMAP cardBitmaps[CARD_MAX + 1];
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Initializes the cards.dll library. Loads the card bitmaps from the
|
|
|
|
* resources, and initializes the card size variables.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI cdtInit(int *width, int *height)
|
|
|
|
{
|
|
|
|
BITMAP bm;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", width, height);
|
|
|
|
|
|
|
|
for(i = 0; i <= CARD_MAX; i++)
|
|
|
|
cardBitmaps[i] = 0;
|
|
|
|
|
|
|
|
for(i = 0; i <= CARD_MAX; i++)
|
|
|
|
{
|
|
|
|
cardBitmaps[i] = LoadBitmapA(hInst, MAKEINTRESOURCEA(i));
|
|
|
|
if(cardBitmaps[i] == 0)
|
|
|
|
{
|
|
|
|
cdtTerm();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GetObjectA(cardBitmaps[0], sizeof(BITMAP), &bm);
|
|
|
|
*width = cardWidth = bm.bmWidth;
|
|
|
|
*height = cardHeight = bm.bmHeight;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-09-08 13:04:53 +02:00
|
|
|
static DWORD do_blt(HDC hdc, int x, int y, int dx, int dy, HDC hMemoryDC, DWORD rasterOp )
|
|
|
|
{
|
|
|
|
if((cardWidth == dx) && (cardHeight == dy))
|
|
|
|
return BitBlt(hdc, x, y, cardWidth, cardHeight, hMemoryDC, 0, 0, rasterOp);
|
|
|
|
return StretchBlt(hdc, x, y, dx, dy, hMemoryDC, 0, 0, cardWidth, cardHeight, rasterOp);
|
|
|
|
}
|
2004-03-15 21:26:42 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Draw a card. Unlike cdtDrawCard, this version allows you to stretch
|
|
|
|
* card bitmaps to the size you specify (dx, dy). See cdtDraw for info
|
2004-03-16 20:13:47 +01:00
|
|
|
* on card, mode and color parameters.
|
2004-03-15 21:26:42 +01:00
|
|
|
*/
|
2004-03-16 20:13:47 +01:00
|
|
|
BOOL WINAPI cdtDrawExt(HDC hdc, int x, int y, int dx, int dy, int card, int mode, DWORD color)
|
2004-03-15 21:26:42 +01:00
|
|
|
{
|
|
|
|
HDC hMemoryDC;
|
|
|
|
HBITMAP hCardBitmap;
|
|
|
|
HGDIOBJ result;
|
2004-03-16 20:13:47 +01:00
|
|
|
DWORD rasterOp = SRCCOPY;
|
2004-03-25 00:39:03 +01:00
|
|
|
BOOL roundCornersFlag;
|
2004-03-29 22:26:21 +02:00
|
|
|
BOOL eraseFlag = FALSE;
|
|
|
|
BOOL drawFlag = TRUE;
|
2004-03-15 21:26:42 +01:00
|
|
|
|
2022-02-09 09:25:13 +01:00
|
|
|
TRACE("(%p, %d, %d, %d, %d, %d, %d, %ld)\n", hdc, x, y, dx, dy, card, mode, color);
|
2004-03-15 21:26:42 +01:00
|
|
|
|
2004-03-25 00:39:03 +01:00
|
|
|
roundCornersFlag = !(mode & MODEFLAG_DONT_ROUND_CORNERS) &&
|
|
|
|
(dx == cardWidth) && (dy == cardHeight);
|
|
|
|
mode &= ~MODEFLAG_DONT_ROUND_CORNERS;
|
|
|
|
|
2004-03-15 21:26:42 +01:00
|
|
|
if((card < 0) || (card > CARD_MAX))
|
|
|
|
{
|
|
|
|
FIXME("Unexpected card: %d\n", card);
|
2004-03-16 20:13:47 +01:00
|
|
|
return FALSE;
|
2004-03-15 21:26:42 +01:00
|
|
|
}
|
|
|
|
|
2004-03-16 20:13:47 +01:00
|
|
|
if((mode < MODE_FACEUP) || (mode > MODE_DECKO))
|
|
|
|
{
|
|
|
|
FIXME("Unexpected mode: %d\n", mode);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-15 21:26:42 +01:00
|
|
|
|
2004-03-29 22:26:21 +02:00
|
|
|
switch(mode)
|
2004-03-16 20:13:47 +01:00
|
|
|
{
|
2004-03-29 22:26:21 +02:00
|
|
|
case MODE_FACEUP:
|
|
|
|
break;
|
|
|
|
case MODE_FACEDOWN:
|
|
|
|
break;
|
|
|
|
case MODE_HILITE:
|
|
|
|
rasterOp = NOTSRCCOPY;
|
|
|
|
break;
|
|
|
|
case MODE_GHOST:
|
|
|
|
card = CARD_FREE_MASK;
|
|
|
|
eraseFlag = TRUE;
|
|
|
|
rasterOp = SRCAND;
|
|
|
|
break;
|
|
|
|
case MODE_REMOVE:
|
|
|
|
eraseFlag = TRUE;
|
|
|
|
drawFlag = FALSE;
|
|
|
|
break;
|
|
|
|
case MODE_INVISIBLEGHOST:
|
|
|
|
card = CARD_FREE_MASK;
|
|
|
|
rasterOp = SRCAND;
|
|
|
|
break;
|
|
|
|
case MODE_DECKX:
|
|
|
|
card = CARD_BACK_THE_X;
|
|
|
|
break;
|
|
|
|
case MODE_DECKO:
|
|
|
|
card = CARD_BACK_THE_O;
|
|
|
|
break;
|
2004-03-16 20:13:47 +01:00
|
|
|
}
|
2004-03-15 21:26:42 +01:00
|
|
|
|
|
|
|
hMemoryDC = CreateCompatibleDC(hdc);
|
|
|
|
if(hMemoryDC == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-29 22:26:21 +02:00
|
|
|
if(eraseFlag)
|
2004-03-15 21:26:42 +01:00
|
|
|
{
|
2004-03-16 20:13:47 +01:00
|
|
|
HBRUSH hBrush;
|
|
|
|
RECT rect;
|
|
|
|
hBrush = CreateSolidBrush(color);
|
2016-06-27 09:45:31 +02:00
|
|
|
SetRect(&rect, x, y, x + cardWidth - 1, y + cardHeight - 1);
|
2004-03-16 20:13:47 +01:00
|
|
|
FillRect(hdc, &rect, hBrush);
|
2004-03-15 21:26:42 +01:00
|
|
|
}
|
2004-03-16 20:13:47 +01:00
|
|
|
|
2004-03-29 22:26:21 +02:00
|
|
|
if(drawFlag)
|
|
|
|
{
|
2004-03-16 20:13:47 +01:00
|
|
|
hCardBitmap = cardBitmaps[card];
|
|
|
|
if(hCardBitmap == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
result = SelectObject(hMemoryDC, hCardBitmap);
|
|
|
|
if((result == 0) || (result == HGDI_ERROR))
|
|
|
|
{
|
|
|
|
DeleteDC(hMemoryDC);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-15 21:26:42 +01:00
|
|
|
|
2004-03-16 20:13:47 +01:00
|
|
|
SetBkColor(hdc, color);
|
2004-03-15 21:26:42 +01:00
|
|
|
|
2004-03-25 00:39:03 +01:00
|
|
|
if(roundCornersFlag)
|
|
|
|
{
|
2006-04-05 14:05:03 +02:00
|
|
|
/* NOTE: native uses Get/SetPixel for corners, but that really
|
|
|
|
* hurts on X11 since it needs a server round-trip for each pixel.
|
|
|
|
* So we use a clip region instead. */
|
|
|
|
HRGN saved = CreateRectRgn( 0, 0, 0, 0 );
|
|
|
|
HRGN line = CreateRectRgn( x + 2, y, x + dx - 2, y + 1 );
|
|
|
|
HRGN clip = CreateRectRgn( x, y + 2, x + dx, y + dy - 2 );
|
|
|
|
|
|
|
|
CombineRgn( clip, clip, line, RGN_OR );
|
|
|
|
SetRectRgn( line, x + 1, y + 1, x + dx - 1, y + 2 );
|
|
|
|
CombineRgn( clip, clip, line, RGN_OR );
|
|
|
|
SetRectRgn( line, x + 1, y + dy - 2, x + dx - 1, y + dy - 1 );
|
|
|
|
CombineRgn( clip, clip, line, RGN_OR );
|
|
|
|
SetRectRgn( line, x + 2, y + dy - 1, x + dx - 2, y + dy );
|
|
|
|
CombineRgn( clip, clip, line, RGN_OR );
|
|
|
|
DeleteObject( line );
|
|
|
|
|
|
|
|
if (!GetClipRgn( hdc, saved ))
|
|
|
|
{
|
|
|
|
DeleteObject( saved );
|
|
|
|
saved = 0;
|
|
|
|
}
|
|
|
|
ExtSelectClipRgn( hdc, clip, RGN_AND );
|
|
|
|
DeleteObject( clip );
|
|
|
|
|
|
|
|
do_blt(hdc, x, y, dx, dy, hMemoryDC, rasterOp);
|
|
|
|
|
|
|
|
SelectClipRgn( hdc, saved );
|
|
|
|
if (saved) DeleteObject( saved );
|
2004-03-25 00:39:03 +01:00
|
|
|
}
|
2005-09-08 13:04:53 +02:00
|
|
|
else
|
|
|
|
do_blt(hdc, x, y, dx, dy, hMemoryDC, rasterOp);
|
2004-03-16 20:13:47 +01:00
|
|
|
}
|
2004-03-15 21:26:42 +01:00
|
|
|
|
|
|
|
DeleteDC(hMemoryDC);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Draws a card at position x, y in its default size (as returned by
|
|
|
|
* cdtInit.
|
|
|
|
*
|
2004-03-16 20:13:47 +01:00
|
|
|
* Mode controls how the card gets drawn:
|
|
|
|
* MODE_FACEUP ; draw card facing up
|
|
|
|
* MODE_FACEDOWN ; draw card facing down
|
|
|
|
* MODE_HILITE ; draw face up, with NOTSRCCOPY
|
|
|
|
* MODE_GHOST ; draw 'ghost' card
|
|
|
|
* MODE_REMOVE ; draw with background color
|
2004-03-29 22:26:21 +02:00
|
|
|
* MODE_INVISIBLEGHOST ; draw 'ghost' card, without clearing background
|
2004-03-16 20:13:47 +01:00
|
|
|
* MODE_DECKX ; draw X
|
|
|
|
* MODE_DECKO ; draw O
|
2004-03-15 21:26:42 +01:00
|
|
|
*
|
|
|
|
* The card parameter defines the card graphic to be drawn. If we are
|
|
|
|
* drawing fronts of cards, card should have a value from 0 through 51
|
|
|
|
* to represent the card face. If we are drawing card backs, 53 through
|
|
|
|
* 68 represent different card backs.
|
|
|
|
*
|
|
|
|
* When drawing card faces, two lowest bits represent the card suit
|
|
|
|
* (clubs, diamonds, hearts, spades), and the bits above that define the
|
|
|
|
* card value (ace, 2, ..., king). That is,
|
|
|
|
* card = face * 4 + suit.
|
|
|
|
*
|
|
|
|
* Color parameter defines the background color, used when drawing some
|
|
|
|
* card backs.
|
|
|
|
*/
|
2004-03-16 20:13:47 +01:00
|
|
|
BOOL WINAPI cdtDraw(HDC hdc, int x, int y, int card, int mode, DWORD color)
|
2004-03-15 21:26:42 +01:00
|
|
|
{
|
2022-02-09 09:25:13 +01:00
|
|
|
TRACE("(%p, %d, %d, %d, %d, %ld)\n", hdc, x, y, card, mode, color);
|
2004-03-15 21:26:42 +01:00
|
|
|
|
2004-03-16 20:13:47 +01:00
|
|
|
return cdtDrawExt(hdc, x, y, cardWidth, cardHeight, card, mode, color);
|
2004-03-15 21:26:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Animates the card backs, e.g. blinking lights on the robot, the sun
|
|
|
|
* donning sunglasses, bats flying across the caste, etc.. Works only
|
|
|
|
* for cards of normal size (as drawn with cdtDraw). To draw frames of
|
|
|
|
* the card back animation, start with frame = 0, and increment the
|
|
|
|
* frame by one, until cdtAnimate returns FALSE (to indicate that we
|
|
|
|
* have gone through all frames of animation).
|
|
|
|
*/
|
|
|
|
BOOL WINAPI cdtAnimate(HDC hdc, int cardback, int x, int y, int frame)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %d, %d, %d)\n", hdc, cardback, x, y, frame);
|
2004-03-23 02:20:44 +01:00
|
|
|
FIXME("Implement me.\n");
|
2004-03-15 21:26:42 +01:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2011-01-01 14:34:30 +01:00
|
|
|
* Frees resources reserved by cdtInit.
|
2004-03-15 21:26:42 +01:00
|
|
|
*/
|
2007-08-29 21:42:28 +02:00
|
|
|
void WINAPI cdtTerm(void)
|
2004-03-15 21:26:42 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
for(i = 0; i <= CARD_MAX; i++)
|
|
|
|
{
|
|
|
|
if(cardBitmaps[i] != 0)
|
|
|
|
DeleteObject(cardBitmaps[i]);
|
|
|
|
cardBitmaps[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllMain.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
hInst = inst;
|
|
|
|
DisableThreadLibraryCalls( inst );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|