00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BitmapUtil_h
00009 #define BitmapUtil_h
00010
00011 #pragma warning( disable : 4786 )
00012
00013 #include "StdAfx.h"
00014 #include "DIBAPI.h"
00015 #include <vector>
00016
00017 namespace DecoratorSDK
00018 {
00019
00020
00021
00022
00023
00024
00025
00026 const unsigned int MF_NOOP = 0;
00027 const unsigned int MF_GREYED = 1;
00028 const unsigned int MF_TRANSPARENT = 2;
00029
00030
00031
00032
00033
00034
00035
00036 enum ECoordRefPoint
00037 {
00038 CRP_BEGIN = -1 ,
00039 CRP_CENTER = 0 ,
00040 CRP_END = 1
00041 };
00042
00043
00044
00045
00046
00047
00048
00049 class RefCoord
00050 {
00051 private :
00052 ECoordRefPoint m_eType;
00053 long m_lPos;
00054
00055 public :
00056 RefCoord();
00057 RefCoord( ECoordRefPoint eType, long lPos );
00058 RefCoord( const RefCoord& rc );
00059 RefCoord& operator=( const RefCoord& rc );
00060
00061 ECoordRefPoint getRef() const;
00062 long getPos() const;
00063
00064 long calcPos( long lLength );
00065 };
00066
00067
00068
00069
00070
00071
00072
00073 class RefPoint
00074 {
00075 private :
00076 RefCoord m_rcX;
00077 RefCoord m_rcY;
00078
00079 public :
00080 RefPoint();
00081 RefPoint( const RefCoord& rcX, const RefCoord& rcY );
00082 RefPoint( const RefPoint& rp );
00083 RefPoint& operator=( const RefPoint rp );
00084
00085 RefCoord getX() const;
00086 RefCoord getY() const;
00087
00088 CPoint calcPoint( long lWidth, long lHeight );
00089 };
00090
00091
00092
00093
00094
00095
00096
00097 enum EFillType
00098 {
00099 FT_NONE = 0,
00100 FT_STRETCH,
00101 FT_TILE
00102 };
00103
00104
00105
00106
00107
00108
00109
00110 class BackgroundTile
00111 {
00112 private :
00113 RefPoint m_rpPartTopLeft;
00114 RefPoint m_rpPartBottomRight;
00115 RefPoint m_rpTopLeft;
00116 RefPoint m_rpBottomRight;
00117 EFillType m_eFillVertical;
00118 EFillType m_eFillHorizontal;
00119
00120 public :
00121 BackgroundTile();
00122 BackgroundTile( const RefPoint& rpPTL, const RefPoint& rpPBR, const RefPoint& rpTL, const RefPoint& rpBR, EFillType eFH, EFillType eFV );
00123 BackgroundTile( const BackgroundTile& bt );
00124 BackgroundTile& operator=( const BackgroundTile& bt );
00125
00126 RefPoint getPartTopLeft() const;
00127 RefPoint getPartBottomRight() const;
00128 RefPoint getTopLeft() const;
00129 RefPoint getBottomRight() const;
00130 EFillType getHorizontalFill() const;
00131 EFillType getVerticalFill() const;
00132 };
00133
00134 typedef std::vector<BackgroundTile> TileVector;
00135
00136
00137
00138
00139
00140
00141
00142 class BitmapBase
00143 {
00144 protected :
00145 bool m_bHasTransparentColor;
00146 COLORREF m_crTransparentColor;
00147 bool m_bHasBackgroundColor;
00148 COLORREF m_crBackgroundColor;
00149 bool m_bHasGrayedColor;
00150 COLORREF m_crGrayedColor;
00151 long m_lWidth;
00152 long m_lHeight;
00153 CString m_strName;
00154
00155 protected :
00156 BitmapBase( const CString& strName );
00157 BitmapBase( const CString& strName, COLORREF crColor, bool bIsTransparent );
00158 BitmapBase( const CString& strName, COLORREF crTransparentColor, COLORREF crBackgroundColor );
00159 BitmapBase( const CString& strName, COLORREF crTransparentColor, COLORREF crGrayedColor, bool isMasked );
00160
00161 public :
00162 virtual ~BitmapBase();
00163
00164 CString getName() const;
00165 virtual long getWidth() const;
00166 virtual long getHeight() const;
00167 virtual bool isInitialized() const = 0;
00168
00169 bool hasTransparentColor() const;
00170 bool hasBackgroundColor() const;
00171 COLORREF getTransparentColor() const;
00172 COLORREF getBackgroundColor() const;
00173
00174 virtual void draw( Gdiplus::Graphics* gdip, CDC* pDC, const CRect& srcRect, const CRect& dstRect,
00175 DWORD dwOpCode, DWORD dwModifierFlags = MF_NOOP ) const = 0;
00176 void draw( Gdiplus::Graphics* gdip, CDC* pDC, const CRect& cRect, const TileVector& vecTiles,
00177 DWORD dwModifierFlags = MF_NOOP ) const;
00178
00179 protected :
00180 void setSize( long lWidth, long lHeight );
00181 void setName( const CString& strName );
00182 Gdiplus::ColorMatrix GetGreyFadeMatrix(COLORREF greyColor) const;
00183 };
00184
00185
00186
00187
00188
00189
00190
00191 class BitmapDIB
00192 : public BitmapBase
00193 {
00194 private :
00195 HDIB m_hDIB;
00196
00197 public :
00198 BitmapDIB( const CString& strName );
00199 BitmapDIB( const CString& strName, COLORREF crColor, bool bIsTransparent );
00200 BitmapDIB( const CString& strName, COLORREF crTransparentColor, COLORREF crBackgroundColor );
00201 virtual ~BitmapDIB();
00202
00203 public :
00204 virtual bool isInitialized() const;
00205 virtual void draw( Gdiplus::Graphics* gdip, CDC* pDC, const CRect& srcRect, const CRect& dstRect,
00206 DWORD dwOpCode, DWORD dwModifierFlags = MF_NOOP ) const;
00207
00208 private :
00209 HBITMAP DIBToBitmap(HDIB hDIB, HPALETTE hPal = NULL);
00210 void load( const CString& strName );
00211 };
00212
00213
00214
00215
00216
00217
00218
00219 class BitmapMasked
00220 : public BitmapBase
00221 {
00222 private :
00223 LPBYTE m_pBits;
00224 LPBITMAPINFO m_pBMI;
00225 CPalette* m_pPalette;
00226
00227 public :
00228 BitmapMasked( const CString& strName, COLORREF crTransparentColor, COLORREF crGrayColor );
00229 BitmapMasked( UINT nResID, COLORREF crTransparentColor, COLORREF crGrayColor );
00230 virtual ~BitmapMasked();
00231
00232 public :
00233 virtual bool isInitialized() const;
00234 virtual void draw( Gdiplus::Graphics* gdip, CDC* pDC, const CRect& srcRect, const CRect& dstRect,
00235 DWORD dwOpCode, DWORD dwModifierFlags = MF_NOOP ) const;
00236
00237 virtual long getWidth() const;
00238 virtual long getHeight() const;
00239 private :
00240 DWORD Read(CFile& file, BOOL bFromResource = FALSE );
00241 DWORD ReadFromResource(UINT nResID);
00242 WORD NumColors( BITMAPINFOHEADER& bmiHeader ) const;
00243 void Free();
00244 BOOL CreatePalette();
00245 void drawTransparent (Gdiplus::Graphics* gdip, CDC* pDC, const CRect& srcRect, const CRect &dstRect,
00246 COLORREF clrTransparency, bool bGray, COLORREF grayColor) const;
00247 void draw (Gdiplus::Graphics* gdip, CDC* pDC, const CRect& srcRect, const CRect &dstRect,
00248 bool bGray, COLORREF grayColor) const;
00249 };
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 class BitmapGen
00260 : public BitmapBase
00261 {
00262 private :
00263 Gdiplus::Image* m_pImage;
00264
00265 public :
00266 BitmapGen( const CString& strName );
00267 BitmapGen( const CString& strName, COLORREF crColor, bool bIsTransparent );
00268 BitmapGen( const CString& strName, COLORREF crTransparentColor, COLORREF crBackgroundColor );
00269 ~BitmapGen();
00270
00271 public :
00272 virtual bool isInitialized() const;
00273 virtual void draw( Gdiplus::Graphics* gdip, CDC* pDC, const CRect& srcRect, const CRect& dstRect,
00274 DWORD dwOpCode, DWORD dwModifierFlags = MF_NOOP ) const;
00275
00276 private :
00277 void load( const CString& strName );
00278 };
00279
00280
00281
00282
00283
00284
00285
00286 class BitmapRES
00287 : public BitmapBase
00288 {
00289 private :
00290 Gdiplus::Bitmap* m_pBitmap;
00291
00292 public :
00293 BitmapRES( UINT uiID );
00294 BitmapRES( UINT uiID, COLORREF crColor, bool bIsTransparent );
00295 BitmapRES( UINT uiID, COLORREF crTransparentColor, COLORREF crBackgroundColor );
00296 ~BitmapRES();
00297
00298 public :
00299 virtual bool isInitialized() const;
00300 virtual void draw( Gdiplus::Graphics* gdip, CDC* pDC, const CRect& srcRect, const CRect& dstRect,
00301 DWORD dwOpCode, DWORD dwModifierFlags = MF_NOOP ) const;
00302
00303 private :
00304 void load( UINT uiID );
00305 };
00306
00307 };
00308
00309 #endif // BitmapUtil_h