initial commit
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: CustomControls.CustomSwitch
|
||||
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
|
||||
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#nullable disable
|
||||
namespace CustomControls;
|
||||
|
||||
public class CustomSwitch : CheckBox
|
||||
{
|
||||
private Color onBackColor = ColorTranslator.FromHtml("#69f58e");
|
||||
private Color onToggleColor = Color.WhiteSmoke;
|
||||
private Color offBackColor = Color.Gray;
|
||||
private Color offToggleColor = Color.Gainsboro;
|
||||
private bool solidStyle = true;
|
||||
private float togglePosition;
|
||||
private bool isChecked;
|
||||
|
||||
[Category("Custom")]
|
||||
public Color OnBackColor
|
||||
{
|
||||
get => this.onBackColor;
|
||||
set
|
||||
{
|
||||
this.onBackColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
[Category("Custom")]
|
||||
public Color OnToggleColor
|
||||
{
|
||||
get => this.onToggleColor;
|
||||
set
|
||||
{
|
||||
this.onToggleColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
[Category("Custom")]
|
||||
public Color OffBackColor
|
||||
{
|
||||
get => this.offBackColor;
|
||||
set
|
||||
{
|
||||
this.offBackColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
[Category("Custom")]
|
||||
public Color OffToggleColor
|
||||
{
|
||||
get => this.offToggleColor;
|
||||
set
|
||||
{
|
||||
this.offToggleColor = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public override string Text
|
||||
{
|
||||
get => base.Text;
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Category("Custom")]
|
||||
[DefaultValue(true)]
|
||||
public bool SolidStyle
|
||||
{
|
||||
get => this.solidStyle;
|
||||
set
|
||||
{
|
||||
this.solidStyle = value;
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public new event EventHandler CheckedChanged;
|
||||
|
||||
[Category("Custom")]
|
||||
[DefaultValue(false)]
|
||||
public new bool Checked
|
||||
{
|
||||
get => this.isChecked;
|
||||
set
|
||||
{
|
||||
if (this.isChecked == value)
|
||||
return;
|
||||
this.isChecked = value;
|
||||
this.AnimateToggle();
|
||||
this.Invalidate();
|
||||
EventHandler checkedChanged = this.CheckedChanged;
|
||||
if (checkedChanged == null)
|
||||
return;
|
||||
checkedChanged((object) this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public CustomSwitch()
|
||||
{
|
||||
this.MinimumSize = new Size(45, 22);
|
||||
this.togglePosition = 2f;
|
||||
this.isChecked = false;
|
||||
}
|
||||
|
||||
private GraphicsPath GetFigurePath()
|
||||
{
|
||||
int num = this.Height - 1;
|
||||
Rectangle rect1 = new Rectangle(0, 0, num, num);
|
||||
Rectangle rect2 = new Rectangle(this.Width - num - 2, 0, num, num);
|
||||
GraphicsPath figurePath = new GraphicsPath();
|
||||
figurePath.StartFigure();
|
||||
figurePath.AddArc(rect1, 90f, 180f);
|
||||
figurePath.AddArc(rect2, 270f, 180f);
|
||||
figurePath.CloseFigure();
|
||||
return figurePath;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs pevent)
|
||||
{
|
||||
int num = this.Height - 5;
|
||||
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
pevent.Graphics.Clear(this.Parent.BackColor);
|
||||
bool flag = !this.Enabled;
|
||||
Color color1;
|
||||
Color color2;
|
||||
if (this.isChecked)
|
||||
{
|
||||
color1 = this.onBackColor;
|
||||
color2 = this.onToggleColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
color1 = this.offBackColor;
|
||||
color2 = this.offToggleColor;
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
color1 = this.Darken(color1);
|
||||
color2 = this.Darken(color2);
|
||||
}
|
||||
if (this.solidStyle)
|
||||
pevent.Graphics.FillPath((Brush) new SolidBrush(color1), this.GetFigurePath());
|
||||
else
|
||||
pevent.Graphics.DrawPath(new Pen(color1, 2f), this.GetFigurePath());
|
||||
pevent.Graphics.FillEllipse((Brush) new SolidBrush(color2), new Rectangle((int) this.togglePosition, 2, num, num));
|
||||
}
|
||||
|
||||
private Color Darken(Color color, float factor = 0.35f)
|
||||
{
|
||||
return Color.FromArgb((int) color.A, (int) ((double) color.R * (double) factor), (int) ((double) color.G * (double) factor), (int) ((double) color.B * (double) factor));
|
||||
}
|
||||
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
base.OnClick(e);
|
||||
this.Checked = !this.Checked;
|
||||
}
|
||||
|
||||
private async void AnimateToggle()
|
||||
{
|
||||
CustomSwitch customSwitch = this;
|
||||
int num = customSwitch.Checked ? 2 : customSwitch.Width - customSwitch.Height + 1;
|
||||
int end = customSwitch.Checked ? customSwitch.Width - customSwitch.Height + 1 : 2;
|
||||
int step = end > num ? 2 : -2;
|
||||
for (int i = num; (step > 0 ? (i <= end ? 1 : 0) : (i >= end ? 1 : 0)) != 0; i += step)
|
||||
{
|
||||
customSwitch.togglePosition = (float) i;
|
||||
customSwitch.Invalidate();
|
||||
await Task.Delay(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user