4
4
using System . Drawing ;
5
5
using System . Numerics ;
6
6
using Windows ;
7
- using Windows . Win32 . Foundation ;
8
7
using Windows . Win32 . Graphics . Direct2D ;
9
8
10
9
namespace Direct2dDemo ;
@@ -23,63 +22,63 @@ public Direct2dDemo() : base(title: "Simple Direct2D Application", features: Fea
23
22
{
24
23
}
25
24
26
- protected override void RenderTargetCreated ( HwndRenderTarget renderTarget )
25
+ protected override void RenderTargetCreated ( )
27
26
{
28
27
_lightSlateGrayBrush ? . Dispose ( ) ;
29
28
_cornflowerBlueBrush ? . Dispose ( ) ;
30
- _lightSlateGrayBrush = renderTarget . CreateSolidColorBrush ( Color . LightSlateGray ) ;
31
- _cornflowerBlueBrush = renderTarget . CreateSolidColorBrush ( Color . CornflowerBlue ) ;
32
- base . RenderTargetCreated ( renderTarget ) ;
29
+ _lightSlateGrayBrush = RenderTarget . CreateSolidColorBrush ( Color . LightSlateGray ) ;
30
+ _cornflowerBlueBrush = RenderTarget . CreateSolidColorBrush ( Color . CornflowerBlue ) ;
31
+ base . RenderTargetCreated ( ) ;
33
32
}
34
33
35
- protected override LRESULT WindowProcedure ( HWND window , MessageType message , WPARAM wParam , LPARAM lParam )
34
+ protected override void OnPaint ( )
36
35
{
37
- switch ( message )
38
- {
39
- case MessageType . Paint :
40
- if ( IsDirect2dEnabled ( out var renderTarget ) )
41
- {
42
- renderTarget . SetTransform ( Matrix3x2 . Identity ) ;
43
- renderTarget . Clear ( Color . White ) ;
36
+ RenderTarget . SetTransform ( Matrix3x2 . Identity ) ;
37
+ RenderTarget . Clear ( Color . White ) ;
44
38
45
- SizeF size = renderTarget . Size ( ) ;
39
+ SizeF size = RenderTarget . Size ( ) ;
46
40
47
- for ( int x = 0 ; x < size . Width ; x += 10 )
48
- {
49
- renderTarget . DrawLine (
50
- new ( x , 0 ) , new ( x , size . Height ) ,
51
- _lightSlateGrayBrush ! ,
52
- 0.5f ) ;
53
- }
41
+ for ( int x = 0 ; x < size . Width ; x += 10 )
42
+ {
43
+ RenderTarget . DrawLine (
44
+ new ( x , 0 ) , new ( x , size . Height ) ,
45
+ _lightSlateGrayBrush ! ,
46
+ 0.5f ) ;
47
+ }
54
48
55
- for ( int y = 0 ; y < size . Height ; y += 10 )
56
- {
57
- renderTarget . DrawLine (
58
- new ( 0 , y ) , new ( size . Width , y ) ,
59
- _lightSlateGrayBrush ! ,
60
- 0.5f ) ;
61
- }
49
+ for ( int y = 0 ; y < size . Height ; y += 10 )
50
+ {
51
+ RenderTarget . DrawLine (
52
+ new ( 0 , y ) , new ( size . Width , y ) ,
53
+ _lightSlateGrayBrush ! ,
54
+ 0.5f ) ;
55
+ }
62
56
63
- RectangleF rectangle1 = RectangleF . FromLTRB (
64
- size . Width / 2 - 50 ,
65
- size . Height / 2 - 50 ,
66
- size . Width / 2 + 50 ,
67
- size . Height / 2 + 50 ) ;
57
+ RectangleF rectangle1 = RectangleF . FromLTRB (
58
+ size . Width / 2 - 50 ,
59
+ size . Height / 2 - 50 ,
60
+ size . Width / 2 + 50 ,
61
+ size . Height / 2 + 50 ) ;
68
62
69
- RectangleF rectangle2 = RectangleF . FromLTRB (
70
- size . Width / 2 - 100 ,
71
- size . Height / 2 - 100 ,
72
- size . Width / 2 + 100 ,
73
- size . Height / 2 + 100 ) ;
63
+ RectangleF rectangle2 = RectangleF . FromLTRB (
64
+ size . Width / 2 - 100 ,
65
+ size . Height / 2 - 100 ,
66
+ size . Width / 2 + 100 ,
67
+ size . Height / 2 + 100 ) ;
74
68
75
- renderTarget . FillRectangle ( rectangle1 , _lightSlateGrayBrush ! ) ;
76
- renderTarget . DrawRectangle ( rectangle2 , _cornflowerBlueBrush ! ) ;
77
- }
69
+ RenderTarget . FillRectangle ( rectangle1 , _lightSlateGrayBrush ! ) ;
70
+ RenderTarget . DrawRectangle ( rectangle2 , _cornflowerBlueBrush ! ) ;
71
+ }
78
72
79
- return ( LRESULT ) 0 ;
73
+ protected override void Dispose ( bool disposing )
74
+ {
75
+ if ( disposing )
76
+ {
77
+ _lightSlateGrayBrush ? . Dispose ( ) ;
78
+ _cornflowerBlueBrush ? . Dispose ( ) ;
80
79
}
81
80
82
- return base . WindowProcedure ( window , message , wParam , lParam ) ;
81
+ base . Dispose ( disposing ) ;
83
82
}
84
83
}
85
84
}
0 commit comments