44using Newtonsoft . Json . Linq ;
55using SkiaSharp ;
66using System ;
7- using System . Collections . Generic ;
8- using System . Drawing ;
97using System . IO ;
10- using System . Linq ;
11- using System . Text ;
128using System . Threading . Tasks ;
139
1410namespace SamplePlugin
@@ -110,31 +106,21 @@ public override void Dispose()
110106 public async override void KeyPressed ( KeyPayload payload )
111107 {
112108 Logger . Instance . LogMessage ( TracingLevel . INFO , "Key Pressed" ) ;
113- TitleParameters tp = new TitleParameters ( new FontFamily ( "Arial" ) , FontStyle . Bold , 20 , Color . White , true , TitleVerticalAlignment . Middle ) ;
114- using ( Image image = Tools . GenerateGenericKeyImage ( out Graphics graphics ) )
109+ using ( SKBitmap image = SkiaTools . GenerateGenericKeyImage ( out SKCanvas canvas ) )
115110 {
116- graphics . FillRectangle ( new SolidBrush ( Color . White ) , 0 , 0 , image . Width , image . Height ) ;
117- graphics . AddTextPath ( tp , image . Height , image . Width , "Test" ) ;
118- graphics . Dispose ( ) ;
119-
111+ canvas . Clear ( SKColors . DarkBlue ) ;
112+ using var font = SkiaTools . CreateFont ( "Arial" , 18 , SKFontStyle . Bold ) ;
113+ using var paint = new SKPaint { Color = SKColors . White , IsAntialias = true } ;
114+ float x = canvas . GetTextCenter ( "Pressed!" , image . Width , font ) ;
115+ canvas . DrawTextLine ( "Pressed!" , font , paint , new SKPoint ( x , image . Height / 2f - 10 ) ) ;
116+ canvas . Dispose ( ) ;
120117 await Connection . SetImageAsync ( image ) ;
121118 }
122119 }
123120
124- public async override void KeyReleased ( KeyPayload payload )
121+ public async override void KeyReleased ( KeyPayload payload )
125122 {
126- // Cross-platform approach using SkiaSharp (works on Windows, macOS, Linux)
127- using ( SKBitmap image = SkiaTools . GenerateGenericKeyImage ( out SKCanvas canvas ) )
128- {
129- canvas . Clear ( SKColors . White ) ;
130- using ( var font = SkiaTools . CreateFont ( "Arial" , 20 , SKFontStyle . Bold ) )
131- using ( var paint = new SKPaint { Color = SKColors . Black , IsAntialias = true } )
132- {
133- canvas . DrawText ( "Cross-Platform" , 10 , 50 , font , paint ) ;
134- }
135- canvas . Dispose ( ) ;
136- await Connection . SetImageAsync ( image ) ;
137- }
123+ await Connection . SetDefaultImageAsync ( ) ;
138124 }
139125
140126 public override void OnTick ( ) { }
@@ -156,4 +142,4 @@ private Task SaveSettings()
156142
157143 #endregion
158144 }
159- }
145+ }
0 commit comments