|
@@ -1,92 +1,78 @@
|
|
|
-using System;
|
|
|
+using System.ComponentModel;
|
|
|
using System.Drawing;
|
|
|
using System.Drawing.Drawing2D;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace Optimizer
|
|
|
{
|
|
|
- public sealed class MoonToggle : CheckBox
|
|
|
+ public class MoonToggle : CheckBox
|
|
|
{
|
|
|
- private readonly Timer _animationTimer = new Timer();
|
|
|
+ bool solidStyle = true;
|
|
|
|
|
|
- private int _circlePosX = 3, _circlePosY = 3;
|
|
|
- private int _circleColorR = 255, _circleColorG = 255, _circleColorB = 255;
|
|
|
- private int _alpha = 0;
|
|
|
-
|
|
|
- public MoonToggle()
|
|
|
+ [Browsable(true)]
|
|
|
+ public override string Text
|
|
|
{
|
|
|
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
|
|
|
- DoubleBuffered = true;
|
|
|
- Height = 22; Width = 46;
|
|
|
- _animationTimer.Interval = 1;
|
|
|
- _animationTimer.Tick += new EventHandler(AnimationTick);
|
|
|
+ get { return base.Text; }
|
|
|
+ set { }
|
|
|
}
|
|
|
|
|
|
- protected override void OnHandleCreated(EventArgs e)
|
|
|
+ [DefaultValue(true)]
|
|
|
+ public bool SolidStyle
|
|
|
{
|
|
|
- base.OnHandleCreated(e);
|
|
|
- _animationTimer.Start();
|
|
|
+ get { return solidStyle; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ solidStyle = value;
|
|
|
+ this.Invalidate();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- protected override void OnPaint(PaintEventArgs pevent)
|
|
|
+ public MoonToggle()
|
|
|
{
|
|
|
- pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
|
- pevent.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
|
|
- pevent.Graphics.InterpolationMode = InterpolationMode.High;
|
|
|
+ this.DoubleBuffered = true;
|
|
|
+ this.MinimumSize = new Size(46, 22);
|
|
|
+ this.ForeColor = Color.White;
|
|
|
+ }
|
|
|
|
|
|
- pevent.Graphics.Clear(Parent.BackColor);
|
|
|
+ private GraphicsPath GetFigurePath()
|
|
|
+ {
|
|
|
+ int arcSize = this.Height - 1;
|
|
|
+ Rectangle leftArc = new Rectangle(0, 0, arcSize, arcSize);
|
|
|
+ Rectangle rightArc = new Rectangle(this.Width - arcSize - 2, 0, arcSize, arcSize);
|
|
|
|
|
|
- GraphicsPath backRect = new GraphicsPath();
|
|
|
- backRect.AddArc(new RectangleF(0.5f, 0.5f, Height - 1, Height - 1), 90, 180);
|
|
|
- backRect.AddArc(new RectangleF(Width - Height + 0.5f, 0.5f, Height - 1, Height - 1), 270, 180);
|
|
|
- backRect.CloseAllFigures();
|
|
|
+ GraphicsPath path = new GraphicsPath();
|
|
|
+ path.StartFigure();
|
|
|
+ path.AddArc(leftArc, 90, 180);
|
|
|
+ path.AddArc(rightArc, 270, 180);
|
|
|
+ path.CloseFigure();
|
|
|
|
|
|
- pevent.Graphics.FillPath(new SolidBrush(Options.BackAccentColor), backRect);
|
|
|
- pevent.Graphics.FillPath(new SolidBrush(Color.FromArgb(_alpha, Options.ForegroundColor)), backRect);
|
|
|
- pevent.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(_circleColorR, _circleColorG, _circleColorB)), new RectangleF(_circlePosX, _circlePosY, (Width / 2) - 7, Height - 6));
|
|
|
+ return path;
|
|
|
}
|
|
|
|
|
|
- private void AnimationTick(object sender, EventArgs e)
|
|
|
+ protected override void OnPaint(PaintEventArgs pevent)
|
|
|
{
|
|
|
- if (Checked)
|
|
|
- {
|
|
|
- if (Options.TextColor == Color.Black)
|
|
|
- {
|
|
|
- if (_circleColorR != 0 && _circleColorG != 0 && _circleColorB != 0)
|
|
|
- {
|
|
|
- _circleColorR -= 15; _circleColorG -= 15; _circleColorB -= 15;
|
|
|
- Invalidate();
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (_circleColorR != 255 && _circleColorG != 255 && _circleColorB != 255)
|
|
|
- {
|
|
|
- _circleColorR += 15; _circleColorG += 15; _circleColorB += 15;
|
|
|
- Invalidate();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (_circlePosX < (Width / 2) + 4)
|
|
|
- _circlePosX += 2; Invalidate();
|
|
|
+ int toggleSize = this.Height - 5;
|
|
|
+ pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
|
|
+ pevent.Graphics.Clear(this.Parent.BackColor);
|
|
|
|
|
|
- if (_alpha < 255)
|
|
|
- _alpha += 15; Invalidate();
|
|
|
+ if (this.Checked) //ON
|
|
|
+ {
|
|
|
+ if (solidStyle)
|
|
|
+ pevent.Graphics.FillPath(new SolidBrush(Options.ForegroundColor), GetFigurePath());
|
|
|
+ else pevent.Graphics.DrawPath(new Pen(Options.ForegroundColor, 2), GetFigurePath());
|
|
|
+ //Draw the toggle
|
|
|
+ pevent.Graphics.FillEllipse(new SolidBrush(Options.TextColor),
|
|
|
+ new Rectangle(this.Width - this.Height + 1, 2, toggleSize, toggleSize));
|
|
|
}
|
|
|
- else
|
|
|
+ else //OFF
|
|
|
{
|
|
|
- if (_circleColorR != 255 && _circleColorG != 255 && _circleColorB != 255)
|
|
|
- {
|
|
|
- _circleColorR += 15; _circleColorG += 15; _circleColorB += 15;
|
|
|
- Invalidate();
|
|
|
- }
|
|
|
-
|
|
|
- if (_circlePosX > 3)
|
|
|
- _circlePosX -= 2; Invalidate();
|
|
|
-
|
|
|
- if (_alpha > 0)
|
|
|
- _alpha -= 15; Invalidate();
|
|
|
+ if (solidStyle)
|
|
|
+ pevent.Graphics.FillPath(new SolidBrush(Options.BackAccentColor), GetFigurePath());
|
|
|
+ else pevent.Graphics.DrawPath(new Pen(Options.BackAccentColor, 2), GetFigurePath());
|
|
|
+ //Draw the toggle
|
|
|
+ pevent.Graphics.FillEllipse(new SolidBrush(Color.White),
|
|
|
+ new Rectangle(2, 2, toggleSize, toggleSize));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|