Browse Source

Improved infobox visuals

flabbet 9 months ago
parent
commit
c6ada01d3d

+ 3 - 0
src/PixiEditor/Helpers/ThemeResources.cs

@@ -16,4 +16,7 @@ public static class ThemeResources
     
     public static Color BackgroundColor =>
         ResourceLoader.GetResource<SolidColorBrush>("ThemeBackgroundBrush", Application.Current.ActualThemeVariant).Color.ToColor();
+
+    public static Color BorderMidColor =>
+        ResourceLoader.GetResource<SolidColorBrush>("ThemeBorderMidBrush", Application.Current.ActualThemeVariant).Color.ToColor();
 }

+ 16 - 3
src/PixiEditor/Views/Overlays/Drawables/InfoBox.cs

@@ -18,6 +18,11 @@ public class InfoBox
     {
         Color = Colors.White, StrokeWidth = 1, Style = PaintStyle.Fill, IsAntiAliased = true
     };
+    
+    private Paint borderPen = new Paint()
+    {
+        Color = Colors.Black, StrokeWidth = 1, Style = PaintStyle.Stroke, IsAntiAliased = true
+    };
 
     public double ZoomScale { get; set; } = 1;
 
@@ -28,21 +33,29 @@ public class InfoBox
         font = ThemeResources.ThemeFont;
         fontPen.Color = ThemeResources.ForegroundColor;
         backgroundPen.Color = ThemeResources.BackgroundColor;
+        borderPen.Color = ThemeResources.BorderMidColor;
     }
 
     public void DrawInfo(Canvas context, string text, VecD pointerPos)
     {
+        const float padding = 10;
         font.FontSize = 14 / ZoomScale;
 
         double widthTextSize = font.MeasureText(text);
 
         VecD aboveCursor = pointerPos + new VecD(0, -20 / ZoomScale);
-        float rectWidth = (float)widthTextSize + (10 / (float)ZoomScale);
-        float rectHeight = 20 / (float)ZoomScale;
+        float rectWidth = (float)widthTextSize + (padding * 2 / (float)ZoomScale);
+        float rectHeight = (float)font.FontSize + padding / (float)ZoomScale;
         float x = (float)aboveCursor.X - rectWidth / 2;
-        float y = (float)aboveCursor.Y - ((float)font.FontSize);
+        float y = (float)aboveCursor.Y - ((float)font.FontSize) - (padding / 4) / (float)ZoomScale;
+        
         context.DrawRoundRect(x, y, rectWidth, rectHeight, 5 / (float)ZoomScale,
             5 / (float)ZoomScale, backgroundPen);
+        
+        borderPen.StrokeWidth = 1 / (float)ZoomScale;
+        
+        context.DrawRoundRect(x, y, rectWidth, rectHeight, 5 / (float)ZoomScale,
+            5 / (float)ZoomScale, borderPen);
 
         context.DrawText(text, aboveCursor, TextAlign.Center, font, fontPen);
     }