@@ -10,8 +10,7 @@ namespace Windows;
10
10
public static unsafe partial class DeviceContextExtensions
11
11
{
12
12
/// <inheritdoc cref="Interop.GetGraphicsMode(HDC)"/>
13
- public static GRAPHICS_MODE GetGraphicsMode < T > ( this T context )
14
- where T : IHandle < HDC >
13
+ public static GRAPHICS_MODE GetGraphicsMode < T > ( this T context ) where T : IHandle < HDC >
15
14
{
16
15
GRAPHICS_MODE mode = ( GRAPHICS_MODE ) Interop . GetGraphicsMode ( context . Handle ) ;
17
16
GC . KeepAlive ( context . Wrapper ) ;
@@ -97,8 +96,8 @@ public static PolyFillMode SetPolyFillMode<T>(this T context, PolyFillMode mode)
97
96
return result ;
98
97
}
99
98
100
- public static bool Polygon < T > ( this T context , params Point [ ] points )
101
- where T : IHandle < HDC > => Polygon ( context , points . AsSpan ( ) ) ;
99
+ public static bool Polygon < T > ( this T context , params Point [ ] points ) where T : IHandle < HDC > =>
100
+ Polygon ( context , points . AsSpan ( ) ) ;
102
101
103
102
public static bool Polygon < T > ( this T context , ReadOnlySpan < Point > points )
104
103
where T : IHandle < HDC >
@@ -147,7 +146,14 @@ private static (int Height, uint LengthDrawn, Rectangle Bounds) DrawTextHelper<T
147
146
// The string won't be changed, we can just pin
148
147
fixed ( char * c = text )
149
148
{
150
- int result = Interop . DrawTextEx ( context . Handle , ( PWSTR ) c , text . Length , bounds , ( DRAW_TEXT_FORMAT ) format , dtp ) ;
149
+ int result = Interop . DrawTextEx (
150
+ context . Handle ,
151
+ ( PWSTR ) c ,
152
+ text . Length ,
153
+ bounds ,
154
+ ( DRAW_TEXT_FORMAT ) format ,
155
+ dtp ) ;
156
+
151
157
if ( result == 0 )
152
158
{
153
159
Error . ThrowIfLastErrorNot ( WIN32_ERROR . ERROR_SUCCESS ) ;
@@ -182,7 +188,14 @@ public static void DrawIcon<TDeviceContext, TIcon>(
182
188
where TDeviceContext : IHandle < HDC >
183
189
where TIcon : IHandle < HICON >
184
190
{
185
- if ( ! Interop . DrawIconEx ( context . Handle , location . X , location . Y , icon . Handle , size . Width , size . Height , 0 , default , flags ) )
191
+ if ( ! Interop . DrawIconEx (
192
+ context . Handle ,
193
+ location . X , location . Y ,
194
+ icon . Handle ,
195
+ size . Width , size . Height ,
196
+ 0 ,
197
+ HBRUSH . Null ,
198
+ flags ) )
186
199
{
187
200
Error . ThrowLastError ( ) ;
188
201
}
@@ -204,8 +217,7 @@ public static DeviceContext CreateCompatibleDeviceContext<TDeviceContext>(this T
204
217
return DeviceContext . Create ( hdc , ownsHandle : true ) ;
205
218
}
206
219
207
- public static Bitmap CreateCompatibleBitmap < T > ( this T context , Size size )
208
- where T : IHandle < HDC >
220
+ public static Bitmap CreateCompatibleBitmap < T > ( this T context , Size size ) where T : IHandle < HDC >
209
221
{
210
222
HBITMAP hbitmap = Interop . CreateCompatibleBitmap ( context . Handle , size . Width , size . Height ) ;
211
223
if ( hbitmap . IsNull )
@@ -242,26 +254,54 @@ public static RegionType SelectClippingRegion<T>(this T context, HRGN region)
242
254
return type ;
243
255
}
244
256
245
- public static bool MoveTo < T > ( this T context , Point point )
246
- where T : IHandle < HDC >
247
- => context . MoveTo ( point . X , point . Y ) ;
257
+ public static bool MoveTo < T > ( this T context , Point point ) where T : IHandle < HDC > =>
258
+ context . MoveTo ( point . X , point . Y ) ;
248
259
249
- public static bool MoveTo < T > ( this T context , int x , int y )
250
- where T : IHandle < HDC >
260
+ public static bool MoveTo < T > ( this T context , int x , int y ) where T : IHandle < HDC >
251
261
{
252
262
bool result = Interop . MoveToEx ( context . Handle , x , y , null ) ;
253
263
GC . KeepAlive ( context . Wrapper ) ;
254
264
return result ;
255
265
}
256
266
257
- public static bool LineTo < T > ( this T context , Point point )
267
+ public static bool LineTo < T > ( this T context , Point point ) where T : IHandle < HDC > =>
268
+ context . LineTo ( point . X , point . Y ) ;
269
+
270
+ public static bool LineTo < T > ( this T context , int x , int y ) where T : IHandle < HDC >
271
+ {
272
+ bool success = Interop . LineTo ( context . Handle , x , y ) ;
273
+ GC . KeepAlive ( context . Wrapper ) ;
274
+ return success ;
275
+ }
276
+
277
+ public static bool Rectangle < T > ( this T context , Rectangle rectangle ) where T : IHandle < HDC > =>
278
+ context . Rectangle ( rectangle . Left , rectangle . Top , rectangle . Right , rectangle . Bottom ) ;
279
+
280
+ public static bool Rectangle < T > ( this T context , int left , int top , int right , int bottom )
258
281
where T : IHandle < HDC >
259
- => context . LineTo ( point . X , point . Y ) ;
282
+ {
283
+ bool success = Interop . Rectangle ( context . Handle , left , top , right , bottom ) ;
284
+ GC . KeepAlive ( context . Wrapper ) ;
285
+ return success ;
286
+ }
287
+
288
+ public static bool RoundRectangle < T > ( this T context , Rectangle rectangle , Size corner ) where T : IHandle < HDC > =>
289
+ context . RoundRectangle ( rectangle . Left , rectangle . Top , rectangle . Right , rectangle . Bottom , corner . Width , corner . Height ) ;
260
290
261
- public static bool LineTo < T > ( this T context , int x , int y )
291
+ public static bool RoundRectangle < T > ( this T context , int left , int top , int right , int bottom , int width , int height )
262
292
where T : IHandle < HDC >
263
293
{
264
- bool success = Interop . LineTo ( context . Handle , x , y ) ;
294
+ bool success = Interop . RoundRect ( context . Handle , left , top , right , bottom , width , height ) ;
295
+ GC . KeepAlive ( context . Wrapper ) ;
296
+ return success ;
297
+ }
298
+
299
+ public static bool Ellipse < T > ( this T context , Rectangle rectangle ) where T : IHandle < HDC > =>
300
+ context . Ellipse ( rectangle . Left , rectangle . Top , rectangle . Right , rectangle . Bottom ) ;
301
+
302
+ public static bool Ellipse < T > ( this T context , int left , int top , int right , int bottom ) where T : IHandle < HDC >
303
+ {
304
+ bool success = Interop . Ellipse ( context . Handle , left , top , right , bottom ) ;
265
305
GC . KeepAlive ( context . Wrapper ) ;
266
306
return success ;
267
307
}
0 commit comments