Преглед на файлове

commit: larger text with outline

HOME преди 4 години
родител
ревизия
e3a6b13a82
променени са 1 файла, в които са добавени 49 реда и са изтрити 25 реда
  1. 49 25
      BsWidget/MainForm.cs

+ 49 - 25
BsWidget/MainForm.cs

@@ -62,7 +62,7 @@ namespace BsWidget
         protected override void OnLoad(EventArgs e)
         {
             base.OnLoad(e);
-            Font = new Font("", 20, FontStyle.Bold, GraphicsUnit.Pixel);
+            Font = new Font("", 30, FontStyle.Bold, GraphicsUnit.Pixel);
             TopMost = true;
             WindowState = FormWindowState.Normal;
             Left = 0;
@@ -79,7 +79,6 @@ namespace BsWidget
             base.OnClosing(e);
         }
 
-
         protected override void OnKeyDown(KeyEventArgs e)
         {
             base.OnKeyDown(e);
@@ -156,6 +155,10 @@ namespace BsWidget
 
         protected override void RenderGraphic(Graphics g)
         {
+            const int margin = 10;
+            const int fontHeight = 50;
+            const int coverSize = 200;
+
             if (_queue.Count == 0) return;
 
             var flags = _queue.Take();
@@ -164,6 +167,8 @@ namespace BsWidget
 
             g.SetHighQuality();
 
+            var nextY = 0;
+
             if (flags.HasFlag(UpdateFlags.BeatMap))
             {
                 // Cover: 10,10 128x128
@@ -174,47 +179,50 @@ namespace BsWidget
                 // Diff/BMP/NJS:  10,148
 
                 //clear region 0,0 Wx180
-                g.ClearRect(Color.Transparent, 0, 0, ViewSize.Width, 180);
+                g.ClearRect(Color.Transparent, 0, 0, ViewSize.Width, margin + coverSize + margin + fontHeight);
 
                 //draw cover and text
-                g.DrawImage(SongIcon, 10, 10, 128, 128);
-                g.DrawRectangle(Pens.White, 10, 10, 128, 128);
-
-                g.DrawString(SongName, Font, Brushes.White, 148, 10);
-                g.DrawString(SongSubName, Font, Brushes.White, 148, 40);
-                g.DrawString(SongArtist, Font, Brushes.White, 148, 70);
-                g.DrawString(BeatMapper, Font, Brushes.White, 148, 100);
-
-                g.DrawString($"[{Difficulty}]   {SongBpm} BPM   {SongNjs} NJS", Font, Brushes.White, 10, 148);
+                g.DrawImage(SongIcon, margin, margin, coverSize, coverSize);
+                g.DrawRectangle(Pens.White, 10, 10, coverSize, coverSize);
+
+                g.DrawStringWithOutline(SongName, Font, coverSize + margin, margin, Color.Black, Color.White);
+                g.DrawStringWithOutline(SongSubName, Font, coverSize + margin, margin + fontHeight, Color.Black, Color.White);
+                g.DrawStringWithOutline(SongArtist, Font, coverSize + margin, margin + fontHeight * 2, Color.Black, Color.White);
+                g.DrawStringWithOutline(BeatMapper, Font, coverSize + margin, margin + fontHeight * 3, Color.Black, Color.White);
+                g.DrawStringWithOutline($"[{Difficulty}]   {SongBpm} BPM   {SongNjs} NJS", Font, 10, margin * 2 + coverSize, Color.Black, Color.White);
             }
 
+            nextY = margin + coverSize + margin + fontHeight;
+
             if (flags.HasFlag(UpdateFlags.Performance))
             {
                 //clear region 0,180 Wx180
-                g.ClearRect(Color.Transparent, 0, 180, ViewSize.Width, 25);
+                g.ClearRect(Color.Transparent, 0, nextY + margin, ViewSize.Width, fontHeight * 2);
 
                 //draw text
-                g.DrawString($"{CurrentScore:N0} POINTS   {CurrentCombo} COMBO   {CurrentRank} RANK", Font, Brushes.White, 10, 180);
+                g.DrawStringWithOutline($"{CurrentScore:N0} POINTS   {CurrentRank} RANK", Font, margin, nextY + margin, Color.Black, Color.White);
+                g.DrawStringWithOutline($"{CurrentCombo} COMBO", Font, margin, nextY + margin + fontHeight, Color.Black, Color.White);
             }
 
+            nextY += margin + fontHeight * 2;
+
             if (flags.HasFlag(UpdateFlags.NoteFullyCut) && CutHistory.Count > 1)
             {
-                const int ChLeft = 10;
-                const int ChTop = 210;
-                const int ChWidth = 320;
-                const int ChHeight = 100;
+                int ChLeft = margin;
+                int ChTop = nextY + margin;
+                int ChWidth = 256;
+                int ChHeight = 100;
 
-                const int ChBottom = ChTop + ChHeight;
+                int ChBottom = ChTop + ChHeight;
 
-                const float RecordPixel = 2;
-                const float LineWidth = 3f;
+                float RecordPixel = 2;
+                float LineWidth = 3f;
 
-                const int DisplayCount = (int)(ChWidth / RecordPixel);
+                int DisplayCount = (int)(ChWidth / RecordPixel);
 
                 using var scorePen = new Pen(Color.FromArgb(233, 255, 0, 0), LineWidth) { LineJoin = LineJoin.Round };
                 using var comboPen = new Pen(Color.FromArgb(233, 0, 0, 255), LineWidth) { LineJoin = LineJoin.Round };
 
-
                 //clear region 0,210 Wx200
                 g.ClearRect(Color.Transparent, 0, ChTop - 3, ViewSize.Width, ChHeight + 6);
 
@@ -249,7 +257,6 @@ namespace BsWidget
 
                 g.DrawLines(scorePen, scorePts.ToArray());
                 g.DrawLines(comboPen, comboPts.ToArray());
-
             }
         }
     }
@@ -269,7 +276,24 @@ namespace BsWidget
             g.InterpolationMode = InterpolationMode.HighQualityBicubic;
             g.PixelOffsetMode = PixelOffsetMode.HighQuality;
             g.SmoothingMode = SmoothingMode.HighQuality;
-            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
+            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
+        }
+
+        public static void DrawStringWithOutline(this Graphics g, string text, Font font, int x, int y, Color outlineColor, Color fillColor, float outlineWidth = 1)
+        {
+            // assuming g is the Graphics object on which you want to draw the text
+            GraphicsPath p = new GraphicsPath();
+            p.AddString(
+                text,             // text to draw
+                font.FontFamily,  // or any other font family
+                (int)FontStyle.Regular,      // font style (bold, italic, etc.)
+                g.DpiY * font.Size / 72,       // em size
+                new Point(x, y),              // location where to draw text
+                new StringFormat());          // set options here (e.g. center alignment)
+            using var outlinePen = new Pen(outlineColor, outlineWidth);
+            using var fillBrush = new SolidBrush(fillColor);
+            g.FillPath(fillBrush, p);
+            g.DrawPath(outlinePen, p);
         }
     }
 }