/** * @file XTPSkinImage.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPSKINIMAGE_H__) # define __XTPSKINIMAGE_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPSkinManagerResourceFile; /** * @brief * The CXTPSkinImage class represents a simple bitmap holder and * draw operations for Skin Framework. */ class _XTP_EXT_CLASS CXTPSkinImage : public CXTPSynchronized { private: struct SOLIDRECT { RECT rc; COLORREF clr; }; public: /** * @brief * Constructs a CXTPSkinImage object. */ CXTPSkinImage(); /** * @brief * Destroys a CXTPSkinImage object, handles cleanup and deallocation. */ virtual ~CXTPSkinImage(); public: /** * @brief * Loads a specified bitmap from a .dll using its name identifier. * @param lpszFileName File name on disk to load. * @return * TRUE if successful, otherwise FALSE. */ BOOL LoadFile(LPCTSTR lpszFileName); /** * @brief * Loads a specified bitmap from a .dll using its name identifier. * @param hModule Module handle. * @param lpszBitmapFileName Bitmap file name. * @return * TRUE if successful, otherwise FALSE. */ BOOL LoadFile(HMODULE hModule, LPCTSTR lpszBitmapFileName); /** * @brief * Assigns a bitmap handle to the CXTPSkinImage class. * @param hBitmap Bitmap handle. * @param bAlpha TRUE if the bitmap contains alpha pixels. */ void SetBitmap(HBITMAP hBitmap, BOOL bAlpha = FALSE); /** * @brief * Draws the image in a specified location. * @param pDC Destination device context. * @param rcDest Reference to the location of the destination rectangle. * @param rcSrc Reference to the location of the source rectangle. * @param rcSizingMargins Reference to sizing margins. * @param nSizingType Stretch type. * @param bBorderOnly TRUE to only draw borders. */ void DrawImage(CDC* pDC, const CRect& rcDest, const CRect& rcSrc, const CRect& rcSizingMargins, int nSizingType, BOOL bBorderOnly); /** * @brief * Draws the image in a specified location. * @param pDC Destination device context. * @param rcDest Reference to the location of the destination rectangle. * @param rcSrc Reference to the location of the source rectangle. * @param rcSizingMargins Reference to sizing margins. * @param nSizingType Stretch type. * @param bBorderOnly TRUE to only draw borders. * @param clrTransparent Transparent color. */ void DrawImage(CDC* pDC, const CRect& rcDest, const CRect& rcSrc, const CRect& rcSizingMargins, COLORREF clrTransparent, int nSizingType, BOOL bBorderOnly); /** * @brief * Gets the height of the bitmap. * @return * The height of the bitmap. */ DWORD GetHeight() const; /** * @brief * Gets the width of the bitmap. * @return * The width of the bitmap. */ DWORD GetWidth() const; /** * @brief * Gets the extent of the bitmap. * @return * The extent of the bitmap. */ CSize GetExtent() const; /** * @brief * Determines if the bitmap has alpha pixels. * @return * TRUE if the bitmap has alpha pixels, otherwise FALSE. */ BOOL IsAlphaImage() const; /** * @brief * Calculates the position of a specified image. * @param nState Index of the image. * @param nCount Total image count. * @return * The position of the specified image. */ CRect GetSource(int nState = 0, int nCount = 1) const; /** * @brief * Helper method that splits an image into solid rectangles for faster drawing. * @param nBitmaps Image identifier. * @param bHorizontalImage TRUE if the images are arranged horizontally. * @param rcSizingMargins Reference to sizing margins. */ void CreateSolidRectArray(int nBitmaps, BOOL bHorizontalImage, const CRect& rcSizingMargins); private: void DrawImageInternal(CDC* pDC, const CRect& rcDest, const CRect& rcSrc, const CRect& rcSizingMargins, int nSizingType, BOOL bBorderOnly, COLORREF clrTransparent = COLORREF_NULL); BOOL DrawImagePart(CDC* pDCDest, const CRect& rcDest, CDC* pDCSrc, const CRect& rcSrc) const; BOOL DrawImageTile(CDC* pDCDest, const CRect& rcDest, CDC* pDCSrc, const CRect& rcSrc, BOOL bTile, COLORREF clrTransparent = COLORREF_NULL) const; void FilterImage(COLORREF clrTransparent); void InvertBitmap(); BOOL FindSolidRect(const CRect& rcSrc, SOLIDRECT& sr) const; CSize _GetExtent() const; BOOL CheckBitmapRect(LPBYTE pBits, CRect rcCheck, CSize sz, SOLIDRECT& sr); public: BOOL m_bMirrorImage; /**< TRUE to invert image in RTL mode. */ protected: HBITMAP m_hBitmap; /**< Bitmap handle. */ BOOL m_bAlpha; /**< TRUE if the bitmap has alpha pixels. */ BOOL m_bFiltered; /**< TRUE if the image is filtered. */ BOOL m_bInvert; /**< TRUE if the image is inverted for RTL mode. */ BOOL m_bOptimized; /**< TRUE if the image is split into solid rectangles. */ CSize m_szBitmap; /**< Bitmap size of the image. */ CArray m_arrSolidRects; /**< Solid rectangles of the image. */ }; /** * @brief * CXTPSkinImages represents a cached collection of CXTPSkinImage classes. */ class _XTP_EXT_CLASS CXTPSkinImages : public CXTPSynchronized { public: /** * @brief * Constructs a CXTPSkinImages object. */ CXTPSkinImages(); /** * @brief * Destroys a CXTPSkinImages object, handles cleanup and deallocation. */ ~CXTPSkinImages(); public: /** * @brief * Removes all images from the collection. */ void RemoveAll(); /** * @brief * Loads a specified image from a resource file. * @param pResourceFile Pointer to the resource file. * @param lpszImageFile Path to the image. * @return * A pointer to the newly loaded CXTPSkinImage object if successful, * otherwise NULL. */ CXTPSkinImage* LoadFile(CXTPSkinManagerResourceFile* pResourceFile, LPCTSTR lpszImageFile); /** * @brief * Gets the extent of a specified image located within a resource file. * @param pResourceFile Pointer to the resource file. * @param lpszImageFile Path to the image. * @return * The extent of the image. */ CSize GetExtent(CXTPSkinManagerResourceFile* pResourceFile, LPCTSTR lpszImageFile); protected: CMapStringToPtr m_mapImages; /**< Collection of images. */ }; # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPSKINIMAGE_H__) /** @endcond */