From c1a26057d172820cf597da34b175fff9e051d738 Mon Sep 17 00:00:00 2001 From: Brandon Chong Date: Sat, 14 Apr 2018 12:02:17 -0700 Subject: [PATCH] Fix measurement for control size --- src/AudioBand/NowPlayingDisplay.cs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/AudioBand/NowPlayingDisplay.cs b/src/AudioBand/NowPlayingDisplay.cs index 330b101e..91151c23 100644 --- a/src/AudioBand/NowPlayingDisplay.cs +++ b/src/AudioBand/NowPlayingDisplay.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; -using System.Drawing.Imaging; using System.Drawing.Text; using System.Windows.Forms; using Timer = System.Windows.Forms.Timer; @@ -103,7 +102,6 @@ public Color TrackNameColor private int _duplicateXPos; private readonly Timer _nowPlayingTimer = new Timer { Interval = 20 }; private const int TextMargin = 60; //Spacing between scrolling text - private Rectangle _clipRectangle; // Real size private Font _artistFont; private Color _artistColor; private Brush _artistBrush; @@ -114,7 +112,6 @@ public Color TrackNameColor public NowPlayingDisplay() { DoubleBuffered = true; - UpdateClipRectangle(); _nowPlayingTimer.Tick += NowPlayingTimerOnTick; } @@ -125,7 +122,7 @@ private void CheckNowPlayingText() var textSize = MeasureNowPlayingText(graphics); _nowPlayingTextWidth = (int) textSize.Width + 1; - if (textSize.Width <= _clipRectangle.Width) + if (textSize.Width <= ClientRectangle.Width) { _scrolling = false; _nowPlayingTimer.Stop(); @@ -139,7 +136,7 @@ private void CheckNowPlayingText() return; } - _nowPlayingXPos = _clipRectangle.Width / 4; + _nowPlayingXPos = ClientRectangle.Width / 4; _duplicateXPos = _nowPlayingXPos + _nowPlayingTextWidth + TextMargin; _scrolling = true; @@ -176,17 +173,6 @@ protected override void Dispose(bool disposing) _nowPlayingTimer.Stop(); } - protected override void OnResize(EventArgs e) - { - base.OnResize(e); - UpdateClipRectangle(); - } - - private void UpdateClipRectangle() - { - _clipRectangle = RectangleToClient(ClientRectangle); - } - private void UpdateTextPositions() { if (_nowPlayingXPos + _nowPlayingTextWidth + TextMargin < 0) @@ -207,8 +193,9 @@ private void DrawNowPlayingText(Graphics graphics, float? x) { if (x == null) { + var size = MeasureNowPlayingText(graphics); - x = _clipRectangle.Width / 2 - size.Width / 2; + x = ClientRectangle.Width / 2 - size.Width / 2; } var artistText = NowPlayingText.Artist; @@ -242,11 +229,11 @@ private void UpdateBrushes(bool fade) private LinearGradientBrush CreateFadeBrush(Color color) { - return new LinearGradientBrush(_clipRectangle, color, color, LinearGradientMode.Horizontal) + return new LinearGradientBrush(ClientRectangle, color, color, LinearGradientMode.Horizontal) { InterpolationColors = new ColorBlend(4) { - Colors = new[] { Color.FromArgb(0, BackColor), color, color, Color.FromArgb(0, BackColor) }, + Colors = new[] { Color.FromArgb(0, 0, 0, 0), color, color, Color.FromArgb(0, 0, 0, 0) }, Positions = new[] { 0, 0.1f, 0.9f, 1 } } };