flabbet 7 hónapja
szülő
commit
03b7482869

+ 28 - 2
src/PixiEditor/Views/Overlays/TextOverlay/Blinker.cs

@@ -8,7 +8,20 @@ namespace PixiEditor.Views.Overlays.TextOverlay;
 
 internal class Blinker : IDisposable
 {
-    public int BlinkerPosition { get; set; }
+    public int BlinkerPosition
+    {
+        get => blinkerPosition;
+        set
+        {
+            if (blinkerPosition != value)
+            {
+                blinkerPosition = value;
+                visible = true;
+                lastUpdate = DateTime.Now;
+            }
+        }
+    }
+
     public double FontSize { get; set; }
     public VecF[] GlyphPositions { get; set; }
     public VecD Offset { get; set; }
@@ -17,6 +30,10 @@ internal class Blinker : IDisposable
 
     private Paint paint = new Paint() { Color = Colors.White, Style = PaintStyle.StrokeAndFill, StrokeWidth = 3 };
 
+    private bool visible;
+    private DateTime lastUpdate = DateTime.Now;
+    private int blinkerPosition;
+
     public void Render(Canvas canvas)
     {
         if (GlyphPositions.Length == 0)
@@ -32,11 +49,20 @@ internal class Blinker : IDisposable
 
         var x = glyphPosition.X + Offset.X;
         var y = glyphPosition.Y + Offset.Y;
-        
+
         paint.StrokeWidth = BlinkerWidth;
 
         VecD from = new VecD(x, y + glyphHeight / 4f);
         VecD to = new VecD(x, y - glyphHeight);
+
+        if (DateTime.Now - lastUpdate > TimeSpan.FromMilliseconds(500))
+        {
+            visible = !visible;
+            lastUpdate = DateTime.Now;
+        }
+
+        paint.Color = new Color(Colors.White.R, Colors.White.G, Colors.White.B, (byte)(visible ? 255 : 0));
+
         canvas.DrawLine(from, to, paint);
     }
 

+ 3 - 1
src/PixiEditor/Views/Overlays/TextOverlay/TextOverlay.cs

@@ -141,11 +141,13 @@ internal class TextOverlay : Overlay
         int saved = context.Save();
         
         context.SetMatrix(context.TotalMatrix.Concat(Matrix));
-
+        
         blinker.BlinkerWidth = 3f / (float)ZoomScale;
         blinker.Render(context);
         
         context.RestoreToCount(saved);
+        
+        Refresh();
     }
 
     protected override void OnKeyPressed(Key key, KeyModifiers keyModifiers, string? keySymbol)