2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System . Drawing ;
5
+ using System . Numerics ;
5
6
using Windows . Support ;
6
7
using Windows . Win32 . Graphics . Direct2D . Common ;
8
+ using Windows . Win32 . Graphics . DirectWrite ;
7
9
using Windows . Win32 . Graphics . Dxgi . Common ;
8
10
using Windows . Win32 . Graphics . Imaging ;
9
11
@@ -17,6 +19,123 @@ public RenderTarget(ID2D1RenderTarget* renderTarget) : base((ID2D1Resource*)rend
17
19
{
18
20
}
19
21
22
+ public void BeginDraw ( )
23
+ {
24
+ Pointer ->BeginDraw ( ) ;
25
+ GC . KeepAlive ( this ) ;
26
+ }
27
+
28
+ public void EndDraw ( out bool recreateTarget )
29
+ {
30
+ HRESULT result = Pointer ->EndDraw ( null , null ) ;
31
+ if ( result == HRESULT . D2DERR_RECREATE_TARGET )
32
+ {
33
+ recreateTarget = true ;
34
+ }
35
+ else
36
+ {
37
+ result . ThrowOnFailure ( ) ;
38
+ recreateTarget = false ;
39
+ }
40
+
41
+ GC . KeepAlive ( this ) ;
42
+ }
43
+
44
+ public SolidColorBrush CreateSolidColorBrush ( Color color )
45
+ {
46
+ ID2D1SolidColorBrush * solidColorBrush ;
47
+ D2D1_COLOR_F colorf = ( D2D1_COLOR_F ) color ;
48
+ Pointer ->CreateSolidColorBrush ( & colorf , null , & solidColorBrush ) . ThrowOnFailure ( ) ;
49
+ GC . KeepAlive ( this ) ;
50
+ return new SolidColorBrush ( solidColorBrush ) ;
51
+ }
52
+
53
+ public void SetTransform ( Matrix3x2 transform )
54
+ {
55
+ Pointer ->SetTransform ( ( D2D_MATRIX_3X2_F * ) & transform ) ;
56
+ GC . KeepAlive ( this ) ;
57
+ }
58
+
59
+ public void Clear ( Color color )
60
+ {
61
+ D2D1_COLOR_F colorf = ( D2D1_COLOR_F ) color ;
62
+ Pointer ->Clear ( & colorf ) ;
63
+ GC . KeepAlive ( this ) ;
64
+ }
65
+
66
+ public void DrawLine ( PointF point0 , PointF point1 , Brush brush , float strokeWidth = 1.0f )
67
+ {
68
+ Pointer ->DrawLine ( * ( D2D_POINT_2F * ) & point0 , * ( D2D_POINT_2F * ) & point1 , brush . Pointer , strokeWidth , null ) ;
69
+ GC. KeepAlive ( this ) ;
70
+ }
71
+
72
+ public void FillRectangle ( RectangleF rect , Brush brush )
73
+ {
74
+ D2D_RECT_F rectf = ( D2D_RECT_F ) rect ;
75
+ Pointer ->FillRectangle ( & rectf , brush . Pointer ) ;
76
+ GC . KeepAlive ( this ) ;
77
+ }
78
+
79
+ public void DrawRectangle ( RectangleF rect , Brush brush , float strokeWidth = 1.0f )
80
+ {
81
+ D2D_RECT_F rectf = ( D2D_RECT_F ) rect ;
82
+ Pointer ->DrawRectangle ( & rectf , brush . Pointer , strokeWidth , null ) ;
83
+ GC . KeepAlive ( this ) ;
84
+ }
85
+
86
+ public SizeF Size ( )
87
+ {
88
+ D2D_SIZE_F size = Pointer ->GetSizeHack ( ) ;
89
+ GC . KeepAlive ( this ) ;
90
+ return * ( SizeF * ) & size ;
91
+ }
92
+
93
+ /// <inheritdoc cref="ID2D1RenderTarget.DrawTextLayout(D2D_POINT_2F, IDWriteTextLayout*, ID2D1Brush*, D2D1_DRAW_TEXT_OPTIONS)"/>
94
+ public void DrawTextLayout (
95
+ PointF origin ,
96
+ TextLayout textLayout ,
97
+ Brush defaultFillBrush ,
98
+ DrawTextOptions options = DrawTextOptions . None )
99
+ {
100
+ Pointer ->DrawTextLayout (
101
+ origin ,
102
+ textLayout . Pointer ,
103
+ defaultFillBrush . Pointer ,
104
+ ( D2D1_DRAW_TEXT_OPTIONS ) options ) ;
105
+
106
+ GC . KeepAlive ( this ) ;
107
+ GC . KeepAlive ( textLayout ) ;
108
+ GC . KeepAlive ( defaultFillBrush ) ;
109
+ }
110
+
111
+ public void DrawBitmap (
112
+ Bitmap bitmap ,
113
+ RectangleF destinationRectangle = default ,
114
+ float opacity = 1.0f ,
115
+ BitmapInterpolationMode interpolationMode = BitmapInterpolationMode . Linear )
116
+ {
117
+ D2D_RECT_F destination = ( D2D_RECT_F ) destinationRectangle ;
118
+ if ( destinationRectangle . IsEmpty )
119
+ {
120
+ D2D_SIZE_F size = Pointer ->GetSizeHack ( ) ;
121
+ destination = new D2D_RECT_F { left = 0 , top = 0 , right = size . width , bottom = size . height } ;
122
+ }
123
+ else
124
+ {
125
+ destination = ( D2D_RECT_F ) destinationRectangle ;
126
+ }
127
+
128
+ Pointer ->DrawBitmap (
129
+ bitmap . Pointer ,
130
+ & destination ,
131
+ opacity ,
132
+ ( D2D1_BITMAP_INTERPOLATION_MODE ) interpolationMode ,
133
+ null ) ;
134
+
135
+ GC . KeepAlive ( this ) ;
136
+ GC . KeepAlive ( bitmap ) ;
137
+ }
138
+
20
139
/// <inheritdoc cref="ID2D1RenderTarget.CreateBitmapFromWicBitmap(IWICBitmapSource*, D2D1_BITMAP_PROPERTIES*, ID2D1Bitmap**)"/>
21
140
public Bitmap CreateBitmapFromWicBitmap < TBitmapSource > (
22
141
TBitmapSource wicBitmap )
0 commit comments