File tree Expand file tree Collapse file tree 6 files changed +32
-5
lines changed
System.Private.Windows.Core/src
Windows/Win32/Graphics/Gdi
System.Windows.Forms.Primitives
System.Windows.Forms/System/Windows/Forms/Rendering Expand file tree Collapse file tree 6 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -118,10 +118,12 @@ GetSystemMetrics
118
118
GetThreadLocale
119
119
GetViewportExtEx
120
120
GetViewportOrgEx
121
+ GetWindowOrgEx
121
122
GetWindowRect
122
123
GetWindowText
123
124
GetWindowTextLength
124
125
GetWindowThreadProcessId
126
+ GetWorldTransform
125
127
GlobalAlloc
126
128
GlobalFree
127
129
GlobalLock
Original file line number Diff line number Diff line change 1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Drawing ;
5
+ using System . Numerics ;
6
+ using System . Runtime . CompilerServices ;
7
+
4
8
namespace Windows . Win32 . Graphics . Gdi ;
5
9
6
10
internal readonly partial struct HDC : IHandle < HDC >
7
11
{
8
12
HDC IHandle < HDC > . Handle => this ;
9
13
object ? IHandle < HDC > . Wrapper => null ;
14
+
15
+ internal Point GetViewPointOrigin ( ) =>
16
+ PInvokeCore . GetViewportOrgEx ( this , out Point point ) ? point : Point . Empty ;
17
+
18
+ internal Point GetWindowOrigin ( ) =>
19
+ PInvokeCore . GetWindowOrgEx ( this , out Point point ) ? point : Point . Empty ;
20
+
21
+ internal Matrix3x2 GetWorldTransform ( )
22
+ {
23
+ if ( PInvokeCore . GetWorldTransform ( this , out XFORM matrix ) )
24
+ {
25
+ return Unsafe . As < XFORM , Matrix3x2 > ( ref matrix ) ;
26
+ }
27
+
28
+ // If we can't get the transform, return the identity matrix.
29
+ return Matrix3x2 . Identity ;
30
+ }
10
31
}
Original file line number Diff line number Diff line change @@ -224,7 +224,6 @@ GetWindow
224
224
GetWindowDisplayAffinity
225
225
GetWindowDpiAwarenessContext
226
226
GetWindowPlacement
227
- GetWorldTransform
228
227
GMR_*
229
228
HC_*
230
229
HDHITTESTINFO
Original file line number Diff line number Diff line change @@ -32,9 +32,7 @@ public DeviceContextState(HDC hdc)
32
32
TextAlign = PInvoke . GetTextAlign ( hdc ) ;
33
33
BackgroundMode = PInvoke . GetBkMode ( hdc ) ;
34
34
35
- Matrix3x2 transform = default ;
36
- PInvoke . GetWorldTransform ( hdc , ( XFORM * ) ( void * ) & transform ) ;
37
- Transform = transform ;
35
+ Transform = hdc . GetWorldTransform ( ) ;
38
36
39
37
Point point = default ;
40
38
PInvoke . GetBrushOrgEx ( hdc , & point ) ;
Original file line number Diff line number Diff line change @@ -462,6 +462,13 @@ internal static void DrawBackgroundImage(
462
462
}
463
463
464
464
g . FillRectangle ( textureBrush , clipRect ) ;
465
+
466
+ // If the Graphics backing HDC has an offset origin (SetViewportOrgEx), drawing with a texture brush will
467
+ // reset it. Getting the HDC and releasing it will restore the offset.
468
+ //
469
+ // See https://github.com/dotnet/winforms/issues/13784 for a repro.
470
+ g . GetHdc( ) ;
471
+ g. ReleaseHdc( ) ;
465
472
}
466
473
else
467
474
{
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ private static unsafe void ValidateHdc(HDC hdc)
111
111
Debug . Assert ( PInvoke . GetBkMode ( hdc ) == BACKGROUND_MODE . OPAQUE ) ;
112
112
113
113
Matrix3x2 matrix = default ;
114
- Debug . Assert ( PInvoke . GetWorldTransform ( hdc , ( XFORM * ) ( void * ) & matrix ) ) ;
114
+ Debug . Assert ( PInvokeCore . GetWorldTransform ( hdc , ( XFORM * ) ( void * ) & matrix ) ) ;
115
115
Debug . Assert ( matrix . IsIdentity ) ;
116
116
}
117
117
}
You can’t perform that action at this time.
0 commit comments