// This is a part of the Microsoft Foundation Classes C++ library. // Copyright (C) Microsoft Corporation // All rights reserved. // // This source code is only intended as a supplement to the // Microsoft Foundation Classes Reference and related // electronic documentation provided with the library. // See these sources for detailed information regarding the // Microsoft Foundation Classes product. #pragma once #pragma warning(push) #pragma warning(disable:4458) // This header resets packing to the default packing; we must defend ourselves // against this. #pragma pack(push) #include #pragma pack(pop) #include #include #include #include #include #pragma warning(pop) #include <__atlmfc_core.h> #pragma warning(push) #pragma warning(disable : _ATLMFC_DISABLED_WARNINGS) class CRenderTarget; class CBitmapRenderTarget; class CHwndRenderTarget; #ifdef _AFX_PACKING #pragma pack(push, _AFX_PACKING) #endif #ifdef _AFX_MINREBUILD #pragma component(minrebuild, off) #endif /// /// D2D1_POINT_2F wrapper /// class CD2DPointF : public D2D1_POINT_2F { public: /// /// Constructs a CD2DPointF object from CPoint object. /// source point CD2DPointF(const CPoint& pt); /// /// Constructs a CD2DPointF object from D2D1_POINT_2F object. /// source point CD2DPointF(const D2D1_POINT_2F& pt); /// /// Constructs a CD2DPointF object from D2D1_POINT_2F object. /// source point CD2DPointF(const D2D1_POINT_2F* pt); /// /// Constructs a CD2DPointF object from two FLOAT values. /// source X /// source Y CD2DPointF(FLOAT fX = 0., FLOAT fY = 0.); /// /// Converts CD2DPointF to CPoint object. /// /// Current value of D2D point. /// operator CPoint() { return CPoint((LONG)x, (LONG)y); } }; /// /// D2D1_POINT_2U wrapper /// class CD2DPointU : public D2D1_POINT_2U { public: /// /// Constructs a CD2DPointU object from CPoint object. /// source point CD2DPointU(const CPoint& pt); /// /// Constructs a CD2DPointU from object D2D1_POINT_2U object. /// source point CD2DPointU(const D2D1_POINT_2U& pt); /// /// Constructs a CD2DPointU from object D2D1_POINT_2U object. /// source point CD2DPointU(const D2D1_POINT_2U* pt); /// /// Constructs a CD2DPointU object from two UINT32 values. /// source X /// source Y CD2DPointU(UINT32 uX = 0, UINT32 uY = 0); /// /// Converts CD2DPointU to CPoint object. /// /// Current value of D2D point. /// operator CPoint() { return CPoint((LONG)x, (LONG)y); } }; /// /// D2D1_SIZE_F wrapper /// class CD2DSizeF : public D2D1_SIZE_F { public: /// /// Constructs a CD2DSizeF object from CSize object. /// source size CD2DSizeF(const CSize& size); /// /// Constructs a CD2DSizeF object from D2D1_SIZE_F object. /// source size CD2DSizeF(const D2D1_SIZE_F& size); /// /// Constructs a CD2DSizeF object from D2D1_SIZE_F object. /// source size CD2DSizeF(const D2D1_SIZE_F* size); /// /// Constructs a CD2DSizeF object from two FLOAT values. /// source width /// source height CD2DSizeF(FLOAT cx = 0., FLOAT cy = 0.); /// /// Returns a Boolean value that indicates whether an expression contains no valid data (Null). /// /// TRUE if width and height are empty; otherwise FALSE. /// BOOL IsNull() const { return width == 0. && height == 0.; } /// /// Converts CD2DSizeF to CSize object. /// /// Current value of D2D size. /// operator CSize() { return CSize((LONG)width, (LONG)height); } }; /// /// D2D1_SIZE_U wrapper /// class CD2DSizeU : public D2D1_SIZE_U { public: /// /// Constructs a CD2DSizeU object from CSize object. /// source size CD2DSizeU(const CSize& size); /// /// Constructs a CD2DSizeU object from D2D1_SIZE_U object. /// source size CD2DSizeU(const D2D1_SIZE_U& size); /// /// Constructs a CD2DSizeU object from D2D1_SIZE_U object. /// source size CD2DSizeU(const D2D1_SIZE_U* size); /// /// Constructs a CD2DSizeU object from two UINT32 values. /// source width /// source height CD2DSizeU(UINT32 cx = 0, UINT32 cy = 0); /// /// Returns a Boolean value that indicates whether an expression contains no valid data (Null). /// /// TRUE if width and height are empty; otherwise FALSE. /// BOOL IsNull() const { return width == 0 && height == 0; } /// /// Converts CD2DSizeU to CSize object. /// /// Current value of D2D size. /// operator CSize() { return CSize((LONG)width, (LONG)height); } }; /// /// D2D1_RECT_F wrapper /// class CD2DRectF : public D2D1_RECT_F { public: /// /// Constructs a CD2DRectF object from CRect object. /// source rectangle CD2DRectF(const CRect& rect); /// /// Constructs a CD2DRectF object from D2D1_RECT_F object. /// source rectangle CD2DRectF(const D2D1_RECT_F& rect); /// /// Constructs a CD2DRectF object from D2D1_RECT_F object. /// source rectangle CD2DRectF(const D2D1_RECT_F* rect); /// /// Constructs a CD2DRectF object from four FLOAT values. /// source left coordinate /// source top coordinate /// source right coordinate /// source bottom coordinate CD2DRectF(FLOAT fLeft = 0., FLOAT fTop = 0., FLOAT fRight = 0., FLOAT fBottom = 0.); /// /// Returns a Boolean value that indicates whether an expression contains no valid data (Null). /// /// TRUE if rectangle's top, left, bottom, and right values are all equal to 0; otherwise FALSE. /// BOOL IsNull() const { return left == 0. && right == 0. && top == 0. && bottom == 0.; } /// /// Converts CD2DRectF to CRect object. /// /// Current value of D2D rectangle. /// operator CRect() { return CRect((LONG)left, (LONG)top, (LONG)right, (LONG)bottom); } }; /// /// D2D1_RECT_U wrapper /// class CD2DRectU : public D2D1_RECT_U { public: /// /// Constructs a CD2DRectU object from CRect object. /// source rectangle CD2DRectU(const CRect& rect); /// /// Constructs a CD2DRectU object from D2D1_RECT_U object. /// source rectangle CD2DRectU(const D2D1_RECT_U& rect); /// /// Constructs a CD2DRectU object from D2D1_RECT_U object. /// source rectangle CD2DRectU(const D2D1_RECT_U* rect); /// /// Constructs a CD2DRectU object from four UINT32 values. /// source left coordinate /// source top coordinate /// source right coordinate /// source bottom coordinate CD2DRectU(UINT32 uLeft = 0, UINT32 uTop = 0, UINT32 uRight = 0, UINT32 uBottom = 0); /// /// Returns a Boolean value that indicates whether an expression contains no valid data (Null). /// /// TRUE if rectangle's top, left, bottom, and right values are all equal to 0; otherwise FALSE. /// BOOL IsNull() const { return left == 0 && right == 0 && top == 0 && bottom == 0; } /// /// Converts CD2DRectU to CRect object. /// /// Current value of D2D rectangle. /// operator CRect() { return CRect((LONG)left, (LONG)top, (LONG)right, (LONG)bottom); } }; /// /// D2D1_ROUNDED_RECT wrapper /// class CD2DRoundedRect : public D2D1_ROUNDED_RECT { public: /// /// Constructs a CD2DRoundedRect object from CD2DRectF object. /// source rectangle /// radius size CD2DRoundedRect(const CD2DRectF& rectIn, const CD2DSizeF& sizeRadius); /// /// Constructs a CD2DRoundedRect object from D2D1_ROUNDED_RECT object. /// source rectangle CD2DRoundedRect(const D2D1_ROUNDED_RECT& rectIn); /// /// Constructs a CD2DRoundedRect object from D2D1_ROUNDED_RECT object. /// source rectangle CD2DRoundedRect(const D2D1_ROUNDED_RECT* rectIn); }; /// /// D2D1_ELLIPSE wrapper /// class CD2DEllipse : public D2D1_ELLIPSE { public: /// /// Constructs a CD2DEllipse object from CD2DRectF object. /// source rectangle CD2DEllipse(const CD2DRectF& rect); /// /// Constructs a CD2DEllipse object from D2D1_ELLIPSE object. /// source ellipse CD2DEllipse(const D2D1_ELLIPSE& ellipse); /// /// Constructs a CD2DEllipse object from D2D1_ELLIPSE object. /// source ellipse CD2DEllipse(const D2D1_ELLIPSE* ellipse); /// /// Constructs a CD2DEllipse from CD2DPointF and CD2DSizeF objects. /// The center point of the ellipse. /// The X-radius and Y-radius of the ellipse. CD2DEllipse(const CD2DPointF& ptCenter, const CD2DSizeF& sizeRadius); }; /// /// An abstract class, which provides a interface for creating and managing D2D resources such as brushes, layers and texts. /// class CD2DResource : public CObject { DECLARE_DYNAMIC(CD2DResource) friend class CRenderTarget; friend class CHwndRenderTarget; protected: /// /// Constructs a CD2DResource object. /// A pointer to the render target. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DResource(CRenderTarget* pParentTarget, BOOL bAutoDestroy); /// /// The destructor. Called when a D2D resource object is being destroyed. /// virtual ~CD2DResource(); /// /// Check auto destroy flag. /// /// TRUE if the object will be destroyed by its owner; otherwise FALSE. BOOL IsAutoDestroy() const { return m_bIsAutoDestroy; } /// /// Re-creates a CD2DResource. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. virtual HRESULT ReCreate(CRenderTarget* pRenderTarget); public: /// /// Creates a CD2DResource. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. virtual HRESULT Create(CRenderTarget* pRenderTarget) = 0; /// /// Destroys a CD2DResource object. virtual void Destroy() = 0; /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. virtual BOOL IsValid() const = 0; protected: /// /// Resource will be destroyed by owner (CRenderTarget) BOOL m_bIsAutoDestroy; /// /// Pointer to the parent CRenderTarget) CRenderTarget* m_pParentTarget; }; /// /// ID2D1Layer wrapper. /// class CD2DLayer : public CD2DResource { DECLARE_DYNAMIC(CD2DLayer) public: /// /// Constructs a CD2DLayer object. /// A pointer to the render target. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DLayer(CRenderTarget* pParentTarget, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D layer object is being destroyed. /// virtual ~CD2DLayer(); /// /// Returns the size of the render target in device-independent pixels /// /// The current size of the render target in device-independent pixels CD2DSizeF GetSize() const; /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const override { return m_pLayer != NULL; } /// /// Returns ID2D1Layer interface /// /// Pointer to an ID2D1Layer interface or NULL if object is not initialized yet. ID2D1Layer* Get() { return m_pLayer; } /// /// Returns ID2D1Layer interface /// /// Pointer to an ID2D1Layer interface or NULL if object is not initialized yet. operator ID2D1Layer* () { return m_pLayer; } /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1Layer* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1Layer* Detach(); public: /// /// Creates a CD2DLayer. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DLayer object. void Destroy() override; protected: /// /// Stores a pointer to an ID2D1Layer object. /// ID2D1Layer* m_pLayer; }; /// /// ID2D1Bitmap wrapper. /// class CD2DBitmap : public CD2DResource { DECLARE_DYNAMIC(CD2DBitmap) friend class CRenderTarget; friend class CD2DBitmapBrush; friend class CBitmapRenderTarget; public: /// /// Constructs a CD2DBitmap object from resource. /// A pointer to the render target. /// The resource ID number of the resource. /// Pointer to a null-terminated string that contains the resource type. /// Destination size of the bitmap. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBitmap(CRenderTarget* pParentTarget, UINT uiResID, LPCTSTR lpszType = NULL, CD2DSizeU sizeDest = CD2DSizeU(0, 0), BOOL bAutoDestroy = TRUE); /// /// Constructs a CD2DBitmap object from file. /// A pointer to the render target. /// Pointer to a null-terminated string that contains the name of file. /// Destination size of the bitmap. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBitmap(CRenderTarget* pParentTarget, LPCTSTR lpszPath, CD2DSizeU sizeDest = CD2DSizeU(0, 0), BOOL bAutoDestroy = TRUE); /// /// Constructs a CD2DBitmap object from HBITMAP. /// A pointer to the render target. /// Handle to the bitmap. /// Destination size of the bitmap. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBitmap(CRenderTarget* pParentTarget, HBITMAP hbmpSrc, CD2DSizeU sizeDest = CD2DSizeU(0, 0), BOOL bAutoDestroy = TRUE); protected: /// /// Constructs a CD2DBitmap object. /// A pointer to the render target. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBitmap(CRenderTarget* pParentTarget, BOOL bAutoDestroy = TRUE); public: /// /// The destructor. Called when a D2D bitmap object is being destroyed. /// virtual ~CD2DBitmap(); /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1Bitmap* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1Bitmap* Detach(); /// /// Returns the size, in device-independent pixels (DIPs), of the bitmap /// /// The size, in DIPs, of the bitmap. CD2DSizeF GetSize() const; /// /// Returns the size, in device-dependent units (pixels), of the bitmap /// /// The size, in pixels, of the bitmap.. CD2DSizeU GetPixelSize() const; /// /// Retrieves the pixel format and alpha mode of the bitmap /// /// The pixel format and alpha mode of the bitmap. D2D1_PIXEL_FORMAT GetPixelFormat() const; /// /// Return the dots per inch (DPI) of the bitmap /// /// The horizontal and vertical DPI of the bitmap. CD2DSizeF GetDPI() const; /// /// Copies the specified region from the specified bitmap into the current bitmap /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// The bitmap to copy from /// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied /// The area of bitmap to copy HRESULT CopyFromBitmap(const CD2DBitmap* pBitmap, const CD2DPointU* destPoint = NULL, const CD2DRectU* srcRect = NULL); /// /// Copies the specified region from the specified render target into the current bitmap /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// The render target that contains the region to copy /// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied /// The area of renderTarget to copy HRESULT CopyFromRenderTarget(const CRenderTarget* pRenderTarget, const CD2DPointU* destPoint = NULL, const CD2DRectU* srcRect = NULL); /// /// Copies the specified region from memory into the current bitmap /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// The data to copy /// The stride, or pitch, of the source bitmap stored in srcData. The stride is the byte count of a scanline (one row of pixels in memory). The stride can be computed from the following formula: pixel width * bytes per pixel + memory padding /// In the current bitmap, the upper-left corner of the area to which the region specified by srcRect is copied HRESULT CopyFromMemory(const void *srcData, UINT32 pitch, const CD2DRectU* destRect = NULL); /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const override { return m_pBitmap != NULL; } /// /// Returns ID2D1Bitmap interface /// /// Pointer to an ID2D1Bitmap interface or NULL if object is not initialized yet. ID2D1Bitmap* Get() { return m_pBitmap; } /// /// Returns ID2D1Bitmap interface /// /// Pointer to an ID2D1Bitmap interface or NULL if object is not initialized yet. operator ID2D1Bitmap*() { return m_pBitmap; } protected: /// /// Initializes the object void CommonInit(); public: /// /// Creates a CD2DBitmap. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DBitmap object. void Destroy() override; protected: /// /// Stores a pointer to an ID2D1Bitmap object. /// ID2D1Bitmap* m_pBitmap; /// /// Bitmap resource ID. /// UINT m_uiResID; /// /// Resource type. /// LPCTSTR m_lpszType; /// /// Bitmap file path. /// CString m_strPath; /// /// Bitmap destination size. /// CD2DSizeU m_sizeDest; /// /// Source bitmap handle. /// HBITMAP m_hBmpSrc; /// /// TRUE if m_hBmpSrc should be destroyed; otherwise FALSE. /// BOOL m_bAutoDestroyHBMP; }; /// /// D2D1_BRUSH_PROPERTIES wrapper. /// class CD2DBrushProperties : public D2D1_BRUSH_PROPERTIES { public: /// /// Creates a CD2D_BRUSH_PROPERTIES structure CD2DBrushProperties(); /// /// Creates a CD2D_BRUSH_PROPERTIES structure /// The base opacity of the brush. The default value is 1.0. CD2DBrushProperties(FLOAT _opacity); /// /// Creates a CD2D_BRUSH_PROPERTIES structure /// The transformation to apply to the brush /// The base opacity of the brush. The default value is 1.0. CD2DBrushProperties(D2D1_MATRIX_3X2_F _transform, FLOAT _opacity = 1.); protected: /// /// Initializes the object void CommonInit(); }; /// /// ID2D1Brush wrapper. /// class CD2DBrush : public CD2DResource { DECLARE_DYNAMIC(CD2DBrush) friend class CRenderTarget; protected: /// /// Constructs a CD2DBrush object. /// A pointer to the render target. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBrush(CRenderTarget* pParentTarget, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D brush object is being destroyed. /// virtual ~CD2DBrush(); public: /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1Brush* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1Brush* Detach(); /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const override { return m_pBrush != NULL; } /// /// Returns ID2D1Brush interface /// /// Pointer to an ID2D1Brush interface or NULL if object is not initialized yet. ID2D1Brush* Get() { return m_pBrush; } /// /// Returns ID2D1Brush interface /// /// Pointer to an ID2D1Brush interface or NULL if object is not initialized yet. operator ID2D1Brush*() { return m_pBrush; } public: /// /// Destroys a CD2DBrush object. void Destroy() override; /// /// Sets the degree of opacity of this brush /// A value between zero and 1 that indicates the opacity of the brush. This value is a constant multiplier that linearly scales the alpha value of all pixels filled by the brush. The opacity values are clamped in the range 0 to 1 before they are multiplied together void SetOpacity(FLOAT opacity); /// /// Gets the degree of opacity of this brush /// /// A value between zero and 1 that indicates the opacity of the brush. This value is a constant multiplier that linearly scales the alpha value of all pixels filled by the brush. The opacity values are clamped in the range 0 to 1 before they are multiplied together FLOAT GetOpacity() const; /// /// Applies the specified transform to the render target, replacing the existing transformation. All subsequent drawing operations occur in the transformed space /// The transform to apply to the render target void SetTransform(const D2D1_MATRIX_3X2_F *transform); /// /// Gets the current transform of the render target /// When this returns, contains the current transform of the render target. This parameter is passed uninitialized void GetTransform(D2D1_MATRIX_3X2_F *transform) const; protected: /// /// Stores a pointer to an ID2D1Brush object. /// ID2D1Brush* m_pBrush; /// /// Brush properties. /// CD2DBrushProperties* m_pBrushProperties; }; /// /// ID2D1SolidColorBrush wrapper. /// class CD2DSolidColorBrush : public CD2DBrush { DECLARE_DYNAMIC(CD2DSolidColorBrush) public: /// /// Constructs a CD2DSolidColorBrush object. /// A pointer to the render target. /// The red, green, blue, and alpha values of the brush's color. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DSolidColorBrush(CRenderTarget* pParentTarget, D2D1_COLOR_F color, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// Constructs a CD2DSolidColorBrush object. /// A pointer to the render target. /// The red, green, and blue values of the brush's color. /// The opacity of the brush's color. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DSolidColorBrush(CRenderTarget* pParentTarget, COLORREF color, int nAlpha = 255, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D solid brush object is being destroyed. /// virtual ~CD2DSolidColorBrush(); public: /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1SolidColorBrush* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1SolidColorBrush* Detach(); /// /// Returns ID2D1SolidColorBrush interface /// /// Pointer to an ID2D1SolidColorBrush interface or NULL if object is not initialized yet. ID2D1SolidColorBrush* Get() { return m_pSolidColorBrush; } /// /// Returns ID2D1SolidColorBrush interface /// /// Pointer to an ID2D1SolidColorBrush interface or NULL if object is not initialized yet. operator ID2D1SolidColorBrush*() { return m_pSolidColorBrush; } /// /// Specifies the color of this solid color brush /// The color of this solid color brush void SetColor(D2D1_COLOR_F color); /// /// Retrieves the color of the solid color brush /// /// The color of this solid color brush D2D1_COLOR_F GetColor() const; public: /// /// Creates a CD2DSolidColorBrush. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DSolidColorBrush object. void Destroy() override; protected: /// /// Stores a pointer to an ID2D1SolidColorBrush object. /// ID2D1SolidColorBrush* m_pSolidColorBrush; /// /// Brush solid color. /// D2D1_COLOR_F m_colorSolid; }; /// /// ID2D1BitmapBrush wrapper. /// class CD2DBitmapBrush : public CD2DBrush { DECLARE_DYNAMIC(CD2DBitmapBrush) public: /// /// Constructs a CD2DBitmapBrush object. /// A pointer to the render target. /// A pointer to the extend modes and the interpolation mode of a bitmap brush. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBitmapBrush(CRenderTarget* pParentTarget, D2D1_BITMAP_BRUSH_PROPERTIES* pBitmapBrushProperties = NULL, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// Constructs a CD2DBitmapBrush object from resource. /// A pointer to the render target. /// The resource ID number of the resource. /// Pointer to a null-terminated string that contains the resource type. /// Destination size of the bitmap. /// A pointer to the extend modes and the interpolation mode of a bitmap brush. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBitmapBrush(CRenderTarget* pParentTarget, UINT uiResID, LPCTSTR lpszType = NULL, CD2DSizeU sizeDest = CD2DSizeU(0, 0), D2D1_BITMAP_BRUSH_PROPERTIES* pBitmapBrushProperties = NULL, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// Constructs a CD2DBitmapBrush object from file. /// A pointer to the render target. /// Pointer to a null-terminated string that contains the name of file. /// Destination size of the bitmap. /// A pointer to the extend modes and the interpolation mode of a bitmap brush. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DBitmapBrush(CRenderTarget* pParentTarget, LPCTSTR lpszImagePath, CD2DSizeU sizeDest = CD2DSizeU(0, 0), D2D1_BITMAP_BRUSH_PROPERTIES* pBitmapBrushProperties = NULL, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D bitmap brush object is being destroyed. /// virtual ~CD2DBitmapBrush(); /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1BitmapBrush* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1BitmapBrush* Detach(); /// /// Returns ID2D1BitmapBrush interface /// /// Pointer to an ID2D1BitmapBrush interface or NULL if object is not initialized yet. ID2D1BitmapBrush* Get() { return m_pBitmapBrush; } /// /// Returns ID2D1BitmapBrush interface /// /// Pointer to an ID2D1BitmapBrush interface or NULL if object is not initialized yet. operator ID2D1BitmapBrush*() { return m_pBitmapBrush; } /// /// Gets the bitmap source that this brush uses to paint /// /// Pointer to an CD2DBitmap object or NULL if object is not initialized yet. CD2DBitmap* GetBitmap() { ASSERT_VALID(m_pBitmap); return m_pBitmap; } /// /// Specifies how the brush horizontally tiles those areas that extend past its bitmap /// A value that specifies how the brush horizontally tiles those areas that extend past its bitmap void SetExtendModeX(D2D1_EXTEND_MODE extendModeX); /// /// Specifies how the brush vertically tiles those areas that extend past its bitmap /// A value that specifies how the brush vertically tiles those areas that extend past its bitmap void SetExtendModeY(D2D1_EXTEND_MODE extendModeY); /// /// Specifies the interpolation mode used when the brush bitmap is scaled or rotated /// The interpolation mode used when the brush bitmap is scaled or rotated void SetInterpolationMode(D2D1_BITMAP_INTERPOLATION_MODE interpolationMode); /// /// Specifies the bitmap source that this brush uses to paint /// The bitmap source used by the brush void SetBitmap(CD2DBitmap* pBitmap); /// /// Gets the method by which the brush horizontally tiles those areas that extend past its bitmap /// /// A value that specifies how the brush horizontally tiles those areas that extend past its bitmap D2D1_EXTEND_MODE GetExtendModeX() const; /// /// Gets the method by which the brush vertically tiles those areas that extend past its bitmap /// /// A value that specifies how the brush vertically tiles those areas that extend past its bitmap D2D1_EXTEND_MODE GetExtendModeY() const; /// /// Gets the interpolation method used when the brush bitmap is scaled or rotated /// /// The interpolation method used when the brush bitmap is scaled or rotated D2D1_BITMAP_INTERPOLATION_MODE GetInterpolationMode() const; public: /// /// Creates a CD2DBitmapBrush. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DBitmapBrush object. void Destroy() override; protected: /// /// Initializes the object /// A pointer to the bitmap brush properties. void CommonInit(D2D1_BITMAP_BRUSH_PROPERTIES* pBitmapBrushProperties); protected: /// /// Stores a pointer to a CD2DBitmap object. /// CD2DBitmap* m_pBitmap; /// /// Stores a pointer to an ID2D1BitmapBrush object. /// ID2D1BitmapBrush* m_pBitmapBrush; /// /// Bitmap brush properties. /// D2D1_BITMAP_BRUSH_PROPERTIES* m_pBitmapBrushProperties; }; /// /// The base class of CD2DLinearGradientBrush and CD2DRadialGradientBrush classes. /// class CD2DGradientBrush : public CD2DBrush { DECLARE_DYNAMIC(CD2DGradientBrush) public: /// /// Constructs a CD2DGradientBrush object. /// A pointer to the render target. /// A pointer to an array of D2D1_GRADIENT_STOP structures. /// A value greater than or equal to 1 that specifies the number of gradient stops in the gradientStops array. /// The space in which color interpolation between the gradient stops is performed. /// The behavior of the gradient outside the [0,1] normalized range. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DGradientBrush(CRenderTarget* pParentTarget, const D2D1_GRADIENT_STOP* gradientStops, UINT gradientStopsCount, D2D1_GAMMA colorInterpolationGamma = D2D1_GAMMA_2_2, D2D1_EXTEND_MODE extendMode = D2D1_EXTEND_MODE_CLAMP, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D gradient brush object is being destroyed. /// virtual ~CD2DGradientBrush(); protected: /// /// Destroys a CD2DGradientBrush object. void Destroy() override; protected: /// /// Array of the D2D1_GRADIENT_STOP structures. /// CArray m_arGradientStops; /// /// The space in which color interpolation between the gradient stops is performed. /// D2D1_GAMMA m_colorInterpolationGamma; /// /// The behavior of the gradient outside the [0,1] normalized range. /// D2D1_EXTEND_MODE m_extendMode; /// /// A pointer to an array of D2D1_GRADIENT_STOP structures. /// ID2D1GradientStopCollection* m_pGradientStops; }; /// /// ID2D1LinearGradientBrush wrapper. /// class CD2DLinearGradientBrush : public CD2DGradientBrush { DECLARE_DYNAMIC(CD2DLinearGradientBrush) public: /// /// Constructs a CD2DLinearGradientBrush object. /// A pointer to the render target. /// A pointer to an array of D2D1_GRADIENT_STOP structures. /// A value greater than or equal to 1 that specifies the number of gradient stops in the gradientStops array. /// The start and end points of the gradient. /// The space in which color interpolation between the gradient stops is performed. /// The behavior of the gradient outside the [0,1] normalized range. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DLinearGradientBrush(CRenderTarget* pParentTarget, const D2D1_GRADIENT_STOP* gradientStops, UINT gradientStopsCount, D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES LinearGradientBrushProperties, D2D1_GAMMA colorInterpolationGamma = D2D1_GAMMA_2_2, D2D1_EXTEND_MODE extendMode = D2D1_EXTEND_MODE_CLAMP, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D linear gradient brush object is being destroyed. /// virtual ~CD2DLinearGradientBrush(); public: /// /// Creates a CD2DLinearGradientBrush. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DLinearGradientBrush object. void Destroy() override; /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1LinearGradientBrush* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1LinearGradientBrush* Detach(); /// /// Returns ID2D1LinearGradientBrush interface /// /// Pointer to an ID2D1LinearGradientBrush interface or NULL if object is not initialized yet. ID2D1LinearGradientBrush* Get() { return m_pLinearGradientBrush; } /// /// Returns ID2D1LinearGradientBrush interface /// /// Pointer to an ID2D1LinearGradientBrush interface or NULL if object is not initialized yet. operator ID2D1LinearGradientBrush*() { return m_pLinearGradientBrush; } /// /// Sets the starting coordinates of the linear gradient in the brush's coordinate space /// The starting two-dimensional coordinates of the linear gradient, in the brush's coordinate space void SetStartPoint(CD2DPointF point); /// /// Sets the ending coordinates of the linear gradient in the brush's coordinate space /// The ending two-dimensional coordinates of the linear gradient, in the brush's coordinate space void SetEndPoint(CD2DPointF point); /// /// Retrieves the starting coordinates of the linear gradient /// /// The starting two-dimensional coordinates of the linear gradient, in the brush's coordinate space CD2DPointF GetStartPoint() const; /// /// Retrieves the ending coordinates of the linear gradient /// /// The ending two-dimensional coordinates of the linear gradient, in the brush's coordinate space CD2DPointF GetEndPoint() const; protected: /// /// The start and end points of the gradient. /// D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES m_LinearGradientBrushProperties; /// /// A pointer to an ID2D1LinearGradientBrush. /// ID2D1LinearGradientBrush* m_pLinearGradientBrush; }; /// /// ID2D1RadialGradientBrush wrapper. /// class CD2DRadialGradientBrush : public CD2DGradientBrush { DECLARE_DYNAMIC(CD2DRadialGradientBrush) public: /// /// Constructs a CD2DLinearGradientBrush object. /// A pointer to the render target. /// A pointer to an array of D2D1_GRADIENT_STOP structures. /// A value greater than or equal to 1 that specifies the number of gradient stops in the gradientStops array. /// The center, gradient origin offset, and x-radius and y-radius of the brush's gradient. /// The space in which color interpolation between the gradient stops is performed. /// The behavior of the gradient outside the [0,1] normalized range. /// A pointer to the opacity and transformation of a brush. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DRadialGradientBrush(CRenderTarget* pParentTarget, const D2D1_GRADIENT_STOP* gradientStops, UINT gradientStopsCount, D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES RadialGradientBrushProperties, D2D1_GAMMA colorInterpolationGamma = D2D1_GAMMA_2_2, D2D1_EXTEND_MODE extendMode = D2D1_EXTEND_MODE_CLAMP, CD2DBrushProperties* pBrushProperties = NULL, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D radial gradient brush object is being destroyed. /// virtual ~CD2DRadialGradientBrush(); public: /// /// Creates a CD2DRadialGradientBrush. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DRadialGradientBrush object. void Destroy() override; /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1RadialGradientBrush* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1RadialGradientBrush* Detach(); /// /// Returns ID2D1RadialGradientBrush interface /// /// Pointer to an ID2D1RadialGradientBrush interface or NULL if object is not initialized yet. ID2D1RadialGradientBrush* Get() { return m_pRadialGradientBrush; } /// /// Returns ID2D1RadialGradientBrush interface /// /// Pointer to an ID2D1RadialGradientBrush interface or NULL if object is not initialized yet. operator ID2D1RadialGradientBrush*() { return m_pRadialGradientBrush; } /// /// Specifies the center of the gradient ellipse in the brush's coordinate space /// The center of the gradient ellipse, in the brush's coordinate space void SetCenter(CD2DPointF point); /// /// Specifies the offset of the gradient origin relative to the gradient ellipse's center /// The offset of the gradient origin from the center of the gradient ellipse void SetGradientOriginOffset(CD2DPointF gradientOriginOffset); /// /// Specifies the x-radius of the gradient ellipse, in the brush's coordinate space /// The x-radius of the gradient ellipse. This value is in the brush's coordinate space void SetRadiusX(FLOAT radiusX); /// /// Specifies the y-radius of the gradient ellipse, in the brush's coordinate space /// The y-radius of the gradient ellipse. This value is in the brush's coordinate space void SetRadiusY(FLOAT radiusY); /// /// Retrieves the center of the gradient ellipse /// /// The center of the gradient ellipse. This value is expressed in the brush's coordinate space CD2DPointF GetCenter() const; /// /// Retrieves the offset of the gradient origin relative to the gradient ellipse's center /// /// The offset of the gradient origin from the center of the gradient ellipse. This value is expressed in the brush's coordinate space CD2DPointF GetGradientOriginOffset() const; /// /// Retrieves the x-radius of the gradient ellipse /// /// The x-radius of the gradient ellipse. This value is expressed in the brush's coordinate space FLOAT GetRadiusX() const; /// /// Retrieves the y-radius of the gradient ellipse /// /// The y-radius of the gradient ellipse. This value is expressed in the brush's coordinate space FLOAT GetRadiusY() const; protected: /// /// The center, gradient origin offset, and x-radius and y-radius of the brush's gradient. /// D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES m_RadialGradientBrushProperties; /// /// A pointer to an ID2D1RadialGradientBrush. /// ID2D1RadialGradientBrush* m_pRadialGradientBrush; }; /// /// IDWriteTextFormat wrapper. /// class CD2DTextFormat : public CD2DResource { DECLARE_DYNAMIC(CD2DTextFormat) friend class CRenderTarget; public: /// /// Constructs a CD2DTextFormat object. /// A pointer to the render target. /// A CString object that contains the name of the font family. /// The logical size of the font in DIP ("device-independent pixel") units. A DIPequals 1/96 inch. /// A value that indicates the font weight for the text object. /// A value that indicates the font style for the text object. /// A value that indicates the font stretch for the text object. /// A CString object that contains the locale name. /// A pointer to a font collection object. When this is NULL, indicates the system font collection. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DTextFormat(CRenderTarget* pParentTarget, const CString& strFontFamilyName, FLOAT fontSize, DWRITE_FONT_WEIGHT fontWeight = DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE fontStyle = DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH fontStretch = DWRITE_FONT_STRETCH_NORMAL, const CString& strFontLocale = _T(""), IDWriteFontCollection* pFontCollection = NULL, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D text format object is being destroyed. /// virtual ~CD2DTextFormat(); /// /// Re-creates a CD2DTextFormat. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT ReCreate(CRenderTarget* pRenderTarget) override { UNREFERENCED_PARAMETER(pRenderTarget); return S_OK; } /// /// Creates a CD2DTextFormat. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override { UNREFERENCED_PARAMETER(pRenderTarget); return S_OK; } /// /// Destroys a CD2DTextFormat object. void Destroy() override {} /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const override { return m_pTextFormat != NULL; } /// /// Returns IDWriteTextFormat interface /// /// Pointer to an IDWriteTextFormat interface or NULL if object is not initialized yet. IDWriteTextFormat* Get() { return m_pTextFormat; } /// /// Returns IDWriteTextFormat interface /// /// Pointer to an IDWriteTextFormat interface or NULL if object is not initialized yet. operator IDWriteTextFormat*() { return m_pTextFormat; } /// /// Gets a copy of the font family name. /// /// CString object that contains the current font family name. CString GetFontFamilyName() const; /// /// Gets a copy of the locale name. /// /// CString object that contains the current locale name. CString GetLocaleName() const; protected: /// /// A pointer to an IDWriteTextFormat. /// IDWriteTextFormat* m_pTextFormat; }; /// /// IDWriteTextLayout wrapper. /// class CD2DTextLayout : public CD2DResource { DECLARE_DYNAMIC(CD2DTextLayout) public: /// /// Constructs a CD2DTextLayout object. /// A pointer to the render target. /// A CString object that contains the string to create a new CD2DTextLayout object from. /// A CString object that contains the format to apply to the string. /// The size of the layout box. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DTextLayout(CRenderTarget* pParentTarget, const CString& strText, CD2DTextFormat& textFormat, const CD2DSizeF& sizeMax, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D text layout object is being destroyed. /// virtual ~CD2DTextLayout(); /// /// Re-creates a CD2DTextLayout. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT ReCreate(CRenderTarget* pRenderTarget) override { UNREFERENCED_PARAMETER(pRenderTarget); return S_OK; } /// /// Creates a CD2DTextLayout. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override { UNREFERENCED_PARAMETER(pRenderTarget); return S_OK; } /// /// Destroys a CD2DTextLayout object. void Destroy() override {} /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const override { return m_pTextLayout != NULL; } /// /// Returns IDWriteTextLayout interface /// /// Pointer to an IDWriteTextLayout interface or NULL if object is not initialized yet. IDWriteTextLayout* Get() { return m_pTextLayout; } /// /// Returns IDWriteTextLayout interface /// /// Pointer to an IDWriteTextLayout interface or NULL if object is not initialized yet. operator IDWriteTextLayout*() { return m_pTextLayout; } /// /// Sets null-terminated font family name for text within a specified text range /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE /// The font family name that applies to the entire text string within the range specified by textRange /// Text range to which this change applies BOOL SetFontFamilyName(LPCWSTR pwzFontFamilyName, DWRITE_TEXT_RANGE textRange); /// /// Sets the locale name for text within a specified text range /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE /// A null-terminated locale name string /// Text range to which this change applies BOOL SetLocaleName(LPCWSTR pwzLocaleName, DWRITE_TEXT_RANGE textRange); /// /// Copies the font family name of the text at the specified position. /// /// CString object that contains the current font family name. /// The position of the text to examine. /// The range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the font family name. CString GetFontFamilyName(UINT32 currentPosition, DWRITE_TEXT_RANGE* textRange = NULL) const; /// /// Gets the locale name of the text at the specified position. /// /// CString object that contains the current locale name. /// The position of the text to inspect. /// The range of text that has the same formatting as the text at the position specified by currentPosition. This means the run has the exact formatting as the position specified, including but not limited to the locale name. CString GetLocaleName(UINT32 currentPosition, DWRITE_TEXT_RANGE* textRange = NULL) const; protected: /// /// A pointer to an IDWriteTextLayout. /// IDWriteTextLayout* m_pTextLayout; }; /// /// ID2D1Geometry wrapper. /// class CD2DGeometry : public CD2DResource { DECLARE_DYNAMIC(CD2DGeometry) public: /// /// Constructs a CD2DGeometry object. /// A pointer to the render target. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DGeometry(CRenderTarget* pParentTarget, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D geometry object is being destroyed. /// virtual ~CD2DGeometry(); /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1Geometry* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1Geometry* Detach(); /// /// Returns ID2D1Geometry interface /// /// Pointer to an ID2D1Geometry interface or NULL if object is not initialized yet. ID2D1Geometry* Get() { return m_pGeometry; } /// /// Returns ID2D1Geometry interface /// /// Pointer to an ID2D1Geometry interface or NULL if object is not initialized yet. operator ID2D1Geometry*() { return m_pGeometry; } /// /// Destroys a CD2DGeometry object. void Destroy() override; /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const override { return m_pGeometry != NULL; } /// /// Combines this geometry with the specified geometry and stores the result in an ID2D1SimplifiedGeometrySink. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The geometry to combine with this instance. /// The type of combine operation to perform. /// The transform to apply to inputGeometry before combining. /// The result of the combine operation. /// The maximum bounds on the distance between points in the polygonal approximation of the geometries. Smaller values produce more accurate results but cause slower execution. BOOL CombineWithGeometry(CD2DGeometry& inputGeometry, D2D1_COMBINE_MODE combineMode, const D2D1_MATRIX_3X2_F& inputGeometryTransform, ID2D1SimplifiedGeometrySink* geometrySink, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Describes the intersection between this geometry and the specified geometry. The comparison is performed using the specified flattening tolerance. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The geometry to test. /// The transform to apply to inputGeometry. /// The maximum bounds on the distance between points in the polygonal approximation of the geometries. Smaller values produce more accurate results but cause slower execution. D2D1_GEOMETRY_RELATION CompareWithGeometry(CD2DGeometry& inputGeometry, const D2D1_MATRIX_3X2_F& inputGeometryTransform, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Computes the area of the geometry after it has been transformed by the specified matrix and flattened using the specified tolerance. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The transform to apply to this geometry before computing its area. /// When this method returns, contains a pointer to the area of the transformed, flattened version of this geometry. You must allocate storage for this parameter. /// The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. BOOL ComputeArea(const D2D1_MATRIX_3X2_F& worldTransform, FLOAT& area, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Calculates the length of the geometry as though each segment were unrolled into a line. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The transform to apply to the geometry before calculating its length. /// When this method returns, contains a pointer to the length of the geometry. For closed geometries, the length includes an implicit closing segment. You must allocate storage for this parameter. /// The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. BOOL ComputeLength(const D2D1_MATRIX_3X2_F& worldTransform, FLOAT& length, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Calculates the point and tangent vector at the specified distance along the geometry after it has been transformed by the specified matrix and flattened using the specified tolerance. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The distance along the geometry of the point and tangent to find. If this distance is less then 0, this method calculates the first point in the geometry. If this distance is greater than the length of the geometry, this method calculates the last point in the geometry. /// The transform to apply to the geometry before calculating the specified point and tangent. /// The location at the specified distance along the geometry. If the geometry is empty, this point contains NaN as its x and y values. /// When this method returns, contains a pointer to the tangent vector at the specified distance along the geometry. If the geometry is empty, this vector contains NaN as its x and y values. You must allocate storage for this parameter. /// The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. BOOL ComputePointAtLength(FLOAT length, const D2D1_MATRIX_3X2_F &worldTransform, CD2DPointF& point, CD2DPointF& unitTangentVector, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Retrieves the bounds of the geometry. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The transform to apply to this geometry before calculating its bounds. /// When this method returns, contains the bounds of this geometry. If the bounds are empty, this will be a rect where bounds.left is greater than bounds.right. You must allocate storage for this parameter. BOOL GetBounds(const D2D1_MATRIX_3X2_F& worldTransform, CD2DRectF& bounds) const; /// /// Gets the bounds of the geometry after it has been widened by the specified stroke width and style and transformed by the specified matrix. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The amount by which to widen the geometry by stroking its outline. /// The style of the stroke that widens the geometry. /// A transform to apply to the geometry after the geometry is transformed and after the geometry has been stroked. /// When this method returns, contains the bounds of the widened geometry. You must allocate storage for this parameter. /// The maximum bounds on the distance between points in the polygonal approximation of the geometries. Smaller values produce more accurate results but cause slower execution. BOOL GetWidenedBounds(FLOAT strokeWidth, ID2D1StrokeStyle* strokeStyle, const D2D1_MATRIX_3X2_F& worldTransform, CD2DRectF& bounds, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Indicates whether the area filled by the geometry would contain the specified point given the specified flattening tolerance. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The point to test. /// The transform to apply to the geometry prior to testing for containment. /// When this method returns, contains a bool value that is TRUE if the area filled by the geometry contains point; otherwise, FALSE. You must allocate storage for this parameter. /// The numeric accuracy with which the precise geometric path and path intersection is calculated. Points missing the fill by less than the tolerance are still considered inside. Smaller values produce more accurate results but cause slower execution. BOOL FillContainsPoint(CD2DPointF point, const D2D1_MATRIX_3X2_F& worldTransform, BOOL* contains, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Determines whether the geometry's stroke contains the specified point given the specified stroke thickness, style, and transform. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The point to test for containment. /// The thickness of the stroke to apply. /// The style of the stroke to apply. /// The transform to apply to the stroked geometry. /// When this method returns, contains a boolean value set to TRUE if the geometry's stroke contains the specified point; otherwise, FALSE. You must allocate storage for this parameter. /// The numeric accuracy with which the precise geometric path and path intersection is calculated. Points missing the stroke by less than the tolerance are still considered inside. Smaller values produce more accurate results but cause slower execution. BOOL StrokeContainsPoint(CD2DPointF point, FLOAT strokeWidth, ID2D1StrokeStyle* strokeStyle, const D2D1_MATRIX_3X2_F& worldTransform, BOOL* contains, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Computes the outline of the geometry and writes the result to an ID2D1SimplifiedGeometrySink. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The transform to apply to the geometry outline. /// The ID2D1SimplifiedGeometrySink to which the geometry transformed outline is appended. /// The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. BOOL Outline(const D2D1_MATRIX_3X2_F& worldTransform, ID2D1SimplifiedGeometrySink* geometrySink, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Creates a simplified version of the geometry that contains only lines and (optionally) cubic Bezier curves and writes the result to an ID2D1SimplifiedGeometrySink. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// A value that specifies whether the simplified geometry should contain curves. /// The transform to apply to the simplified geometry. /// The ID2D1SimplifiedGeometrySink to which the simplified geometry is appended. /// The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. BOOL Simplify(D2D1_GEOMETRY_SIMPLIFICATION_OPTION simplificationOption, const D2D1_MATRIX_3X2_F& worldTransform, ID2D1SimplifiedGeometrySink* geometrySink, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Creates a set of clockwise-wound triangles that cover the geometry after it has been transformed using the specified matrix and flattened using the specified tolerance. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The transform to apply to this geometry, or NULL. /// The ID2D1TessellationSink to which the tessellated is appended. /// The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. BOOL Tessellate(const D2D1_MATRIX_3X2_F& worldTransform, ID2D1TessellationSink* tessellationSink, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; /// /// Widens the geometry by the specified stroke and writes the result to an ID2D1SimplifiedGeometrySink after it has been transformed by the specified matrix and flattened using the specified tolerance. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The amount by which to widen the geometry. /// The style of stroke to apply to the geometry, or NULL. /// The transform to apply to the geometry after widening it. /// The ID2D1SimplifiedGeometrySink to which the widened geometry is appended. /// The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. BOOL Widen(FLOAT strokeWidth, ID2D1StrokeStyle* strokeStyle, const D2D1_MATRIX_3X2_F& worldTransform, ID2D1SimplifiedGeometrySink* geometrySink, FLOAT flatteningTolerance = D2D1_DEFAULT_FLATTENING_TOLERANCE) const; protected: /// /// A pointer to an ID2D1Geometry. /// ID2D1Geometry* m_pGeometry; }; /// /// ID2D1PathGeometry wrapper. /// class CD2DPathGeometry : public CD2DGeometry { DECLARE_DYNAMIC(CD2DPathGeometry) public: /// /// Constructs a CD2DPathGeometry object. /// A pointer to the render target. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DPathGeometry(CRenderTarget* pParentTarget, BOOL bAutoDestroy = TRUE); /// /// Creates a CD2DPathGeometry. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DPathGeometry object. void Destroy() override; /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1PathGeometry* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1PathGeometry* Detach(); /// /// Retrieves the geometry sink that is used to populate the path geometry with figures and segments. /// /// A pointer to the ID2D1GeometrySink that is used to populate the path geometry with figures and segments. ID2D1GeometrySink* Open(); /// /// Copies the contents of the path geometry to the specified ID2D1GeometrySink. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The sink to which the path geometry's contents are copied. Modifying this sink does not change the contents of this path geometry. BOOL Stream(ID2D1GeometrySink* geometrySink); /// /// Retrieves the number of segments in the path geometry. /// /// Returns the number of segments in the path geometry. int GetSegmentCount() const; /// /// Retrieves the number of figures in the path geometry. /// /// Returns the number of figures in the path geometry. int GetFigureCount() const; protected: /// /// A pointer to an ID2D1PathGeometry. /// ID2D1PathGeometry* m_pPathGeometry; }; /// /// ID2D1GeometrySink wrapper. /// class CD2DGeometrySink { public: /// /// Constructs a CD2DGeometrySink object from CD2DPathGeometry object. /// An existing CD2DPathGeometry object. CD2DGeometrySink(CD2DPathGeometry& pathGeometry); /// /// The destructor. Called when a D2D geometry sink object is being destroyed. /// virtual ~CD2DGeometrySink(); /// /// Checks geometry sink validity /// /// TRUE if geometry sink is valid; otherwise FALSE. BOOL IsValid() const { return m_pSink != NULL; } /// /// Returns ID2D1GeometrySink interface /// /// Pointer to an ID2D1GeometrySink interface or NULL if object is not initialized yet. ID2D1GeometrySink* Get() { return m_pSink; } /// /// Returns ID2D1GeometrySink interface /// /// Pointer to an ID2D1GeometrySink interface or NULL if object is not initialized yet. operator ID2D1GeometrySink*() { return m_pSink; } /// /// Starts a new figure at the specified point. /// The point at which to begin the new figure. /// Whether the new figure should be hollow or filled. void BeginFigure(CD2DPointF startPoint, D2D1_FIGURE_BEGIN figureBegin); /// /// Ends the current figure; optionally, closes it. /// A value that indicates whether the current figure is closed. If the figure is closed, a line is drawn between the current point and the start point specified by BeginFigure. void EndFigure(D2D1_FIGURE_END figureEnd); /// /// Adds a single arc to the path geometry /// The arc segment to add to the figure void AddArc(const D2D1_ARC_SEGMENT& arc); /// /// Creates a cubic Bezier curve between the current point and the specified end point. /// A structure that describes the control points and end point of the Bezier curve to add. void AddBezier(const D2D1_BEZIER_SEGMENT& bezier); /// /// Creates a sequence of cubic Bezier curves and adds them to the geometry sink. /// An array of Bezier segments that describes the Bezier curves to create. A curve is drawn from the geometry sink's current point (the end point of the last segment drawn or the location specified by BeginFigure) to the end point of the first Bezier segment in the array. if the array contains additional Bezier segments, each subsequent Bezier segment uses the end point of the preceding Bezier segment as its start point. void AddBeziers(const CArray& beziers); /// /// Creates a quadratic Bezier curve between the current point and the specified end point. /// A structure that describes the control point and the end point of the quadratic Bezier curve to add. void AddQuadraticBezier(const D2D1_QUADRATIC_BEZIER_SEGMENT& bezier); /// /// Adds a sequence of quadratic Bezier segments as an array in a single call. /// An array of a sequence of quadratic Bezier segments. void AddQuadraticBeziers(const CArray& beziers); /// /// Creates a line segment between the current point and the specified end point and adds it to the geometry sink. /// The end point of the line to draw. void AddLine(CD2DPointF point); /// /// Creates a sequence of lines using the specified points and adds them to the geometry sink. /// An array of one or more points that describe the lines to draw. A line is drawn from the geometry sink's current point (the end point of the last segment drawn or the location specified by BeginFigure) to the first point in the array. if the array contains additional points, a line is drawn from the first point to the second point in the array, from the second point to the third point, and so on. An array of a sequence of the end points of the lines to draw. void AddLines(const CArray& points); /// /// Closes the geometry sink /// /// Nonzero if successful; otherwise FALSE. BOOL Close(); /// /// Specifies the method used to determine which points are inside the geometry described by this geometry sink and which points are outside. /// The method used to determine whether a given point is part of the geometry. void SetFillMode(D2D1_FILL_MODE fillMode); /// /// Specifies stroke and join options to be applied to new segments added to the geometry sink. /// Stroke and join options to be applied to new segments added to the geometry sink. void SetSegmentFlags(D2D1_PATH_SEGMENT vertexFlags); protected: /// /// A pointer to an ID2D1GeometrySink. /// ID2D1GeometrySink* m_pSink; }; /// /// ID2D1Mesh wrapper. /// class CD2DMesh : public CD2DResource { DECLARE_DYNAMIC(CD2DMesh) public: /// /// Constructs a CD2DMesh object. /// A pointer to the render target. /// Indicates that the object will be destroyed by owner (pParentTarget). CD2DMesh(CRenderTarget* pParentTarget, BOOL bAutoDestroy = TRUE); /// /// The destructor. Called when a D2D mesh object is being destroyed. /// virtual ~CD2DMesh(); /// /// Attaches existing resource interface to the object /// Existing resource interface. Cannot be NULL void Attach(ID2D1Mesh* pResource); /// /// Detaches resource interface from the object /// /// Pointer to detached resource interface. ID2D1Mesh* Detach(); /// /// Returns ID2D1Mesh interface /// /// Pointer to an ID2D1Mesh interface or NULL if object is not initialized yet. ID2D1Mesh* Get() { return m_pMesh; } /// /// Returns ID2D1Mesh interface /// /// Pointer to an ID2D1Mesh interface or NULL if object is not initialized yet. operator ID2D1Mesh*() { return m_pMesh; } /// /// Opens the mesh for population. /// /// A pointer to an ID2D1TessellationSink that is used to populate the mesh. ID2D1TessellationSink* Open(); /// /// Creates a CD2DMesh. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// A pointer to the render target. HRESULT Create(CRenderTarget* pRenderTarget) override; /// /// Destroys a CD2DMesh object. void Destroy() override; /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const override { return m_pMesh != NULL; } protected: /// /// A pointer to an ID2D1Mesh. /// ID2D1Mesh* m_pMesh; }; /// /// ID2D1RenderTarget wrapper. /// class CRenderTarget : public CObject { DECLARE_DYNAMIC(CRenderTarget) friend class CD2DResource; friend class CD2DBitmapBrush; friend class CD2DBitmap; public: /// /// Constructs a CRenderTarget object. CRenderTarget(); /// /// The destructor. Called when a render target object is being destroyed. /// virtual ~CRenderTarget(); /// /// Deletes one or more resources /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE /// If bDeleteResources is TRUE, all resources located in m_lstResources will be automatically destroyed. BOOL Destroy(BOOL bDeleteResources = TRUE); // Attributes: public: /// /// Checks resource validity /// /// TRUE if resource is valid; otherwise FALSE. BOOL IsValid() const { return m_pRenderTarget != NULL; } /// /// Returns ID2D1RenderTarget interface /// /// Pointer to an ID2D1RenderTarget interface or NULL if object is not initialized yet. ID2D1RenderTarget* GetRenderTarget() { return m_pRenderTarget; } /// /// Returns ID2D1RenderTarget interface /// /// Pointer to an ID2D1RenderTarget interface or NULL if object is not initialized yet. operator ID2D1RenderTarget*() { return m_pRenderTarget; } /// /// Returns the size of the render target in device-independent pixels /// /// The current size of the render target in device-independent pixels CD2DSizeF GetSize() const; /// /// Sets the dots per inch (DPI) of the render target. /// A value greater than or equal to zero that specifies the horizontal/verticalDPI of the render target. void SetDpi(const CD2DSizeF& sizeDPI); /// /// Returns the render target's dots per inch (DPI) /// /// The render target's dots per inch (DPI). CD2DSizeF GetDpi() const; /// /// Retrieves the pixel format and alpha mode of the render target /// /// The pixel format and alpha mode of the render target D2D1_PIXEL_FORMAT GetPixelFormat() const; /// /// Returns the size of the render target in device pixels /// /// The size of the render target in device pixels CD2DSizeU GetPixelSize() const; /// /// Gets the label for subsequent drawing operations. /// Contains the first label for subsequent drawing operations. This parameter is passed uninitialized. If NULL is specified, no value is retrieved for this parameter. /// Contains the second label for subsequent drawing operations. This parameter is passed uninitialized. If NULL is specified, no value is retrieved for this parameter. void GetTags(D2D1_TAG *tag1 = NULL, D2D1_TAG *tag2 = NULL) const; /// /// Specifies a label for subsequent drawing operations. /// A label to apply to subsequent drawing operations. /// A label to apply to subsequent drawing operations. void SetTags(D2D1_TAG tag1, D2D1_TAG tag2); /// /// Indicates whether the render target supports the specified properties /// /// TRUE if the specified render target properties are supported by this render target; otherwise, FALSE /// The render target properties to test BOOL IsSupported(const D2D1_RENDER_TARGET_PROPERTIES& renderTargetProperties) const; /// /// Gets the maximum size, in device-dependent units (pixels), of any one bitmap dimension supported by the render target /// /// The maximum size, in pixels, of any one bitmap dimension supported by the render target UINT32 GetMaximumBitmapSize() const; // Operations: public: /// /// Attaches existing render target interface to the object /// Existing render target interface. Cannot be NULL void Attach(ID2D1RenderTarget* pRenderTarget); /// /// Detaches render target interface from the object /// /// Pointer to detached render target interface. ID2D1RenderTarget* Detach (); /// /// Initiates drawing on this render target. void BeginDraw(); /// /// Ends drawing operations on the render target and indicates the current error state and associated tags. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. HRESULT EndDraw(); /// /// Converts GDI color and alpha values to the D2D1_COLOR_F object. /// RGB value. /// Alpha value. /// /// D2D1_COLOR_F value. static D2D1_COLOR_F COLORREF_TO_D2DCOLOR(COLORREF color, int nAlpha = 255); /// /// Clears the drawing area to the specified color. /// The color to which the drawing area is cleared. void Clear(D2D1_COLOR_F color); /// /// Draws the outline of a rectangle that has the specified dimensions and stroke style. /// The dimensions of the rectangle to draw, in device-independent pixels /// The brush used to paint the rectangle's stroke /// A value greater than or equal to 0.0f that specifies the width of the rectangle's stroke. The stroke is centered on the rectangle's outline. /// The style of stroke to paint, or NULL to paint a solid stroke. void DrawRectangle(const CD2DRectF& rect, CD2DBrush* pBrush, FLOAT fStrokeWidth = 1.0, ID2D1StrokeStyle* strokeStyle = NULL); /// /// Paints the interior of the specified rectangle. /// The dimension of the rectangle to paint, in device-independent pixels. /// The brush used to paint the rectangle's interior. void FillRectangle(const CD2DRectF& rect, CD2DBrush* pBrush); /// /// Draws the outline of the specified rounded rectangle using the specified stroke style. /// The dimensions of the rounded rectangle to draw, in device-independent pixels. /// The brush used to paint the rounded rectangle's outline. /// The width of the rounded rectangle's stroke. The stroke is centered on the rounded rectangle's outline. The default value is 1.0f. /// The style of the rounded rectangle's stroke, or NULL to paint a solid stroke. The default value is NULL. void DrawRoundedRectangle(const CD2DRoundedRect& rectRounded, CD2DBrush* pBrush, FLOAT fStrokeWidth = 1.0, ID2D1StrokeStyle* strokeStyle = NULL); /// /// Paints the interior of the specified rounded rectangle. /// The dimensions of the rounded rectangle to paint, in device independent pixels. /// The brush used to paint the interior of the rounded rectangle. void FillRoundedRectangle(const CD2DRoundedRect& rectRounded, CD2DBrush* pBrush); /// /// Draws the outline of the specified ellipse using the specified stroke style. /// The position and radius of the ellipse to draw, in device-independent pixels. /// The brush used to paint the ellipse's outline. /// The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline. /// The style of stroke to apply to the ellipse's outline, or NULL to paint a solid stroke. void DrawEllipse(const CD2DEllipse& ellipse, CD2DBrush* pBrush, FLOAT fStrokeWidth = 1.0, ID2D1StrokeStyle* strokeStyle = NULL); /// /// Paints the interior of the specified ellipse. /// The position and radius, in device-independent pixels, of the ellipse to paint. /// The brush used to paint the interior of the ellipse. void FillEllipse(const CD2DEllipse& ellipse, CD2DBrush* pBrush); /// /// Draws a line between the specified points using the specified stroke style. /// The start point of the line, in device-independent pixels. /// The end point of the line, in device-independent pixels. /// The brush used to paint the line's stroke. /// A value greater than or equal to 0.0f that specifies the width of the stroke. If this parameter isn't specified, it defaults to 1.0f. The stroke is centered on the line. /// The style of stroke to paint, or NULL to paint a solid line. void DrawLine(const CD2DPointF& ptFrom, const CD2DPointF& ptTo, CD2DBrush* pBrush, FLOAT fStrokeWidth = 1.0, ID2D1StrokeStyle* strokeStyle = NULL); /// /// Applies the opacity mask described by the specified bitmap to a brush and uses that brush to paint a region of the render target. /// The position and radius, in device-independent pixels, of the ellipse to paint. /// The brush used to paint the region of the render target specified by destinationRectangle. /// The type of content the opacity mask contains. The value is used to determine the color space in which the opacity mask is blended. /// The region of the render target to paint, in device-independent pixels. /// The region of the bitmap to use as the opacity mask, in device-independent pixels. void FillOpacityMask(CD2DBitmap* pOpacityMask, CD2DBrush* pBrush, D2D1_OPACITY_MASK_CONTENT content, const CD2DRectF& rectDest, const CD2DRectF& rectSrc); /// /// Draws the specified text using the format information provided by an IDWriteTextFormat object. /// A pointer to an array of Unicode characters to draw. /// The size and position of the area in which the text is drawn. /// The brush used to paint the text. /// An object that describes formatting details of the text to draw, such as the font, the font size, and flow direction. /// A value that indicates whether the text should be snapped to pixel boundaries and whether the text should be clipped to the layout rectangle. The default value is D2D1_DRAW_TEXT_OPTIONS_NONE, which indicates that text should be snapped to pixel boundaries and it should not be clipped to the layout rectangle. /// A value that indicates how glyph metrics are used to measure text when it is formatted. The default value is DWRITE_MEASURING_MODE_NATURAL. void DrawText(const CString& strText, const CD2DRectF& rect, CD2DBrush* pForegroundBrush, CD2DTextFormat* textFormat = NULL, D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE measuringMode = DWRITE_MEASURING_MODE_NATURAL); /// /// Draws the formatted text described by the specified IDWriteTextLayout object. /// The point, described in device-independent pixels, at which the upper-left corner of the text described by textLayout is drawn. /// The formatted text to draw. Any drawing effects that do not inherit from ID2D1Resource are ignored. If there are drawing effects that inherit from ID2D1Resource that are not brushes, this method fails and the render target is put in an error state. /// The brush used to paint any text in textLayout that does not already have a brush associated with it as a drawing effect (specified by the IDWriteTextLayout::SetDrawingEffect method). /// A value that indicates whether the text should be snapped to pixel boundaries and whether the text should be clipped to the layout rectangle. The default value is D2D1_DRAW_TEXT_OPTIONS_NONE, which indicates that text should be snapped to pixel boundaries and it should not be clipped to the layout rectangle. void DrawTextLayout(const CD2DPointF& ptOrigin, CD2DTextLayout* textLayout, CD2DBrush* pBrushForeground, D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS_NONE); /// /// Draws the formatted text described by the specified IDWriteTextLayout object. /// The bitmap to render. /// The size and position, in device-independent pixels in the render target's coordinate space, of the area to which the bitmap is drawn. If the rectangle is not well-ordered, nothing is drawn, but the render target does not enter an error state. /// A value between 0.0f and 1.0f, inclusive, that specifies an opacity value to apply to the bitmap; this value is multiplied against the alpha values of the bitmap's contents. /// The interpolation mode to use if the bitmap is scaled or rotated by the drawing operation. /// The size and position, in device-independent pixels in the bitmap's coordinate space, of the area within the bitmap to draw. void DrawBitmap(CD2DBitmap* pBitmap, const CD2DRectF& rectDest, float fOpacity = 1.0, D2D1_BITMAP_INTERPOLATION_MODE interpolationMode = D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, const CD2DRectF* pRectSrc = NULL); /// /// Draws the outline of the specified geometry using the specified stroke style. /// The geometry to draw. /// The brush used to paint the geometry's stroke. /// The thickness of the geometry's stroke. The stroke is centered on the geometry's outline. /// The style of stroke to apply to the geometry's outline, or NULL to paint a solid stroke. void DrawGeometry(CD2DGeometry* pGeometry, CD2DBrush* pBrush, FLOAT fStrokeWidth = 1.0, ID2D1StrokeStyle* strokeStyle = NULL); /// /// Paints the interior of the specified geometry. /// The geometry to paint. /// The brush used to paint the geometry's interior. /// The opacity mask to apply to the geometry;NULL for no opacity mask. If an opacity mask (the opacityBrush parameter) is specified, brush must be an ID2D1BitmapBrush that has its x- and y-extend modes set to D2D1_EXTEND_MODE_CLAMP. For more information, see the Remarks section. void FillGeometry(CD2DGeometry* pGeometry, CD2DBrush* pBrush, CD2DBrush* pOpacityBrush = NULL); /// /// Draws the specified glyphs. /// The origin, in device-independent pixels, of the glyphs' baseline. /// The glyphs to render. /// The brush used to paint the specified glyphs. /// A value that indicates how glyph metrics are used to measure text when it is formatted. The default value is DWRITE_MEASURING_MODE_NATURAL. void DrawGlyphRun(const CD2DPointF& ptBaseLineOrigin, const DWRITE_GLYPH_RUN& glyphRun, CD2DBrush* pForegroundBrush, DWRITE_MEASURING_MODE measuringMode = DWRITE_MEASURING_MODE_NATURAL); /// /// Paints the interior of the specified mesh. /// The mesh to paint. /// The brush used to paint the mesh. void FillMesh(CD2DMesh* pMesh, CD2DBrush* pBrush); /// /// Sets the antialiasing mode of the render target. The antialiasing mode applies to all subsequent drawing operations, excluding text and glyph drawing operations. /// The antialiasing mode for future drawing operations. void SetAntialiasMode(D2D1_ANTIALIAS_MODE antialiasMode); /// /// Retrieves the current antialiasing mode for nontext drawing operations. /// /// Current antialiasing mode for nontext drawing operations. D2D1_ANTIALIAS_MODE GetAntialiasMode() const; /// /// Specifies the antialiasing mode to use for subsequent text and glyph drawing operations. /// The antialiasing mode to use for subsequent text and glyph drawing operations. void SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode); /// /// Gets the current antialiasing mode for text and glyph drawing operations. /// /// Current antialiasing mode for text and glyph drawing operations. D2D1_TEXT_ANTIALIAS_MODE GetTextAntialiasMode() const; /// /// Specifies text rendering options to be applied to all subsequent text and glyph drawing operations. /// The text rendering options to be applied to all subsequent text and glyph drawing operations; NULL to clear current text rendering options. void SetTextRenderingParams(IDWriteRenderingParams* textRenderingParams = NULL); /// /// Retrieves the render target's current text rendering options. /// When this method returns, textRenderingParamscontains the address of a pointer to the render target's current text rendering options. void GetTextRenderingParams(IDWriteRenderingParams** textRenderingParams); /// /// Applies the specified transform to the render target, replacing the existing transformation. All subsequent drawing operations occur in the transformed space. /// The transform to apply to the render target. void SetTransform(const D2D1_MATRIX_3X2_F* transform); /// /// Applies the specified transform to the render target, replacing the existing transformation. All subsequent drawing operations occur in the transformed space. /// The transform to apply to the render target. void SetTransform(const D2D1_MATRIX_3X2_F& transform); /// /// Applies the specified transform to the render target, replacing the existing transformation. All subsequent drawing operations occur in the transformed space. /// The transform to apply to the render target. void GetTransform(D2D1_MATRIX_3X2_F* transform); /// /// Creates a new bitmap render target for use during intermediate offscreen drawing that is compatible with the current render target . /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// When this method returns, contains the address of a pointer to a new bitmap render target. This parameter is passed uninitialized. /// The desired size of the new render target in device-independent pixels if it should be different from the original render target, or NULL. For more information, see the Remarks section. /// The desired size of the new render target in pixels if it should be different from the original render target, or NULL. For more information, see the Remarks section. /// The desired pixel format and alpha mode of the new render target, or NULL. If the pixel format is set to DXGI_FORMAT_UNKNOWN or if this parameter is null, the new render target uses the same pixel format as the original render target. If the alpha mode is D2D1_ALPHA_MODE_UNKNOWN or this parameter is NULL, the alpha mode of the new render target defaults to D2D1_ALPHA_MODE_PREMULTIPLIED. For information about supported pixel formats, see Supported Pixel Formats and Alpha Modes. /// A value that specifies whether the new render target must be compatible with GDI. BOOL CreateCompatibleRenderTarget(CBitmapRenderTarget& bitmapTarget, CD2DSizeF sizeDesired = CD2DSizeF(0., 0.), CD2DSizeU sizePixelDesired = CD2DSizeU(0, 0), D2D1_PIXEL_FORMAT* desiredFormat = NULL, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options = D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE); /// /// Adds the specified layer to the render target so that it receives all subsequent drawing operations until PopLayer is called. /// The content bounds, geometric mask, opacity, opacity mask, and antialiasing options for the layer. /// The layer that receives subsequent drawing operations. void PushLayer(const D2D1_LAYER_PARAMETERS& layerParameters, CD2DLayer& layer); /// /// Stops redirecting drawing operations to the layer that is specified by the last PushLayer call. void PopLayer(); /// /// Executes all pending drawing commands. /// Contains the tag for drawing operations that caused errors or 0 if there were no errors. This parameter is passed uninitialized. /// Contains the tag for drawing operations that caused errors or 0 if there were no errors. This parameter is passed uninitialized. void Flush(D2D1_TAG* tag1 = NULL, D2D1_TAG* tag2 = NULL); /// /// Saves the current drawing state to the specified ID2D1DrawingStateBlock. /// When this method returns, contains the current drawing state of the render target. This parameter must be initialized before passing it to the method. void SaveDrawingState(ID2D1DrawingStateBlock& drawingStateBlock) const; /// /// Sets the render target's drawing state to that of the specified ID2D1DrawingStateBlock. /// The new drawing state of the render target. void RestoreDrawingState(ID2D1DrawingStateBlock& drawingStateBlock); /// /// Removes the last axis-aligned clip from the render target. After this method is called, the clip is no longer applied to subsequent drawing operations. /// The size and position of the clipping area, in device-independent pixels. /// The antialiasing mode that is used to draw the edges of clip rects that have subpixel boundaries, and to blend the clip with the scene contents. The blending is performed once when the PopAxisAlignedClip method is called, and does not apply to each primitive within the layer. void PushAxisAlignedClip(const CD2DRectF& rectClip, D2D1_ANTIALIAS_MODE mode = D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); /// /// Removes the last axis-aligned clip from the render target. After this method is called, the clip is no longer applied to subsequent drawing operations. void PopAxisAlignedClip(); protected: /// /// Verifies CD2DResource object validity; creates the object if it didn't already exist. /// Pointer to CD2DResource object. /// /// TRUE is object if valid; otherwise FALSE. BOOL VerifyResource(CD2DResource* pResource); /// /// A pointer to an ID2D1RenderTarget object. /// ID2D1RenderTarget* m_pRenderTarget; /// /// A list of pointers to CD2DResource objects. /// CObList m_lstResources; /// /// A pointer to CD2DTextFormat object that contains a default text format. /// CD2DTextFormat* m_pTextFormatDefault; }; /// /// ID2D1HwndRenderTarget wrapper. /// class CHwndRenderTarget : public CRenderTarget { DECLARE_DYNAMIC(CHwndRenderTarget) public: /// /// Constructs a CHwndRenderTarget object from HWND. /// The HWND associated with this render target CHwndRenderTarget(HWND hwnd = NULL); /// /// Attaches existing render target interface to the object /// Existing render target interface. Cannot be NULL void Attach(ID2D1HwndRenderTarget* pTarget); /// /// Detaches render target interface from the object /// /// Pointer to detached render target interface. ID2D1HwndRenderTarget* Detach(); /// /// Creates a render target associated with the window /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE /// The HWND associated with this render target BOOL Create(HWND hWnd); /// /// Re-creates a render target associated with the window /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The HWND associated with this render target BOOL ReCreate(HWND hWnd); /// /// Returns ID2D1HwndRenderTarget interface. /// /// Pointer to an ID2D1HwndRenderTarget interface or NULL if object is not initialized yet. ID2D1HwndRenderTarget* GetHwndRenderTarget() { return m_pHwndRenderTarget; } /// /// Returns ID2D1HwndRenderTarget interface. /// /// Pointer to an ID2D1HwndRenderTarget interface or NULL if object is not initialized yet. operator ID2D1HwndRenderTarget*() { return m_pHwndRenderTarget; } /// /// Returns the HWND associated with this render target. /// /// The HWND associated with this render target. HWND GetHwnd() const { return m_pHwndRenderTarget == NULL ? NULL : m_pHwndRenderTarget->GetHwnd(); } /// /// Indicates whether the HWND associated with this render target is occluded. /// /// A value that indicates whether the HWND associated with this render target is occluded. D2D1_WINDOW_STATE CheckWindowState() const { return m_pHwndRenderTarget == NULL ? D2D1_WINDOW_STATE_NONE : m_pHwndRenderTarget->CheckWindowState(); } /// /// Changes the size of the render target to the specified pixel size /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The new size of the render target in device pixels BOOL Resize(const CD2DSizeU& size); protected: /// /// A pointer to an ID2D1HwndRenderTarget object. /// ID2D1HwndRenderTarget* m_pHwndRenderTarget; }; /// /// ID2D1DCRenderTarget wrapper. /// class CDCRenderTarget : public CRenderTarget { DECLARE_DYNAMIC(CDCRenderTarget) public: /// /// Constructs a CDCRenderTarget object. CDCRenderTarget(); /// /// Attaches existing render target interface to the object /// Existing render target interface. Cannot be NULL void Attach(ID2D1DCRenderTarget* pTarget); /// /// Detaches render target interface from the object /// /// Pointer to detached render target interface. ID2D1DCRenderTarget* Detach(); /// /// Creates a CDCRenderTarget. /// /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The rendering mode, pixel format, remoting options, DPI information, and the minimum DirectX support required for hardware rendering. BOOL Create(const D2D1_RENDER_TARGET_PROPERTIES& props); /// /// Binds the render target to the device context to which it issues drawing commands /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// The device context to which the render target issues drawing commands /// The dimensions of the handle to a device context (HDC) to which the render target is bound BOOL BindDC(const CDC& dc, const CRect& rect); /// /// Returns ID2D1DCRenderTarget interface /// /// Pointer to an ID2D1DCRenderTarget interface or NULL if object is not initialized yet. ID2D1DCRenderTarget* GetDCRenderTarget() { return m_pDCRenderTarget; } /// /// Returns ID2D1DCRenderTarget interface /// /// Pointer to an ID2D1DCRenderTarget interface or NULL if object is not initialized yet. operator ID2D1DCRenderTarget*() { return m_pDCRenderTarget; } protected: /// /// A pointer to an ID2D1DCRenderTarget object. /// ID2D1DCRenderTarget* m_pDCRenderTarget; }; class CBitmapRenderTarget : public CRenderTarget { DECLARE_DYNAMIC(CBitmapRenderTarget) friend class CRenderTarget; public: /// /// Constructs a CBitmapRenderTarget object. CBitmapRenderTarget() { m_pBitmapRenderTarget = NULL; } public: /// /// Attaches existing render target interface to the object /// Existing render target interface. Cannot be NULL void Attach(ID2D1BitmapRenderTarget* pTarget); /// /// Detaches render target interface from the object /// /// Pointer to detached render target interface. ID2D1BitmapRenderTarget* Detach(); /// /// Returns ID2D1BitmapRenderTarget interface /// /// Pointer to an ID2D1BitmapRenderTarget interface or NULL if object is not initialized yet. ID2D1BitmapRenderTarget* GetBitmapRenderTarget() { return m_pBitmapRenderTarget; } /// /// Returns ID2D1BitmapRenderTarget interface /// /// Pointer to an ID2D1BitmapRenderTarget interface or NULL if object is not initialized yet. operator ID2D1BitmapRenderTarget*() { return m_pBitmapRenderTarget; } /// /// Retrieves the bitmap for this render target. The returned bitmap can be used for drawing operations. /// If the method succeeds, it returns TRUE. Otherwise, it returns FALSE. /// When this method returns, contains the valid bitmap for this render target. This bitmap can be used for drawing operations. BOOL GetBitmap(CD2DBitmap& bitmap); protected: /// /// A pointer to an ID2D1BitmapRenderTarget object. /// ID2D1BitmapRenderTarget* m_pBitmapRenderTarget; }; /*============================================================================*/ // _AFX_D2D_STATE typedef HRESULT (WINAPI * D2D1MAKEROTATEMATRIX)(FLOAT angle, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix); class _AFX_D2D_STATE : public CNoTrackObject { public: _AFX_D2D_STATE(); virtual ~_AFX_D2D_STATE(); BOOL IsD2DInitialized() const { return m_bD2DInitialized; } BOOL InitD2D(D2D1_FACTORY_TYPE d2dFactoryType = D2D1_FACTORY_TYPE_SINGLE_THREADED, DWRITE_FACTORY_TYPE writeFactoryType = DWRITE_FACTORY_TYPE_SHARED); void ReleaseD2DRefs(); ID2D1Factory* GetDirect2dFactory() { InitD2D(); return m_pDirect2dFactory; } IDWriteFactory* GetWriteFactory() { InitD2D(); return m_pWriteFactory; } IWICImagingFactory* GetWICFactory() { InitD2D(); return m_pWicFactory; } HRESULT D2D1MakeRotateMatrix(FLOAT angle, D2D1_POINT_2F center, D2D1_MATRIX_3X2_F *matrix) { return m_pfD2D1MakeRotateMatrix == NULL ? E_FAIL : (*m_pfD2D1MakeRotateMatrix)(angle, center, matrix); } protected: HINSTANCE m_hinstD2DDLL; HINSTANCE m_hinstDWriteDLL; ID2D1Factory* m_pDirect2dFactory; IDWriteFactory* m_pWriteFactory; IWICImagingFactory* m_pWicFactory; D2D1MAKEROTATEMATRIX m_pfD2D1MakeRotateMatrix; BOOL m_bD2DInitialized; BOOL m_bComInitialized; }; AFX_DATA EXTERN_PROCESS_LOCAL(_AFX_D2D_STATE, _afxD2DState) _AFX_D2D_STATE* AFX_CDECL AfxGetD2DState(); void AFX_CDECL AfxReleaseD2DRefs(); #ifdef _AFX_MINREBUILD #pragma component(minrebuild, on) #endif #ifdef _AFX_PACKING #pragma pack(pop) #endif // _ATLMFC_DISABLED_WARNINGS #pragma warning(pop)