Skip to content

Commit

Permalink
Fix measurement for control size
Browse files Browse the repository at this point in the history
  • Loading branch information
dsafa committed Apr 14, 2018
1 parent 3ee4f51 commit c1a2605
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/AudioBand/NowPlayingDisplay.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -114,7 +112,6 @@ public Color TrackNameColor
public NowPlayingDisplay()
{
DoubleBuffered = true;
UpdateClipRectangle();
_nowPlayingTimer.Tick += NowPlayingTimerOnTick;
}

Expand All @@ -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();
Expand All @@ -139,7 +136,7 @@ private void CheckNowPlayingText()
return;
}

_nowPlayingXPos = _clipRectangle.Width / 4;
_nowPlayingXPos = ClientRectangle.Width / 4;
_duplicateXPos = _nowPlayingXPos + _nowPlayingTextWidth + TextMargin;
_scrolling = true;

Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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 }
}
};
Expand Down

0 comments on commit c1a2605

Please sign in to comment.