Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Minor update.
Browse files Browse the repository at this point in the history
- Added FourSpinner
- Added FourVProgressBar (copied slider tbh)
  • Loading branch information
BuildTools committed Sep 28, 2023
1 parent 1208597 commit 419f2a7
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 76 deletions.
1 change: 0 additions & 1 deletion FourCircleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ protected override void OnPaint(PaintEventArgs pevent)
{
cornerRadius = 1;
}
MinimumSize = new Size(Height - 1, Height - 1);
using (SolidBrush brush = new SolidBrush(Parent.BackColor))
{
pevent.Graphics.FillRectangle(brush, ClientRectangle);
Expand Down
26 changes: 5 additions & 21 deletions FourPictureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class FourPictureBox : Control
private int _cornerRadius = 5;
private float _rotationAngle = 0;
private Matrix _translationMatrix = new Matrix();
private bool _displayImage = true;
public FourPictureBox()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);

}

[Category("FourUI")]
Expand Down Expand Up @@ -67,7 +67,7 @@ protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

if (_image != null && _displayImage)
if (_image != null)
{
int diameter = _cornerRadius * 2;
int offset = 1;
Expand All @@ -90,14 +90,14 @@ protected override void OnPaint(PaintEventArgs e)
var scaleX = (float)Width / _image.Width;
var scaleY = (float)Height / _image.Height;

var matrix = new Matrix();
Matrix matrix = new Matrix();

matrix.Multiply(_translationMatrix);

matrix.RotateAt(_rotationAngle, new PointF(Width / 2, Height / 2));

matrix.Scale(scaleX, scaleY);


brush.Transform = matrix;
brush.WrapMode = WrapMode.Clamp;

Expand All @@ -106,20 +106,4 @@ protected override void OnPaint(PaintEventArgs e)
}
}
}

protected override void OnResize(EventArgs e)
{
base.OnResize(e);

_displayImage = false;
Invalidate();
}

protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);

_displayImage = true;
Invalidate();
}
}
79 changes: 79 additions & 0 deletions FourSpinner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Drawing;
using System.Windows.Forms;

public class FourSpinner : Control
{
private float rotationAngle = 0;
private DateTime lastRenderTime = DateTime.Now;
private int sweepAngle = 270;
private int borderSize = 1;

public FourSpinner()
{
DoubleBuffered = true;
ResizeRedraw = true;
Application.Idle += Application_Idle;

ForeColor = Color.FromArgb(33, 133, 255);
}

public int SweepAngle
{
get => sweepAngle;

set
{
if (value > 0 && value <= 360)
sweepAngle = value;
else
throw new ArgumentException("SweepAngle must be between 1 and 360 degrees.");
}
}

public int BorderSize
{
get => borderSize;

set
{
if (value > 0)
borderSize = value;
else
throw new ArgumentException("BorderSize must be greater than 0.");
}
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

int centerX = Width / 2;
int centerY = Height / 2;

e.Graphics.TranslateTransform(centerX-1, centerY-1);
e.Graphics.RotateTransform(rotationAngle);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

int spinnerSize = Math.Min(centerX, centerY);
int spinnerThickness = (spinnerSize / 10) * borderSize;

using (var pen = new Pen(ForeColor, spinnerThickness))
{
float startAngle = 0;
e.Graphics.DrawArc(pen, -spinnerSize / 2, -spinnerSize / 2, spinnerSize, spinnerSize, startAngle, sweepAngle);
}
}

private const float RotationSpeed = 180.0f;

private void Application_Idle(object sender, EventArgs e)
{
DateTime currentTime = DateTime.Now;
double elapsedMilliseconds = (currentTime - lastRenderTime).TotalMilliseconds;
float angleChange = (float)(RotationSpeed * elapsedMilliseconds / 900.0);
rotationAngle = (rotationAngle + angleChange) % 360;
lastRenderTime = currentTime;
Invalidate();
}
}
64 changes: 51 additions & 13 deletions FourStarRating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

public class FourStarRating : Control
{
private float rating = 0.0f; private Color starColor = Color.FromArgb(255, 174, 35);
private float rating = 0.0f;
private Color starColor = Color.FromArgb(255, 174, 35);
private float starBorderSize = 2.0f;
private int starCount = 5;

public event EventHandler RatingChanged;

Expand All @@ -15,18 +18,52 @@ public float Rating
get { return rating; }
set
{
if (value < 0.0f)
rating = 0.0f;
else if (value > 10.0f)
rating = 10.0f;
if (value <= (starCount * 2))
{
if (value < 0.0f)
rating = 0.0f;
else if (value > 10.0f)
rating = 10.0f;
else
rating = value;
}
else
rating = value;
throw new ArgumentException("Rating must be equal or less than StarCount*2.");

RatingChanged?.Invoke(this, EventArgs.Empty);
Invalidate();
}
}

