5 #ifndef __d2ddrawcontext__ 6 #define __d2ddrawcontext__ 8 #include "../../../coffscreencontext.h" 10 #if WINDOWS && VSTGUI_DIRECT2D_SUPPORT 12 #include "d2dbitmap.h" 21 class D2DDrawContext :
public COffscreenContext
24 D2DDrawContext (HWND window,
const CRect& drawSurface);
25 D2DDrawContext (D2DBitmap* bitmap);
28 ID2D1RenderTarget* getRenderTarget ()
const {
return renderTarget; }
29 ID2D1SolidColorBrush* getFillBrush ()
const {
return fillBrush; }
30 ID2D1SolidColorBrush* getStrokeBrush ()
const {
return strokeBrush; }
31 ID2D1SolidColorBrush* getFontBrush ()
const {
return fontBrush; }
32 ID2D1StrokeStyle* getStrokeStyle ()
const {
return strokeStyle; }
35 void drawLine (
const LinePair& line)
override;
36 void drawLines (
const LineList& lines)
override;
37 void drawPolygon (
const PointList& polygonPointList,
const CDrawStyle drawStyle = kDrawStroked)
override;
38 void drawRect (
const CRect &rect,
const CDrawStyle drawStyle = kDrawStroked)
override;
39 void drawArc (
const CRect &rect,
const float startAngle1,
const float endAngle2,
const CDrawStyle drawStyle = kDrawStroked)
override;
40 void drawEllipse (
const CRect &rect,
const CDrawStyle drawStyle = kDrawStroked)
override;
41 void drawPoint (
const CPoint &point,
const CColor& color)
override;
42 void drawBitmap (CBitmap* bitmap,
const CRect& dest,
const CPoint& offset = CPoint (0, 0),
float alpha = 1.f)
override;
43 void clearRect (
const CRect& rect)
override;
44 void setLineStyle (
const CLineStyle& style)
override;
45 void setLineWidth (CCoord width)
override;
46 void setDrawMode (CDrawMode mode)
override;
47 void setClipRect (
const CRect &clip)
override;
48 void resetClipRect ()
override;
49 void setFillColor (
const CColor& color)
override;
50 void setFrameColor (
const CColor& color)
override;
51 void setFontColor (
const CColor& color)
override;
52 void setGlobalAlpha (
float newAlpha)
override;
53 void saveGlobalState ()
override;
54 void restoreGlobalState ()
override;
55 CGraphicsPath* createGraphicsPath ()
override;
56 CGraphicsPath* createTextPath (
const CFontRef font, UTF8StringPtr text)
override;
57 void drawGraphicsPath (CGraphicsPath* path, PathDrawMode mode = kPathFilled, CGraphicsTransform* transformation = 0)
override;
58 void fillLinearGradient (CGraphicsPath* path,
const CGradient& gradient,
const CPoint& startPoint,
const CPoint& endPoint,
bool evenOdd =
false, CGraphicsTransform* transformation = 0)
override;
59 void fillRadialGradient (CGraphicsPath* path,
const CGradient& gradient,
const CPoint& center, CCoord radius,
const CPoint& originOffset = CPoint (0, 0),
bool evenOdd =
false, CGraphicsTransform* transformation = 0)
override;
61 void beginDraw ()
override;
62 void endDraw ()
override;
64 double getScaleFactor ()
const override {
return scaleFactor; }
70 D2DApplyClip (D2DDrawContext* drawContext,
bool halfPointOffset =
false);
72 bool isEmpty ()
const {
return applyClip.isEmpty (); }
74 D2DDrawContext* drawContext;
76 bool layerIsUsed {
false};
79 template<
typename T>
void pixelAllign (T& rect)
const;
83 void init ()
override;
84 void createRenderTarget ();
85 void releaseRenderTarget ();
86 ID2D1GradientStopCollection* createGradientStopCollection (
const CGradient& gradient)
const;
88 void setFillColorInternal (
const CColor& color);
89 void setFrameColorInternal (
const CColor& color);
90 void setFontColorInternal (
const CColor& color);
91 void setLineStyleInternal (
const CLineStyle& style);
92 void setDrawModeInternal (CDrawMode mode);
93 void drawLineInternal (CPoint start, CPoint end);
95 bool needsHalfPointOffset ()
const;
98 ID2D1RenderTarget* renderTarget;
99 ID2D1SolidColorBrush* fillBrush;
100 ID2D1SolidColorBrush* strokeBrush;
101 ID2D1SolidColorBrush* fontBrush;
102 ID2D1StrokeStyle* strokeStyle;
104 double scaleFactor {1.};
108 template<
typename T>
void D2DDrawContext::pixelAllign (T& obj)
const 110 const CGraphicsTransform& t = getCurrentTransform ();
111 CGraphicsTransform tInv = t.inverse ();
114 tInv.transform (obj);
118 static inline D2D1_RECT_F makeD2DRect (
const CRect& r)
120 D2D1_RECT_F dr = {(FLOAT)r.left, (FLOAT)r.top, (FLOAT)r.right, (FLOAT)r.bottom};
125 static inline D2D1_POINT_2F makeD2DPoint (
const CPoint& p)
127 D2D1_POINT_2F dp = {(FLOAT)p.x, (FLOAT)p.y};
131 static inline D2D1_SIZE_F makeD2DSize (CCoord width, CCoord height)
133 D2D1_SIZE_F ds = {(FLOAT)width, (FLOAT)height};
138 static inline D2D1_MATRIX_3X2_F convert (
const CGraphicsTransform& t)
140 D2D1_MATRIX_3X2_F matrix;
141 matrix._11 =
static_cast<FLOAT
> (t.m11);
142 matrix._12 =
static_cast<FLOAT
> (t.m21);
143 matrix._21 =
static_cast<FLOAT
> (t.m12);
144 matrix._22 =
static_cast<FLOAT
> (t.m22);
145 matrix._31 =
static_cast<FLOAT
> (t.dx);
146 matrix._32 =
static_cast<FLOAT
> (t.dy);
154 #endif // __d2ddrawcontext__ Definition: customcontrols.cpp:8