ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cards.c
Go to the documentation of this file.
00001 /*
00002  *  ReactOS Cards
00003  *
00004  *  Copyright (C) 2003  Filip Navara <xnavara@volny.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <stdarg.h>
00022 
00023 #include "windows.h"
00024 #include "cards.h"
00025 
00026 HBITMAP g_CardBitmaps[MAX_CARD_BITMAPS];
00027 HINSTANCE g_hModule = 0;
00028 
00029 /*
00030  * Redundant function from 16-bit Windows time
00031  */
00032 BOOL WINAPI WEP(DWORD Unknown)
00033 {
00034     UNREFERENCED_PARAMETER(Unknown);
00035     return TRUE;
00036 }
00037 
00038 /*
00039  * Initialize card library and return cards width and height
00040  */
00041 BOOL WINAPI cdtInit(INT *Width, INT *Height)
00042 {
00043     DWORD dwIndex;
00044 
00045     /* Report card width and height to user */
00046     *Width = CARD_WIDTH;
00047     *Height = CARD_HEIGHT;
00048 
00049     /* Load images */
00050     for (dwIndex = 0; dwIndex < MAX_CARD_BITMAPS; ++dwIndex)
00051         g_CardBitmaps[dwIndex] =
00052             (HBITMAP)LoadBitmapA(g_hModule, MAKEINTRESOURCEA(dwIndex + 1));
00053 
00054     return TRUE;
00055 }
00056 
00057 /*
00058  * Terminate card library
00059  */
00060 VOID WINAPI cdtTerm(VOID)
00061 {
00062     DWORD dwIndex;
00063 
00064     /* Unload images */
00065     for (dwIndex = 0; dwIndex < MAX_CARD_BITMAPS; dwIndex++)
00066         DeleteObject(g_CardBitmaps[dwIndex]);
00067 }
00068 
00069 /*
00070  * Render card with no stretching
00071  */
00072 BOOL WINAPI cdtDraw(HDC hdc, INT x, INT y, INT card, INT type, COLORREF color)
00073 {
00074     return cdtDrawExt(hdc, x, y, CARD_WIDTH, CARD_HEIGHT, card, type, color);
00075 }
00076 
00077 /*
00078  * internal
00079  */
00080 static __inline VOID BltCard(HDC hdc, INT x, INT y, INT dx, INT dy, HDC hdcCard, DWORD dwRasterOp, BOOL bStretch)
00081 {
00082     if (bStretch)
00083     {
00084         StretchBlt(hdc, x, y, dx, dy, hdcCard, 0, 0, CARD_WIDTH, CARD_HEIGHT, dwRasterOp);
00085     } else
00086     {
00087         BitBlt(hdc, x, y, dx, dy, hdcCard, 0, 0, dwRasterOp);
00088 /*
00089  * This is need when using Microsoft images, because they use two-color red/white images for
00090  * red cards and thus needs fix-up of the edge to black color.
00091  */
00092 #if 0
00093         if (ISREDCARD(card))
00094         {
00095             PatBlt(hdc, x, y + 2, 1, dy - 4, BLACKNESS);
00096             PatBlt(hdc, x + dx - 1, y + 2, 1, dy - 4, BLACKNESS);
00097             PatBlt(hdc, x + 2, y, dx - 4, 1, BLACKNESS);
00098             PatBlt(hdc, x + 2, y + dy - 1, dx - 4, 1, BLACKNESS);
00099             SetPixel(hdc, x + 1, y + 1, 0);
00100             SetPixel(hdc, x + dx - 2, y + 1, 0);
00101             SetPixel(hdc, x + 1, y + dy - 2, 0);
00102             SetPixel(hdc, x + dx - 2, y + dy - 2, 0);
00103         }
00104 #endif
00105     }
00106 }
00107 
00108 /*
00109  * Render card
00110  *
00111  * Parameters:
00112  *    hdc - Handle of destination device context
00113  *    x - Position left
00114  *    y - Position right
00115  *    dx - Destination width
00116  *    dy - Destination height
00117  *    card - Image id (meaning depend on type)
00118  *    type - One of edt* constants
00119  *    color - Background color (?)
00120  */
00121 BOOL WINAPI cdtDrawExt(HDC hdc, INT x, INT y, INT dx, INT dy, INT card, INT type, COLORREF color)
00122 {
00123     HDC hdcCard;
00124     DWORD dwRasterOp = SRCCOPY, OldBkColor;
00125     BOOL bSaveEdges = TRUE;
00126     BOOL bStretch = FALSE;
00127 
00128     if (type & ectSAVEEDGESMASK)
00129     {
00130         type &= ~ectSAVEEDGESMASK;
00131         bSaveEdges = FALSE;
00132     }
00133 
00134     if (dx != CARD_WIDTH || dy != CARD_HEIGHT)
00135     {
00136         bStretch = TRUE;
00137         bSaveEdges = FALSE;
00138     }
00139 
00140     switch (type)
00141     {
00142         case ectINVERTED:
00143             dwRasterOp = NOTSRCCOPY;
00144         case ectFACES:
00145             card = (card % 4) * 13 + (card / 4);
00146             break;
00147         case ectBACKS:
00148             --card;
00149             break;
00150         case ectEMPTYNOBG:
00151             dwRasterOp = SRCAND;
00152         case ectEMPTY:
00153             card = 52;
00154             break;
00155         case ectERASE:
00156             break;
00157         case ectREDX:
00158             card = 66;
00159             break;
00160         case ectGREENO:
00161             card = 67;
00162             break;
00163         default:
00164             return FALSE;
00165     }
00166 
00167     if (type == ectEMPTY || type == ectERASE)
00168     {
00169         POINT pPoint;
00170         HBRUSH hBrush;
00171 
00172         hBrush = CreateSolidBrush(color);
00173         GetDCOrgEx(hdc, &pPoint);
00174         SetBrushOrgEx(hdc, pPoint.x, pPoint.y, 0);
00175         SelectObject(hdc, hBrush);
00176         PatBlt(hdc, x, y, dx, dy, PATCOPY);
00177     }
00178     if (type != ectERASE)
00179     {
00180         hdcCard = CreateCompatibleDC(hdc);
00181         SelectObject(hdcCard, g_CardBitmaps[card]);
00182         OldBkColor = SetBkColor(hdc, (type == ectFACES) ? 0xFFFFFF : color);
00183         if (bSaveEdges)
00184         {
00185             COLORREF SavedPixels[12];
00186             SavedPixels[0] = GetPixel(hdc, x, y);
00187             SavedPixels[1] = GetPixel(hdc, x + 1, y);
00188             SavedPixels[2] = GetPixel(hdc, x, y + 1);
00189             SavedPixels[3] = GetPixel(hdc, x + dx - 1, y);
00190             SavedPixels[4] = GetPixel(hdc, x + dx - 2, y);
00191             SavedPixels[5] = GetPixel(hdc, x + dx - 1, y + 1);
00192             SavedPixels[6] = GetPixel(hdc, x, y + dy - 1);
00193             SavedPixels[7] = GetPixel(hdc, x + 1, y + dy - 1);
00194             SavedPixels[8] = GetPixel(hdc, x, y + dy - 2);
00195             SavedPixels[9] = GetPixel(hdc, x + dx - 1, y + dy - 1);
00196             SavedPixels[10] = GetPixel(hdc, x + dx - 2, y + dy - 1);
00197             SavedPixels[11] = GetPixel(hdc, x + dx - 1, y + dy - 2);
00198 
00199             BltCard(hdc, x, y, dx, dy, hdcCard, dwRasterOp, bStretch);
00200 
00201             SetPixel(hdc, x, y, SavedPixels[0]);
00202             SetPixel(hdc, x + 1, y, SavedPixels[1]);
00203             SetPixel(hdc, x, y + 1, SavedPixels[2]);
00204             SetPixel(hdc, x + dx - 1, y, SavedPixels[3]);
00205             SetPixel(hdc, x + dx - 2, y, SavedPixels[4]);
00206             SetPixel(hdc, x + dx - 1, y + 1, SavedPixels[5]);
00207             SetPixel(hdc, x, y + dy - 1, SavedPixels[6]);
00208             SetPixel(hdc, x + 1, y + dy - 1, SavedPixels[7]);
00209             SetPixel(hdc, x, y + dy - 2, SavedPixels[8]);
00210             SetPixel(hdc, x + dx - 1, y + dy - 1, SavedPixels[9]);
00211             SetPixel(hdc, x + dx - 2, y + dy - 1, SavedPixels[10]);
00212             SetPixel(hdc, x + dx - 1, y + dy - 2, SavedPixels[11]);
00213         }
00214         else
00215         {
00216             BltCard(hdc, x, y, dx, dy, hdcCard, dwRasterOp, bStretch);
00217         }
00218         SetBkColor(hdc, OldBkColor);
00219         DeleteDC(hdcCard);
00220     }
00221 
00222     return TRUE;
00223 }
00224 
00225 
00226 /***********************************************************************
00227  *             cdtAnimate   (CARDS.@)
00228  *
00229  * Animate card background, we don't use it
00230  */
00231 BOOL WINAPI cdtAnimate(HDC hdc, int cardback, int x, int y, int frame)
00232 {
00233     UNREFERENCED_PARAMETER(frame);
00234     UNREFERENCED_PARAMETER(y);
00235     UNREFERENCED_PARAMETER(x);
00236     UNREFERENCED_PARAMETER(cardback);
00237     UNREFERENCED_PARAMETER(hdc);
00238     return TRUE;
00239 }
00240 
00241 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
00242 {
00243     UNREFERENCED_PARAMETER(lpvReserved);
00244     if (fdwReason == DLL_PROCESS_ATTACH)
00245         g_hModule = hinstDLL;
00246 
00247     return TRUE;
00248 }

Generated on Sun May 27 2012 04:22:57 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.