public int StarCount
{
get { return starCount; }
set
{
if (value > 2) //who is ever finna do a 2 star rating??
starCount = value;

if (starCount * 2 < rating)
{
rating = starCount * 2;
Rating = starCount * 2;
RatingChanged?.Invoke(this, EventArgs.Empty);
Refresh();
}
Invalidate();
}
}

public float StarBorderSize
{
get { return starBorderSize; }
set
{
starBorderSize = Math.Max(1, value);
Invalidate();
}
}

public Color StarColor
{
get { return starColor; }
Expand All @@ -48,14 +85,10 @@ protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);





Graphics g = e.Graphics;
g.InterpolationMode = InterpolationMode.NearestNeighbor; g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
int starCount = 5;
int starWidth = Height - 2;
int spacing = 5;

Expand All @@ -76,14 +109,19 @@ protected override void OnPaint(PaintEventArgs e)
g.FillRectangle(new SolidBrush(BackColor), starRect);
}

g.DrawPath(new Pen(starColor), starPath);
// Create a pen with the specified border size
using (Pen starBorderPen = new Pen(starColor, StarBorderSize))
{
g.DrawPath(starBorderPen, starPath);
}
}
}






public static GraphicsPath GetRounded5PointStarPath(float centerX, float centerY, float outerRadius, float innerRadius, int numPoints)
{
if (numPoints % 2 == 0 || numPoints < 5)
Expand Down
50 changes: 9 additions & 41 deletions FourSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class FourSwitch : Control
private int endX;
private int thumbWidth;

int refreshRate = -6;

private designchoice dchoice = FourSwitch.designchoice.Inward;

public enum designchoice
Expand Down Expand Up @@ -130,37 +128,11 @@ public FourSwitch()



private async void InitializeTimer()
private void InitializeTimer()
{
//BackColor = Parent.BackColor;
refreshRate = -6; //i cant believe that someone ever got -6 fps
if (!DesignMode)
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController");
foreach (ManagementObject mo in searcher.Get())
{
refreshRate = Convert.ToInt32(mo["CurrentRefreshRate"]) + 1;
//MessageBox.Show(refreshRate + " Hz");
}
}
catch
{
refreshRate = 60;
}
}
else
{
refreshRate = 60;
}

while (refreshRate == -6)
{
await Task.Delay(100);
}
smoothMoveTimer = new Timer();
smoothMoveTimer.Interval = 1000 / refreshRate;
smoothMoveTimer.Interval = 4;
smoothMoveTimer.Tick += SmoothMoveTimer_Tick;
}

Expand Down Expand Up @@ -219,10 +191,11 @@ protected override void OnPaint(PaintEventArgs e)
}
else if (dchoice == designchoice.Outward)
{
endX = Width - (Height - 10);
rectWidth = rectWidth - 1;
endX = Width - (Height - 6);
rectWidth = rectWidth - 5;
rectHeight = rectHeight - 2;
cornerRadius = (rectHeight / 6);
using (GraphicsPath path = RoundedRectangle(rectX + rectWidth / 10, (rectY + rectHeight / 3) + 1, rectWidth - rectWidth / 10, rectHeight / 3, cornerRadius))
using (GraphicsPath path = RoundedRectangle(-1 + rectX + rectWidth / 10, (rectY + rectHeight / 3), rectWidth - rectWidth / 10, 3 + rectHeight / 3, cornerRadius))
{

using (Brush bgBrush = new SolidBrush(trackColor))
Expand Down Expand Up @@ -293,14 +266,9 @@ private GraphicsPath RoundedRectangle(int x, int y, int width, int height, int r
private void AnimateThumb()
{
Timer animationTimer = new Timer();
if (refreshRate > 1)
{
animationTimer.Interval = 1000 / refreshRate;
}
else
{
animationTimer.Interval = 60;
}

animationTimer.Interval = 4;




Expand Down
6 changes: 6 additions & 0 deletions FourUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<Compile Include="FourPictureBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="FourSpinner.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="FourVProgressBar.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="FourStarRating.cs">
<SubType>Component</SubType>
</Compile>
Expand Down
Loading

0 comments on commit 419f2a7

Please sign in to comment.