diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ee5ad15 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +trim_trailing_whitespace = false +insert_final_newline = true + +[*.cs] +indent_style = space +indent_size = 4 +max_line_length = 120 + +csharpier_print_width = 120 +dotnet_diagnostic.IDE1006.severity = none # naming conventions diff --git a/Examples/SDUI.AnimationEngineTest/MenuCloseButton.cs b/Examples/SDUI.AnimationEngineTest/MenuCloseButton.cs index 6d138b0..e31fef4 100644 --- a/Examples/SDUI.AnimationEngineTest/MenuCloseButton.cs +++ b/Examples/SDUI.AnimationEngineTest/MenuCloseButton.cs @@ -1,10 +1,9 @@ -using SDUI.AnimationEngine; -using System.Drawing.Drawing2D; +using System.Drawing.Drawing2D; +using SDUI.AnimationEngine; namespace SDUI.AnimationEngineTest { - public class MenuCloseButton - : Control + public class MenuCloseButton : Control { public MenuCloseButton() : base() @@ -15,24 +14,38 @@ public MenuCloseButton() //Every Point is between (-1|-1) and (1|1) this.NormalState = new PointF[] { - new PointF(-1, .8f), new PointF(1, .8f), //Topmost line - new PointF(-1, 0), new PointF(1, 0), //Middle line - new PointF(-1, -.8f), new PointF(1, -.8f) //Lowest line + new PointF(-1, .8f), + new PointF(1, .8f), //Topmost line + new PointF(-1, 0), + new PointF(1, 0), //Middle line + new PointF(-1, -.8f), + new PointF(1, -.8f), //Lowest line }; this.ExtendedState = new PointF[] { - new PointF(1, -1), new PointF(-1, 1), //Bottom right to top left - new PointF(1, 0), new PointF(-1, 0), //Collapsed - new PointF(1, 1), new PointF(-1, -1) //Top right to bottom left + new PointF(1, -1), + new PointF(-1, 1), //Bottom right to top left + new PointF(1, 0), + new PointF(-1, 0), //Collapsed + new PointF(1, 1), + new PointF(-1, -1), //Top right to bottom left }; - this.PointProvider = new ValueProvider(this.NormalState, ValueFactoryCreator.CreateArrayFactory(ValueFactories.PointFFactory), EasingMethods.ExponentialEaseOut); - this.MiddleLineOpacityProvider = new ValueProvider(255, ValueFactories.ByteFactory, EasingMethods.ExponentialEaseInOut); + this.PointProvider = new ValueProvider( + this.NormalState, + ValueFactoryCreator.CreateArrayFactory(ValueFactories.PointFFactory), + EasingMethods.ExponentialEaseOut + ); + this.MiddleLineOpacityProvider = new ValueProvider( + 255, + ValueFactories.ByteFactory, + EasingMethods.ExponentialEaseInOut + ); this.DoubleBuffered = true; //For updates. - new System.Windows.Forms.Timer() { Enabled = true, Interval = 1000/60 }.Tick += (s, e) => + new System.Windows.Forms.Timer() { Enabled = true, Interval = 1000 / 60 }.Tick += (s, e) => { this.Invalidate(); }; @@ -41,7 +54,6 @@ public MenuCloseButton() protected PointF[] NormalState; protected PointF[] ExtendedState; - protected double durationFactor = 1; private bool extended = false; public bool Extended @@ -51,8 +63,14 @@ public bool Extended { if (value != this.extended) { - this.PointProvider.StartTransition(value ? this.ExtendedState : this.NormalState, TimeSpan.FromSeconds(1 * durationFactor)); - this.MiddleLineOpacityProvider.StartTransition(value ? (byte)0 : (byte)255, TimeSpan.FromSeconds(.25 * durationFactor)); + this.PointProvider.StartTransition( + value ? this.ExtendedState : this.NormalState, + TimeSpan.FromSeconds(1 * durationFactor) + ); + this.MiddleLineOpacityProvider.StartTransition( + value ? (byte)0 : (byte)255, + TimeSpan.FromSeconds(.25 * durationFactor) + ); this.extended = value; } } @@ -70,9 +88,18 @@ protected override void OnPaint(PaintEventArgs pevent) pevent.Graphics.DrawLine(linePen, this.Project(currentState[0]), this.Project(currentState[1])); pevent.Graphics.DrawLine(linePen, this.Project(currentState[4]), this.Project(currentState[5])); - using (Pen middleLinePen = new Pen(Color.FromArgb(this.MiddleLineOpacityProvider.CurrentValue, this.ForeColor), linePen.Width)) + using ( + Pen middleLinePen = new Pen( + Color.FromArgb(this.MiddleLineOpacityProvider.CurrentValue, this.ForeColor), + linePen.Width + ) + ) { - pevent.Graphics.DrawLine(middleLinePen, this.Project(currentState[2]), this.Project(currentState[3])); + pevent.Graphics.DrawLine( + middleLinePen, + this.Project(currentState[2]), + this.Project(currentState[3]) + ); } } @@ -82,7 +109,10 @@ protected override void OnPaint(PaintEventArgs pevent) protected PointF Project(PointF relativePoint, float spacing = .1f) { PointF center = new PointF(this.Width / 2f, this.Height / 2f); - return new PointF(center.X + (center.X * relativePoint.X) - ((center.X * spacing) * relativePoint.X), center.Y + (center.Y * relativePoint.Y) - ((center.Y * spacing) * relativePoint.Y)); + return new PointF( + center.X + (center.X * relativePoint.X) - ((center.X * spacing) * relativePoint.X), + center.Y + (center.Y * relativePoint.Y) - ((center.Y * spacing) * relativePoint.Y) + ); } protected override void OnClick(EventArgs e) diff --git a/Examples/SDUI.AnimationEngineTest/Program.cs b/Examples/SDUI.AnimationEngineTest/Program.cs index 269d289..d0da09d 100644 --- a/Examples/SDUI.AnimationEngineTest/Program.cs +++ b/Examples/SDUI.AnimationEngineTest/Program.cs @@ -14,4 +14,4 @@ static void Main() Application.Run(new Main()); } } -} \ No newline at end of file +} diff --git a/Examples/SDUI.AnimationEngineTest/SDUI.AnimationEngineTest.csproj b/Examples/SDUI.AnimationEngineTest/SDUI.AnimationEngineTest.csproj index 5285793..b125abc 100644 --- a/Examples/SDUI.AnimationEngineTest/SDUI.AnimationEngineTest.csproj +++ b/Examples/SDUI.AnimationEngineTest/SDUI.AnimationEngineTest.csproj @@ -1,5 +1,4 @@  - WinExe net6.0-windows @@ -11,5 +10,4 @@ - - \ No newline at end of file + diff --git a/Examples/SDUI.Examples.Mac/MainWindow.cs b/Examples/SDUI.Examples.Mac/MainWindow.cs index 89c9d26..f71e54f 100644 --- a/Examples/SDUI.Examples.Mac/MainWindow.cs +++ b/Examples/SDUI.Examples.Mac/MainWindow.cs @@ -12,4 +12,4 @@ public MainWindow() AddMousePressMove(panel1); } } -} \ No newline at end of file +} diff --git a/Examples/SDUI.Examples.Mac/Program.cs b/Examples/SDUI.Examples.Mac/Program.cs index 685b578..029ad6c 100644 --- a/Examples/SDUI.Examples.Mac/Program.cs +++ b/Examples/SDUI.Examples.Mac/Program.cs @@ -14,4 +14,4 @@ static void Main() Application.Run(new MainWindow()); } } -} \ No newline at end of file +} diff --git a/Examples/SDUI.Examples.Mac/SDUI.Examples.Mac.csproj b/Examples/SDUI.Examples.Mac/SDUI.Examples.Mac.csproj index bd78f77..2047e5f 100644 --- a/Examples/SDUI.Examples.Mac/SDUI.Examples.Mac.csproj +++ b/Examples/SDUI.Examples.Mac/SDUI.Examples.Mac.csproj @@ -1,5 +1,4 @@  - WinExe net8.0-windows @@ -11,5 +10,4 @@ - - \ No newline at end of file + diff --git a/Examples/SDUI.Test/App.config b/Examples/SDUI.Test/App.config index 193aecc..35e8549 100644 --- a/Examples/SDUI.Test/App.config +++ b/Examples/SDUI.Test/App.config @@ -1,6 +1,6 @@  - - - - \ No newline at end of file + + + + diff --git a/Examples/SDUI.Test/ConfigPage.cs b/Examples/SDUI.Test/ConfigPage.cs index b8dd8dc..8166695 100644 --- a/Examples/SDUI.Test/ConfigPage.cs +++ b/Examples/SDUI.Test/ConfigPage.cs @@ -1,8 +1,8 @@ -using SDUI.Controls; -using System; +using System; using System.ComponentModel; using System.Drawing.Drawing2D; using System.Windows.Forms; +using SDUI.Controls; namespace SDUI.Test { diff --git a/Examples/SDUI.Test/GeneralPage.cs b/Examples/SDUI.Test/GeneralPage.cs index 51fc7c6..f3e12ea 100644 --- a/Examples/SDUI.Test/GeneralPage.cs +++ b/Examples/SDUI.Test/GeneralPage.cs @@ -1,10 +1,10 @@ -using SDUI.Controls; -using System; +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Threading.Tasks; using System.Windows.Forms; +using SDUI.Controls; namespace SDUI.Test { @@ -78,7 +78,6 @@ private void textBox1_KeyDown(object sender, KeyEventArgs e) MessageBox.Show(textBox1.Text); } - private void buttonOpenInputDialog_Click(object sender, EventArgs e) { var dialog = new InputDialog("The input dialog", "This is a input dialog", "Please set the value!"); @@ -100,7 +99,7 @@ private void buttonRandomColor_Click(object sender, EventArgs e) return; var parent = form as UIWindow; - if(parent != null) + if (parent != null) { ColorScheme.BackColor = Color.FromArgb(r, g, b); parent.BackColor = ColorScheme.BackColor; diff --git a/Examples/SDUI.Test/ListViewPage.cs b/Examples/SDUI.Test/ListViewPage.cs index fad2ef3..3f16e47 100644 --- a/Examples/SDUI.Test/ListViewPage.cs +++ b/Examples/SDUI.Test/ListViewPage.cs @@ -1,7 +1,7 @@ -using SDUI.Controls; -using System.ComponentModel; +using System.ComponentModel; using System.Drawing; using System.Windows.Forms; +using SDUI.Controls; namespace SDUI.Test { @@ -22,7 +22,10 @@ public ListViewPage() for (int i = 0; i <= 5; i++) { var title = "Item " + i.ToString(); - var listItem = new ListViewItem(new[] { i.ToString(), title + " Column 2", title + " Column 3", title + " Column 4" }, group1); + var listItem = new ListViewItem( + new[] { i.ToString(), title + " Column 2", title + " Column 3", title + " Column 4" }, + group1 + ); if (i == 0) { listItem.BackColor = ControlPaint.Light(ColorScheme.BackColor, .15f); @@ -34,7 +37,12 @@ public ListViewPage() for (int i = 6; i <= 1000; i++) { string sItem = "Item " + i.ToString(); - listView1.Items.Add(new ListViewItem(new[] { i.ToString(), sItem + " Column 2", sItem + " Column 3", sItem + " Column 4" }, group2)); + listView1.Items.Add( + new ListViewItem( + new[] { i.ToString(), sItem + " Column 2", sItem + " Column 3", sItem + " Column 4" }, + group2 + ) + ); } //listView1.SetGroupInfo(listView1.Handle, 1, NativeMethods.LVGS_COLLAPSIBLE); diff --git a/Examples/SDUI.Test/MainWindow.cs b/Examples/SDUI.Test/MainWindow.cs index f3d074c..787d6c4 100644 --- a/Examples/SDUI.Test/MainWindow.cs +++ b/Examples/SDUI.Test/MainWindow.cs @@ -1,5 +1,5 @@ -using SDUI.Controls; using System; +using SDUI.Controls; namespace SDUI.Test; @@ -7,7 +7,7 @@ public partial class MainWindow : UIWindow { public MainWindow() { - InitializeComponent(); + InitializeComponent(); } protected override void OnBackColorChanged(EventArgs e) @@ -19,11 +19,14 @@ protected override void OnBackColorChanged(EventArgs e) private void MainWindow_Load(object sender, EventArgs e) { - windowPageControl.Controls.AddRange(new System.Windows.Forms.Control[] { - new GeneralPage(), - new ListViewPage(), - new ConfigPage(), - new MultiPageControlTestPage() - }); + windowPageControl.Controls.AddRange( + new System.Windows.Forms.Control[] + { + new GeneralPage(), + new ListViewPage(), + new ConfigPage(), + new MultiPageControlTestPage(), + } + ); } -} \ No newline at end of file +} diff --git a/Examples/SDUI.Test/MultiPageControlTestPage.cs b/Examples/SDUI.Test/MultiPageControlTestPage.cs index 1369d5b..e0a1318 100644 --- a/Examples/SDUI.Test/MultiPageControlTestPage.cs +++ b/Examples/SDUI.Test/MultiPageControlTestPage.cs @@ -1,7 +1,7 @@ -using SDUI.Controls; -using System; +using System; using System.ComponentModel; using System.Windows.Forms; +using SDUI.Controls; namespace SDUI.Test { @@ -9,6 +9,7 @@ namespace SDUI.Test public partial class MultiPageControlTestPage : DoubleBufferedControl { private Type[] _types = { typeof(GeneralPage), typeof(ListViewPage), typeof(ConfigPage) }; + public MultiPageControlTestPage() { InitializeComponent(); diff --git a/Examples/SDUI.Test/SDUI.Test.csproj b/Examples/SDUI.Test/SDUI.Test.csproj index 8137380..743ecc4 100644 --- a/Examples/SDUI.Test/SDUI.Test.csproj +++ b/Examples/SDUI.Test/SDUI.Test.csproj @@ -1,5 +1,4 @@  - net8.0-windows enable @@ -11,5 +10,4 @@ - diff --git a/SDUI/AnimationEngine/AnimationDirection.cs b/SDUI/AnimationEngine/AnimationDirection.cs index acadef2..1f82d6e 100644 --- a/SDUI/AnimationEngine/AnimationDirection.cs +++ b/SDUI/AnimationEngine/AnimationDirection.cs @@ -10,6 +10,6 @@ public enum AnimationDirection InOutIn, InOutOut, InOutRepeatingIn, - InOutRepeatingOut + InOutRepeatingOut, } } diff --git a/SDUI/AnimationEngine/AnimationManager.cs b/SDUI/AnimationEngine/AnimationManager.cs index 4406d20..c5f09f1 100644 --- a/SDUI/AnimationEngine/AnimationManager.cs +++ b/SDUI/AnimationEngine/AnimationManager.cs @@ -47,7 +47,8 @@ public AnimationEngine(bool singular = true) // Lazy initialization - Timer sadece gerektiğinde oluturulur private void EnsureTimer() { - if (_timer != null) return; + if (_timer != null) + return; try { @@ -81,7 +82,8 @@ public void StartNewAnimation(AnimationDirection direction, System.Drawing.Point { if (!SystemAnimations.AreAnimationsEnabled) { - var instantTarget = direction == AnimationDirection.In || direction == AnimationDirection.InOutIn ? 1.0 : 0.0; + var instantTarget = + direction == AnimationDirection.In || direction == AnimationDirection.InOutIn ? 1.0 : 0.0; SetProgress(instantTarget); OnAnimationProgress?.Invoke(this); OnAnimationFinished?.Invoke(this); @@ -97,10 +99,17 @@ public void StartNewAnimation(AnimationDirection direction, System.Drawing.Point UpdateEasingMethod(); double target = direction == AnimationDirection.In || direction == AnimationDirection.InOutIn ? 1.0 : 0.0; - double currentIncrement = direction == AnimationDirection.InOutOut || direction == AnimationDirection.InOutRepeatingOut ? SecondaryIncrement : Increment; + double currentIncrement = + direction == AnimationDirection.InOutOut || direction == AnimationDirection.InOutRepeatingOut + ? SecondaryIncrement + : Increment; double duration = Math.Abs(target - _valueProvider.CurrentValue) / currentIncrement * 16; // milliseconds - _valueProvider.StartTransition(_valueProvider.CurrentValue, target, TimeSpan.FromMilliseconds(Math.Max(16, duration))); + _valueProvider.StartTransition( + _valueProvider.CurrentValue, + target, + TimeSpan.FromMilliseconds(Math.Max(16, duration)) + ); _isRunning = true; @@ -204,13 +213,14 @@ private void UpdateEasingMethod() AnimationType.QuarticEaseIn => EasingMethods.QuarticEaseIn, AnimationType.QuarticEaseOut => EasingMethods.QuarticEaseOut, AnimationType.QuarticEaseInOut => EasingMethods.QuarticEaseInOut, - _ => EasingMethods.DefaultEase + _ => EasingMethods.DefaultEase, }; } public void Dispose() { - if (_disposed) return; + if (_disposed) + return; if (_timer != null) { @@ -223,4 +233,4 @@ public void Dispose() _disposed = true; } } -} \ No newline at end of file +} diff --git a/SDUI/AnimationEngine/AnimationType.cs b/SDUI/AnimationEngine/AnimationType.cs index 54154bf..502e789 100644 --- a/SDUI/AnimationEngine/AnimationType.cs +++ b/SDUI/AnimationEngine/AnimationType.cs @@ -15,6 +15,6 @@ public enum AnimationType QuarticEaseIn, QuarticEaseOut, QuarticEaseInOut, - CustomQuadratic + CustomQuadratic, } } diff --git a/SDUI/AnimationEngine/EasingMethods.cs b/SDUI/AnimationEngine/EasingMethods.cs index 4e659bf..3dd30cd 100644 --- a/SDUI/AnimationEngine/EasingMethods.cs +++ b/SDUI/AnimationEngine/EasingMethods.cs @@ -25,7 +25,8 @@ public static partial class EasingMethods /// An easing method that uses the first specified easing method for the first half of the animation and the second one for the second half of the animation. public static EasingMethod Chain(this EasingMethod first, EasingMethod second) { - return (double progress) => (progress < 0.5) ? .5 * first(progress * 2) : .5 + .5 * second((progress - .5) * 2); + return (double progress) => + (progress < 0.5) ? .5 * first(progress * 2) : .5 + .5 * second((progress - .5) * 2); } /// @@ -36,7 +37,6 @@ public static EasingMethod Chain(this EasingMethod first, EasingMethod second) public static EasingMethod Invert(this EasingMethod method) { return (double progress) => 1 - method(1 - progress); - } /// diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Circular.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Circular.cs index 141b142..0773e3e 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Circular.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Circular.cs @@ -16,7 +16,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double CircularEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : -(Math.Sqrt(1 - progress * progress) - 1); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : -(Math.Sqrt(1 - progress * progress) - 1); } /// @@ -28,10 +30,16 @@ public static double CircularEaseIn(double progress) /// The value progress of the animation. public static double CircularEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Sqrt(1 - Math.Pow(progress - 1, 2)); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Sqrt(1 - Math.Pow(progress - 1, 2)); } - private static readonly EasingMethod circularEaseInOut = EasingMethods.Chain(EasingMethods.CircularEaseIn, EasingMethods.CircularEaseOut); + private static readonly EasingMethod circularEaseInOut = EasingMethods.Chain( + EasingMethods.CircularEaseIn, + EasingMethods.CircularEaseOut + ); + /// /// A combination of the and methods. /// It accelerates from 0 to infinite velocity and then decelerates back to a velocity of 0. diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Cubic.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Cubic.cs index 0287241..14e7652 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Cubic.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Cubic.cs @@ -16,7 +16,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double CubicEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(progress, 3); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(progress, 3); } /// @@ -28,10 +30,16 @@ public static double CubicEaseIn(double progress) /// The value progress of the animation. public static double CubicEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(progress - 1, 3) + 1; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(progress - 1, 3) + 1; } - private static EasingMethod cubicEaseInOut = EasingMethods.Chain(EasingMethods.CubicEaseIn, EasingMethods.CubicEaseOut); + private static EasingMethod cubicEaseInOut = EasingMethods.Chain( + EasingMethods.CubicEaseIn, + EasingMethods.CubicEaseOut + ); + /// /// A combination of the and methods. /// It accelerates from 0 to a velocity of 3 and then decelerates back to a velocity of 0. diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Default.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Default.cs index 54b1f1e..d2284d3 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Default.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Default.cs @@ -18,7 +18,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double DefaultEase(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : .3 * progress + 2.4 * Math.Pow(progress, 2) - 1.7 * Math.Pow(progress, 3); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : .3 * progress + 2.4 * Math.Pow(progress, 2) - 1.7 * Math.Pow(progress, 3); } } } diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Exponential.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Exponential.cs index bfd8923..ac2c6de 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Exponential.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Exponential.cs @@ -16,7 +16,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double ExponentialEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(2, 10 * (progress - 1)); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(2, 10 * (progress - 1)); } /// @@ -28,10 +30,16 @@ public static double ExponentialEaseIn(double progress) /// The value progress of the animation. public static double ExponentialEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : -Math.Pow(2, -10 * progress) + 1; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : -Math.Pow(2, -10 * progress) + 1; } - private static readonly EasingMethod exponentialEaseInOut = EasingMethods.Chain(EasingMethods.ExponentialEaseIn, EasingMethods.ExponentialEaseOut); + private static readonly EasingMethod exponentialEaseInOut = EasingMethods.Chain( + EasingMethods.ExponentialEaseIn, + EasingMethods.ExponentialEaseOut + ); + /// /// A combination of the and methods. /// It accelerates from approximately 0 to a velocity of approximately 7 (log 1024) and then decelerates back to a velocity of approximately 0. diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Linear.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Linear.cs index f6e1c26..e3812f2 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Linear.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Linear.cs @@ -17,7 +17,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double Linear(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : progress; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : progress; } } } diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quadratic.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quadratic.cs index 91c5c8d..0e11890 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quadratic.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quadratic.cs @@ -16,7 +16,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double QuadraticEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : progress * progress; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : progress * progress; } /// @@ -28,10 +30,16 @@ public static double QuadraticEaseIn(double progress) /// The value progress of the animation. public static double QuadraticEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : -(progress * (progress - 2)); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : -(progress * (progress - 2)); } - private static readonly EasingMethod quadraticEaseInOut = EasingMethods.Chain(EasingMethods.QuadraticEaseIn, EasingMethods.QuadraticEaseOut); + private static readonly EasingMethod quadraticEaseInOut = EasingMethods.Chain( + EasingMethods.QuadraticEaseIn, + EasingMethods.QuadraticEaseOut + ); + /// /// A combination of the and methods. /// It accelerates from 0 to a velocity of 2 and then decelerates back to a velocity of 0. diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quartic.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quartic.cs index ba7cb86..d34ae5e 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quartic.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quartic.cs @@ -16,7 +16,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double QuarticEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(progress, 4); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(progress, 4); } /// @@ -28,10 +30,16 @@ public static double QuarticEaseIn(double progress) /// The value progress of the animation. public static double QuarticEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : -(Math.Pow(progress - 1, 4) - 1); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : -(Math.Pow(progress - 1, 4) - 1); } - private static readonly EasingMethod quarticEaseInOut = EasingMethods.Chain(EasingMethods.QuarticEaseIn, EasingMethods.QuarticEaseOut); + private static readonly EasingMethod quarticEaseInOut = EasingMethods.Chain( + EasingMethods.QuarticEaseIn, + EasingMethods.QuarticEaseOut + ); + /// /// A combination of the and methods. /// It accelerates from 0 to a velocity of 4 and then decelerates back to a velocity of 0. diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quintic.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quintic.cs index 8cba3a3..c4c07d7 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quintic.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Quintic.cs @@ -16,7 +16,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double QuinticEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(progress, 5); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(progress, 5); } /// @@ -28,10 +30,16 @@ public static double QuinticEaseIn(double progress) /// The value progress of the animation. public static double QuinticEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(progress - 1, 5) + 1; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(progress - 1, 5) + 1; } - private static readonly EasingMethod quinticEaseInOut = EasingMethods.Chain(EasingMethods.QuinticEaseIn, EasingMethods.QuinticEaseOut); + private static readonly EasingMethod quinticEaseInOut = EasingMethods.Chain( + EasingMethods.QuinticEaseIn, + EasingMethods.QuinticEaseOut + ); + /// /// A combination of the and methods. /// It accelerates from 0 to a velocity of 5 and then decelerates back to a velocity of 0. diff --git a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Sinus.cs b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Sinus.cs index c98bade..2bad09b 100644 --- a/SDUI/AnimationEngine/EasingMethods/EasingMethods.Sinus.cs +++ b/SDUI/AnimationEngine/EasingMethods/EasingMethods.Sinus.cs @@ -18,7 +18,9 @@ public static partial class EasingMethods /// The value progress of the animation. public static double SinusEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : -Math.Cos(progress * radianFactor) + 1; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : -Math.Cos(progress * radianFactor) + 1; } /// @@ -30,10 +32,16 @@ public static double SinusEaseIn(double progress) /// The value progress of the animation. public static double SinusEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Sin(progress * radianFactor); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Sin(progress * radianFactor); } - private static readonly EasingMethod sinusEaseInOut = EasingMethods.Chain(EasingMethods.SinusEaseIn, EasingMethods.SinusEaseOut); + private static readonly EasingMethod sinusEaseInOut = EasingMethods.Chain( + EasingMethods.SinusEaseIn, + EasingMethods.SinusEaseOut + ); + /// /// A combination of the and methods. /// It accelerates from 0 to a velocity of 1 and then decelerates back to a velocity of 0. diff --git a/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Back.cs b/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Back.cs index 10923d2..169d8e1 100644 --- a/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Back.cs +++ b/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Back.cs @@ -22,9 +22,11 @@ public static partial class Extended /// The value progress of the animation. public static double BackEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(progress, 2) * ((back + 1) * progress - back); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(progress, 2) * ((back + 1) * progress - back); } - + /// /// An easing method that goes up to a value progress of 1.1 and then goes back to 1.0. /// The velocity starts at 4.70158 and goes down to 0. @@ -36,10 +38,16 @@ public static double BackEaseIn(double progress) /// The value progress of the animation. public static double BackEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(progress - 1, 2) * ((back + 1) * (progress - 1) + back) + 1; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(progress - 1, 2) * ((back + 1) * (progress - 1) + back) + 1; } - private static readonly EasingMethod backEaseInOut = EasingMethods.Chain(EasingMethods.Extended.BackEaseIn, EasingMethods.Extended.BackEaseOut); + private static readonly EasingMethod backEaseInOut = EasingMethods.Chain( + EasingMethods.Extended.BackEaseIn, + EasingMethods.Extended.BackEaseOut + ); + /// /// A combination of the and methods. /// Do not use this method if you do not have a proper method for handling progress values greater than 1.0 and lower than 0.0. diff --git a/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Bounce.cs b/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Bounce.cs index be4d2ab..3ace96a 100644 --- a/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Bounce.cs +++ b/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Bounce.cs @@ -10,11 +10,17 @@ public static partial class EasingMethods public static partial class Extended { //Some Constants for the bounce easing methods ^^ - private const double b = 7.5625, bF = 2.75; + private const double b = 7.5625, + bF = 2.75; private const double bF1 = 1 / bF; - private const double b2 = .75, bF2 = 2 / bF, bP2 = 1.5 / bF; - private const double b3 = .9375, bF3 = 2.5 / bF, bP3 = 2.25 / bF; - private const double b4 = .984375, bP4 = 2.625 / bF; + private const double b2 = .75, + bF2 = 2 / bF, + bP2 = 1.5 / bF; + private const double b3 = .9375, + bF3 = 2.5 / bF, + bP3 = 2.25 / bF; + private const double b4 = .984375, + bP4 = 2.625 / bF; /// /// An easing method that starts by bouncing up a little bit until it goes up to 1.0 with a big bounce. @@ -24,7 +30,9 @@ public static partial class Extended /// The value progress of the animation. public static double BounceEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : 1 - EasingMethods.Extended.BounceEaseOut(1 - progress); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : 1 - EasingMethods.Extended.BounceEaseOut(1 - progress); } /// @@ -36,7 +44,12 @@ public static double BounceEaseIn(double progress) /// The value progress of the animation. public static double BounceEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : progress < bF1 ? b * Math.Pow(progress, 2) : progress < bF2 ? b * Math.Pow(progress - bP2, 2) + b2 : progress < bF3 ? b * Math.Pow(progress - bP3, 2) + b3 : b * Math.Pow(progress - bP4, 2) + b4; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : progress < bF1 ? b * Math.Pow(progress, 2) + : progress < bF2 ? b * Math.Pow(progress - bP2, 2) + b2 + : progress < bF3 ? b * Math.Pow(progress - bP3, 2) + b3 + : b * Math.Pow(progress - bP4, 2) + b4; } } } diff --git a/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Elastic.cs b/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Elastic.cs index d53cd3b..63757e1 100644 --- a/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Elastic.cs +++ b/SDUI/AnimationEngine/EasingMethods/Extended/EasingMethods.Extended.Elastic.cs @@ -20,7 +20,9 @@ public static partial class Extended /// The value progress of the animation. public static double ElasticEaseIn(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : -Math.Pow(2, 10 * (progress - 1)) * Math.Sin((progress - 1.075) * elast); + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : -Math.Pow(2, 10 * (progress - 1)) * Math.Sin((progress - 1.075) * elast); } /// @@ -32,10 +34,16 @@ public static double ElasticEaseIn(double progress) /// The value progress of the animation. public static double ElasticEaseOut(double progress) { - return (progress <= 0) ? 0 : (progress >= 1) ? 1 : Math.Pow(2, -10 * progress) * Math.Sin((progress - .075) * elast) + 1; + return (progress <= 0) ? 0 + : (progress >= 1) ? 1 + : Math.Pow(2, -10 * progress) * Math.Sin((progress - .075) * elast) + 1; } - private static readonly EasingMethod elasticEaseInOut = EasingMethods.Chain(EasingMethods.Extended.ElasticEaseIn, EasingMethods.Extended.ElasticEaseOut); + private static readonly EasingMethod elasticEaseInOut = EasingMethods.Chain( + EasingMethods.Extended.ElasticEaseIn, + EasingMethods.Extended.ElasticEaseOut + ); + /// /// A combination of the and methods. /// Do not use this method if you do not have a proper method for handling progress values greater than 1.0 and lower than 0.0. diff --git a/SDUI/AnimationEngine/ValueFactories.cs b/SDUI/AnimationEngine/ValueFactories.cs index 06abc0e..4a7256c 100644 --- a/SDUI/AnimationEngine/ValueFactories.cs +++ b/SDUI/AnimationEngine/ValueFactories.cs @@ -70,37 +70,64 @@ public static double DoubleFactory(double startValue, double targetValue, double public static Point PointFactory(Point startValue, Point targetValue, double progress) { - return new Point(IntegerFactory(startValue.X, targetValue.X, progress), IntegerFactory(startValue.Y, targetValue.Y, progress)); + return new Point( + IntegerFactory(startValue.X, targetValue.X, progress), + IntegerFactory(startValue.Y, targetValue.Y, progress) + ); } public static PointF PointFFactory(PointF startValue, PointF targetValue, double progress) { - return new PointF(FloatFactory(startValue.X, targetValue.X, progress), FloatFactory(startValue.Y, targetValue.Y, progress)); + return new PointF( + FloatFactory(startValue.X, targetValue.X, progress), + FloatFactory(startValue.Y, targetValue.Y, progress) + ); } public static Size SizeFactory(Size startValue, Size targetValue, double progress) { - return new Size(IntegerFactory(startValue.Width, targetValue.Width, progress), IntegerFactory(startValue.Height, targetValue.Height, progress)); + return new Size( + IntegerFactory(startValue.Width, targetValue.Width, progress), + IntegerFactory(startValue.Height, targetValue.Height, progress) + ); } public static SizeF SizeFFactory(SizeF startValue, SizeF targetValue, double progress) { - return new SizeF(FloatFactory(startValue.Width, targetValue.Width, progress), FloatFactory(startValue.Height, targetValue.Height, progress)); + return new SizeF( + FloatFactory(startValue.Width, targetValue.Width, progress), + FloatFactory(startValue.Height, targetValue.Height, progress) + ); } public static Rectangle RectangleFactory(Rectangle startValue, Rectangle targetValue, double progress) { - return new Rectangle(IntegerFactory(startValue.X, targetValue.X, progress), IntegerFactory(startValue.Y, targetValue.Y, progress), IntegerFactory(startValue.Width, targetValue.Width, progress), IntegerFactory(startValue.Height, targetValue.Height, progress)); + return new Rectangle( + IntegerFactory(startValue.X, targetValue.X, progress), + IntegerFactory(startValue.Y, targetValue.Y, progress), + IntegerFactory(startValue.Width, targetValue.Width, progress), + IntegerFactory(startValue.Height, targetValue.Height, progress) + ); } public static RectangleF RectangleFFactory(RectangleF startValue, RectangleF targetValue, double progress) { - return new RectangleF(FloatFactory(startValue.X, targetValue.X, progress), FloatFactory(startValue.Y, targetValue.Y, progress), FloatFactory(startValue.Width, targetValue.Width, progress), FloatFactory(startValue.Height, targetValue.Height, progress)); + return new RectangleF( + FloatFactory(startValue.X, targetValue.X, progress), + FloatFactory(startValue.Y, targetValue.Y, progress), + FloatFactory(startValue.Width, targetValue.Width, progress), + FloatFactory(startValue.Height, targetValue.Height, progress) + ); } public static Color ColorRgbFactory(Color startValue, Color targetValue, double progress) { - return Color.FromArgb(IntegerFactory(startValue.A, targetValue.A, progress), IntegerFactory(startValue.R, targetValue.R, progress), IntegerFactory(startValue.G, targetValue.G, progress), IntegerFactory(startValue.B, targetValue.B, progress)); + return Color.FromArgb( + IntegerFactory(startValue.A, targetValue.A, progress), + IntegerFactory(startValue.R, targetValue.R, progress), + IntegerFactory(startValue.G, targetValue.G, progress), + IntegerFactory(startValue.B, targetValue.B, progress) + ); } #endregion @@ -119,7 +146,9 @@ public static decimal DecimalFactory(decimal startValue, decimal targetValue, do public static TimeSpan TimeSpanFactory(TimeSpan startValue, TimeSpan targetValue, double progress) { - return startValue.Add(TimeSpan.FromMilliseconds(targetValue.Subtract(startValue).TotalMilliseconds * progress)); + return startValue.Add( + TimeSpan.FromMilliseconds(targetValue.Subtract(startValue).TotalMilliseconds * progress) + ); } #endregion diff --git a/SDUI/AnimationEngine/ValueFactoryCreator.cs b/SDUI/AnimationEngine/ValueFactoryCreator.cs index 16a1e89..f9e3e5b 100644 --- a/SDUI/AnimationEngine/ValueFactoryCreator.cs +++ b/SDUI/AnimationEngine/ValueFactoryCreator.cs @@ -17,9 +17,14 @@ public static ValueFactory> CreateListFactory(ValueFactory origina if (targetValue == null) throw new ArgumentNullException("targetValue", "The target value must not be null."); if (startValue.Count != targetValue.Count) - throw new ArgumentOutOfRangeException("targetValue", "The target value item count must be equal to the start value item count."); + throw new ArgumentOutOfRangeException( + "targetValue", + "The target value item count must be equal to the start value item count." + ); - return startValue.Zip(targetValue, (start, target) => originalFactory(start, target, progress)).ToList(); + return startValue + .Zip(targetValue, (start, target) => originalFactory(start, target, progress)) + .ToList(); }; } @@ -32,57 +37,128 @@ public static ValueFactory CreateArrayFactory(ValueFactory originalFa if (targetValue == null) throw new ArgumentNullException("targetValue", "The target value must not be null."); if (startValue.Length != targetValue.Length) - throw new ArgumentOutOfRangeException("targetValue", "The target value item count must be equal to the start value item count."); + throw new ArgumentOutOfRangeException( + "targetValue", + "The target value item count must be equal to the start value item count." + ); - return startValue.Zip(targetValue, (start, target) => originalFactory(start, target, progress)).ToArray(); + return startValue + .Zip(targetValue, (start, target) => originalFactory(start, target, progress)) + .ToArray(); }; } - public static ValueFactory> CreateTupleFactory(ValueFactory t1Factory, ValueFactory t2Factory) + public static ValueFactory> CreateTupleFactory( + ValueFactory t1Factory, + ValueFactory t2Factory + ) { return (startValue, targetValue, progress) => { - return Tuple.Create(t1Factory(startValue.Item1, targetValue.Item1, progress), t2Factory(startValue.Item2, targetValue.Item2, progress)); + return Tuple.Create( + t1Factory(startValue.Item1, targetValue.Item1, progress), + t2Factory(startValue.Item2, targetValue.Item2, progress) + ); }; } - public static ValueFactory> CreateTupleFactory(ValueFactory t1Factory, ValueFactory t2Factory, ValueFactory t3Factory) + public static ValueFactory> CreateTupleFactory( + ValueFactory t1Factory, + ValueFactory t2Factory, + ValueFactory t3Factory + ) { return (startValue, targetValue, progress) => { - return Tuple.Create(t1Factory(startValue.Item1, targetValue.Item1, progress), t2Factory(startValue.Item2, targetValue.Item2, progress), t3Factory(startValue.Item3, targetValue.Item3, progress)); + return Tuple.Create( + t1Factory(startValue.Item1, targetValue.Item1, progress), + t2Factory(startValue.Item2, targetValue.Item2, progress), + t3Factory(startValue.Item3, targetValue.Item3, progress) + ); }; } - public static ValueFactory> CreateTupleFactory(ValueFactory t1Factory, ValueFactory t2Factory, ValueFactory t3Factory, ValueFactory t4Factory) + public static ValueFactory> CreateTupleFactory( + ValueFactory t1Factory, + ValueFactory t2Factory, + ValueFactory t3Factory, + ValueFactory t4Factory + ) { return (startValue, targetValue, progress) => { - return Tuple.Create(t1Factory(startValue.Item1, targetValue.Item1, progress), t2Factory(startValue.Item2, targetValue.Item2, progress), t3Factory(startValue.Item3, targetValue.Item3, progress), t4Factory(startValue.Item4, targetValue.Item4, progress)); + return Tuple.Create( + t1Factory(startValue.Item1, targetValue.Item1, progress), + t2Factory(startValue.Item2, targetValue.Item2, progress), + t3Factory(startValue.Item3, targetValue.Item3, progress), + t4Factory(startValue.Item4, targetValue.Item4, progress) + ); }; } - public static ValueFactory> CreateTupleFactory(ValueFactory t1Factory, ValueFactory t2Factory, ValueFactory t3Factory, ValueFactory t4Factory, ValueFactory t5Factory) + public static ValueFactory> CreateTupleFactory( + ValueFactory t1Factory, + ValueFactory t2Factory, + ValueFactory t3Factory, + ValueFactory t4Factory, + ValueFactory t5Factory + ) { return (startValue, targetValue, progress) => { - return Tuple.Create(t1Factory(startValue.Item1, targetValue.Item1, progress), t2Factory(startValue.Item2, targetValue.Item2, progress), t3Factory(startValue.Item3, targetValue.Item3, progress), t4Factory(startValue.Item4, targetValue.Item4, progress), t5Factory(startValue.Item5, targetValue.Item5, progress)); + return Tuple.Create( + t1Factory(startValue.Item1, targetValue.Item1, progress), + t2Factory(startValue.Item2, targetValue.Item2, progress), + t3Factory(startValue.Item3, targetValue.Item3, progress), + t4Factory(startValue.Item4, targetValue.Item4, progress), + t5Factory(startValue.Item5, targetValue.Item5, progress) + ); }; } - public static ValueFactory> CreateTupleFactory(ValueFactory t1Factory, ValueFactory t2Factory, ValueFactory t3Factory, ValueFactory t4Factory, ValueFactory t5Factory, ValueFactory t6Factory) + public static ValueFactory> CreateTupleFactory( + ValueFactory t1Factory, + ValueFactory t2Factory, + ValueFactory t3Factory, + ValueFactory t4Factory, + ValueFactory t5Factory, + ValueFactory t6Factory + ) { return (startValue, targetValue, progress) => { - return Tuple.Create(t1Factory(startValue.Item1, targetValue.Item1, progress), t2Factory(startValue.Item2, targetValue.Item2, progress), t3Factory(startValue.Item3, targetValue.Item3, progress), t4Factory(startValue.Item4, targetValue.Item4, progress), t5Factory(startValue.Item5, targetValue.Item5, progress), t6Factory(startValue.Item6, targetValue.Item6, progress)); + return Tuple.Create( + t1Factory(startValue.Item1, targetValue.Item1, progress), + t2Factory(startValue.Item2, targetValue.Item2, progress), + t3Factory(startValue.Item3, targetValue.Item3, progress), + t4Factory(startValue.Item4, targetValue.Item4, progress), + t5Factory(startValue.Item5, targetValue.Item5, progress), + t6Factory(startValue.Item6, targetValue.Item6, progress) + ); }; } - public static ValueFactory> CreateTupleFactory(ValueFactory t1Factory, ValueFactory t2Factory, ValueFactory t3Factory, ValueFactory t4Factory, ValueFactory t5Factory, ValueFactory t6Factory, ValueFactory t7Factory) + public static ValueFactory> CreateTupleFactory( + ValueFactory t1Factory, + ValueFactory t2Factory, + ValueFactory t3Factory, + ValueFactory t4Factory, + ValueFactory t5Factory, + ValueFactory t6Factory, + ValueFactory t7Factory + ) { return (startValue, targetValue, progress) => { - return Tuple.Create(t1Factory(startValue.Item1, targetValue.Item1, progress), t2Factory(startValue.Item2, targetValue.Item2, progress), t3Factory(startValue.Item3, targetValue.Item3, progress), t4Factory(startValue.Item4, targetValue.Item4, progress), t5Factory(startValue.Item5, targetValue.Item5, progress), t6Factory(startValue.Item6, targetValue.Item6, progress), t7Factory(startValue.Item7, targetValue.Item7, progress)); + return Tuple.Create( + t1Factory(startValue.Item1, targetValue.Item1, progress), + t2Factory(startValue.Item2, targetValue.Item2, progress), + t3Factory(startValue.Item3, targetValue.Item3, progress), + t4Factory(startValue.Item4, targetValue.Item4, progress), + t5Factory(startValue.Item5, targetValue.Item5, progress), + t6Factory(startValue.Item6, targetValue.Item6, progress), + t7Factory(startValue.Item7, targetValue.Item7, progress) + ); }; } } diff --git a/SDUI/AnimationEngine/ValueProvider.cs b/SDUI/AnimationEngine/ValueProvider.cs index 1e17452..7deb87f 100644 --- a/SDUI/AnimationEngine/ValueProvider.cs +++ b/SDUI/AnimationEngine/ValueProvider.cs @@ -17,8 +17,7 @@ public class ValueProvider /// The start value. /// The value factory. public ValueProvider(T startValue, ValueFactory valueFactory) - : this(startValue, valueFactory, EasingMethods.DefaultEase) - { } + : this(startValue, valueFactory, EasingMethods.DefaultEase) { } /// /// Initializes a new instance of the class. @@ -75,7 +74,7 @@ public ValueProvider(T startValue, ValueFactory valueFactory, EasingMethod ea /// /// The target value. /// - public bool Completed => CurrentProgress >= 1; + public bool Completed => CurrentProgress >= 1; /// /// Gets or sets the start time. @@ -104,7 +103,8 @@ public virtual T CurrentValue get { double progress = this.CurrentProgress; - if (progress >= 1) return this.TargetValue; + if (progress >= 1) + return this.TargetValue; return this.ValueFactory(this.StartValue, this.TargetValue, this.EasingMethod(progress)); } } @@ -122,7 +122,7 @@ public double CurrentProgress var currentDuration = DateTime.Now - this.StartTime; if (currentDuration >= this.Duration) return 1; - return currentDuration.TotalMilliseconds/ this.Duration.TotalMilliseconds; + return currentDuration.TotalMilliseconds / this.Duration.TotalMilliseconds; } } diff --git a/SDUI/Controls/Button.cs b/SDUI/Controls/Button.cs index bca0da2..67a8a05 100644 --- a/SDUI/Controls/Button.cs +++ b/SDUI/Controls/Button.cs @@ -1,8 +1,8 @@ -using SDUI.Animation; -using System; +using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using SDUI.Animation; namespace SDUI.Controls; @@ -65,12 +65,18 @@ public int Radius public Button() { - SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor, true); + SetStyle( + ControlStyles.UserPaint + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.SupportsTransparentBackColor, + true + ); animationManager = new Animation.AnimationEngine(false) { Increment = 0.03, - AnimationType = AnimationType.EaseOut + AnimationType = AnimationType.EaseOut, }; hoverAnimationManager = new Animation.AnimationEngine @@ -79,9 +85,7 @@ public Button() AnimationType = AnimationType.Linear, }; - hoverAnimationManager.OnAnimationFinished += (sender) => - { - }; + hoverAnimationManager.OnAnimationFinished += (sender) => { }; hoverAnimationManager.OnAnimationProgress += sender => Invalidate(); animationManager.OnAnimationProgress += sender => Invalidate(); @@ -145,7 +149,6 @@ protected override void OnPaint(PaintEventArgs e) else color = ColorScheme.ForeColor.Alpha(20); - using var brush = new SolidBrush(color); using var outerPen = new Pen(ColorScheme.BorderColor); @@ -177,10 +180,17 @@ protected override void OnPaint(PaintEventArgs e) var animationValue = animationManager.GetProgress(i); var animationSource = animationManager.GetSource(i); - using var rippleBrush = new SolidBrush(ColorScheme.BackColor.Alpha((int)(101 - (animationValue * 100)))); + using var rippleBrush = new SolidBrush( + ColorScheme.BackColor.Alpha((int)(101 - (animationValue * 100))) + ); var rippleSize = (float)(animationValue * Width * 2.0); - var rippleRect = new RectangleF(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize); + var rippleRect = new RectangleF( + animationSource.X - rippleSize / 2, + animationSource.Y - rippleSize / 2, + rippleSize, + rippleSize + ); path.AddEllipse(rippleRect); graphics.FillPath(rippleBrush, path); } @@ -237,4 +247,4 @@ public override Size GetPreferredSize(Size proposedSize) return new Size((int)Math.Ceiling(textSize.Width) + extra, 23); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/ChatBubble.cs b/SDUI/Controls/ChatBubble.cs index f30e56a..0d0f04a 100644 --- a/SDUI/Controls/ChatBubble.cs +++ b/SDUI/Controls/ChatBubble.cs @@ -55,7 +55,14 @@ public bool DrawBubbleArrow public ChatBubble() { - SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.AllPaintingInWmPaint + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.SupportsTransparentBackColor + | ControlStyles.UserPaint, + true + ); _arrowPosition = AnchorStyles.Left; Size = new Size(152, 38); @@ -126,18 +133,20 @@ protected override void OnPaint(PaintEventArgs e) switch (_arrowPosition) { case AnchorStyles.Left: - p = new Point[] { - new Point(9, Height - 19), - new Point(0, Height - 25), - new Point(9, Height - 30) - }; + p = new Point[] + { + new Point(9, Height - 19), + new Point(0, Height - 25), + new Point(9, Height - 30), + }; break; case AnchorStyles.Right: - p = new Point[] { - new Point(Width - 8, Height - 19), - new Point(Width, Height - 25), - new Point(Width - 8, Height - 30) - }; + p = new Point[] + { + new Point(Width - 8, Height - 19), + new Point(Width, Height - 25), + new Point(Width - 8, Height - 30), + }; break; default: return; @@ -156,4 +165,4 @@ protected override void OnPaint(PaintEventArgs e) this.DrawString(e.Graphics, ContentAlignment.TopLeft, ForeColor, textRect); } } -} \ No newline at end of file +} diff --git a/SDUI/Controls/CheckBox.cs b/SDUI/Controls/CheckBox.cs index ac3c1c5..ad25b4c 100644 --- a/SDUI/Controls/CheckBox.cs +++ b/SDUI/Controls/CheckBox.cs @@ -1,10 +1,10 @@ -using SDUI.Animation; -using System; +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Windows.Forms; +using SDUI.Animation; namespace SDUI.Controls { @@ -14,7 +14,7 @@ public class CheckBox : System.Windows.Forms.CheckBox private const int CHECKBOX_SIZE_HALF = CHECKBOX_SIZE / 2; - private static readonly Point[] CHECKMARK_LINE = { new (1, 6), new (5, 10), new (12, 3) }; + private static readonly Point[] CHECKMARK_LINE = { new(1, 6), new(5, 10), new(12, 3) }; private readonly Animation.AnimationEngine animationManager; @@ -69,25 +69,27 @@ public CheckBox() { //SetExtendedState(ExtendedStates.UserPreferredSizeCache, true); - SetStyle(ControlStyles.UserPaint | - ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer, true); + SetStyle( + ControlStyles.UserPaint + | ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer, + true + ); - SetStyle(ControlStyles.FixedHeight | - ControlStyles.Selectable, false); + SetStyle(ControlStyles.FixedHeight | ControlStyles.Selectable, false); SetStyle(ControlStyles.ResizeRedraw, true); animationManager = new Animation.AnimationEngine { AnimationType = AnimationType.EaseInOut, - Increment = 0.10 + Increment = 0.10, }; rippleAnimationManager = new Animation.AnimationEngine(false) { AnimationType = AnimationType.Linear, Increment = 0.10, - SecondaryIncrement = 0.07 + SecondaryIncrement = 0.07, }; animationManager.OnAnimationProgress += sender => Invalidate(); rippleAnimationManager.OnAnimationProgress += sender => Invalidate(); @@ -132,7 +134,8 @@ protected override void OnCreateControl() { base.OnCreateControl(); - if (DesignMode) return; + if (DesignMode) + return; _mouseState = 0; MouseEnter += (sender, args) => @@ -181,9 +184,13 @@ protected override void OnPaint(PaintEventArgs pevent) var disabledOffColor = ColorScheme.BorderColor; int colorAlpha = Enabled ? (int)(animationProgress * 255.0) : disabledOffColor.A; - int backgroundAlpha = Enabled ? (int)(ColorScheme.BorderColor.A * (1.0 - animationProgress)) : disabledOffColor.A; + int backgroundAlpha = Enabled + ? (int)(ColorScheme.BorderColor.A * (1.0 - animationProgress)) + : disabledOffColor.A; - using var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? ColorScheme.AccentColor : disabledOffColor)); + using var brush = new SolidBrush( + Color.FromArgb(colorAlpha, Enabled ? ColorScheme.AccentColor : disabledOffColor) + ); using var pen = new Pen(brush.Color); // draw ripple animation @@ -193,11 +200,25 @@ protected override void OnPaint(PaintEventArgs pevent) { var animationValue = rippleAnimationManager.GetProgress(i); var animationSource = new Point(CHECKBOX_CENTER, CHECKBOX_CENTER); - using var rippleBrush = new SolidBrush(Color.FromArgb((int)((animationValue * 40)), ((bool)rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color)); + using var rippleBrush = new SolidBrush( + Color.FromArgb( + (int)((animationValue * 40)), + ((bool)rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color + ) + ); var rippleHeight = (Height % 2 == 0) ? Height - 3 : Height - 2; - var rippleSize = (rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) : rippleHeight; - - using var path = DrawingExtensions.CreateRoundPath(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize, rippleSize / 2); + var rippleSize = + (rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) + ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) + : rippleHeight; + + using var path = DrawingExtensions.CreateRoundPath( + animationSource.X - rippleSize / 2, + animationSource.Y - rippleSize / 2, + rippleSize, + rippleSize, + rippleSize / 2 + ); graphics.FillPath(rippleBrush, path); } } @@ -205,7 +226,12 @@ protected override void OnPaint(PaintEventArgs pevent) var checkMarkLineFill = new Rectangle(boxOffset, boxOffset, (int)(14.0 * animationProgress), 14); using (var checkmarkPath = DrawingExtensions.CreateRoundPath(boxOffset, boxOffset, 14, 14, 2)) { - using var brush2 = new SolidBrush(ColorScheme.BackColor.BlendWith(Enabled ? ColorScheme.BorderColor : disabledOffColor, backgroundAlpha)); + using var brush2 = new SolidBrush( + ColorScheme.BackColor.BlendWith( + Enabled ? ColorScheme.BorderColor : disabledOffColor, + backgroundAlpha + ) + ); using var pen2 = new Pen(brush2.Color); graphics.FillPath(ColorScheme.BorderColor.Brush(), checkmarkPath); @@ -221,7 +247,12 @@ protected override void OnPaint(PaintEventArgs pevent) // draw checkbox text var textColor = Enabled ? ColorScheme.ForeColor : Color.Gray; - this.DrawString(graphics, TextAlign, textColor, new RectangleF(new Point(boxOffset + CHECKBOX_SIZE, 0), ClientRectangle.Size)); + this.DrawString( + graphics, + TextAlign, + textColor, + new RectangleF(new Point(boxOffset + CHECKBOX_SIZE, 0), ClientRectangle.Size) + ); if (ColorScheme.DrawDebugBorders) { @@ -239,4 +270,4 @@ protected override void OnSizeChanged(EventArgs e) boxRectangle = new Rectangle(boxOffset, boxOffset, CHECKBOX_SIZE - 1, CHECKBOX_SIZE - 1); } } -} \ No newline at end of file +} diff --git a/SDUI/Controls/ComboBox.cs b/SDUI/Controls/ComboBox.cs index 4cb7fa6..237323a 100644 --- a/SDUI/Controls/ComboBox.cs +++ b/SDUI/Controls/ComboBox.cs @@ -36,12 +36,13 @@ public float ShadowDepth public ComboBox() { SetStyle( - ControlStyles.UserPaint | - ControlStyles.ResizeRedraw | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.Selectable | - ControlStyles.SupportsTransparentBackColor, true + ControlStyles.UserPaint + | ControlStyles.ResizeRedraw + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.Selectable + | ControlStyles.SupportsTransparentBackColor, + true ); DrawMode = DrawMode.OwnerDrawVariable; @@ -56,9 +57,11 @@ protected override void OnDrawItem(DrawItemEventArgs e) var foreColor = ColorScheme.ForeColor; - if ((e.State & DrawItemState.Selected) == DrawItemState.Selected || - (e.State & DrawItemState.Focus) == DrawItemState.Focus || - (e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect) + if ( + (e.State & DrawItemState.Selected) == DrawItemState.Selected + || (e.State & DrawItemState.Focus) == DrawItemState.Focus + || (e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect + ) { foreColor = Color.White; using var brush = new SolidBrush(Color.Blue); @@ -72,7 +75,7 @@ protected override void OnDrawItem(DrawItemEventArgs e) LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Near, FormatFlags = StringFormatFlags.NoWrap, - Trimming = StringTrimming.EllipsisCharacter + Trimming = StringTrimming.EllipsisCharacter, }; using var textBrush = new SolidBrush(foreColor); @@ -122,21 +125,29 @@ protected override void OnPaint(PaintEventArgs e) using var backBrush = new SolidBrush(backColor); e.Graphics.FillPath(backBrush, path); - - var _extendBoxRect = new RectangleF(rectf.Width - (24f * (DeviceDpi / 96)), 0, (16 * (DeviceDpi / 96)), rectf.Height - (4 * (DeviceDpi / 96)) + _shadowDepth); + var _extendBoxRect = new RectangleF( + rectf.Width - (24f * (DeviceDpi / 96)), + 0, + (16 * (DeviceDpi / 96)), + rectf.Height - (4 * (DeviceDpi / 96)) + _shadowDepth + ); using var symbolPen = new Pen(ColorScheme.ForeColor); - graphics.DrawLine(symbolPen, - _extendBoxRect.Left + _extendBoxRect.Width / 2 - (5 * (DeviceDpi / 96)) - 1, - _extendBoxRect.Top + _extendBoxRect.Height / 2 - (2 * (DeviceDpi / 96)), - _extendBoxRect.Left + _extendBoxRect.Width / 2 - (1 * (DeviceDpi / 96)), - _extendBoxRect.Top + _extendBoxRect.Height / 2 + (3 * (DeviceDpi / 96))); + graphics.DrawLine( + symbolPen, + _extendBoxRect.Left + _extendBoxRect.Width / 2 - (5 * (DeviceDpi / 96)) - 1, + _extendBoxRect.Top + _extendBoxRect.Height / 2 - (2 * (DeviceDpi / 96)), + _extendBoxRect.Left + _extendBoxRect.Width / 2 - (1 * (DeviceDpi / 96)), + _extendBoxRect.Top + _extendBoxRect.Height / 2 + (3 * (DeviceDpi / 96)) + ); - graphics.DrawLine(symbolPen, + graphics.DrawLine( + symbolPen, _extendBoxRect.Left + _extendBoxRect.Width / 2 + (5 * (DeviceDpi / 96)) - 1, _extendBoxRect.Top + _extendBoxRect.Height / 2 - (2 * (DeviceDpi / 96)), _extendBoxRect.Left + _extendBoxRect.Width / 2 - (1 * (DeviceDpi / 96)), - _extendBoxRect.Top + _extendBoxRect.Height / 2 + (3 * (DeviceDpi / 96))); + _extendBoxRect.Top + _extendBoxRect.Height / 2 + (3 * (DeviceDpi / 96)) + ); graphics.DrawShadow(rectf, _shadowDepth, _radius); e.Graphics.DrawPath(ColorScheme.BorderColor, path); diff --git a/SDUI/Controls/ContextMenuStrip.cs b/SDUI/Controls/ContextMenuStrip.cs index 94aadb0..9c02602 100644 --- a/SDUI/Controls/ContextMenuStrip.cs +++ b/SDUI/Controls/ContextMenuStrip.cs @@ -1,5 +1,5 @@ -using SDUI.Renderers; -using System; +using System; +using SDUI.Renderers; namespace SDUI.Controls; @@ -15,4 +15,4 @@ protected override void OnParentBackColorChanged(EventArgs e) base.OnParentBackColorChanged(e); Invalidate(); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/DoubleBufferedControl.cs b/SDUI/Controls/DoubleBufferedControl.cs index 7e9484b..1a2eb0a 100644 --- a/SDUI/Controls/DoubleBufferedControl.cs +++ b/SDUI/Controls/DoubleBufferedControl.cs @@ -4,7 +4,8 @@ namespace SDUI.Controls { public class DoubleBufferedControl : UserControl { - public DoubleBufferedControl() { + public DoubleBufferedControl() + { SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); diff --git a/SDUI/Controls/FlowLayoutPanel.cs b/SDUI/Controls/FlowLayoutPanel.cs index bc73f43..eb1330a 100644 --- a/SDUI/Controls/FlowLayoutPanel.cs +++ b/SDUI/Controls/FlowLayoutPanel.cs @@ -1,8 +1,8 @@ -using SDUI.Helpers; using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using SDUI.Helpers; namespace SDUI.Controls; @@ -64,10 +64,13 @@ public float ShadowDepth public FlowLayoutPanel() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.UserPaint, + true + ); BackColor = Color.Transparent; DoubleBuffered = true; @@ -116,7 +119,13 @@ protected override void OnPaint(PaintEventArgs e) e.Graphics.FillPath(brush, path); //e.Graphics.DrawShadow(rect, _shadowDepth, _radius); - ShadowUtils.DrawShadow(graphics, ColorScheme.ShadowColor, rect.ToRectangle(), (int)(_shadowDepth + 1) + 40, DockStyle.Right); + ShadowUtils.DrawShadow( + graphics, + ColorScheme.ShadowColor, + rect.ToRectangle(), + (int)(_shadowDepth + 1) + 40, + DockStyle.Right + ); using var pen = new Pen(borderColor, _border.All); e.Graphics.DrawPath(pen, path); @@ -128,10 +137,21 @@ protected override void OnPaint(PaintEventArgs e) e.Graphics.DrawShadow(rect, _shadowDepth, _radius == 0 ? 1 : _radius); - ControlPaint.DrawBorder(e.Graphics, ClientRectangle, - borderColor, _border.Left, ButtonBorderStyle.Solid, - borderColor, _border.Top, ButtonBorderStyle.Solid, - borderColor, _border.Right, ButtonBorderStyle.Solid, - borderColor, _border.Bottom, ButtonBorderStyle.Solid); + ControlPaint.DrawBorder( + e.Graphics, + ClientRectangle, + borderColor, + _border.Left, + ButtonBorderStyle.Solid, + borderColor, + _border.Top, + ButtonBorderStyle.Solid, + borderColor, + _border.Right, + ButtonBorderStyle.Solid, + borderColor, + _border.Bottom, + ButtonBorderStyle.Solid + ); } } diff --git a/SDUI/Controls/FormControlBox.cs b/SDUI/Controls/FormControlBox.cs index 58104cf..d7e57fc 100644 --- a/SDUI/Controls/FormControlBox.cs +++ b/SDUI/Controls/FormControlBox.cs @@ -6,7 +6,6 @@ namespace SDUI.Controls; public class FormControlBox : Control { - int _mouseState = 0; int _mousePos; Rectangle _closeButtonRect = new(3, 3, 16, 16); @@ -17,10 +16,10 @@ public class FormControlBox : Control public bool IsVertical { get => _isVertical; - set + set { _isVertical = value; - if(value) + if (value) { _closeButtonRect = new(3, 3, 16, 16); _minimizeButtonRect = new(3, 23, 16, 16); @@ -46,6 +45,7 @@ protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) _mouseState = 2; Invalidate(); } + protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) { base.OnMouseUp(e); @@ -80,22 +80,25 @@ protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) _mouseState = 1; Invalidate(); } + protected override void OnMouseEnter(System.EventArgs e) { base.OnMouseEnter(e); _mouseState = 1; Invalidate(); } + protected override void OnMouseLeave(System.EventArgs e) { base.OnMouseLeave(e); _mouseState = 0; Invalidate(); } + protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { base.OnMouseMove(e); - if(_isVertical) + if (_isVertical) _mousePos = e.Location.Y; else _mousePos = e.Location.X; @@ -107,10 +110,7 @@ protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) bool _maximize = true; public bool EnableMaximize { - get - { - return _maximize; - } + get { return _maximize; } set { _maximize = value; @@ -122,7 +122,13 @@ public bool EnableMaximize public FormControlBox() { - SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true); + SetStyle( + ControlStyles.UserPaint + | ControlStyles.SupportsTransparentBackColor + | ControlStyles.ResizeRedraw + | ControlStyles.DoubleBuffer, + true + ); DoubleBuffered = true; BackColor = Color.Transparent; Font = new Font("Webdings", 9); @@ -145,7 +151,6 @@ protected override void OnPaint(PaintEventArgs e) using var brushMax = new SolidBrush(Color.YellowGreen); - switch (_mouseState) { case 1: @@ -177,7 +182,7 @@ protected override void OnPaint(PaintEventArgs e) graphics.FillEllipse(brushMax, _maximizeButtonRect); graphics.DrawEllipse(new Pen(brushMax.Color.Alpha(200)), _maximizeButtonRect); - if(_isVertical) + if (_isVertical) graphics.DrawString("@", Font, new SolidBrush(ColorScheme.ForeColor), new RectangleF(4, 42, 0, 0)); else graphics.DrawString("@", Font, new SolidBrush(ColorScheme.ForeColor), new RectangleF(43, 2, 0, 0)); diff --git a/SDUI/Controls/GroupBox.cs b/SDUI/Controls/GroupBox.cs index 38e66f1..f4006c1 100644 --- a/SDUI/Controls/GroupBox.cs +++ b/SDUI/Controls/GroupBox.cs @@ -1,8 +1,8 @@ -using SDUI.Helpers; -using System; +using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using SDUI.Helpers; namespace SDUI.Controls; @@ -36,13 +36,16 @@ public int Radius public GroupBox() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.DoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.Opaque | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.DoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.Opaque + | ControlStyles.UserPaint, + true + ); UpdateStyles(); this.DoubleBuffered = true; @@ -112,4 +115,4 @@ public override Size GetPreferredSize(Size proposedSize) return preferredSize; } -} \ No newline at end of file +} diff --git a/SDUI/Controls/InputDialog.cs b/SDUI/Controls/InputDialog.cs index d57540e..be672d7 100644 --- a/SDUI/Controls/InputDialog.cs +++ b/SDUI/Controls/InputDialog.cs @@ -9,7 +9,7 @@ public enum InputType { Combobox, Textbox, - Numeric + Numeric, } /// @@ -47,7 +47,13 @@ public enum InputType /// The title. /// The message. /// If you want to active the selector instead of textbox true; otherwise false - public InputDialog(string formTitle, string title, string message, InputType inputType = InputType.Textbox, object defaultValue = null) + public InputDialog( + string formTitle, + string title, + string message, + InputType inputType = InputType.Textbox, + object defaultValue = null + ) { InitializeComponent(); this.AcceptButton = this.btnOK; @@ -103,8 +109,8 @@ public InputDialog(string formTitle, string title, string message, InputType inp /// The dialog message /// If you want to active the selector instead of textbox true; otherwise false /// The - public static DialogResult Show(string formTitle, string title, string message, InputType inputType) - => new InputDialog(formTitle, title, message, inputType).ShowDialog(); + public static DialogResult Show(string formTitle, string title, string message, InputType inputType) => + new InputDialog(formTitle, title, message, inputType).ShowDialog(); /// /// Handles the Click event of the btnOK control. @@ -178,4 +184,4 @@ private void numValue_KeyUp(object sender, KeyEventArgs e) Value = numValue.Value; DialogResult = DialogResult.OK; } -} \ No newline at end of file +} diff --git a/SDUI/Controls/InputDailog.resx b/SDUI/Controls/InputDialog.resx similarity index 100% rename from SDUI/Controls/InputDailog.resx rename to SDUI/Controls/InputDialog.resx diff --git a/SDUI/Controls/Label.cs b/SDUI/Controls/Label.cs index 64d3eb4..117e0ef 100644 --- a/SDUI/Controls/Label.cs +++ b/SDUI/Controls/Label.cs @@ -31,13 +31,17 @@ public Color[] Gradient get => _gradient; set { - _gradient = value; Invalidate(); + _gradient = value; + Invalidate(); } } public Label() { - SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.OptimizedDoubleBuffer, true); + SetStyle( + ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.OptimizedDoubleBuffer, + true + ); } protected override void OnSizeChanged(EventArgs e) @@ -67,7 +71,12 @@ protected override void OnPaint(PaintEventArgs e) if (ApplyGradient) { - using var brush = new LinearGradientBrush(ClientRectangle, _gradient[0], _gradient[1], Angle/*LinearGradientMode.Horizontal */); + using var brush = new LinearGradientBrush( + ClientRectangle, + _gradient[0], + _gradient[1], + Angle /*LinearGradientMode.Horizontal */ + ); using var format = this.CreateStringFormat(TextAlign, AutoEllipsis, UseMnemonic); e.Graphics.DrawString(Text, Font, brush, ClientRectangle, format); @@ -75,4 +84,4 @@ protected override void OnPaint(PaintEventArgs e) else this.DrawString(e.Graphics, TextAlign, ColorScheme.ForeColor, AutoEllipsis, UseMnemonic); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/ListView.cs b/SDUI/Controls/ListView.cs index 64564a9..826dc50 100644 --- a/SDUI/Controls/ListView.cs +++ b/SDUI/Controls/ListView.cs @@ -1,9 +1,9 @@ -using SDUI.Controls.Subclasses; -using SDUI.Helpers; -using System; +using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; +using SDUI.Controls.Subclasses; +using SDUI.Helpers; using static SDUI.NativeMethods; namespace SDUI.Controls; @@ -27,11 +27,13 @@ public ListView() : base() { SetStyle( - ControlStyles.Opaque | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.ResizeRedraw | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.EnableNotifyMessage, true); + ControlStyles.Opaque + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.ResizeRedraw + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.EnableNotifyMessage, + true + ); LvwColumnSorter = new ListViewColumnSorter(); ListViewItemSorter = LvwColumnSorter; @@ -96,9 +98,8 @@ protected override void OnColumnClick(ColumnClickEventArgs e) if (e.Column == LvwColumnSorter.SortColumn) { // Reverse the current sort direction for this column. - LvwColumnSorter.Order = (LvwColumnSorter.Order == SortOrder.Ascending) - ? SortOrder.Descending - : SortOrder.Ascending; + LvwColumnSorter.Order = + (LvwColumnSorter.Order == SortOrder.Ascending) ? SortOrder.Descending : SortOrder.Ascending; } else { @@ -178,17 +179,19 @@ protected override void WndProc(ref Message m) case CDDS.CDDS_PREPAINT: if (pnmlv.dwItemType == LVCDI_GROUP) { - var rectHeader = new Rect - { - Top = LVGGR_HEADER - }; + var rectHeader = new Rect { Top = LVGGR_HEADER }; var nItem = (int)pnmlv.nmcd.dwItemSpec; SendMessage(m.HWnd, LVM_GETGROUPRECT, nItem, ref rectHeader); using (var graphics = Graphics.FromHdc(pnmlv.nmcd.hdc)) { - var rect = new Rectangle(rectHeader.Left, rectHeader.Top, rectHeader.Right - rectHeader.Left, rectHeader.Bottom - rectHeader.Top); + var rect = new Rectangle( + rectHeader.Left, + rectHeader.Top, + rectHeader.Right - rectHeader.Left, + rectHeader.Bottom - rectHeader.Top + ); //var backgroundBrush = new SolidBrush(_groupHeadingBackColor); //graphics.FillRectangle(backgroundBrush, rect); @@ -205,7 +208,9 @@ protected override void WndProc(ref Message m) rect.Offset(10, rectHeightMiddle); - var color = Color.FromArgb(80, 1, 52, 153).Brightness(ColorScheme.BackColor.Determine().GetBrightness()); + var color = Color + .FromArgb(80, 1, 52, 153) + .Brightness(ColorScheme.BackColor.Determine().GetBrightness()); using (var drawBrush = new SolidBrush(color)) { TextRenderer.DrawText(graphics, sText, Font, rect, color, TextFormatFlags.Left); @@ -214,12 +219,19 @@ protected override void WndProc(ref Message m) using (var lineBrush = new SolidBrush(color)) { - graphics.DrawLine(new Pen(lineBrush), rect.X + graphics.MeasureString(sText, Font).Width + 10, rect.Y + (int)Math.Round(rect.Height / 2d), rect.X + (int)Math.Round(rect.Width * 95 / 100d), rect.Y + (int)Math.Round(rect.Height / 2d)); + graphics.DrawLine( + new Pen(lineBrush), + rect.X + graphics.MeasureString(sText, Font).Width + 10, + rect.Y + (int)Math.Round(rect.Height / 2d), + rect.X + (int)Math.Round(rect.Width * 95 / 100d), + rect.Y + (int)Math.Round(rect.Height / 2d) + ); } } } - m.Result = new IntPtr((int)CDRF.CDRF_SKIPDEFAULT); return; + m.Result = new IntPtr((int)CDRF.CDRF_SKIPDEFAULT); + return; } else { @@ -228,40 +240,40 @@ protected override void WndProc(ref Message m) break; - /*case CDDS.CDDS_ITEMPREPAINT: - m.Result = new IntPtr((int)(CDRF.CDRF_NOTIFYSUBITEMDRAW | CDRF.CDRF_NOTIFYPOSTPAINT)); + /*case CDDS.CDDS_ITEMPREPAINT: + m.Result = new IntPtr((int)(CDRF.CDRF_NOTIFYSUBITEMDRAW | CDRF.CDRF_NOTIFYPOSTPAINT)); - ListView lv = this; - IntPtr hHeader = GetHeaderControl(lv); - IntPtr hdc = GetDC(hHeader); + ListView lv = this; + IntPtr hHeader = GetHeaderControl(lv); + IntPtr hdc = GetDC(hHeader); - using (var graphics = Graphics.FromHdc(hdc)) - { - graphics.FillRectangle(new SolidBrush(ColorScheme.BackColor), graphics.ClipBounds); + using (var graphics = Graphics.FromHdc(hdc)) + { + graphics.FillRectangle(new SolidBrush(ColorScheme.BackColor), graphics.ClipBounds); - var width = 0; - foreach (ColumnHeader column in Columns) - { - var size = TextRenderer.MeasureText(column.Text, Font); - var bounds = new Rectangle(new Point(width, 0), new Size(column.Width + 5, 24)); + var width = 0; + foreach (ColumnHeader column in Columns) + { + var size = TextRenderer.MeasureText(column.Text, Font); + var bounds = new Rectangle(new Point(width, 0), new Size(column.Width + 5, 24)); - if(column.TextAlign == HorizontalAlignment.Left) - TextRenderer.DrawText(graphics, column.Text, Font, bounds, ColorScheme.ForeColor, TextFormatFlags.Left | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.PathEllipsis | TextFormatFlags.VerticalCenter); - else if (column.TextAlign == HorizontalAlignment.Right) - TextRenderer.DrawText(graphics, column.Text, Font, bounds, ColorScheme.ForeColor, TextFormatFlags.Right | TextFormatFlags.VerticalCenter); - else - TextRenderer.DrawText(graphics, column.Text, Font, bounds, ColorScheme.ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); + if(column.TextAlign == HorizontalAlignment.Left) + TextRenderer.DrawText(graphics, column.Text, Font, bounds, ColorScheme.ForeColor, TextFormatFlags.Left | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.PathEllipsis | TextFormatFlags.VerticalCenter); + else if (column.TextAlign == HorizontalAlignment.Right) + TextRenderer.DrawText(graphics, column.Text, Font, bounds, ColorScheme.ForeColor, TextFormatFlags.Right | TextFormatFlags.VerticalCenter); + else + TextRenderer.DrawText(graphics, column.Text, Font, bounds, ColorScheme.ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); - var x = bounds.X - 2; - graphics.DrawLine(new Pen(ColorScheme.BorderColor), x, 0, x, Height); + var x = bounds.X - 2; + graphics.DrawLine(new Pen(ColorScheme.BorderColor), x, 0, x, Height); - width += column.Width; - } + width += column.Width; } + } - //ReleaseDC(hHeader, hdc); + //ReleaseDC(hHeader, hdc); - break;*/ + break;*/ } } } @@ -270,16 +282,12 @@ protected override void WndProc(ref Message m) //AllowDarkModeForWindow(m.HWnd, ColorScheme.BackColor.IsDark()); try { - BackColor = ColorScheme.BackColor; ForeColor = ColorScheme.ForeColor; } - catch (Exception) - { - } + catch (Exception) { } } - else if (m.Msg != WM_KILLFOCUS && - (m.Msg == WM_HSCROLL || m.Msg == WM_VSCROLL)) + else if (m.Msg != WM_KILLFOCUS && (m.Msg == WM_HSCROLL || m.Msg == WM_VSCROLL)) Invalidate(); base.WndProc(ref m); @@ -311,4 +319,4 @@ public void SetSortArrow(int column, SortOrder sortOrder) SendMessage(pHeader, HDM_SETITEM, pColumn, ref headerItem); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/MenuStrip.cs b/SDUI/Controls/MenuStrip.cs index abb5920..285e83d 100644 --- a/SDUI/Controls/MenuStrip.cs +++ b/SDUI/Controls/MenuStrip.cs @@ -1,5 +1,5 @@ -using SDUI.Renderers; -using System; +using System; +using SDUI.Renderers; namespace SDUI.Controls; diff --git a/SDUI/Controls/MultiPageControl.cs b/SDUI/Controls/MultiPageControl.cs index 11fefed..9a8ba29 100644 --- a/SDUI/Controls/MultiPageControl.cs +++ b/SDUI/Controls/MultiPageControl.cs @@ -22,10 +22,7 @@ public class MultiPageControlItem : Panel [Localizable(true), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)] public override string Text { - get - { - return base.Text; - } + get { return base.Text; } set { base.Text = value; @@ -78,17 +75,21 @@ public event EventHandler ClosePageButtonClicked public MultiPageControl() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.UserPaint, + true + ); Padding = new Padding(0, 30, 0, 0); ReorganizePages(); } private MultiPageControlCollection _collection = new(); + [Editor(typeof(MultiPageControlCollectionEditor), typeof(UITypeEditor))] [MergableProperty(false)] public new MultiPageControlCollection Controls @@ -106,7 +107,7 @@ public int SelectedIndex var sys = Stopwatch.StartNew(); //if (_selectedIndex == value) - // return; + // return; if (Controls.Count > 0) { @@ -126,7 +127,9 @@ public int SelectedIndex for (int i = 0; i < Controls.Count; i++) Controls[i].Visible = i == _selectedIndex; - Debug.WriteLine($"Index: {_selectedIndex} Finished: {sys.ElapsedMilliseconds} ms {Controls.Count} & {Controls.Count}"); + Debug.WriteLine( + $"Index: {_selectedIndex} Finished: {sys.ElapsedMilliseconds} ms {Controls.Count} & {Controls.Count}" + ); Invalidate(); } } @@ -182,18 +185,23 @@ public bool RenderPageClose private void ReorganizePages() { - _lastTabX = 6 * DPI;// this.Radius / 2; + _lastTabX = 6 * DPI; // this.Radius / 2; - for(int i = 0; i < Controls.Count; i++) + for (int i = 0; i < Controls.Count; i++) { var control = Controls[i]; var stringSize = TextRenderer.MeasureText(control.Text, Font); var width = stringSize.Width + 80 * DPI; RectangleF rectangle = new(_lastTabX, 6 * DPI, width, _headerControlSize.Height * DPI - 6); - + control.Rectangle = rectangle; - control.RectangleClose = new(rectangle.X + rectangle.Width - 20 * DPI, rectangle.Y + 6 * DPI, 12 * DPI, 12 * DPI); + control.RectangleClose = new( + rectangle.X + rectangle.Width - 20 * DPI, + rectangle.Y + 6 * DPI, + 12 * DPI, + 12 * DPI + ); control.RectangleIcon = new(rectangle.X + 6 * DPI, rectangle.Y + 5 * DPI, 16 * DPI, 16 * DPI); _lastTabX += width; @@ -210,7 +218,13 @@ public MultiPageControlItem Add() public MultiPageControlItem Add(string text) { SuspendLayout(); - var newPage = new MultiPageControlItem { Parent = this, Text = text, Visible = false, Dock = DockStyle.Fill }; + var newPage = new MultiPageControlItem + { + Parent = this, + Text = text, + Visible = false, + Dock = DockStyle.Fill, + }; Controls.Add(newPage); ReorganizePages(); @@ -293,7 +307,7 @@ protected override void OnPaint(PaintEventArgs e) var isMouseHoverOnCloseBrn = control.RectangleClose.Contains(_mouseLocation); if (isMouseHoverOnCloseBrn) closeBrush.Color = Color.DarkGray; - + using var closePen = new Pen(closeBrush.Color); graphics.DrawArc(closePen, control.RectangleClose, 0, 360); @@ -302,7 +316,15 @@ protected override void OnPaint(PaintEventArgs e) inlineCloseRect.Offset(0, 0); inlineCloseRect.Inflate(-2, -2); - graphics.FillPie(closeBrush, inlineCloseRect.X, inlineCloseRect.Y, inlineCloseRect.Width, inlineCloseRect.Height, 0, 360); + graphics.FillPie( + closeBrush, + inlineCloseRect.X, + inlineCloseRect.Y, + inlineCloseRect.Width, + inlineCloseRect.Height, + 0, + 360 + ); } if (_renderPageIcon) @@ -355,7 +377,7 @@ protected override void OnMouseWheel(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); - _mouseState = 2; + _mouseState = 2; Invalidate(); } @@ -376,14 +398,14 @@ protected override void OnMouseLeave(EventArgs e) protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); - if(_mouseState == 2) + if (_mouseState == 2) { for (int i = 0; i < Controls.Count; i++) { var item = Controls[i]; if (item.RectangleClose.Contains(_mouseLocation)) { - if(_onClosePageButtonClicked == null) + if (_onClosePageButtonClicked == null) RemoveAt(i); else _onClosePageButtonClicked(this, EventArgs.Empty); @@ -397,7 +419,7 @@ protected override void OnMouseUp(MouseEventArgs e) if (_newButtonPath.GetBounds().Contains(_mouseLocation)) { - if(_onNewPageButtonClicked == null) + if (_onNewPageButtonClicked == null) Add(); else _onNewPageButtonClicked(this, EventArgs.Empty); @@ -416,8 +438,7 @@ public override DesignerActionListCollection ActionLists get { if (actionList == null) - actionList = new DesignerActionListCollection(new[] { - new MultiPageControlActions(this) }); + actionList = new DesignerActionListCollection(new[] { new MultiPageControlActions(this) }); return actionList; } } @@ -450,7 +471,7 @@ public override DesignerActionItemCollection GetSortedActionItems() return new() { new DesignerActionMethodItem(this, "AddTab", "Add Tab", true), - new DesignerActionMethodItem(this, "RemoveTab", "Remove Tab", true) + new DesignerActionMethodItem(this, "RemoveTab", "Remove Tab", true), }; } } @@ -458,9 +479,7 @@ public override DesignerActionItemCollection GetSortedActionItems() public class MultiPageControlCollectionEditor : CollectionEditor { public MultiPageControlCollectionEditor() - : base(typeof(MultiPageControlCollection)) - { - } + : base(typeof(MultiPageControlCollection)) { } protected override object SetItems(object editValue, object[] value) { @@ -480,7 +499,10 @@ protected override CollectionForm CreateCollectionForm() { var form = base.CreateCollectionForm(); Type type = form.GetType(); - PropertyInfo propertyInfo = type.GetProperty("CollectionEditable", BindingFlags.Instance | BindingFlags.NonPublic); + PropertyInfo propertyInfo = type.GetProperty( + "CollectionEditable", + BindingFlags.Instance | BindingFlags.NonPublic + ); propertyInfo.SetValue(form, true); return form; } @@ -496,6 +518,4 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide } } -public class MultiPageControlCollection : List, IList -{ -} \ No newline at end of file +public class MultiPageControlCollection : List, IList { } diff --git a/SDUI/Controls/NumUpDown.cs b/SDUI/Controls/NumUpDown.cs index 3395fd4..c8fb3a2 100644 --- a/SDUI/Controls/NumUpDown.cs +++ b/SDUI/Controls/NumUpDown.cs @@ -1,9 +1,9 @@ -using SDUI; -using System; +using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Security.Policy; using System.Windows.Forms; +using SDUI; namespace SDUI.Controls { @@ -28,10 +28,7 @@ public class NumUpDown : Control public decimal Value { - get - { - return _value; - } + get { return _value; } set { if (value <= _max & value >= _min) @@ -45,10 +42,7 @@ public decimal Value public decimal Minimum { - get - { - return _min; - } + get { return _min; } set { if (value < _max) @@ -65,10 +59,7 @@ public decimal Minimum public decimal Maximum { - get - { - return _max; - } + get { return _max; } set { if (value > _min) @@ -81,16 +72,23 @@ public decimal Maximum } } - public override Color BackColor { get => base.BackColor; set => base.BackColor = Color.Transparent; } + public override Color BackColor + { + get => base.BackColor; + set => base.BackColor = Color.Transparent; + } public NumUpDown() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.DoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.DoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.UserPaint, + true + ); UpdateStyles(); this.DoubleBuffered = true; @@ -164,9 +162,7 @@ protected override void OnKeyPress(KeyPressEventArgs e) if (_isUsingKeyboard == true && _value < _max) Value = long.Parse(_value.ToString() + e.KeyChar.ToString()); } - catch (Exception) - { - } + catch (Exception) { } } protected override void OnKeyUp(KeyEventArgs e) @@ -236,14 +232,20 @@ protected override void OnPaint(PaintEventArgs e) graphics.FillPath(backColorBrush, round); graphics.DrawPath(borderPen, round); - this.DrawString(graphics, "▲", ColorScheme.ForeColor, _upButtonRect); this.DrawString(graphics, "▼", ColorScheme.ForeColor, _downButtonRect); graphics.DrawLine(borderPen, _upButtonRect.X, 0, _upButtonRect.X, _upButtonRect.Height); graphics.DrawLine(borderPen, _downButtonRect.X, 0, _downButtonRect.X, _downButtonRect.Height); - TextRenderer.DrawText(graphics, Value.ToString(), Font, new Rectangle(Padding.Left, 0, Width - 1, Height - 1), ColorScheme.ForeColor, TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.VerticalCenter | TextFormatFlags.Left); + TextRenderer.DrawText( + graphics, + Value.ToString(), + Font, + new Rectangle(Padding.Left, 0, Width - 1, Height - 1), + ColorScheme.ForeColor, + TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.VerticalCenter | TextFormatFlags.Left + ); } } } diff --git a/SDUI/Controls/Panel.cs b/SDUI/Controls/Panel.cs index fd2928b..12610f5 100644 --- a/SDUI/Controls/Panel.cs +++ b/SDUI/Controls/Panel.cs @@ -1,8 +1,8 @@ -using SDUI.Helpers; using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using SDUI.Helpers; namespace SDUI.Controls; @@ -64,10 +64,13 @@ public float ShadowDepth public Panel() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.UserPaint, + true + ); BackColor = Color.Transparent; } @@ -115,7 +118,13 @@ protected override void OnPaint(PaintEventArgs e) e.Graphics.FillPath(brush, path); //e.Graphics.DrawShadow(rect, _shadowDepth, _radius); - ShadowUtils.DrawShadow(graphics, ColorScheme.ShadowColor, rect.ToRectangle(), (int)(_shadowDepth + 1) + 40, DockStyle.Right); + ShadowUtils.DrawShadow( + graphics, + ColorScheme.ShadowColor, + rect.ToRectangle(), + (int)(_shadowDepth + 1) + 40, + DockStyle.Right + ); using var pen = new Pen(borderColor, _border.All); e.Graphics.DrawPath(pen, path); @@ -127,10 +136,21 @@ protected override void OnPaint(PaintEventArgs e) e.Graphics.DrawShadow(rect, _shadowDepth, _radius == 0 ? 1 : _radius); - ControlPaint.DrawBorder(e.Graphics, ClientRectangle, - borderColor, _border.Left, ButtonBorderStyle.Solid, - borderColor, _border.Top, ButtonBorderStyle.Solid, - borderColor, _border.Right, ButtonBorderStyle.Solid, - borderColor, _border.Bottom, ButtonBorderStyle.Solid); + ControlPaint.DrawBorder( + e.Graphics, + ClientRectangle, + borderColor, + _border.Left, + ButtonBorderStyle.Solid, + borderColor, + _border.Top, + ButtonBorderStyle.Solid, + borderColor, + _border.Right, + ButtonBorderStyle.Solid, + borderColor, + _border.Bottom, + ButtonBorderStyle.Solid + ); } } diff --git a/SDUI/Controls/ProgressBar.cs b/SDUI/Controls/ProgressBar.cs index 3e8adf7..b4908c0 100644 --- a/SDUI/Controls/ProgressBar.cs +++ b/SDUI/Controls/ProgressBar.cs @@ -93,10 +93,7 @@ public bool ShowValue private int _radius = 4; public int Radius { - get - { - return _radius; - } + get { return _radius; } set { _radius = value <= 0 ? 1 : value; @@ -129,12 +126,15 @@ public HatchStyle HatchType public ProgressBar() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.Opaque | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.Opaque + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.UserPaint, + true + ); UpdateStyles(); BackColor = Color.Transparent; @@ -161,8 +161,17 @@ protected override void OnPaint(PaintEventArgs e) var intValue = ((_value / (float)_maximum) * Width); var percent = ((100.0f * Value) / Maximum); - using var linearGradientBrush = new LinearGradientBrush(new RectangleF(0, 0, Width, Height), _gradient[0], _gradient[1], 90); - using var hatchBrush = new HatchBrush(HatchType, Color.FromArgb(50, _gradient[0]), Color.FromArgb(50, _gradient[1])); + using var linearGradientBrush = new LinearGradientBrush( + new RectangleF(0, 0, Width, Height), + _gradient[0], + _gradient[1], + 90 + ); + using var hatchBrush = new HatchBrush( + HatchType, + Color.FromArgb(50, _gradient[0]), + Color.FromArgb(50, _gradient[1]) + ); var rect = ClientRectangle.ToRectangleF(); @@ -177,7 +186,10 @@ protected override void OnPaint(PaintEventArgs e) graphics.FillPath(hatchBrush, path); } - graphics.DrawPath(new Pen(Color.FromArgb(10, Parent.BackColor.Determine())), new Rectangle(0, 0, Width - 1, Height - 1).Radius(_radius)); + graphics.DrawPath( + new Pen(Color.FromArgb(10, Parent.BackColor.Determine())), + new Rectangle(0, 0, Width - 1, Height - 1).Radius(_radius) + ); if (ShowValue) { @@ -203,21 +215,24 @@ protected override void OnPaint(PaintEventArgs e) // draw shadow var shadowBrush = new SolidBrush(textShadowColor); - e.Graphics.DrawString(Text, Font, shadowBrush, new Rectangle(1, 1, Width, Height), new StringFormat - { - Alignment = StringAlignment.Center, - LineAlignment = StringAlignment.Center - }); + e.Graphics.DrawString( + Text, + Font, + shadowBrush, + new Rectangle(1, 1, Width, Height), + new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center } + ); shadowBrush.Dispose(); // draw text var textBrush = new SolidBrush(textColor); - e.Graphics.DrawString(Text, Font, textBrush, new Rectangle(0, 0, Width, Height), new StringFormat - { - Alignment = StringAlignment.Center, - LineAlignment = StringAlignment.Center - }); + e.Graphics.DrawString( + Text, + Font, + textBrush, + new Rectangle(0, 0, Width, Height), + new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center } + ); } } - } diff --git a/SDUI/Controls/RadioButton.cs b/SDUI/Controls/RadioButton.cs index 9ed1ab2..0a6acec 100644 --- a/SDUI/Controls/RadioButton.cs +++ b/SDUI/Controls/RadioButton.cs @@ -1,16 +1,15 @@ -using SDUI.Animation; -using System; +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Windows.Forms; +using SDUI.Animation; namespace SDUI.Controls; public class Radio : RadioButton { - private const int RADIOBUTTON_INNER_CIRCLE_SIZE = RADIOBUTTON_SIZE - (2 * RADIOBUTTON_OUTER_CIRCLE_WIDTH); private const int RADIOBUTTON_OUTER_CIRCLE_WIDTH = 1; @@ -56,23 +55,23 @@ public bool Ripple public Radio() { - SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); + SetStyle( + ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, + true + ); - animationManager = new Animation.AnimationEngine - { - AnimationType = AnimationType.EaseInOut, - Increment = 0.06 - }; + animationManager = new Animation.AnimationEngine { AnimationType = AnimationType.EaseInOut, Increment = 0.06 }; rippleAnimationManager = new Animation.AnimationEngine(false) { AnimationType = AnimationType.Linear, Increment = 0.10, - SecondaryIncrement = 0.08 + SecondaryIncrement = 0.08, }; animationManager.OnAnimationProgress += sender => Invalidate(); rippleAnimationManager.OnAnimationProgress += sender => Invalidate(); - CheckedChanged += (sender, args) => animationManager.StartNewAnimation(Checked ? AnimationDirection.In : AnimationDirection.Out); + CheckedChanged += (sender, args) => + animationManager.StartNewAnimation(Checked ? AnimationDirection.In : AnimationDirection.Out); SizeChanged += OnSizeChanged; @@ -89,7 +88,8 @@ public override Size GetPreferredSize(Size proposedSize) protected override void OnCreateControl() { base.OnCreateControl(); - if (DesignMode) return; + if (DesignMode) + return; _mouseState = 0; MouseEnter += (sender, args) => @@ -137,13 +137,17 @@ protected override void OnPaint(PaintEventArgs pevent) var disabledOffColor = Color.LightGray; - var colorAlpha = Enabled ? (int)(animationProgress * 255.0) :disabledOffColor.A; - var backgroundAlpha = Enabled ? (int)(ColorScheme.BorderColor.A * (1.0 - animationProgress)) :disabledOffColor.A; + var colorAlpha = Enabled ? (int)(animationProgress * 255.0) : disabledOffColor.A; + var backgroundAlpha = Enabled + ? (int)(ColorScheme.BorderColor.A * (1.0 - animationProgress)) + : disabledOffColor.A; var animationSize = (float)(animationProgress * 8f); var animationSizeHalf = animationSize / 2; animationSize = (float)(animationProgress * 9f); - using var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? ColorScheme.AccentColor : disabledOffColor)); + using var brush = new SolidBrush( + Color.FromArgb(colorAlpha, Enabled ? ColorScheme.AccentColor : disabledOffColor) + ); using var pen = new Pen(brush.Color); // draw ripple animation @@ -154,28 +158,42 @@ protected override void OnPaint(PaintEventArgs pevent) var animationValue = rippleAnimationManager.GetProgress(i); var animationSource = new Point(RADIOBUTTON_CENTER, RADIOBUTTON_CENTER); - using var rippleBrush = new SolidBrush(Color.FromArgb((int)((animationValue * 40)), ((bool)rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color)); + using var rippleBrush = new SolidBrush( + Color.FromArgb( + (int)((animationValue * 40)), + ((bool)rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color + ) + ); var rippleHeight = (Height % 2 == 0) ? Height - 3 : Height - 2; - var rippleSize = (rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) : rippleHeight; - - using var path = DrawingExtensions.CreateRoundPath(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize, rippleSize / 2); + var rippleSize = + (rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) + ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) + : rippleHeight; + + using var path = DrawingExtensions.CreateRoundPath( + animationSource.X - rippleSize / 2, + animationSource.Y - rippleSize / 2, + rippleSize, + rippleSize, + rippleSize / 2 + ); graphics.FillPath(rippleBrush, path); } } using var ellipseBrush = new SolidBrush(ColorScheme.BorderColor); - graphics.FillEllipse( - ellipseBrush, - boxOffset, - boxOffset, - RADIOBUTTON_SIZE, - RADIOBUTTON_SIZE); + graphics.FillEllipse(ellipseBrush, boxOffset, boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE); - using (var path = DrawingExtensions.CreateRoundPath(boxOffset, boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE, 7)) + using ( + var path = DrawingExtensions.CreateRoundPath(boxOffset, boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE, 7) + ) { // draw radiobutton circle - var uncheckedColor = ColorScheme.BackColor.BlendWith(Enabled ? ColorScheme.BorderColor : disabledOffColor, backgroundAlpha); + var uncheckedColor = ColorScheme.BackColor.BlendWith( + Enabled ? ColorScheme.BorderColor : disabledOffColor, + backgroundAlpha + ); using var brush2 = new SolidBrush(uncheckedColor); //graphics.FillPath(brush2, path); @@ -185,30 +203,38 @@ protected override void OnPaint(PaintEventArgs pevent) boxOffset, boxOffset, RADIOBUTTON_INNER_CIRCLE_SIZE, - RADIOBUTTON_INNER_CIRCLE_SIZE); + RADIOBUTTON_INNER_CIRCLE_SIZE + ); if (Enabled) - graphics.FillEllipse( - brush, - boxOffset, - boxOffset, - RADIOBUTTON_SIZE, - RADIOBUTTON_SIZE); + graphics.FillEllipse(brush, boxOffset, boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE); // // graphics.FillPath(brush, path); - } if (Checked) { - using (var path = DrawingExtensions.CreateRoundPath(RADIOBUTTON_CENTER - animationSizeHalf, RADIOBUTTON_CENTER - animationSizeHalf, animationSize, animationSize, 7)) + using ( + var path = DrawingExtensions.CreateRoundPath( + RADIOBUTTON_CENTER - animationSizeHalf, + RADIOBUTTON_CENTER - animationSizeHalf, + animationSize, + animationSize, + 7 + ) + ) graphics.FillPath(brush, path); } var textColor = Enabled ? ColorScheme.ForeColor : Color.Gray; - this.DrawString(graphics, TextAlign, textColor, new RectangleF(new Point(boxOffset + RADIOBUTTON_SIZE, 0), ClientRectangle.Size)); + this.DrawString( + graphics, + TextAlign, + textColor, + new RectangleF(new Point(boxOffset + RADIOBUTTON_SIZE, 0), ClientRectangle.Size) + ); } private bool IsMouseInCheckArea() @@ -221,4 +247,4 @@ private void OnSizeChanged(object sender, EventArgs eventArgs) boxOffset = Height / 2 - (int)Math.Ceiling(RADIOBUTTON_SIZE / 2d); radioButtonBounds = new Rectangle(boxOffset, boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/Separator.cs b/SDUI/Controls/Separator.cs index 5c37ca7..c39ae8f 100644 --- a/SDUI/Controls/Separator.cs +++ b/SDUI/Controls/Separator.cs @@ -7,7 +7,10 @@ public class Separator : UserControl { public Separator() { - SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); + SetStyle( + ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, + true + ); UpdateStyles(); diff --git a/SDUI/Controls/ShapeProgressBar.cs b/SDUI/Controls/ShapeProgressBar.cs index e8939b3..65d72cf 100644 --- a/SDUI/Controls/ShapeProgressBar.cs +++ b/SDUI/Controls/ShapeProgressBar.cs @@ -74,10 +74,7 @@ public bool DrawHatch private HatchStyle _hatchType = HatchStyle.Min; public HatchStyle HatchType { - get - { - return _hatchType; - } + get { return _hatchType; } set { _hatchType = value; @@ -99,8 +96,13 @@ public ShapeProgressBar() { Size = new Size(100, 100); Font = new Font("Segoe UI", 15); - SetStyle(ControlStyles.UserPaint | - ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true); + SetStyle( + ControlStyles.UserPaint + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.SupportsTransparentBackColor, + true + ); BackColor = Color.Transparent; } @@ -117,7 +119,14 @@ protected override void OnPaint(PaintEventArgs e) var renderWidth = ClientRectangle.Width - _weight - 1; var renderHeight = ClientRectangle.Height - _weight - 1; - using (var brush = new LinearGradientBrush(ClientRectangle, _gradient[0], _gradient[1], LinearGradientMode.ForwardDiagonal)) + using ( + var brush = new LinearGradientBrush( + ClientRectangle, + _gradient[0], + _gradient[1], + LinearGradientMode.ForwardDiagonal + ) + ) { using (var pen = new Pen(brush, _weight)) { @@ -129,7 +138,13 @@ protected override void OnPaint(PaintEventArgs e) if (_drawHatch) { - using (var hatchBrush = new HatchBrush(HatchType, Color.FromArgb(50, _gradient[0]), Color.FromArgb(50, _gradient[1]))) + using ( + var hatchBrush = new HatchBrush( + HatchType, + Color.FromArgb(50, _gradient[0]), + Color.FromArgb(50, _gradient[1]) + ) + ) { using (var pen = new Pen(hatchBrush, 14f)) { @@ -140,7 +155,14 @@ protected override void OnPaint(PaintEventArgs e) } } - using (var brush = new LinearGradientBrush(ClientRectangle, ColorScheme.BackColor, ColorScheme.BackColor2, LinearGradientMode.Vertical)) + using ( + var brush = new LinearGradientBrush( + ClientRectangle, + ColorScheme.BackColor, + ColorScheme.BackColor2, + LinearGradientMode.Vertical + ) + ) graphics.FillEllipse(brush, _weight / 2, _weight / 2, renderWidth, renderHeight); var percent = (100 / _maximum) * _value; @@ -148,7 +170,12 @@ protected override void OnPaint(PaintEventArgs e) var stringSize = graphics.MeasureString(percentString, Font); using (var textBrush = new SolidBrush(ColorScheme.ForeColor)) - graphics.DrawString(percentString, Font, textBrush, Width / 2 - stringSize.Width / 2, Height / 2 - stringSize.Height / 2); - + graphics.DrawString( + percentString, + Font, + textBrush, + Width / 2 - stringSize.Width / 2, + Height / 2 - stringSize.Height / 2 + ); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/Subclasses/ListViewHeaderSubclassedWindow.cs b/SDUI/Controls/Subclasses/ListViewHeaderSubclassedWindow.cs index d0221b1..64c5c66 100644 --- a/SDUI/Controls/Subclasses/ListViewHeaderSubclassedWindow.cs +++ b/SDUI/Controls/Subclasses/ListViewHeaderSubclassedWindow.cs @@ -59,7 +59,6 @@ public void AssignHandle(IntPtr handle) ++_uses; Handle = handle; - IntPtr hHeader = SendMessage(handle, LVM_GETHEADER, 0, 0); var isDark = ColorScheme.BackColor.IsDark(); @@ -108,7 +107,11 @@ UIntPtr dwRefData break; case (int)CDDS.CDDS_ITEMPREPAINT: - var info = (SubclassInfo)Marshal.PtrToStructure(unchecked((IntPtr)(long)(ulong)dwRefData), typeof(SubclassInfo)); + var info = (SubclassInfo) + Marshal.PtrToStructure( + unchecked((IntPtr)(long)(ulong)dwRefData), + typeof(SubclassInfo) + ); SetTextColor(nmcd.hdc, info.headerTextColor); m.Result = new IntPtr((int)CDRF.CDRF_DODEFAULT); @@ -128,7 +131,6 @@ UIntPtr dwRefData //SetWindowTheme(hHeader, isDark ? "DarkMode_ItemsView" : "ItemsView", null); // DarkMode //SetWindowTheme(Handle, isDark ? "DarkMode_ItemsView" : "ItemsView", null); // DarkMode - //AllowDarkModeForWindow(Handle, ColorScheme.BackColor.IsDark()); //AllowDarkModeForWindow(hHeader, ColorScheme.BackColor.IsDark()); @@ -188,7 +190,10 @@ UIntPtr dwRefData } finally { - if (msg == 0x82/*WM_NCDESTROY*/ && Handle != IntPtr.Zero) + if ( + msg == 0x82 /*WM_NCDESTROY*/ + && Handle != IntPtr.Zero + ) { InternalReleaseHandle(); } @@ -219,18 +224,17 @@ private void CheckReleased() /// public void DefWndProc(ref System.Windows.Forms.Message m) { - Debug.Assert(m.HWnd == Handle, "ListViewHeaderSubclassedWindow is not attached to the window m is addressed to."); - - + Debug.Assert( + m.HWnd == Handle, + "ListViewHeaderSubclassedWindow is not attached to the window m is addressed to." + ); } /// /// Specifies a notification method that is called when the handle for a /// window is changed. /// - protected virtual void OnHandleChange() - { - } + protected virtual void OnHandleChange() { } /// /// On class load, we connect an event to Application to let us know when @@ -251,9 +255,7 @@ private static void OnShutdown(object sender, EventArgs e) /// /// When overridden in a derived class, manages an unhandled thread exception. /// - protected virtual void OnThreadException(Exception e) - { - } + protected virtual void OnThreadException(Exception e) { } private void InternalReleaseHandle() { diff --git a/SDUI/Controls/TabControl.cs b/SDUI/Controls/TabControl.cs index 355b74a..f657123 100644 --- a/SDUI/Controls/TabControl.cs +++ b/SDUI/Controls/TabControl.cs @@ -16,13 +16,17 @@ public Padding Radius Invalidate(); } } + public TabControl() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.UserPaint, + true + ); UpdateStyles(); } @@ -37,7 +41,7 @@ protected override void CreateHandle() { base.CreateHandle(); - if(SizeMode != TabSizeMode.Fixed) + if (SizeMode != TabSizeMode.Fixed) ItemSize = new Size(80, 24); Alignment = TabAlignment.Top; @@ -54,11 +58,20 @@ protected override void OnPaint(PaintEventArgs e) graphics.SetHighQuality(); using var borderBrush = new Pen(Color.FromArgb(70, 0, 0, 0)); - using var backBrush = new SolidBrush(ColorScheme.BackColor.IsDark() ? Color.FromArgb(10, 255, 255, 255) : Color.FromArgb(50, 0, 0, 0)); + using var backBrush = new SolidBrush( + ColorScheme.BackColor.IsDark() ? Color.FromArgb(10, 255, 255, 255) : Color.FromArgb(50, 0, 0, 0) + ); // Draw container rectangle var r = new RectangleF(0, ItemSize.Height, Width - 1, Height - ItemSize.Height - 1); - using (var path = r.Radius(SelectedIndex == 0 ? 2 : _borderRadius.Left, _borderRadius.Top, _borderRadius.Right, _borderRadius.Bottom)) + using ( + var path = r.Radius( + SelectedIndex == 0 ? 2 : _borderRadius.Left, + _borderRadius.Top, + _borderRadius.Right, + _borderRadius.Bottom + ) + ) { //graphics.FillPath(backBrush, path); graphics.DrawPath(borderBrush, path); @@ -91,7 +104,7 @@ protected override CreateParams CreateParams get { var parms = base.CreateParams; - parms.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN + parms.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN return parms; } } diff --git a/SDUI/Controls/TestTrackBar.cs b/SDUI/Controls/TestTrackBar.cs index 1d7cc70..5d02d26 100644 --- a/SDUI/Controls/TestTrackBar.cs +++ b/SDUI/Controls/TestTrackBar.cs @@ -8,7 +8,6 @@ namespace SDUI.Controls { public class TestTrackBar : Control { - #region Enums public enum ValueDivisor @@ -16,7 +15,7 @@ public enum ValueDivisor By1 = 1, By10 = 10, By100 = 100, - By1000 = 1000 + By1000 = 1000, } #endregion @@ -44,13 +43,9 @@ public enum ValueDivisor public int Minimum { - get - { - return _Minimum; - } + get { return _Minimum; } set { - if (value >= _Maximum) { value = _Maximum - 10; @@ -67,13 +62,9 @@ public int Minimum public int Maximum { - get - { - return _Maximum; - } + get { return _Maximum; } set { - if (value <= _Minimum) { value = _Minimum + 10; @@ -93,22 +84,13 @@ public int Maximum public event ValueChangedEventHandler ValueChanged { - add - { - ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Combine(ValueChangedEvent, value); - } - remove - { - ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Remove(ValueChangedEvent, value); - } + add { ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Combine(ValueChangedEvent, value); } + remove { ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Remove(ValueChangedEvent, value); } } public int Value { - get - { - return _Value; - } + get { return _Value; } set { if (_Value != value) @@ -137,10 +119,7 @@ public int Value public ValueDivisor ValueDivison { - get - { - return DividedValue; - } + get { return DividedValue; } set { DividedValue = value; @@ -151,22 +130,13 @@ public ValueDivisor ValueDivison [Browsable(false)] public float ValueToSet { - get - { - return _Value / (int)DividedValue; - } - set - { - Value = (int)(value * (int)DividedValue); - } + get { return _Value / (int)DividedValue; } + set { Value = (int)(value * (int)DividedValue); } } public bool JumpToMouse { - get - { - return _JumpToMouse; - } + get { return _JumpToMouse; } set { _JumpToMouse = value; @@ -176,10 +146,7 @@ public bool JumpToMouse public bool DrawValueString { - get - { - return _DrawValueString; - } + get { return _DrawValueString; } set { _DrawValueString = value; @@ -206,7 +173,9 @@ protected override void OnMouseMove(MouseEventArgs e) bool flag = this.Cap && e.X > -1 && e.X < this.Width + 1; if (flag) { - this.Value = this._Minimum + (int)Math.Round((double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width)); + this.Value = + this._Minimum + + (int)Math.Round((double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width)); } } } @@ -219,14 +188,23 @@ protected override void OnMouseDown(MouseEventArgs e) { if (flag) { - this.ValueDrawer = (int)Math.Round(((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) * (double)(this.Width - 11)); + this.ValueDrawer = (int) + Math.Round( + ((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) + * (double)(this.Width - 11) + ); this.TrackBarHandleRect = new Rectangle(this.ValueDrawer, 0, 25, 25); this.Cap = this.TrackBarHandleRect.Contains(e.Location); this.Focus(); flag = this._JumpToMouse; if (flag) { - this.Value = this._Minimum + (int)Math.Round((double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width)); + this.Value = + this._Minimum + + (int) + Math.Round( + (double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width) + ); } } } @@ -242,7 +220,13 @@ protected override void OnMouseUp(MouseEventArgs e) public TestTrackBar() { - SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.UserPaint + | ControlStyles.ResizeRedraw + | ControlStyles.DoubleBuffer, + true + ); Size = new Size(80, 22); MinimumSize = new Size(47, 22); @@ -275,17 +259,25 @@ protected override void OnPaint(PaintEventArgs e) try { - this.ValueDrawer = (int)Math.Round(((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) * (double)(this.Width - 11)); - } - catch (Exception) - { + this.ValueDrawer = (int) + Math.Round( + ((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) + * (double)(this.Width - 11) + ); } + catch (Exception) { } TrackBarHandleRect = new Rectangle(ValueDrawer, 0, 10, 20); gfx.SetClip(PipeBorder); // Set the clipping region of this Graphics to the specified GraphicsPath gfx.FillPath(new SolidBrush(SDUI.ColorScheme.BackColor), PipeBorder); - FillValue = DrawingExtensions.CreateRoundPath(1, 8, TrackBarHandleRect.X + TrackBarHandleRect.Width - 4, 5, 2); + FillValue = DrawingExtensions.CreateRoundPath( + 1, + 8, + TrackBarHandleRect.X + TrackBarHandleRect.Width - 4, + 5, + 2 + ); gfx.ResetClip(); // Reset the clip region of this Graphics to an infinite region @@ -293,8 +285,34 @@ protected override void OnPaint(PaintEventArgs e) gfx.DrawPath(new Pen(SDUI.ColorScheme.BorderColor), PipeBorder); // Draw pipe border gfx.FillPath(Color.Blue.Brush(), FillValue); - gfx.FillEllipse(new SolidBrush(SDUI.ColorScheme.BackColor), this.TrackThumb.X + (int)Math.Round(unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum))) - (int)Math.Round((double)this.ThumbSize.Width / 2.0), this.TrackThumb.Y + (int)Math.Round((double)this.TrackThumb.Height / 2.0) - (int)Math.Round((double)this.ThumbSize.Height / 2.0), this.ThumbSize.Width, this.ThumbSize.Height); - gfx.DrawEllipse(new Pen(Color.FromArgb(180, 180, 180)), this.TrackThumb.X + (int)Math.Round(unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum))) - (int)Math.Round((double)this.ThumbSize.Width / 2.0), this.TrackThumb.Y + (int)Math.Round((double)this.TrackThumb.Height / 2.0) - (int)Math.Round((double)this.ThumbSize.Height / 2.0), this.ThumbSize.Width, this.ThumbSize.Height); + gfx.FillEllipse( + new SolidBrush(SDUI.ColorScheme.BackColor), + this.TrackThumb.X + + (int) + Math.Round( + unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum)) + ) + - (int)Math.Round((double)this.ThumbSize.Width / 2.0), + this.TrackThumb.Y + + (int)Math.Round((double)this.TrackThumb.Height / 2.0) + - (int)Math.Round((double)this.ThumbSize.Height / 2.0), + this.ThumbSize.Width, + this.ThumbSize.Height + ); + gfx.DrawEllipse( + new Pen(Color.FromArgb(180, 180, 180)), + this.TrackThumb.X + + (int) + Math.Round( + unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum)) + ) + - (int)Math.Round((double)this.ThumbSize.Width / 2.0), + this.TrackThumb.Y + + (int)Math.Round((double)this.TrackThumb.Height / 2.0) + - (int)Math.Round((double)this.ThumbSize.Height / 2.0), + this.ThumbSize.Width, + this.ThumbSize.Height + ); if (_DrawValueString == true) { diff --git a/SDUI/Controls/TextBox.cs b/SDUI/Controls/TextBox.cs index f07194c..9d9e107 100644 --- a/SDUI/Controls/TextBox.cs +++ b/SDUI/Controls/TextBox.cs @@ -50,13 +50,17 @@ public bool PassFocusShow Invalidate(); } } + protected override void OnEnter(System.EventArgs e) { - if (UseSystemPasswordChar && PassFocusShow) _textBox.UseSystemPasswordChar = false; + if (UseSystemPasswordChar && PassFocusShow) + _textBox.UseSystemPasswordChar = false; } + protected override void OnLeave(System.EventArgs e) { - if (UseSystemPasswordChar && PassFocusShow) _textBox.UseSystemPasswordChar = UseSystemPasswordChar; + if (UseSystemPasswordChar && PassFocusShow) + _textBox.UseSystemPasswordChar = UseSystemPasswordChar; } private int _maxchars = 32767; @@ -185,10 +189,15 @@ protected override void OnPaint(PaintEventArgs e) var colorBegin = determinedColor.Brightness(.1f).Alpha(90); var colorEnd = determinedColor.Brightness(-.1f).Alpha(60); - using var innerBorderBrush = new LinearGradientBrush(new Rectangle(1, 1, Width - 2, Height - 2), colorBegin, colorEnd, 90); + using var innerBorderBrush = new LinearGradientBrush( + new Rectangle(1, 1, Width - 2, Height - 2), + colorBegin, + colorEnd, + 90 + ); using var innerBorderPen = new Pen(innerBorderBrush); graphics.DrawPath(innerBorderPen, new Rectangle(1, 1, Width - _radius, Height - _radius).Radius(_radius)); graphics.DrawLine(ColorScheme.BorderColor, new Point(1, 1), new Point(Width - 3, 1)); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/ToggleButton.cs b/SDUI/Controls/ToggleButton.cs index 1e46663..90b38bf 100644 --- a/SDUI/Controls/ToggleButton.cs +++ b/SDUI/Controls/ToggleButton.cs @@ -1,9 +1,9 @@ -using SDUI.Animation; -using System; +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using SDUI.Animation; namespace SDUI.Controls; @@ -22,11 +22,14 @@ public override string Text public ToggleButton() { - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.UserPaint, + true + ); this.DoubleBuffered = true; this.MinimumSize = new Size(46, 22); @@ -35,15 +38,15 @@ public ToggleButton() { AnimationType = AnimationType.EaseInOut, Increment = 0.10, - SecondaryIncrement = 0.07 + SecondaryIncrement = 0.07, }; } - protected override void OnCreateControl() { base.OnCreateControl(); - if (DesignMode) return; + if (DesignMode) + return; _mouseState = 0; MouseEnter += (sender, args) => @@ -107,9 +110,12 @@ protected override void OnPaint(PaintEventArgs e) using var solidBrush = new SolidBrush(ColorScheme.BorderColor.Alpha(50)); var progress = (float)animationManager.GetProgress(); - if (this.Checked) - e.Graphics.FillEllipse(solidBrush, new RectangleF(this.Width - this.Height + 1 * progress, 2, toggleSize, toggleSize)); + if (this.Checked) + e.Graphics.FillEllipse( + solidBrush, + new RectangleF(this.Width - this.Height + 1 * progress, 2, toggleSize, toggleSize) + ); else e.Graphics.FillEllipse(solidBrush, new Rectangle(2, 2, toggleSize, toggleSize)); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/ToolStrip.cs b/SDUI/Controls/ToolStrip.cs index 947ba68..59737f5 100644 --- a/SDUI/Controls/ToolStrip.cs +++ b/SDUI/Controls/ToolStrip.cs @@ -1,6 +1,6 @@ -using SDUI.Renderers; -using System; +using System; using System.Windows.Forms; +using SDUI.Renderers; namespace SDUI.Controls; @@ -9,10 +9,13 @@ public class ToolStrip : System.Windows.Forms.ToolStrip public ToolStrip() { Renderer = new MenuRenderer(); - SetStyle(ControlStyles.SupportsTransparentBackColor | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.UserPaint, true); + SetStyle( + ControlStyles.SupportsTransparentBackColor + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.ResizeRedraw + | ControlStyles.UserPaint, + true + ); } protected override void OnParentBackColorChanged(EventArgs e) @@ -20,4 +23,4 @@ protected override void OnParentBackColorChanged(EventArgs e) base.OnParentBackColorChanged(e); Invalidate(); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/UIWindow.cs b/SDUI/Controls/UIWindow.cs index 8253a99..e0aa350 100644 --- a/SDUI/Controls/UIWindow.cs +++ b/SDUI/Controls/UIWindow.cs @@ -1,12 +1,12 @@ -using SDUI.Animation; -using SDUI.Helpers; -using Svg; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +using SDUI.Animation; +using SDUI.Helpers; +using Svg; namespace SDUI.Controls; @@ -124,6 +124,7 @@ public enum TabDesingMode private float _symbolSizeDPI => _symbolSize * DPI; private float _iconWidth = 42; + [DefaultValue(42)] [Description("Gets or sets the header bar icon width")] public float IconWidth @@ -199,7 +200,6 @@ public bool NewTabButton } } - private float _symbolSize = 24; [DefaultValue(24)] @@ -399,7 +399,8 @@ public Color[] Gradient get => _gradient; set { - _gradient = value; Invalidate(); + _gradient = value; + Invalidate(); } } @@ -448,7 +449,6 @@ public Color BorderColor /// /// Tab desing mode /// - private TabDesingMode _tabDesingMode = TabDesingMode.Rectangle; public TabDesingMode TitleTabDesingMode { @@ -539,6 +539,7 @@ public HatchStyle Hatch private const int TAB_INDICATOR_HEIGHT = 3; private long _stickyBorderTime = 5000000; + [Description("Set or get the maximum time to stay at the edge of the display(ms)")] [DefaultValue(500)] public long StickyBorderTime @@ -565,61 +566,31 @@ public UIWindow() : base() { SetStyle( - ControlStyles.UserPaint | - ControlStyles.DoubleBuffer | - ControlStyles.OptimizedDoubleBuffer | - ControlStyles.AllPaintingInWmPaint | - ControlStyles.SupportsTransparentBackColor, true); + ControlStyles.UserPaint + | ControlStyles.DoubleBuffer + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.AllPaintingInWmPaint + | ControlStyles.SupportsTransparentBackColor, + true + ); UpdateStyles(); enableFullDraggable = false; - pageAreaAnimationManager = new() - { - AnimationType = AnimationType.EaseOut, - Increment = 0.07 - }; + pageAreaAnimationManager = new() { AnimationType = AnimationType.EaseOut, Increment = 0.07 }; - minBoxHoverAnimationManager = new() - { - Increment = 0.15, - AnimationType = AnimationType.Linear - }; - maxBoxHoverAnimationManager = new() - { - Increment = 0.15, - AnimationType = AnimationType.Linear - }; - closeBoxHoverAnimationManager = new() - { - Increment = 0.15, - AnimationType = AnimationType.Linear - }; + minBoxHoverAnimationManager = new() { Increment = 0.15, AnimationType = AnimationType.Linear }; + maxBoxHoverAnimationManager = new() { Increment = 0.15, AnimationType = AnimationType.Linear }; + closeBoxHoverAnimationManager = new() { Increment = 0.15, AnimationType = AnimationType.Linear }; - extendBoxHoverAnimationManager = new() - { - Increment = 0.15, - AnimationType = AnimationType.Linear - }; + extendBoxHoverAnimationManager = new() { Increment = 0.15, AnimationType = AnimationType.Linear }; - tabCloseHoverAnimationManager = new() - { - Increment = 0.15, - AnimationType = AnimationType.Linear - }; + tabCloseHoverAnimationManager = new() { Increment = 0.15, AnimationType = AnimationType.Linear }; - newTabHoverAnimationManager = new() - { - Increment = 0.15, - AnimationType = AnimationType.Linear - }; + newTabHoverAnimationManager = new() { Increment = 0.15, AnimationType = AnimationType.Linear }; - formMenuHoverAnimationManager = new() - { - Increment = 0.15, - AnimationType = AnimationType.Linear - }; + formMenuHoverAnimationManager = new() { Increment = 0.15, AnimationType = AnimationType.Linear }; minBoxHoverAnimationManager.OnAnimationProgress += sender => Invalidate(); maxBoxHoverAnimationManager.OnAnimationProgress += sender => Invalidate(); @@ -633,7 +604,13 @@ public UIWindow() //WindowsHelper.ApplyRoundCorner(this.Handle); } - private bool _inCloseBox, _inMaxBox, _inMinBox, _inExtendBox, _inTabCloseBox, _inNewTabBox, _inFormMenuBox; + private bool _inCloseBox, + _inMaxBox, + _inMinBox, + _inExtendBox, + _inTabCloseBox, + _inNewTabBox, + _inFormMenuBox; protected override void OnBackColorChanged(EventArgs e) { @@ -661,7 +638,12 @@ private void CalcSystemBoxPos() if (MaximizeBox) { - _maximizeBoxRect = new(_controlBoxRect.Left - _iconWidthDPI, _controlBoxRect.Top, _iconWidthDPI, _titleHeightDPI); + _maximizeBoxRect = new( + _controlBoxRect.Left - _iconWidthDPI, + _controlBoxRect.Top, + _iconWidthDPI, + _titleHeightDPI + ); _controlBoxLeft = _maximizeBoxRect.Left - 2; } else @@ -671,7 +653,12 @@ private void CalcSystemBoxPos() if (MinimizeBox) { - _minimizeBoxRect = new(MaximizeBox ? _maximizeBoxRect.Left - _iconWidthDPI - 2 : _controlBoxRect.Left - _iconWidthDPI - 2, _controlBoxRect.Top, _iconWidthDPI, _titleHeightDPI); + _minimizeBoxRect = new( + MaximizeBox ? _maximizeBoxRect.Left - _iconWidthDPI - 2 : _controlBoxRect.Left - _iconWidthDPI - 2, + _controlBoxRect.Top, + _iconWidthDPI, + _titleHeightDPI + ); _controlBoxLeft = _minimizeBoxRect.Left - 2; } else @@ -683,17 +670,31 @@ private void CalcSystemBoxPos() { if (MinimizeBox) { - _extendBoxRect = new(_minimizeBoxRect.Left - _iconWidthDPI - 2, _controlBoxRect.Top, _iconWidthDPI, _titleHeightDPI); + _extendBoxRect = new( + _minimizeBoxRect.Left - _iconWidthDPI - 2, + _controlBoxRect.Top, + _iconWidthDPI, + _titleHeightDPI + ); } else { - _extendBoxRect = new(_controlBoxRect.Left - _iconWidthDPI - 2, _controlBoxRect.Top, _iconWidthDPI, _titleHeightDPI); + _extendBoxRect = new( + _controlBoxRect.Left - _iconWidthDPI - 2, + _controlBoxRect.Top, + _iconWidthDPI, + _titleHeightDPI + ); } } } else { - _extendBoxRect = _maximizeBoxRect = _minimizeBoxRect = _controlBoxRect = new Rectangle(Width + 1, Height + 1, 1, 1); + _extendBoxRect = + _maximizeBoxRect = + _minimizeBoxRect = + _controlBoxRect = + new Rectangle(Width + 1, Height + 1, 1, 1); } var titleIconSize = 24 * DPI; @@ -1021,17 +1022,21 @@ private void ShowMaximize(bool IsOnMoving = false) if (_sizeOfBeforeMaximized.Width == 0 || _sizeOfBeforeMaximized.Height == 0) { int w = 800; - if (MinimumSize.Width > 0) w = MinimumSize.Width; + if (MinimumSize.Width > 0) + w = MinimumSize.Width; int h = 600; - if (MinimumSize.Height > 0) h = MinimumSize.Height; + if (MinimumSize.Height > 0) + h = MinimumSize.Height; _sizeOfBeforeMaximized = new Size(w, h); } Size = _sizeOfBeforeMaximized; if (_locationOfBeforeMaximized.X == 0 && _locationOfBeforeMaximized.Y == 0) { - _locationOfBeforeMaximized = new Point(screen.Bounds.Left + screen.Bounds.Width / 2 - _sizeOfBeforeMaximized.Width / 2, - screen.Bounds.Top + screen.Bounds.Height / 2 - _sizeOfBeforeMaximized.Height / 2); + _locationOfBeforeMaximized = new Point( + screen.Bounds.Left + screen.Bounds.Width / 2 - _sizeOfBeforeMaximized.Width / 2, + screen.Bounds.Top + screen.Bounds.Height / 2 - _sizeOfBeforeMaximized.Height / 2 + ); } Location = _locationOfBeforeMaximized; @@ -1089,7 +1094,12 @@ protected override void OnPaint(PaintEventArgs e) } else if (_gradient.Length == 2 && !(_gradient[0] == Color.Transparent && _gradient[1] == Color.Transparent)) { - using var brush = new LinearGradientBrush(new RectangleF(0, 0, Width, _titleHeightDPI), _gradient[0], _gradient[1], 45); + using var brush = new LinearGradientBrush( + new RectangleF(0, 0, Width, _titleHeightDPI), + _gradient[0], + _gradient[1], + 45 + ); graphics.FillRectangle(brush, 0, 0, Width, _titleHeightDPI); foreColor = _gradient[0].Determine(); @@ -1101,58 +1111,85 @@ protected override void OnPaint(PaintEventArgs e) var closeHoverColor = Color.FromArgb(222, 179, 30, 30); if (_inCloseBox) - graphics.FillRectangle(Color.FromArgb((int)(closeBoxHoverAnimationManager.GetProgress() * closeHoverColor.A), closeHoverColor.RemoveAlpha()), _controlBoxRect); + graphics.FillRectangle( + Color.FromArgb( + (int)(closeBoxHoverAnimationManager.GetProgress() * closeHoverColor.A), + closeHoverColor.RemoveAlpha() + ), + _controlBoxRect + ); using var closePen = new Pen(_inCloseBox ? Color.White : foreColor); - graphics.DrawLine(closePen, + graphics.DrawLine( + closePen, _controlBoxRect.Left + _controlBoxRect.Width / 2 - (6 * DPI), _controlBoxRect.Top + _controlBoxRect.Height / 2 - (6 * DPI), _controlBoxRect.Left + _controlBoxRect.Width / 2 + (6 * DPI), - _controlBoxRect.Top + _controlBoxRect.Height / 2 + (6 * DPI)); + _controlBoxRect.Top + _controlBoxRect.Height / 2 + (6 * DPI) + ); - graphics.DrawLine(closePen, + graphics.DrawLine( + closePen, _controlBoxRect.Left + _controlBoxRect.Width / 2 - (6 * DPI), _controlBoxRect.Top + _controlBoxRect.Height / 2 + (6 * DPI), _controlBoxRect.Left + _controlBoxRect.Width / 2 + (6 * DPI), - _controlBoxRect.Top + _controlBoxRect.Height / 2 - (6 * DPI)); + _controlBoxRect.Top + _controlBoxRect.Height / 2 - (6 * DPI) + ); } // Maximize Box if (MaximizeBox) { if (_inMaxBox) - graphics.FillRectangle(Color.FromArgb((int)(maxBoxHoverAnimationManager.GetProgress() * hoverColor.A), hoverColor.RemoveAlpha()), _maximizeBoxRect); - - graphics.DrawRectangle(foreColor, + graphics.FillRectangle( + Color.FromArgb( + (int)(maxBoxHoverAnimationManager.GetProgress() * hoverColor.A), + hoverColor.RemoveAlpha() + ), + _maximizeBoxRect + ); + + graphics.DrawRectangle( + foreColor, _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 - (12 * DPI / 2), _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (11 * DPI / 2), - 12 * DPI, 11 * DPI); + 12 * DPI, + 11 * DPI + ); if (WindowState == FormWindowState.Maximized) { - graphics.DrawLine(foreColor, + graphics.DrawLine( + foreColor, _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 - (3 * DPI), _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (5 * DPI), _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 - (3 * DPI), - _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (7 * DPI)); + _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (7 * DPI) + ); - graphics.DrawLine(foreColor, + graphics.DrawLine( + foreColor, _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 - (3 * DPI), _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (7 * DPI), _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 + (9 * DPI), - _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (7 * DPI)); + _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (7 * DPI) + ); - graphics.DrawLine(foreColor, + graphics.DrawLine( + foreColor, _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 + (9 * DPI), _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 - (6 * DPI), _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 + (9 * DPI), - _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 + (4 * DPI)); + _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 + (4 * DPI) + ); - graphics.DrawLine(foreColor, + graphics.DrawLine( + foreColor, _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 + (8 * DPI), _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 + (5 * DPI), _maximizeBoxRect.Left + _maximizeBoxRect.Width / 2 + (5 * DPI), - _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 + (5 * DPI)); + _maximizeBoxRect.Top + _maximizeBoxRect.Height / 2 + (5 * DPI) + ); } } @@ -1160,13 +1197,21 @@ protected override void OnPaint(PaintEventArgs e) if (MinimizeBox) { if (_inMinBox) - graphics.FillRectangle(Color.FromArgb((int)(minBoxHoverAnimationManager.GetProgress() * hoverColor.A), hoverColor.RemoveAlpha()), _minimizeBoxRect); - - graphics.DrawLine(foreColor, + graphics.FillRectangle( + Color.FromArgb( + (int)(minBoxHoverAnimationManager.GetProgress() * hoverColor.A), + hoverColor.RemoveAlpha() + ), + _minimizeBoxRect + ); + + graphics.DrawLine( + foreColor, _minimizeBoxRect.Left + _minimizeBoxRect.Width / 2 - (7 * DPI), _minimizeBoxRect.Top + _minimizeBoxRect.Height / 2, _minimizeBoxRect.Left + _minimizeBoxRect.Width / 2 + (6 * DPI), - _minimizeBoxRect.Top + _minimizeBoxRect.Height / 2); + _minimizeBoxRect.Top + _minimizeBoxRect.Height / 2 + ); } // Extend Box @@ -1176,51 +1221,90 @@ protected override void OnPaint(PaintEventArgs e) if (_inExtendBox) { var hoverSize = 24 * DPI; - var brush = new SolidBrush(Color.FromArgb((int)(extendBoxHoverAnimationManager.GetProgress() * hoverColor.A), hoverColor.RemoveAlpha())); - graphics.FillPath(brush, new RectangleF(_extendBoxRect.X + 20 * DPI, (_titleHeightDPI / 2) - (hoverSize / 2), hoverSize, hoverSize).Radius(15)); + var brush = new SolidBrush( + Color.FromArgb( + (int)(extendBoxHoverAnimationManager.GetProgress() * hoverColor.A), + hoverColor.RemoveAlpha() + ) + ); + graphics.FillPath( + brush, + new RectangleF( + _extendBoxRect.X + 20 * DPI, + (_titleHeightDPI / 2) - (hoverSize / 2), + hoverSize, + hoverSize + ).Radius(15) + ); } var size = 16 * DPI; - graphics.DrawSvg(SvgIcons.Settings, color, new(_extendBoxRect.X + 24 * DPI, (_titleHeightDPI / 2) - (size / 2), size, size)); + graphics.DrawSvg( + SvgIcons.Settings, + color, + new(_extendBoxRect.X + 24 * DPI, (_titleHeightDPI / 2) - (size / 2), size, size) + ); } // Form Menu/Icon var faviconSize = 16 * DPI; if (showMenuInsteadOfIcon) { - using var brush = new SolidBrush(Color.FromArgb((int)(formMenuHoverAnimationManager.GetProgress() * hoverColor.A), hoverColor.RemoveAlpha())); + using var brush = new SolidBrush( + Color.FromArgb( + (int)(formMenuHoverAnimationManager.GetProgress() * hoverColor.A), + hoverColor.RemoveAlpha() + ) + ); graphics.FillPath(brush, _formMenuRect.Radius(10)); - graphics.DrawLine(foreColor, + graphics.DrawLine( + foreColor, _formMenuRect.Left + _formMenuRect.Width / 2 - (5 * DPI) - 1, _formMenuRect.Top + _formMenuRect.Height / 2 - (2 * DPI), _formMenuRect.Left + _formMenuRect.Width / 2 - (1 * DPI), - _formMenuRect.Top + _formMenuRect.Height / 2 + (3 * DPI)); + _formMenuRect.Top + _formMenuRect.Height / 2 + (3 * DPI) + ); - graphics.DrawLine(foreColor, + graphics.DrawLine( + foreColor, _formMenuRect.Left + _formMenuRect.Width / 2 + (5 * DPI) - 1, _formMenuRect.Top + _formMenuRect.Height / 2 - (2 * DPI), _formMenuRect.Left + _formMenuRect.Width / 2 - (1 * DPI), - _formMenuRect.Top + _formMenuRect.Height / 2 + (3 * DPI)); + _formMenuRect.Top + _formMenuRect.Height / 2 + (3 * DPI) + ); } else { if (ShowIcon && Icon != null) - graphics.DrawImage(Icon.ToBitmap(), 10, (_titleHeightDPI / 2) - (faviconSize / 2), faviconSize, faviconSize); + graphics.DrawImage( + Icon.ToBitmap(), + 10, + (_titleHeightDPI / 2) - (faviconSize / 2), + faviconSize, + faviconSize + ); } // Window Title or Tabs if (_windowPageControl == null || _windowPageControl.Count == 0) { var stringSize = graphics.MeasureString(Text, Font); - var textPoint = new PointF((showMenuInsteadOfIcon ? _formMenuRect.X + _formMenuRect.Width : faviconSize + 14), (_titleHeightDPI / 2 - stringSize.Height / 2)); + var textPoint = new PointF( + (showMenuInsteadOfIcon ? _formMenuRect.X + _formMenuRect.Width : faviconSize + 14), + (_titleHeightDPI / 2 - stringSize.Height / 2) + ); using var textBrush = new SolidBrush(foreColor); graphics.DrawString(Text, Font, textBrush, textPoint, StringFormat.GenericDefault); } else { - if (!pageAreaAnimationManager.IsAnimating() || pageRect == null || pageRect.Count != _windowPageControl.Count) + if ( + !pageAreaAnimationManager.IsAnimating() + || pageRect == null + || pageRect.Count != _windowPageControl.Count + ) UpdateTabRects(); var animationProgress = pageAreaAnimationManager.GetProgress(); @@ -1232,7 +1316,15 @@ protected override void OnPaint(PaintEventArgs e) var rippleSize = (int)(animationProgress * pageRect[_windowPageControl.SelectedIndex].Width * 1.75); graphics.SetClip(pageRect[_windowPageControl.SelectedIndex]); - graphics.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize)); + graphics.FillEllipse( + rippleBrush, + new Rectangle( + animationSource.X - rippleSize / 2, + animationSource.Y - rippleSize / 2, + rippleSize, + rippleSize + ) + ); graphics.ResetClip(); } @@ -1244,19 +1336,28 @@ protected override void OnPaint(PaintEventArgs e) if (previousSelectedPageIndex == pageRect.Count) previousSelectedPageIndex = -1; - var previousSelectedPageIndexIfHasOne = previousSelectedPageIndex == -1 ? _windowPageControl.SelectedIndex : previousSelectedPageIndex; + var previousSelectedPageIndexIfHasOne = + previousSelectedPageIndex == -1 ? _windowPageControl.SelectedIndex : previousSelectedPageIndex; var previousActivePageRect = pageRect[previousSelectedPageIndexIfHasOne]; var activePageRect = pageRect[_windowPageControl.SelectedIndex]; var y = activePageRect.Bottom - 2; var x = previousActivePageRect.X + (int)((activePageRect.X - previousActivePageRect.X) * animationProgress); - var width = previousActivePageRect.Width + (int)((activePageRect.Width - previousActivePageRect.Width) * animationProgress); + var width = + previousActivePageRect.Width + + (int)((activePageRect.Width - previousActivePageRect.Width) * animationProgress); if (_tabDesingMode == TabDesingMode.Rectangle) { graphics.DrawRectangle(hoverColor, activePageRect.X, 0, width, _titleHeightDPI); graphics.FillRectangle(hoverColor, x, 0, width, _titleHeightDPI); - graphics.FillRectangle(Color.DodgerBlue, x, _titleHeightDPI - TAB_INDICATOR_HEIGHT, width, TAB_INDICATOR_HEIGHT); + graphics.FillRectangle( + Color.DodgerBlue, + x, + _titleHeightDPI - TAB_INDICATOR_HEIGHT, + width, + TAB_INDICATOR_HEIGHT + ); } else if (_tabDesingMode == TabDesingMode.Rounded) { @@ -1297,13 +1398,23 @@ protected override void OnPaint(PaintEventArgs e) rect.X += inlinePaddingX; rect.Width -= inlinePaddingX + closeIconSize; - graphics.DrawString("", Font, foreColor.Brush(), new RectangleF(iconX, _titleHeightDPI / 2 - startingIconMeasure.Height / 2, startingIconMeasure.Width, startingIconMeasure.Height)); + graphics.DrawString( + "", + Font, + foreColor.Brush(), + new RectangleF( + iconX, + _titleHeightDPI / 2 - startingIconMeasure.Height / 2, + startingIconMeasure.Width, + startingIconMeasure.Height + ) + ); using var format = new StringFormat() { LineAlignment = StringAlignment.Center, Trimming = StringTrimming.EllipsisCharacter, - FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap + FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap, }; graphics.DrawString(page.Text, Font, foreColor.Brush(), rect, format); @@ -1318,25 +1429,47 @@ protected override void OnPaint(PaintEventArgs e) if (_tabCloseButton) { var size = 20 * DPI; - using var brush = new SolidBrush(Color.FromArgb((int)(tabCloseHoverAnimationManager.GetProgress() * hoverColor.A), hoverColor.RemoveAlpha())); - - _closeTabBoxRect = new(x + width - TAB_HEADER_PADDING / 2 - size, _titleHeightDPI / 2 - size / 2, size, size); - graphics.FillPie(brush, _closeTabBoxRect.X, _closeTabBoxRect.Y, _closeTabBoxRect.Width, _closeTabBoxRect.Height, 0, 360); + using var brush = new SolidBrush( + Color.FromArgb( + (int)(tabCloseHoverAnimationManager.GetProgress() * hoverColor.A), + hoverColor.RemoveAlpha() + ) + ); + + _closeTabBoxRect = new( + x + width - TAB_HEADER_PADDING / 2 - size, + _titleHeightDPI / 2 - size / 2, + size, + size + ); + graphics.FillPie( + brush, + _closeTabBoxRect.X, + _closeTabBoxRect.Y, + _closeTabBoxRect.Width, + _closeTabBoxRect.Height, + 0, + 360 + ); using var linePen = new Pen(foreColor) { Width = 1.6f }; size = 4f * DPI; - graphics.DrawLine(linePen, + graphics.DrawLine( + linePen, _closeTabBoxRect.Left + _closeTabBoxRect.Width / 2 - size, _closeTabBoxRect.Top + _closeTabBoxRect.Height / 2 - size, _closeTabBoxRect.Left + _closeTabBoxRect.Width / 2 + size, - _closeTabBoxRect.Top + _closeTabBoxRect.Height / 2 + size); + _closeTabBoxRect.Top + _closeTabBoxRect.Height / 2 + size + ); - graphics.DrawLine(linePen, + graphics.DrawLine( + linePen, _closeTabBoxRect.Left + _closeTabBoxRect.Width / 2 - size, _closeTabBoxRect.Top + _closeTabBoxRect.Height / 2 + size, _closeTabBoxRect.Left + _closeTabBoxRect.Width / 2 + size, - _closeTabBoxRect.Top + _closeTabBoxRect.Height / 2 - size); + _closeTabBoxRect.Top + _closeTabBoxRect.Height / 2 - size + ); } // New Tab Button @@ -1344,7 +1477,10 @@ protected override void OnPaint(PaintEventArgs e) { var size = 24 * DPI; var newHoverColor = hoverColor.Alpha(30); - var color = Color.FromArgb((int)(newTabHoverAnimationManager.GetProgress() * newHoverColor.A), newHoverColor.RemoveAlpha()); + var color = Color.FromArgb( + (int)(newTabHoverAnimationManager.GetProgress() * newHoverColor.A), + newHoverColor.RemoveAlpha() + ); using var brush = new SolidBrush(color); color = foreColor.Alpha(220); @@ -1353,21 +1489,30 @@ protected override void OnPaint(PaintEventArgs e) graphics.FillPath(brush, _newTabBoxRect.Radius(4)); var lastTabRect = pageRect[pageRect.Count - 1]; - _newTabBoxRect = new(lastTabRect.X + lastTabRect.Width + size / 2, _titleHeightDPI / 2 - size / 2, size, size); + _newTabBoxRect = new( + lastTabRect.X + lastTabRect.Width + size / 2, + _titleHeightDPI / 2 - size / 2, + size, + size + ); size = 6 * DPI; - graphics.DrawLine(linePen, + graphics.DrawLine( + linePen, _newTabBoxRect.Left + _newTabBoxRect.Width / 2 - size, _newTabBoxRect.Top + _newTabBoxRect.Height / 2, _newTabBoxRect.Left + _newTabBoxRect.Width / 2 + size, - _newTabBoxRect.Top + _newTabBoxRect.Height / 2); + _newTabBoxRect.Top + _newTabBoxRect.Height / 2 + ); - graphics.DrawLine(linePen, + graphics.DrawLine( + linePen, _newTabBoxRect.Left + _newTabBoxRect.Width / 2, _newTabBoxRect.Top + _newTabBoxRect.Height / 2 - size, _newTabBoxRect.Left + _newTabBoxRect.Width / 2, - _newTabBoxRect.Top + _newTabBoxRect.Height / 2 + size); + _newTabBoxRect.Top + _newTabBoxRect.Height / 2 + size + ); } } @@ -1394,7 +1539,7 @@ private void UpdateCachedMetrics() TitleHeightDPI = _titleHeight * DPI, IconWidthDPI = _iconWidth * DPI, SymbolSizeDPI = _symbolSize * DPI, - IsMetricsValid = true + IsMetricsValid = true, }; } @@ -1426,7 +1571,8 @@ private void DrawWindowTitle(Graphics g, Color foreColor) var stringSize = g.MeasureString(Text, Font); var textPoint = new PointF( (showMenuInsteadOfIcon ? _formMenuRect.X + _formMenuRect.Width : 16 * DPI + 14), - (_cachedMetrics.TitleHeightDPI / 2 - stringSize.Height / 2)); + (_cachedMetrics.TitleHeightDPI / 2 - stringSize.Height / 2) + ); using var textBrush = new SolidBrush(foreColor); g.DrawString(Text, Font, textBrush, textPoint); @@ -1551,4 +1697,4 @@ private void UpdateTabRects() for (int i = 1; i < _windowPageControl.Count; i++) pageRect.Add(new(pageRect[i - 1].Right, 0, tabAreaWidth, _titleHeightDPI)); } -} \ No newline at end of file +} diff --git a/SDUI/Controls/UIWindowBase.cs b/SDUI/Controls/UIWindowBase.cs index 1f10e53..dfe5aa5 100644 --- a/SDUI/Controls/UIWindowBase.cs +++ b/SDUI/Controls/UIWindowBase.cs @@ -1,8 +1,8 @@ -using SDUI.Helpers; -using System; +using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; +using SDUI.Helpers; using static SDUI.NativeMethods; namespace SDUI.Controls; @@ -14,7 +14,6 @@ public class UIWindowBase : Form private bool right = false; private Point location; - public int DwmMargin { get => dwmMargin; @@ -141,6 +140,7 @@ protected override void OnLoad(EventArgs e) private const int htBottom = 15; private const int htBottomLeft = 16; private const int htBottomRight = 17; + protected override void WndProc(ref Message m) { if (DesignMode) @@ -152,69 +152,73 @@ protected override void WndProc(ref Message m) switch (m.Msg) { case WM_NCHITTEST: + { + if (WindowState != FormWindowState.Maximized) { - if (WindowState != FormWindowState.Maximized) + int gripDist = 10; + + var pt = PointToClient(Cursor.Position); + + Size clientSize = ClientSize; + ///allow resize on the lower right corner + if ( + pt.X >= clientSize.Width - gripDist + && pt.Y >= clientSize.Height - gripDist + && clientSize.Height >= gripDist + ) + { + m.Result = (IntPtr)(IsMirrored ? htBottomLeft : htBottomRight); + return; + } + ///allow resize on the lower left corner + if (pt.X <= gripDist && pt.Y >= clientSize.Height - gripDist && clientSize.Height >= gripDist) + { + m.Result = (IntPtr)(IsMirrored ? htBottomRight : htBottomLeft); + return; + } + ///allow resize on the upper right corner + if (pt.X <= gripDist && pt.Y <= gripDist && clientSize.Height >= gripDist) + { + m.Result = (IntPtr)(IsMirrored ? htTopRight : htTopLeft); + return; + } + ///allow resize on the upper left corner + if (pt.X >= clientSize.Width - gripDist && pt.Y <= gripDist && clientSize.Height >= gripDist) + { + m.Result = (IntPtr)(IsMirrored ? htTopLeft : htTopRight); + return; + } + ///allow resize on the top border + if (pt.Y <= 2 && clientSize.Height >= 2) { - int gripDist = 10; - - var pt = PointToClient(Cursor.Position); - - Size clientSize = ClientSize; - ///allow resize on the lower right corner - if (pt.X >= clientSize.Width - gripDist && pt.Y >= clientSize.Height - gripDist && clientSize.Height >= gripDist) - { - m.Result = (IntPtr)(IsMirrored ? htBottomLeft : htBottomRight); - return; - } - ///allow resize on the lower left corner - if (pt.X <= gripDist && pt.Y >= clientSize.Height - gripDist && clientSize.Height >= gripDist) - { - m.Result = (IntPtr)(IsMirrored ? htBottomRight : htBottomLeft); - return; - } - ///allow resize on the upper right corner - if (pt.X <= gripDist && pt.Y <= gripDist && clientSize.Height >= gripDist) - { - m.Result = (IntPtr)(IsMirrored ? htTopRight : htTopLeft); - return; - } - ///allow resize on the upper left corner - if (pt.X >= clientSize.Width - gripDist && pt.Y <= gripDist && clientSize.Height >= gripDist) - { - m.Result = (IntPtr)(IsMirrored ? htTopLeft : htTopRight); - return; - } - ///allow resize on the top border - if (pt.Y <= 2 && clientSize.Height >= 2) - { - m.Result = (IntPtr)htTop; - return; - } - ///allow resize on the bottom border - if (pt.Y >= clientSize.Height - gripDist && clientSize.Height >= gripDist) - { - m.Result = (IntPtr)htBottom; - return; - } - ///allow resize on the left border - if (pt.X <= gripDist && clientSize.Height >= gripDist) - { - m.Result = (IntPtr)htLeft; - return; - } - ///allow resize on the right border - if (pt.X >= clientSize.Width - gripDist && clientSize.Height >= gripDist) - { - m.Result = (IntPtr)htRight; - return; - } + m.Result = (IntPtr)htTop; + return; } + ///allow resize on the bottom border + if (pt.Y >= clientSize.Height - gripDist && clientSize.Height >= gripDist) + { + m.Result = (IntPtr)htBottom; + return; + } + ///allow resize on the left border + if (pt.X <= gripDist && clientSize.Height >= gripDist) + { + m.Result = (IntPtr)htLeft; + return; + } + ///allow resize on the right border + if (pt.X >= clientSize.Width - gripDist && clientSize.Height >= gripDist) + { + m.Result = (IntPtr)htRight; + return; + } + } - if ((int)m.Result == HTCLIENT) // drag the form - m.Result = (IntPtr)HTCAPTION; + if ((int)m.Result == HTCLIENT) // drag the form + m.Result = (IntPtr)HTCAPTION; - break; - } + break; + } case WM_NCCALCSIZE: var handle = Handle; @@ -254,7 +258,8 @@ protected override void WndProc(ref Message m) } var inset = new Rect(); SendMessage(handle, TCM_ADJUSTRECT, 0, ref inset); - int marginX = -inset.Right, marginY = -inset.Bottom; + int marginX = -inset.Right, + marginY = -inset.Bottom; if (newWidth != oldWidth) { int left = oldWidth; @@ -272,7 +277,6 @@ protected override void WndProc(ref Message m) oldWidth -= marginX; SetRect(rect, 0, bottom - marginY, oldWidth, newHeight); InvalidateRect(handle, rect, true); - } return; } @@ -302,9 +306,7 @@ public void ChangeControlsTheme(Control control) control.BackColor = ColorScheme.BackColor; control.ForeColor = ColorScheme.ForeColor; } - catch (Exception) - { - } + catch (Exception) { } } WindowsHelper.UseImmersiveDarkMode(control.Handle, isDark); @@ -335,13 +337,26 @@ protected override void OnHandleCreated(EventArgs e) Bottom = dwmMargin, Left = dwmMargin, Right = dwmMargin, - Top = dwmMargin + Top = dwmMargin, }; DwmExtendFrameIntoClientArea(this.Handle, ref margins); } - SetWindowPos(Handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOACTIVATE); + SetWindowPos( + Handle, + IntPtr.Zero, + 0, + 0, + 0, + 0, + SetWindowPosFlags.SWP_FRAMECHANGED + | SetWindowPosFlags.SWP_NOSIZE + | SetWindowPosFlags.SWP_NOMOVE + | SetWindowPosFlags.SWP_NOZORDER + | SetWindowPosFlags.SWP_NOOWNERZORDER + | SetWindowPosFlags.SWP_NOACTIVATE + ); } protected override void OnBackColorChanged(EventArgs e) @@ -364,8 +379,8 @@ protected override void OnBackColorChanged(EventArgs e) Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, ref flag, - Marshal.SizeOf()); + Marshal.SizeOf() + ); } - } -} \ No newline at end of file +} diff --git a/SDUI/Controls/WindowPageControl.cs b/SDUI/Controls/WindowPageControl.cs index d9efe80..4e87aa4 100644 --- a/SDUI/Controls/WindowPageControl.cs +++ b/SDUI/Controls/WindowPageControl.cs @@ -16,10 +16,10 @@ public event EventHandler SelectedIndexChanged } private int _selectedIndex = -1; - public int SelectedIndex - { - get => _selectedIndex; - set + public int SelectedIndex + { + get => _selectedIndex; + set { var sys = Stopwatch.StartNew(); @@ -45,17 +45,15 @@ public int SelectedIndex Controls[i].Visible = i == _selectedIndex; Debug.WriteLine($"Index: {_selectedIndex} Finished: {sys.ElapsedMilliseconds} ms"); - } + } } public int Count => Controls.Count; - public WindowPageControl() + public WindowPageControl() { DoubleBuffered = true; - SetStyle( - ControlStyles.OptimizedDoubleBuffer, true - ); + SetStyle(ControlStyles.OptimizedDoubleBuffer, true); //BackColor = Color.Transparent; UpdateStyles(); diff --git a/SDUI/Extensions/ColorBrushExtensions.cs b/SDUI/Extensions/ColorBrushExtensions.cs index a04c3f9..18cf824 100644 --- a/SDUI/Extensions/ColorBrushExtensions.cs +++ b/SDUI/Extensions/ColorBrushExtensions.cs @@ -22,7 +22,7 @@ public static Color Determine(this Color color) /// Creates color with corrected brightness. /// /// Color to correct. - /// The brightness correction factor. Must be between -1 and 1. + /// The brightness correction factor. Must be between -1 and 1. /// Negative values produce darker colors. /// /// Corrected structure. @@ -106,18 +106,50 @@ public static SolidBrush Brush(this string htmlColor, int alpha = 255) return new SolidBrush(Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor))); } - public static Pen Pen(this string htmlColor, int alpha = 255, float size = 1, LineCap startCap = LineCap.Custom, LineCap endCap = LineCap.Custom) + public static Pen Pen( + this string htmlColor, + int alpha = 255, + float size = 1, + LineCap startCap = LineCap.Custom, + LineCap endCap = LineCap.Custom + ) { - return new Pen(Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor)), size) { StartCap = startCap, EndCap = endCap }; + return new Pen(Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor)), size) + { + StartCap = startCap, + EndCap = endCap, + }; } - public static Brush GlowBrush(Color centerColor, Color[] surroundColor, PointF point, GraphicsPath gp, WrapMode wrapMode = WrapMode.Clamp) + public static Brush GlowBrush( + Color centerColor, + Color[] surroundColor, + PointF point, + GraphicsPath gp, + WrapMode wrapMode = WrapMode.Clamp + ) { - return new PathGradientBrush(gp) { CenterColor = centerColor, SurroundColors = surroundColor, FocusScales = point, WrapMode = wrapMode }; + return new PathGradientBrush(gp) + { + CenterColor = centerColor, + SurroundColors = surroundColor, + FocusScales = point, + WrapMode = wrapMode, + }; } - public static Brush GlowBrush(Color centerColor, Color[] surroundColor, PointF[] point, WrapMode wrapMode = WrapMode.Clamp) + public static Brush GlowBrush( + Color centerColor, + Color[] surroundColor, + PointF[] point, + WrapMode wrapMode = WrapMode.Clamp + ) { - return new PathGradientBrush(point) { CenterColor = centerColor, SurroundColors = surroundColor, WrapMode = wrapMode }; + return new PathGradientBrush(point) + { + CenterColor = centerColor, + SurroundColors = surroundColor, + WrapMode = wrapMode, + }; } -} \ No newline at end of file +} diff --git a/SDUI/Extensions/DrawingExtensions.cs b/SDUI/Extensions/DrawingExtensions.cs index 4933f0d..9905dd2 100644 --- a/SDUI/Extensions/DrawingExtensions.cs +++ b/SDUI/Extensions/DrawingExtensions.cs @@ -5,10 +5,14 @@ public static class DrawingExtensions { - private static readonly ContentAlignment anyRight = ContentAlignment.TopRight | ContentAlignment.MiddleRight | ContentAlignment.BottomRight; - private static readonly ContentAlignment anyBottom = ContentAlignment.BottomLeft | ContentAlignment.BottomCenter | ContentAlignment.BottomRight; - private static readonly ContentAlignment anyCenter = ContentAlignment.TopCenter | ContentAlignment.MiddleCenter | ContentAlignment.BottomCenter; - private static readonly ContentAlignment anyMiddle = ContentAlignment.MiddleLeft | ContentAlignment.MiddleCenter | ContentAlignment.MiddleRight; + private static readonly ContentAlignment anyRight = + ContentAlignment.TopRight | ContentAlignment.MiddleRight | ContentAlignment.BottomRight; + private static readonly ContentAlignment anyBottom = + ContentAlignment.BottomLeft | ContentAlignment.BottomCenter | ContentAlignment.BottomRight; + private static readonly ContentAlignment anyCenter = + ContentAlignment.TopCenter | ContentAlignment.MiddleCenter | ContentAlignment.BottomCenter; + private static readonly ContentAlignment anyMiddle = + ContentAlignment.MiddleLeft | ContentAlignment.MiddleCenter | ContentAlignment.MiddleRight; public static bool InRegion(this Point point, Region region) { @@ -60,7 +64,7 @@ public static GraphicsPath ChromePath(this RectangleF bounds, float radius) y = bounds.Bottom - diameter; // bottom right - path.AddArc(x + diameter, y, diameter, diameter, 180, -90); // Sağ alt dışa doğru eğri + path.AddArc(x + diameter, y, diameter, diameter, 180, -90); // Sağ alt dışa doğru eğri // Bottom left arc x = bounds.Left - diameter; @@ -96,22 +100,37 @@ public static Region Region(this GraphicsPath path) public static GraphicsPath GraphicsPath(this RectangleF rect) { - var points = new PointF[] { - new PointF(rect.Left, rect.Top), - new PointF(rect.Right, rect.Top), - new PointF(rect.Right, rect.Bottom), - new PointF(rect.Left, rect.Bottom), - - new PointF(rect.Left, rect.Top) }; + var points = new PointF[] + { + new PointF(rect.Left, rect.Top), + new PointF(rect.Right, rect.Top), + new PointF(rect.Right, rect.Bottom), + new PointF(rect.Left, rect.Bottom), + new PointF(rect.Left, rect.Top), + }; return points.Path(); } - public static GraphicsPath CreateFanPath(this Graphics g, Point center, float d1, float d2, float startAngle, float sweepAngle) + public static GraphicsPath CreateFanPath( + this Graphics g, + Point center, + float d1, + float d2, + float startAngle, + float sweepAngle + ) { return center.CreateFanPath(d1, d2, startAngle, sweepAngle); } - public static GraphicsPath CreateFanPath(this Graphics g, PointF center, float d1, float d2, float startAngle, float sweepAngle) + public static GraphicsPath CreateFanPath( + this Graphics g, + PointF center, + float d1, + float d2, + float startAngle, + float sweepAngle + ) { return center.CreateFanPath(d1, d2, startAngle, sweepAngle); } @@ -162,6 +181,7 @@ public static void FillRectangle(this Graphics gfx, Color color, int x, int y, i using var brush = color.Brush(); gfx.FillRectangle(brush, new Rectangle(x, y, width, height)); } + public static void FillRectangle(this Graphics gfx, Color color, RectangleF rect) { using var brush = color.Brush(); @@ -215,10 +235,21 @@ public static GraphicsPath CreateRoundPath(float v1, float v2, float v3, float v return new RectangleF(v1, v2, v3, v4).Radius(v5); } - public static void DrawShadow(this Graphics graphics, Rectangle rect, float size, int radius, Color color = default) - => DrawShadow(graphics, rect.ToRectangleF(), size, radius, color); + public static void DrawShadow( + this Graphics graphics, + Rectangle rect, + float size, + int radius, + Color color = default + ) => DrawShadow(graphics, rect.ToRectangleF(), size, radius, color); - public static void DrawShadow(this Graphics graphics, RectangleF rect, float size, int radius, Color color = default) + public static void DrawShadow( + this Graphics graphics, + RectangleF rect, + float size, + int radius, + Color color = default + ) { if (size <= 0) return; @@ -250,6 +281,7 @@ public static StringAlignment TranslateAlignment(ContentAlignment align) result = StringAlignment.Near; return result; } + public static StringAlignment TranslateLineAlignment(ContentAlignment align) { StringAlignment result; @@ -270,10 +302,19 @@ public static StringAlignment TranslateLineAlignment(ContentAlignment align) public static StringFormat StringFormatForAlignment(ContentAlignment align) { - return new StringFormat { Alignment = TranslateAlignment(align), LineAlignment = TranslateLineAlignment(align) }; + return new StringFormat + { + Alignment = TranslateAlignment(align), + LineAlignment = TranslateLineAlignment(align), + }; } - public static StringFormat CreateStringFormat(this Control ctl, ContentAlignment textAlign, bool showEllipsis, bool useMnemonic) + public static StringFormat CreateStringFormat( + this Control ctl, + ContentAlignment textAlign, + bool showEllipsis, + bool useMnemonic + ) { StringFormat format = StringFormatForAlignment(textAlign); if (ctl.RightToLeft == RightToLeft.Yes) @@ -304,7 +345,14 @@ public static StringFormat CreateStringFormat(this Control ctl, ContentAlignment return format; } - public static void DrawString(this Control control, string text, Graphics graphics, ContentAlignment contentAlignment, bool showEllipsis = false, bool useMnemonic = false) + public static void DrawString( + this Control control, + string text, + Graphics graphics, + ContentAlignment contentAlignment, + bool showEllipsis = false, + bool useMnemonic = false + ) { graphics.TextRenderingHint = TextRenderingHint.SystemDefault; using var textFormat = control.CreateStringFormat(contentAlignment, showEllipsis, useMnemonic); @@ -313,7 +361,13 @@ public static void DrawString(this Control control, string text, Graphics graphi graphics.DrawString(text, control.Font, textBrush, control.ClientRectangle, textFormat); } - public static void DrawString(this Control control, Graphics graphics, ContentAlignment contentAlignment, bool showEllipsis = false, bool useMnemonic = false) + public static void DrawString( + this Control control, + Graphics graphics, + ContentAlignment contentAlignment, + bool showEllipsis = false, + bool useMnemonic = false + ) { graphics.TextRenderingHint = TextRenderingHint.SystemDefault; using var textFormat = control.CreateStringFormat(contentAlignment, showEllipsis, useMnemonic); @@ -322,7 +376,14 @@ public static void DrawString(this Control control, Graphics graphics, ContentAl graphics.DrawString(control.Text, control.Font, textBrush, control.ClientRectangle, textFormat); } - public static void DrawString(this Control control, Graphics graphics, ContentAlignment contentAlignment, Color color, bool showEllipsis = false, bool useMnemonic = false) + public static void DrawString( + this Control control, + Graphics graphics, + ContentAlignment contentAlignment, + Color color, + bool showEllipsis = false, + bool useMnemonic = false + ) { graphics.TextRenderingHint = TextRenderingHint.SystemDefault; using var textFormat = control.CreateStringFormat(contentAlignment, showEllipsis, useMnemonic); @@ -331,7 +392,15 @@ public static void DrawString(this Control control, Graphics graphics, ContentAl graphics.DrawString(control.Text, control.Font, textBrush, control.ClientRectangle, textFormat); } - public static void DrawString(this Control control, Graphics graphics, ContentAlignment contentAlignment, Color color, RectangleF rectangle, bool showEllipsis = false, bool useMnemonic = false) + public static void DrawString( + this Control control, + Graphics graphics, + ContentAlignment contentAlignment, + Color color, + RectangleF rectangle, + bool showEllipsis = false, + bool useMnemonic = false + ) { graphics.TextRenderingHint = TextRenderingHint.SystemDefault; using var textFormat = control.CreateStringFormat(contentAlignment, showEllipsis, useMnemonic); @@ -340,7 +409,13 @@ public static void DrawString(this Control control, Graphics graphics, ContentAl graphics.DrawString(control.Text, control.Font, textBrush, rectangle, textFormat); } - public static void DrawString(this Control control, Graphics graphics, string text, Color color, RectangleF rectangle) + public static void DrawString( + this Control control, + Graphics graphics, + string text, + Color color, + RectangleF rectangle + ) { graphics.TextRenderingHint = TextRenderingHint.SystemDefault; using var textBrush = new SolidBrush(color); @@ -348,11 +423,12 @@ public static void DrawString(this Control control, Graphics graphics, string te { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, - Trimming = StringTrimming.EllipsisCharacter + Trimming = StringTrimming.EllipsisCharacter, }; graphics.DrawString(text, control.Font, textBrush, rectangle, textFormat); } + public static void DrawString(this Control control, Graphics graphics, Color color, RectangleF rectangle) { graphics.TextRenderingHint = TextRenderingHint.SystemDefault; @@ -361,7 +437,7 @@ public static void DrawString(this Control control, Graphics graphics, Color col { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, - Trimming = StringTrimming.EllipsisCharacter + Trimming = StringTrimming.EllipsisCharacter, }; graphics.DrawString(control.Text, control.Font, textBrush, rectangle, textFormat); @@ -374,6 +450,5 @@ public static void DrawSvg(this Graphics graphics, string svg, Color color, Rect using var bitmap = svgDocument.Draw(); graphics.DrawImage(bitmap, rectangle); - } -} \ No newline at end of file +} diff --git a/SDUI/Extensions/IntegerExtensions.cs b/SDUI/Extensions/IntegerExtensions.cs index ac7d76b..927bbe0 100644 --- a/SDUI/Extensions/IntegerExtensions.cs +++ b/SDUI/Extensions/IntegerExtensions.cs @@ -8,10 +8,7 @@ public static class IntegerExtensions /// public static uint ToAbgr(this Color color) { - return ((uint)color.A << 24) - | ((uint)color.B << 16) - | ((uint)color.G << 8) - | color.R; + return ((uint)color.A << 24) | ((uint)color.B << 16) | ((uint)color.G << 8) | color.R; } /// @@ -20,10 +17,7 @@ public static uint ToAbgr(this Color color) /// public static Color ToColor(this int argb) { - return Color.FromArgb( - (argb & 0xff0000) >> 16, - (argb & 0xff00) >> 8, - argb & 0xff); + return Color.FromArgb((argb & 0xff0000) >> 16, (argb & 0xff00) >> 8, argb & 0xff); } /// diff --git a/SDUI/Extensions/ListViewExtensions.cs b/SDUI/Extensions/ListViewExtensions.cs index 82892bd..5d14d29 100644 --- a/SDUI/Extensions/ListViewExtensions.cs +++ b/SDUI/Extensions/ListViewExtensions.cs @@ -11,9 +11,14 @@ public static class ListViewExtensions /// The move direction public static void MoveSelectedItems(this ListView sender, MoveDirection direction) { - var valid = sender.SelectedItems.Count > 0 && - ((direction == MoveDirection.Down && (sender.SelectedItems[sender.SelectedItems.Count - 1].Index < sender.Items.Count - 1)) - || (direction == MoveDirection.Up && (sender.SelectedItems[0].Index > 0))); + var valid = + sender.SelectedItems.Count > 0 + && ( + ( + direction == MoveDirection.Down + && (sender.SelectedItems[sender.SelectedItems.Count - 1].Index < sender.Items.Count - 1) + ) || (direction == MoveDirection.Up && (sender.SelectedItems[0].Index > 0)) + ); if (valid) { @@ -46,4 +51,4 @@ public static void MoveSelectedItems(this ListView sender, MoveDirection directi sender.EndUpdate(); } } -} \ No newline at end of file +} diff --git a/SDUI/Extensions/RectangleExtensions.cs b/SDUI/Extensions/RectangleExtensions.cs index 85116c8..316ef39 100644 --- a/SDUI/Extensions/RectangleExtensions.cs +++ b/SDUI/Extensions/RectangleExtensions.cs @@ -54,7 +54,13 @@ public static GraphicsPath Radius(this RectangleF r, float radius) return path; } - public static GraphicsPath Radius(this RectangleF bounds, float topLeft = 0, float topRight = 0, float bottomLeft = 0, float bottomRight = 0) + public static GraphicsPath Radius( + this RectangleF bounds, + float topLeft = 0, + float topRight = 0, + float bottomLeft = 0, + float bottomRight = 0 + ) { var diameter1 = topLeft * 2; var diameter2 = topRight * 2; @@ -67,7 +73,7 @@ public static GraphicsPath Radius(this RectangleF bounds, float topLeft = 0, flo var arc4 = new RectangleF(bounds.Location, new SizeF(diameter4, diameter4)); var path = new GraphicsPath(); - // top left arc + // top left arc if (topLeft == 0) { path.AddLine(arc1.Location, arc1.Location); @@ -77,7 +83,7 @@ public static GraphicsPath Radius(this RectangleF bounds, float topLeft = 0, flo path.AddArc(arc1, 180, 90); } - // top right arc + // top right arc arc2.X = bounds.Right - diameter2; if (topRight == 0) { @@ -88,7 +94,7 @@ public static GraphicsPath Radius(this RectangleF bounds, float topLeft = 0, flo path.AddArc(arc2, 270, 90); } - // bottom right arc + // bottom right arc arc3.X = bounds.Right - diameter3; arc3.Y = bounds.Bottom - diameter3; @@ -101,7 +107,7 @@ public static GraphicsPath Radius(this RectangleF bounds, float topLeft = 0, flo path.AddArc(arc3, 0, 90); } - // bottom left arc + // bottom left arc arc4.X = bounds.Right - diameter4; arc4.Y = bounds.Bottom - diameter4; arc4.X = bounds.Left; @@ -117,7 +123,14 @@ public static GraphicsPath Radius(this RectangleF bounds, float topLeft = 0, flo path.CloseFigure(); return path; } - public static GraphicsPath Radius(this RectangleF bounds, int topLeft = 0, int topRight = 0, int bottomLeft = 0, int bottomRight = 0) + + public static GraphicsPath Radius( + this RectangleF bounds, + int topLeft = 0, + int topRight = 0, + int bottomLeft = 0, + int bottomRight = 0 + ) { int diameter1 = topLeft * 2; int diameter2 = topRight * 2; @@ -130,7 +143,7 @@ public static GraphicsPath Radius(this RectangleF bounds, int topLeft = 0, int t var arc4 = new RectangleF(bounds.Location, new SizeF(diameter4, diameter4)); var path = new GraphicsPath(); - // top left arc + // top left arc if (topLeft == 0) { path.AddLine(arc1.Location, arc1.Location); @@ -140,7 +153,7 @@ public static GraphicsPath Radius(this RectangleF bounds, int topLeft = 0, int t path.AddArc(arc1, 180, 90); } - // top right arc + // top right arc arc2.X = bounds.Right - diameter2; if (topRight == 0) { @@ -151,7 +164,7 @@ public static GraphicsPath Radius(this RectangleF bounds, int topLeft = 0, int t path.AddArc(arc2, 270, 90); } - // bottom right arc + // bottom right arc arc3.X = bounds.Right - diameter3; arc3.Y = bounds.Bottom - diameter3; @@ -164,7 +177,7 @@ public static GraphicsPath Radius(this RectangleF bounds, int topLeft = 0, int t path.AddArc(arc3, 0, 90); } - // bottom left arc + // bottom left arc arc4.X = bounds.Right - diameter4; arc4.Y = bounds.Bottom - diameter4; arc4.X = bounds.Left; @@ -180,7 +193,7 @@ public static GraphicsPath Radius(this RectangleF bounds, int topLeft = 0, int t path.CloseFigure(); return path; } - + public static Rectangle ToRectangle(this RectangleF rect) { return Rectangle.Round(rect); @@ -210,4 +223,4 @@ public static bool InRect(this PointF point, RectangleF rect) { return point.X >= rect.Left && point.X <= rect.Right && point.Y >= rect.Top && point.Y <= rect.Bottom; } -} \ No newline at end of file +} diff --git a/SDUI/Extensions/TextBoxBaseExtensions.cs b/SDUI/Extensions/TextBoxBaseExtensions.cs index a62f2ca..b73ea35 100644 --- a/SDUI/Extensions/TextBoxBaseExtensions.cs +++ b/SDUI/Extensions/TextBoxBaseExtensions.cs @@ -16,7 +16,13 @@ public static class TextBoxBaseExtensions /// The TextBoxBase /// The string to type in the /// The time - public static void Write(this TextBoxBase value, string str, bool time = true, bool writeToFile = false, string filePath = "") + public static void Write( + this TextBoxBase value, + string str, + bool time = true, + bool writeToFile = false, + string filePath = "" + ) { var stringBuilder = new StringBuilder(); if (time) @@ -56,4 +62,4 @@ public static void RunInUIThread(this Control target, Action action) else action(); } -} \ No newline at end of file +} diff --git a/SDUI/Helpers/DropShadow.cs b/SDUI/Helpers/DropShadow.cs index c4b744b..d3d35d2 100644 --- a/SDUI/Helpers/DropShadow.cs +++ b/SDUI/Helpers/DropShadow.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using System; +using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -10,10 +10,11 @@ namespace SDUI.Helpers; using static System.Math; + public static class DropShadow { const int CHANNELS = 4; - const int InflateMultiple = 2;//单边外延radius的倍数 + const int InflateMultiple = 2; //单边外延radius的倍数 /// /// 获取阴影边界。供外部定位阴影用 @@ -66,8 +67,8 @@ public static Bitmap Create(GraphicsPath path, Color color, int radius = 5) try { matrix = new Matrix(); - matrix.Translate(-pathBounds.X + inflate, -pathBounds.Y + inflate);//先清除形状原有偏移再向中心偏移 - pathCopy = (GraphicsPath)path.Clone(); //基于形状副本操作 + matrix.Translate(-pathBounds.X + inflate, -pathBounds.Y + inflate); //先清除形状原有偏移再向中心偏移 + pathCopy = (GraphicsPath)path.Clone(); //基于形状副本操作 pathCopy.Transform(matrix); brush = new SolidBrush(color); @@ -93,7 +94,11 @@ public static Bitmap Create(GraphicsPath path, Color color, int radius = 5) BitmapData data = null; try { - data = shadow.LockBits(new Rectangle(0, 0, shadow.Width, shadow.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); + data = shadow.LockBits( + new Rectangle(0, 0, shadow.Width, shadow.Height), + ImageLockMode.ReadWrite, + PixelFormat.Format32bppArgb + ); //两次方框模糊就能达到不错的效果 //var boxes = DetermineBoxes(radius, 3); @@ -116,13 +121,13 @@ public static Bitmap Create(GraphicsPath path, Color color, int radius = 5) /// 模糊半径 /// 透明色值 #if UNSAFE - private static unsafe void BoxBlur(BitmapData data, int radius, Color color) + private static unsafe void BoxBlur(BitmapData data, int radius, Color color) #else private static void BoxBlur(BitmapData data, int radius, Color color) #endif { #if UNSAFE //unsafe项目下请定义编译条件:UNSAFE - IntPtr p1 = data1.Scan0; + IntPtr p1 = data1.Scan0; #else byte[] p1 = new byte[data.Stride * data.Height]; Marshal.Copy(data.Scan0, p1, 0, p1.Length); @@ -131,7 +136,9 @@ private static void BoxBlur(BitmapData data, int radius, Color color) //这步的意义在于让图片中的透明像素拥有color的色值(但仍然保持透明) //这样在混合时才能合出基于color的颜色(只是透明度不同), //否则它是与RGB(0,0,0)合,就会得到乌黑的渣特技 - byte R = color.R, G = color.G, B = color.B; + byte R = color.R, + G = color.G, + B = color.B; for (int i = 3; i < p1.Length; i += 4) { if (p1[i] == 0) @@ -144,7 +151,9 @@ private static void BoxBlur(BitmapData data, int radius, Color color) byte[] p2 = new byte[p1.Length]; int radius2 = 2 * radius + 1; - int First, Last, Sum; + int First, + Last, + Sum; int stride = data.Stride, width = data.Width, height = data.Height; @@ -171,7 +180,11 @@ private static void BoxBlur(BitmapData data, int radius, Color color) Sum += p1[right + 3] - First; p2[start + 3] = (byte)(Sum / radius2); } - for (var column = radius + 1; column < width - radius; column++, left += CHANNELS, right += CHANNELS, start += CHANNELS) + for ( + var column = radius + 1; + column < width - radius; + column++, left += CHANNELS, right += CHANNELS, start += CHANNELS + ) { Sum += p1[right + 3] - p1[left + 3]; p2[start + 3] = (byte)(Sum / radius2); @@ -243,16 +256,23 @@ public interface IShadowController { bool ShouldShowShadow(); } + enum RenderSide { Top, Bottom, Left, - Right + Right, } - static RenderSide[] VisibleTop = { RenderSide.Bottom/*, RenderSide.Top*/ }; - static RenderSide[] VisibleBottom = { RenderSide.Top/*, RenderSide.Bottom*/ }; + static RenderSide[] VisibleTop = + { + RenderSide.Bottom, /*, RenderSide.Top*/ + }; + static RenderSide[] VisibleBottom = + { + RenderSide.Top, /*, RenderSide.Bottom*/ + }; static RenderSide[] VisibleLeft = { RenderSide.Right }; static RenderSide[] VisibleRight = { RenderSide.Left }; @@ -274,7 +294,6 @@ static bool IsVisible(RenderSide side, DockStyle st) return true; } - public static void DrawShadow(Graphics G, Color c, Rectangle r, int d, DockStyle st = DockStyle.None) { Color[] colors = GetColorVector(c, d).ToArray(); @@ -284,7 +303,11 @@ public static void DrawShadow(Graphics G, Color c, Rectangle r, int d, DockStyle { //TOP using (Pen pen = new Pen(colors[i], 1f)) - G.DrawLine(pen, new Point(r.Left - Max(i - 1, 0), r.Top - i), new Point(r.Right + Max(i - 1, 0), r.Top - i)); + G.DrawLine( + pen, + new Point(r.Left - Max(i - 1, 0), r.Top - i), + new Point(r.Right + Max(i - 1, 0), r.Top - i) + ); } if (IsVisible(RenderSide.Bottom, st)) @@ -292,7 +315,11 @@ public static void DrawShadow(Graphics G, Color c, Rectangle r, int d, DockStyle { //BOTTOM using (Pen pen = new Pen(colors[i], 1f)) - G.DrawLine(pen, new Point(r.Left - Max(i - 1, 0), r.Bottom + i), new Point(r.Right + i, r.Bottom + i)); + G.DrawLine( + pen, + new Point(r.Left - Max(i - 1, 0), r.Bottom + i), + new Point(r.Right + i, r.Bottom + i) + ); } if (IsVisible(RenderSide.Left, st)) for (int i = 1; i < d; i++) @@ -306,13 +333,23 @@ public static void DrawShadow(Graphics G, Color c, Rectangle r, int d, DockStyle { //RIGHT using (Pen pen = new Pen(colors[i], 1f)) - G.DrawLine(pen, new Point(r.Right + i, r.Top - i), new Point(r.Right + i, r.Bottom + Max(i - 1, 0))); + G.DrawLine( + pen, + new Point(r.Right + i, r.Top - i), + new Point(r.Right + i, r.Bottom + Max(i - 1, 0)) + ); } } //Code taken and adapted from StackOverflow (https://stackoverflow.com/a/13653167). //All credits go to Marino Šimić (https://stackoverflow.com/users/610204/marino-%c5%a0imi%c4%87). - public static void DrawRoundedRectangle(this Graphics gfx, Rectangle bounds, int cornerRadius, Pen drawPen, Color fillColor) + public static void DrawRoundedRectangle( + this Graphics gfx, + Rectangle bounds, + int cornerRadius, + Pen drawPen, + Color fillColor + ) { int strokeOffset = Convert.ToInt32(Ceiling(drawPen.Width)); bounds = Rectangle.Inflate(bounds, -strokeOffset, -strokeOffset); @@ -322,8 +359,14 @@ public static void DrawRoundedRectangle(this Graphics gfx, Rectangle bounds, int { gfxPath.AddArc(bounds.X, bounds.Y, cornerRadius, cornerRadius, 180, 90); gfxPath.AddArc(bounds.X + bounds.Width - cornerRadius, bounds.Y, cornerRadius, cornerRadius, 270, 90); - gfxPath.AddArc(bounds.X + bounds.Width - cornerRadius, bounds.Y + bounds.Height - cornerRadius, cornerRadius, - cornerRadius, 0, 90); + gfxPath.AddArc( + bounds.X + bounds.Width - cornerRadius, + bounds.Y + bounds.Height - cornerRadius, + cornerRadius, + cornerRadius, + 0, + 90 + ); gfxPath.AddArc(bounds.X, bounds.Y + bounds.Height - cornerRadius, cornerRadius, cornerRadius, 90, 90); } else @@ -347,7 +390,15 @@ public static void DrawRoundedRectangle(this Graphics gfx, Rectangle bounds, int //Code taken and adapted from StackOverflow (https://stackoverflow.com/a/13653167). //All credits go to Marino Šimić (https://stackoverflow.com/users/610204/marino-%c5%a0imi%c4%87). - public static void DrawOutsetShadow(Graphics g, Color shadowColor, int hShadow, int vShadow, int blur, int spread, Control control) + public static void DrawOutsetShadow( + Graphics g, + Color shadowColor, + int hShadow, + int vShadow, + int blur, + int spread, + Control control + ) { var rOuter = Rectangle.Inflate(control.Bounds, blur / 2, blur / 2); var rInner = Rectangle.Inflate(control.Bounds, blur / 2, blur / 2); @@ -396,19 +447,19 @@ static List GetColorVector(Color fc, int depth) return cv; } - //Code taken and adapted from https://stackoverflow.com/a/25741405 //All credits go to TaW (https://stackoverflow.com/users/3152130/taw) static GraphicsPath GetRectPath(Rectangle R) { byte[] fm = new byte[3]; - for (int b = 0; b < 3; b++) fm[b] = 1; + for (int b = 0; b < 3; b++) + fm[b] = 1; List points = new List - { - new Point(R.Left, R.Bottom), - new Point(R.Right, R.Bottom), - new Point(R.Right, R.Top) - }; + { + new Point(R.Left, R.Bottom), + new Point(R.Right, R.Bottom), + new Point(R.Right, R.Top), + }; return new GraphicsPath(points.ToArray(), fm); } @@ -416,8 +467,13 @@ public static void CreateDropShadow(this Control ctrl) { if (ctrl.Parent != null) { - ctrl.Parent.Paint += (s, e) => { - if (ctrl.Parent != null && ctrl.Visible && (!(ctrl is IShadowController) || ((IShadowController)ctrl).ShouldShowShadow())) + ctrl.Parent.Paint += (s, e) => + { + if ( + ctrl.Parent != null + && ctrl.Visible + && (!(ctrl is IShadowController) || ((IShadowController)ctrl).ShouldShowShadow()) + ) DrawShadow(e.Graphics, Color.Black, ctrl.Bounds, 7, ctrl.Dock); }; } diff --git a/SDUI/Helpers/ListViewColumnSorter.cs b/SDUI/Helpers/ListViewColumnSorter.cs index 20dfb82..b4eea2e 100644 --- a/SDUI/Helpers/ListViewColumnSorter.cs +++ b/SDUI/Helpers/ListViewColumnSorter.cs @@ -40,15 +40,16 @@ public int Compare(object x, object y) { var listviewX = (ListViewItem)x; var listviewY = (ListViewItem)y; - if (listviewX == null || - listviewY == null) + if (listviewX == null || listviewY == null) return 0; if (listviewX.SubItems[0].Text == ".." || listviewY.SubItems[0].Text == "..") return 0; - var compareResult = _objectCompare.Compare(listviewX.SubItems[_columnToSort].Text, - listviewY.SubItems[_columnToSort].Text); + var compareResult = _objectCompare.Compare( + listviewX.SubItems[_columnToSort].Text, + listviewY.SubItems[_columnToSort].Text + ); if (_orderOfSort == SortOrder.Ascending) return compareResult; diff --git a/SDUI/Helpers/SvgIcons.cs b/SDUI/Helpers/SvgIcons.cs index a96e0c2..5b35b3d 100644 --- a/SDUI/Helpers/SvgIcons.cs +++ b/SDUI/Helpers/SvgIcons.cs @@ -2,6 +2,7 @@ { internal class SvgIcons { - public readonly static string Settings = " "; + public static readonly string Settings = + " "; } } diff --git a/SDUI/Helpers/SystemAnimations.cs b/SDUI/Helpers/SystemAnimations.cs index 7c62eac..b82c52d 100644 --- a/SDUI/Helpers/SystemAnimations.cs +++ b/SDUI/Helpers/SystemAnimations.cs @@ -16,7 +16,12 @@ public struct ANIMATIONINFO [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref ANIMATIONINFO pvParam, uint fWinIni); + private static extern bool SystemParametersInfo( + uint uiAction, + uint uiParam, + ref ANIMATIONINFO pvParam, + uint fWinIni + ); private static readonly bool _areAnimationsEnabled = GetAreAnimationsEnabled(); diff --git a/SDUI/Helpers/WindowsHelper.cs b/SDUI/Helpers/WindowsHelper.cs index 72150b2..ace0bf5 100644 --- a/SDUI/Helpers/WindowsHelper.cs +++ b/SDUI/Helpers/WindowsHelper.cs @@ -1,8 +1,8 @@ -using Microsoft.Win32; -using System; +using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms.VisualStyles; +using Microsoft.Win32; using static SDUI.NativeMethods; namespace SDUI.Helpers; @@ -22,16 +22,19 @@ public static class WindowsHelper /// static WindowsHelper() { - var version = new OSVERSIONINFOEX - { - OSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX)) - }; + var version = new OSVERSIONINFOEX { OSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX)) }; if (RtlGetVersion(ref version) != NTSTATUS.STATUS_SUCCESS) return; - IsSeven = version.MajorVersion == 6 && version.MinorVersion == 1 && (version.BuildNumber >= 7600 && version.BuildNumber <= 7601); - IsEight = version.MajorVersion == 6 && version.MinorVersion >= 2 && (version.BuildNumber >= 9200 && version.BuildNumber <= 9999); + IsSeven = + version.MajorVersion == 6 + && version.MinorVersion == 1 + && (version.BuildNumber >= 7600 && version.BuildNumber <= 7601); + IsEight = + version.MajorVersion == 6 + && version.MinorVersion >= 2 + && (version.BuildNumber >= 9200 && version.BuildNumber <= 9999); IsTen = version.MajorVersion == 10 && (version.BuildNumber >= 10240 && version.BuildNumber <= 20000); IsEleven = version.BuildNumber >= 22000; IsModern = IsTen || IsEleven; @@ -108,7 +111,8 @@ public static bool IsDark() { try { - var personalize = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; + var personalize = + "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; value = (int)Registry.GetValue(personalize, "AppsUseLightTheme", 1); } catch diff --git a/SDUI/MoveDirection.cs b/SDUI/MoveDirection.cs index 97108a6..7be52fb 100644 --- a/SDUI/MoveDirection.cs +++ b/SDUI/MoveDirection.cs @@ -6,5 +6,5 @@ public enum MoveDirection { Up = -1, - Down = 1 -}; \ No newline at end of file + Down = 1, +}; diff --git a/SDUI/NativeMethods.cs b/SDUI/NativeMethods.cs index 4214b53..afe445c 100644 --- a/SDUI/NativeMethods.cs +++ b/SDUI/NativeMethods.cs @@ -85,9 +85,9 @@ public class NativeMethods public const int LVGA_FOOTER_CENTER = 0x10; public const int LVGA_FOOTER_RIGHT = 0x20; // Don't forget to validate exclusivity public const int LVGGR_GROUP = 0; // Entire expanded group - public const int LVGGR_HEADER = 1; // Header only (collapsed group) - public const int LVGGR_LABEL = 2; // Label only - public const int LVGGR_SUBSETLINK = 3; // subset link only + public const int LVGGR_HEADER = 1; // Header only (collapsed group) + public const int LVGGR_LABEL = 2; // Label only + public const int LVGGR_SUBSETLINK = 3; // subset link only public const int LVS_EX_DOUBLEBUFFER = 0x10000; public const int LVM_SETEXTENDEDLISTVIEWSTYLE = 4150; @@ -107,7 +107,7 @@ public class NativeMethods public const int TCM_ADJUSTRECT = TCM_FIRST + 40; public const int TCS_MULTILINE = 0x0200; - public struct MARGINS // struct for box shadow + public struct MARGINS // struct for box shadow { public int Left; public int Right; @@ -123,7 +123,12 @@ public struct SubclassInfo [DllImport("kernel32", EntryPoint = "RtlMoveMemory", SetLastError = false)] public static extern void MoveMemory(IntPtr Destination, IntPtr Source, IntPtr Length); - [DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] + [DllImport( + "gdi32.dll", + SetLastError = true, + ExactSpelling = true, + CharSet = System.Runtime.InteropServices.CharSet.Auto + )] [ResourceExposure(ResourceScope.None)] public static extern int CombineRgn(IntPtr hRgn, IntPtr hRgn1, IntPtr hRgn2, int nCombineMode); @@ -139,7 +144,6 @@ public struct SubclassInfo [DllImport("gdi32.dll")] public static extern IntPtr CreateSolidBrush(uint crColor); - [DllImport("user32.dll")] public static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgnclip, uint fdwOptions); @@ -154,10 +158,16 @@ public struct SubclassInfo public static extern IntPtr OpenThemeData(IntPtr hWnd, string classList); [DllImport(uxtheme, EntryPoint = "CloseThemeData")] - public extern static Int32 CloseThemeData(IntPtr hTheme); + public static extern Int32 CloseThemeData(IntPtr hTheme); [DllImport(uxtheme, EntryPoint = "GetThemeColor")] - public extern static Int32 GetThemeColor(IntPtr hTheme, int iPartId, int iStateId, int iPropId, out COLORREF pColor); + public static extern Int32 GetThemeColor( + IntPtr hTheme, + int iPartId, + int iStateId, + int iPropId, + out COLORREF pColor + ); [DllImport(gdi32)] public static extern uint SetTextColor(IntPtr hdc, COLORREF crColor); @@ -187,10 +197,20 @@ public struct SubclassInfo public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); [DllImport(dwmapi, CharSet = CharSet.Unicode, PreserveSig = false)] - public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute, int cbAttribute); + public static extern int DwmSetWindowAttribute( + IntPtr hwnd, + DWMWINDOWATTRIBUTE dwAttribute, + ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute, + int cbAttribute + ); [DllImport(dwmapi)] - public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, ref int pvAttribute, int cbAttribute); + public static extern int DwmSetWindowAttribute( + IntPtr hwnd, + DWMWINDOWATTRIBUTE dwAttribute, + ref int pvAttribute, + int cbAttribute + ); [DllImport(dwmapi)] public static extern int DwmIsCompositionEnabled(ref int pfEnabled); @@ -202,9 +222,8 @@ public struct SubclassInfo [DllImport("user32.dll")] public static extern bool GetClientRect(IntPtr hWnd, ref Rect rect); - [DllImport(uxtheme, ExactSpelling = true)] - public extern static int DrawThemeParentBackground(IntPtr hWnd, IntPtr hdc, ref System.Drawing.Rectangle pRect); + public static extern int DrawThemeParentBackground(IntPtr hWnd, IntPtr hdc, ref System.Drawing.Rectangle pRect); [DllImport(user32, EntryPoint = "SendMessageW", SetLastError = true)] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref LVGROUP lParam); @@ -219,7 +238,7 @@ public struct SubclassInfo public static extern int PostMessage(IntPtr hWnd, int Msg, int wParam, ref IntPtr lParam); [DllImport(uxtheme, CharSet = CharSet.Unicode, SetLastError = true)] - public extern static int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList); + public static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList); [DllImport(uxtheme, EntryPoint = "#133", SetLastError = true)] internal static extern bool AllowDarkModeForWindow(IntPtr window, bool isDarkModeAllowed); @@ -237,10 +256,25 @@ public struct SubclassInfo public static extern IntPtr SetCursor(IntPtr hCursor); [DllImport(user32, SetLastError = true)] - public static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad); + public static extern IntPtr LoadImage( + IntPtr hinst, + string lpszName, + uint uType, + int cxDesired, + int cyDesired, + uint fuLoad + ); [DllImport(user32, SetLastError = true)] - public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags); + public static extern bool SetWindowPos( + IntPtr hWnd, + IntPtr hWndInsertAfter, + int X, + int Y, + int cx, + int cy, + SetWindowPosFlags uFlags + ); [DllImport(user32, EntryPoint = "SetWindowLong", SetLastError = true)] public static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong); @@ -270,18 +304,19 @@ public struct SubclassInfo public static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc); private delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter); + [DllImport(user32)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i); public delegate IntPtr SUBCLASSPROC( - IntPtr hWnd, - int msg, - IntPtr wParam, - IntPtr lParam, - UIntPtr uIdSubclass, - UIntPtr dwRefData - ); + IntPtr hWnd, + int msg, + IntPtr wParam, + IntPtr lParam, + UIntPtr uIdSubclass, + UIntPtr dwRefData + ); [DllImport("comctl32.dll", ExactSpelling = true)] public static extern bool SetWindowSubclass( @@ -292,19 +327,10 @@ UIntPtr dwRefData ); [DllImport("comctl32.dll", ExactSpelling = true)] - public static extern bool RemoveWindowSubclass( - IntPtr hWnd, - IntPtr pfnSubclass, - UIntPtr uIdSubclass - ); + public static extern bool RemoveWindowSubclass(IntPtr hWnd, IntPtr pfnSubclass, UIntPtr uIdSubclass); [DllImport("comctl32.dll", ExactSpelling = true)] - public static extern IntPtr DefSubclassProc( - IntPtr hWnd, - int msg, - IntPtr wParam, - IntPtr lParam - ); + public static extern IntPtr DefSubclassProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); /// /// The CreateDIBSection function creates a DIB that applications can write to directly. @@ -317,7 +343,14 @@ IntPtr lParam /// /// [DllImport("gdi32.dll")] - private static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO pbmi, uint iUsage, IntPtr ppvBits, IntPtr hSection, uint dwOffset); + private static extern IntPtr CreateDIBSection( + IntPtr hdc, + ref BITMAPINFO pbmi, + uint iUsage, + IntPtr ppvBits, + IntPtr hSection, + uint dwOffset + ); /// /// This function transfers pixels from a specified source rectangle to a specified destination rectangle, altering the pixels according to the selected raster operation (ROP) code. @@ -333,7 +366,17 @@ IntPtr lParam /// /// [DllImport("gdi32.dll")] - internal static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop); + internal static extern bool BitBlt( + IntPtr hdc, + int nXDest, + int nYDest, + int nWidth, + int nHeight, + IntPtr hdcSrc, + int nXSrc, + int nYSrc, + uint dwRop + ); /// /// This function selects an object into a specified device context. The new object replaces the previous object of the same type. @@ -378,7 +421,7 @@ internal enum DrawingOptions PRF_CLIENT = 0x04, PRF_ERASEBKGND = 0x08, PRF_CHILDREN = 0x10, - PRF_OWNED = 0x20 + PRF_OWNED = 0x20, } public static void TakeScreenshot(IntPtr hwnd, Graphics g) @@ -388,14 +431,19 @@ public static void TakeScreenshot(IntPtr hwnd, Graphics g) { hdc = g.GetHdc(); - SendMessage(hwnd, WM_PRINT, hdc, - new IntPtr((int)( - DrawingOptions.PRF_CHILDREN | - DrawingOptions.PRF_CLIENT | - DrawingOptions.PRF_NONCLIENT | - DrawingOptions.PRF_OWNED - )) - ); + SendMessage( + hwnd, + WM_PRINT, + hdc, + new IntPtr( + (int)( + DrawingOptions.PRF_CHILDREN + | DrawingOptions.PRF_CLIENT + | DrawingOptions.PRF_NONCLIENT + | DrawingOptions.PRF_OWNED + ) + ) + ); } finally { @@ -434,12 +482,13 @@ public static void DisableVisualStylesForFirstChild(IntPtr parent) public static void EnableAcrylic(IWin32Window window, Color blurColor) { - if (window is null) throw new ArgumentNullException(nameof(window)); + if (window is null) + throw new ArgumentNullException(nameof(window)); var accentPolicy = new AccentPolicy { AccentState = ACCENT.ENABLE_ACRYLICBLURBEHIND, - GradientColor = blurColor.ToArgb() + GradientColor = blurColor.ToArgb(), }; var accentSize = Marshal.SizeOf(accentPolicy); var accentPolicyPtr = Marshal.AllocHGlobal(accentSize); @@ -449,12 +498,10 @@ public static void EnableAcrylic(IWin32Window window, Color blurColor) { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, Data = accentPolicyPtr, - SizeOfData = Marshal.SizeOf() + SizeOfData = Marshal.SizeOf(), }; - SetWindowCompositionAttribute( - window.Handle, - ref data); + SetWindowCompositionAttribute(window.Handle, ref data); } /// @@ -469,10 +516,10 @@ public static void FillForGlass(Graphics g, Rectangle r) Left = r.Left, Right = r.Right, Top = r.Top, - Bottom = r.Bottom + Bottom = r.Bottom, }; - IntPtr destdc = g.GetHdc(); //hwnd must be the handle of form,not control + IntPtr destdc = g.GetHdc(); //hwnd must be the handle of form,not control IntPtr Memdc = CreateCompatibleDC(destdc); IntPtr bitmap; IntPtr bitmapOld = IntPtr.Zero; @@ -491,7 +538,6 @@ public static void FillForGlass(Graphics g, Rectangle r) { bitmapOld = SelectObject(Memdc, bitmap); BitBlt(destdc, rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top, Memdc, 0, 0, SRCCOPY); - } //Remember to clean up @@ -501,11 +547,8 @@ public static void FillForGlass(Graphics g, Rectangle r) ReleaseDC(Memdc, (IntPtr)(-1)); DeleteDC(Memdc); - - } g.ReleaseHdc(); - } [Flags] @@ -667,7 +710,6 @@ public enum SetWindowLongFlags : uint WS_EX_NOACTIVATE = 0x08000000, } - [StructLayout(LayoutKind.Sequential)] public struct COLORREF { @@ -683,10 +725,9 @@ public enum ACCENT ENABLE_TRANSPARENTGRADIENT = 2, ENABLE_BLURBEHIND = 3, ENABLE_ACRYLICBLURBEHIND = 4, - INVALID_STATE = 5 + INVALID_STATE = 5, } - public struct AccentPolicy { public ACCENT AccentState; @@ -698,9 +739,9 @@ public struct AccentPolicy public enum NTSTATUS : uint { /// - /// The operation completed successfully. + /// The operation completed successfully. /// - STATUS_SUCCESS = 0x00000000 + STATUS_SUCCESS = 0x00000000, } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] @@ -712,6 +753,7 @@ public struct OSVERSIONINFOEX public int MinorVersion; public int BuildNumber; public int PlatformId; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string CSDVersion; public ushort ServicePackMajor; @@ -736,6 +778,7 @@ public struct LVITEM public int iSubItem; public int state; public int stateMask; + [MarshalAs(UnmanagedType.LPTStr)] public string pszText; public int cchTextMax; @@ -802,7 +845,6 @@ public int Width get => Right - Left; set => Right = value + Left; } - } // The DWM_WINDOW_CORNER_PREFERENCE enum for DwmSetWindowAttribute's third parameter, which tells the function @@ -813,7 +855,7 @@ public enum DWM_WINDOW_CORNER_PREFERENCE : int DWMWCP_DEFAULT = 0, DWMWCP_DONOTROUND = 1, DWMWCP_ROUND = 2, - DWMWCP_ROUNDSMALL = 3 + DWMWCP_ROUNDSMALL = 3, } [StructLayout(LayoutKind.Sequential)] @@ -891,35 +933,39 @@ public struct HDITEM { public Mask mask; public int cxy; - [MarshalAs(UnmanagedType.LPTStr)] public string pszText; + + [MarshalAs(UnmanagedType.LPTStr)] + public string pszText; public IntPtr hbm; public int cchTextMax; public Format fmt; public IntPtr lParam; - // _WIN32_IE >= 0x0300 + + // _WIN32_IE >= 0x0300 public int iImage; public int iOrder; + // _WIN32_IE >= 0x0500 public uint type; public IntPtr pvFilter; + // _WIN32_WINNT >= 0x0600 public uint state; [Flags] public enum Mask { - Format = 0x4, // HDI_FORMAT + Format = 0x4, // HDI_FORMAT }; [Flags] public enum Format { - SortDown = 0x200, // HDF_SORTDOWN - SortUp = 0x400, // HDF_SORTUP + SortDown = 0x200, // HDF_SORTDOWN + SortUp = 0x400, // HDF_SORTUP }; }; - [Flags] public enum CDRF { @@ -931,7 +977,7 @@ public enum CDRF CDRF_NOTIFYPOSTPAINT = 0x10, CDRF_NOTIFYITEMDRAW = 0x20, CDRF_NOTIFYSUBITEMDRAW = 0x20, - CDRF_NOTIFYPOSTERASE = 0x40 + CDRF_NOTIFYPOSTERASE = 0x40, } [Flags] @@ -946,7 +992,7 @@ public enum CDDS CDDS_ITEMPOSTPAINT = CDDS_ITEM | CDDS_POSTPAINT, CDDS_ITEMPREERASE = CDDS_ITEM | CDDS_PREERASE, CDDS_ITEMPOSTERASE = CDDS_ITEM | CDDS_POSTERASE, - CDDS_SUBITEMField = 0x20000 + CDDS_SUBITEMField = 0x20000, } public enum WindowCompositionAttribute @@ -978,7 +1024,7 @@ public enum WindowCompositionAttribute WCA_EXCLUDED_FROM_DDA = 24, WCA_PASSIVEUPDATEMODE = 25, WCA_USEDARKMODECOLORS = 26, - WCA_LAST = 27 + WCA_LAST = 27, }; [Flags] @@ -1150,6 +1196,7 @@ private struct RGBQUAD public readonly byte rgbRed; public readonly byte rgbReserved; } + /// /// This structure defines the dimensions and color information of a Windows-based device-independent bitmap (DIB). /// @@ -1159,4 +1206,4 @@ private struct BITMAPINFO public BITMAPINFOHEADER bmiHeader; public readonly RGBQUAD bmiColors; } -} \ No newline at end of file +} diff --git a/SDUI/Renderers/MenuRenderer.cs b/SDUI/Renderers/MenuRenderer.cs index 2a1be53..e4ad778 100644 --- a/SDUI/Renderers/MenuRenderer.cs +++ b/SDUI/Renderers/MenuRenderer.cs @@ -13,7 +13,8 @@ protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e) g.DrawLine( new Pen(ColorScheme.BorderColor), new Point(e.Item.Bounds.Left, e.Item.Bounds.Height / 2), - new Point(e.Item.Bounds.Right, e.Item.Bounds.Height / 2)); + new Point(e.Item.Bounds.Right, e.Item.Bounds.Height / 2) + ); } protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e) @@ -21,7 +22,10 @@ protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e) Graphics g = e.Graphics; Rectangle dropDownRect = e.ArrowRectangle; using Brush brush = new SolidBrush(ColorScheme.ForeColor); - Point middle = new Point(dropDownRect.Left + dropDownRect.Width / 2, dropDownRect.Top + dropDownRect.Height / 2); + Point middle = new Point( + dropDownRect.Left + dropDownRect.Width / 2, + dropDownRect.Top + dropDownRect.Height / 2 + ); Point[] arrow; @@ -32,35 +36,43 @@ protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e) { case ArrowDirection.Up: - arrow = new Point[] { - new Point(middle.X - hor, middle.Y + 1), - new Point(middle.X + hor + 1, middle.Y + 1), - new Point(middle.X, middle.Y - ver)}; + arrow = new Point[] + { + new Point(middle.X - hor, middle.Y + 1), + new Point(middle.X + hor + 1, middle.Y + 1), + new Point(middle.X, middle.Y - ver), + }; break; case ArrowDirection.Left: - arrow = new Point[] { - new Point(middle.X + hor, middle.Y - 2 * ver), - new Point(middle.X + hor, middle.Y + 2 * ver), - new Point(middle.X - hor, middle.Y)}; + arrow = new Point[] + { + new Point(middle.X + hor, middle.Y - 2 * ver), + new Point(middle.X + hor, middle.Y + 2 * ver), + new Point(middle.X - hor, middle.Y), + }; break; case ArrowDirection.Right: - arrow = new Point[] { - new Point(middle.X - hor, middle.Y - 2 * ver), - new Point(middle.X - hor, middle.Y + 2 * ver), - new Point(middle.X + hor, middle.Y)}; + arrow = new Point[] + { + new Point(middle.X - hor, middle.Y - 2 * ver), + new Point(middle.X - hor, middle.Y + 2 * ver), + new Point(middle.X + hor, middle.Y), + }; break; case ArrowDirection.Down: default: - arrow = new Point[] { - new Point(middle.X - hor, middle.Y - 1), - new Point(middle.X + hor + 1, middle.Y - 1), - new Point(middle.X, middle.Y + ver) }; + arrow = new Point[] + { + new Point(middle.X - hor, middle.Y - 1), + new Point(middle.X + hor + 1, middle.Y - 1), + new Point(middle.X, middle.Y + ver), + }; break; } g.FillPolygon(brush, arrow); @@ -106,9 +118,7 @@ protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { //base.OnRenderToolStripBorder(e); var rectangle = e.ToolStrip.ClientRectangle; - if (e.ToolStrip is ContextMenuStrip || - e.ToolStrip is ToolStripDropDownMenu || - e.ToolStrip is StatusStrip) + if (e.ToolStrip is ContextMenuStrip || e.ToolStrip is ToolStripDropDownMenu || e.ToolStrip is StatusStrip) { e.Graphics.DrawPath(new Pen(ColorScheme.BorderColor, 1), rectangle.Radius(16)); } @@ -142,7 +152,6 @@ protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs if (!backColor.IsDark()) backColor = ColorScheme.BackColor.Brightness(-.1f); - using var brush = new SolidBrush(backColor); e.Graphics.FillPath(brush, rectangle.Radius(6)); @@ -153,7 +162,10 @@ protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) base.OnRenderToolStripBackground(e); var rectangle = e.ToolStrip.ClientRectangle; - e.Graphics.FillRectangle(new SolidBrush(e.ToolStrip is ToolStripDropDown ? ColorScheme.BackColor : ColorScheme.BackColor2), rectangle); + e.Graphics.FillRectangle( + new SolidBrush(e.ToolStrip is ToolStripDropDown ? ColorScheme.BackColor : ColorScheme.BackColor2), + rectangle + ); } protected override void OnRenderImageMargin(ToolStripRenderEventArgs e) @@ -162,4 +174,4 @@ protected override void OnRenderImageMargin(ToolStripRenderEventArgs e) var bounds = e.AffectedBounds; e.Graphics.FillRectangle(new SolidBrush(ColorScheme.BackColor), bounds); } -} \ No newline at end of file +} diff --git a/SDUI/SDUI.csproj b/SDUI/SDUI.csproj index 0211938..c743d46 100644 --- a/SDUI/SDUI.csproj +++ b/SDUI/SDUI.csproj @@ -1,5 +1,4 @@  - net8.0-windows enable @@ -27,5 +26,4 @@ Resources.Designer.cs - diff --git a/SDUI/SK/Button.cs b/SDUI/SK/Button.cs index d82d952..e86ef30 100644 --- a/SDUI/SK/Button.cs +++ b/SDUI/SK/Button.cs @@ -1,15 +1,16 @@ -using SDUI.Animation; -using SkiaSharp; -using System; +using System; using System.Drawing; using System.Windows.Forms; +using SDUI.Animation; +using SkiaSharp; namespace SDUI.SK; public class Button : SKControl { public DialogResult DialogResult { get; set; } = DialogResult.None; - public System.Windows.Forms.AutoSizeMode AutoSizeMode { get; set; } = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + public System.Windows.Forms.AutoSizeMode AutoSizeMode { get; set; } = + System.Windows.Forms.AutoSizeMode.GrowAndShrink; public bool UseVisualStyleBackColor { get; set; } = true; public Color Color { get; set; } = Color.Transparent; public Bitmap Image { get; set; } @@ -70,7 +71,7 @@ public Button() animationManager = new Animation.AnimationEngine(false) { Increment = 0.03, - AnimationType = AnimationType.EaseOut + AnimationType = AnimationType.EaseOut, }; hoverAnimationManager = new Animation.AnimationEngine @@ -134,15 +135,16 @@ protected override void OnPaintSurface(SKPaintSurfaceEventArgs e) canvas.DrawPath(path, brush); - var animationColor = Color.ToSKColor() != SKColors.Transparent - ? Color.ToSKColor().WithAlpha((byte)(hoverAnimationManager.GetProgress() * 65)) : color.WithAlpha((byte)(hoverAnimationManager.GetProgress() * color.Alpha)); + var animationColor = + Color.ToSKColor() != SKColors.Transparent + ? Color.ToSKColor().WithAlpha((byte)(hoverAnimationManager.GetProgress() * 65)) + : color.WithAlpha((byte)(hoverAnimationManager.GetProgress() * color.Alpha)); using var b = new SKPaint { Color = animationColor, IsAntialias = true }; canvas.DrawPath(path, b); DrawShadow(canvas, rectf, _shadowDepth, _radius); - // Ripple if (animationManager.IsAnimating()) { @@ -150,17 +152,27 @@ protected override void OnPaintSurface(SKPaintSurfaceEventArgs e) { var animationValue = animationManager.GetProgress(i); var animationSource = animationManager.GetSource(i); - using var rippleBrush = new SKPaint { Color = new SKColor(255, 255, 255, (byte)(101 - (animationValue * 100))), IsAntialias = true }; + using var rippleBrush = new SKPaint + { + Color = new SKColor(255, 255, 255, (byte)(101 - (animationValue * 100))), + IsAntialias = true, + }; var rippleSize = (float)(animationValue * Width * 2.0); - var rippleRect = new SKRect(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize); + var rippleRect = new SKRect( + animationSource.X - rippleSize / 2, + animationSource.Y - rippleSize / 2, + rippleSize, + rippleSize + ); path.AddOval(rippleRect); canvas.DrawPath(path, rippleBrush); } } } - var foreColor = Color.ToSKColor() == SKColors.Transparent ? ColorScheme.ForeColor.ToSKColor() : ForeColor.ToSKColor(); + var foreColor = + Color.ToSKColor() == SKColors.Transparent ? ColorScheme.ForeColor.ToSKColor() : ForeColor.ToSKColor(); if (!Enabled) foreColor = ColorScheme.ForeColor.ToSKColor().WithAlpha(200); @@ -182,7 +194,15 @@ protected override void OnPaintSurface(SKPaintSurfaceEventArgs e) textRect.Offset(8 + 24 + 4, 0); } - using var textPaint = new SKPaint { Color = foreColor, IsAntialias = true, TextSize = 13.333f, HintingLevel = SKPaintHinting.Full, IsLinearText = true, TextAlign = SKTextAlign.Center }; + using var textPaint = new SKPaint + { + Color = foreColor, + IsAntialias = true, + TextSize = 13.333f, + HintingLevel = SKPaintHinting.Full, + IsLinearText = true, + TextAlign = SKTextAlign.Center, + }; DrawText(canvas, _text, textRect, textPaint); } @@ -201,7 +221,7 @@ private void DrawShadow(SKCanvas canvas, SKRect rect, float shadowDepth, float r { Color = new SKColor(0, 0, 0, 50), IsAntialias = true, - MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Outer, shadowDepth) + MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Outer, shadowDepth), }; rect.Offset(0, shadowDepth); @@ -227,4 +247,4 @@ public override Size GetPreferredSize(Size proposedSize) return new Size((int)Math.Ceiling(textSize.Width) + extra, 23); } -} \ No newline at end of file +} diff --git a/SDUI/SK/Extensions.cs b/SDUI/SK/Extensions.cs index adf10b4..1cb7f6e 100644 --- a/SDUI/SK/Extensions.cs +++ b/SDUI/SK/Extensions.cs @@ -1,5 +1,5 @@ -using SkiaSharp; -using System; +using System; +using SkiaSharp; public static class SkiaExtensions { @@ -83,8 +83,16 @@ public static System.Drawing.Bitmap ToBitmap(this SKImage skiaImage) { // TODO: maybe keep the same color types where we can, instead of just going to the platform default - var bitmap = new System.Drawing.Bitmap(skiaImage.Width, skiaImage.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); - var data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat); + var bitmap = new System.Drawing.Bitmap( + skiaImage.Width, + skiaImage.Height, + System.Drawing.Imaging.PixelFormat.Format32bppPArgb + ); + var data = bitmap.LockBits( + new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), + System.Drawing.Imaging.ImageLockMode.WriteOnly, + bitmap.PixelFormat + ); // copy using (var pixmap = new SKPixmap(new SKImageInfo(data.Width, data.Height), data.Scan0, data.Stride)) @@ -148,10 +156,18 @@ public static void ToSKPixmap(this System.Drawing.Bitmap bitmap, SKPixmap pixmap if (pixmap.ColorType == SKImageInfo.PlatformColorType) { var info = pixmap.Info; - using (var tempBitmap = new System.Drawing.Bitmap(info.Width, info.Height, info.RowBytes, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, pixmap.GetPixels())) + using ( + var tempBitmap = new System.Drawing.Bitmap( + info.Width, + info.Height, + info.RowBytes, + System.Drawing.Imaging.PixelFormat.Format32bppPArgb, + pixmap.GetPixels() + ) + ) using (var gr = System.Drawing.Graphics.FromImage(tempBitmap)) { - // Clear graphic to prevent display artifacts with transparent bitmaps + // Clear graphic to prevent display artifacts with transparent bitmaps gr.Clear(System.Drawing.Color.Transparent); gr.DrawImageUnscaled(bitmap, 0, 0); @@ -206,5 +222,4 @@ public static SKFont ToSKFont(this System.Drawing.Font drawingFont) return skFont; } - -} \ No newline at end of file +} diff --git a/SDUI/SK/ListView.cs b/SDUI/SK/ListView.cs index df69023..01aacee 100644 --- a/SDUI/SK/ListView.cs +++ b/SDUI/SK/ListView.cs @@ -1,10 +1,10 @@ -using SkiaSharp; -using System; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Timers; using System.Windows.Forms; +using SkiaSharp; namespace SDUI.SK; @@ -55,29 +55,32 @@ private void ElasticTimer_Tick(object sender, ElapsedEventArgs e) if (_horizontalScrollOffset < 0) { _horizontalScrollOffset *= ElasticDecay; - if (_horizontalScrollOffset > -1) _horizontalScrollOffset = 0; + if (_horizontalScrollOffset > -1) + _horizontalScrollOffset = 0; needsRefresh = true; } else if (_horizontalScrollOffset > Columns.Sum(c => c.Width) - Width) { - _horizontalScrollOffset -= (_horizontalScrollOffset - (Columns.Sum(c => c.Width) - Width)) * (1 - ElasticDecay); + _horizontalScrollOffset -= + (_horizontalScrollOffset - (Columns.Sum(c => c.Width) - Width)) * (1 - ElasticDecay); if (_horizontalScrollOffset < Columns.Sum(c => c.Width) - Width + 1) _horizontalScrollOffset = Columns.Sum(c => c.Width) - Width; needsRefresh = true; } - } // Vertical pull-back if (_verticalScrollOffset < 0) { _verticalScrollOffset *= ElasticDecay; - if (_verticalScrollOffset > -1) _verticalScrollOffset = 0; + if (_verticalScrollOffset > -1) + _verticalScrollOffset = 0; needsRefresh = true; } else if (_verticalScrollOffset > (Items.Count - maxVisibleRows) * rowBoundsHeight) { - _verticalScrollOffset -= (_verticalScrollOffset - (Items.Count - maxVisibleRows) * rowBoundsHeight) * (1 - ElasticDecay); + _verticalScrollOffset -= + (_verticalScrollOffset - (Items.Count - maxVisibleRows) * rowBoundsHeight) * (1 - ElasticDecay); if (_verticalScrollOffset < (Items.Count - maxVisibleRows) * rowBoundsHeight + 1) _verticalScrollOffset = (Items.Count - maxVisibleRows) * rowBoundsHeight; needsRefresh = true; @@ -111,7 +114,7 @@ private void DrawColumns(SKCanvas canvas) IsAntialias = true, Color = SKColors.LightGray, Style = SKPaintStyle.Stroke, - StrokeWidth = .5f + StrokeWidth = .5f, }; using var headerPaint = new SKPaint @@ -163,8 +166,12 @@ private void DrawGroups(SKCanvas canvas) rect.Location = new SKPoint(5, y + 8); rect.Size = new SKSize(16, 16); - groupPaint.Style = group.CollapsedState == ListViewGroupCollapsedState.Expanded ? SKPaintStyle.Fill : SKPaintStyle.Stroke; - groupPaint.Color = group.CollapsedState == ListViewGroupCollapsedState.Expanded ? SKColors.DarkSlateGray : SKColors.LightSlateGray; + groupPaint.Style = + group.CollapsedState == ListViewGroupCollapsedState.Expanded ? SKPaintStyle.Fill : SKPaintStyle.Stroke; + groupPaint.Color = + group.CollapsedState == ListViewGroupCollapsedState.Expanded + ? SKColors.DarkSlateGray + : SKColors.LightSlateGray; canvas.DrawRoundRect(rect, 4, 4, groupPaint); canvas.DrawText(group.Header, 25, y + 20, groupTextPaint); @@ -197,7 +204,7 @@ private void DrawRow(SKCanvas canvas, ListViewItem row, float y) IsAntialias = true, Color = SKColors.WhiteSmoke, Style = SKPaintStyle.Stroke, - StrokeWidth = 1f + StrokeWidth = 1f, }; paint.Color = row.Selected ? SKColors.WhiteSmoke : SKColors.White; @@ -226,7 +233,7 @@ private void DrawScrollBars(SKCanvas canvas) { IsAntialias = true, Color = SKColors.Silver, - Style = SKPaintStyle.StrokeAndFill + Style = SKPaintStyle.StrokeAndFill, }; // Horizontal ScrollBar @@ -242,7 +249,10 @@ private void DrawScrollBars(SKCanvas canvas) if (Items.Sum(r => rowBoundsHeight) > Height - 30) { float scrollbarHeight = (Height - 30) * ((Height - 30) / (float)Items.Sum(r => rowBoundsHeight)); - float scrollbarY = _verticalScrollOffset * ((Height - 30) - scrollbarHeight) / (Items.Sum(r => rowBoundsHeight) - (Height - 30)); + float scrollbarY = + _verticalScrollOffset + * ((Height - 30) - scrollbarHeight) + / (Items.Sum(r => rowBoundsHeight) - (Height - 30)); var rect = new SKRect(Width - 5, 35 + scrollbarY, Width - 15, 15 + scrollbarY + scrollbarHeight); canvas.DrawRoundRect(rect, 8, 8, paint); } @@ -255,7 +265,10 @@ protected override void OnMouseWheel(MouseEventArgs e) if ((ModifierKeys & Keys.Shift) == Keys.Shift) { - _horizontalScrollOffset = Math.Max(-Width / 4, Math.Min(_horizontalScrollOffset - delta * 30, Columns.Sum(c => c.Width) - Width + Width / 4)); + _horizontalScrollOffset = Math.Max( + -Width / 4, + Math.Min(_horizontalScrollOffset - delta * 30, Columns.Sum(c => c.Width) - Width + Width / 4) + ); } else { @@ -309,7 +322,10 @@ protected override void OnMouseDown(MouseEventArgs e) var groupRect = new SKRect(0, y, Width, y + rowBoundsHeight); if (groupRect.Contains(e.X, e.Y)) { - group.CollapsedState = group.CollapsedState == ListViewGroupCollapsedState.Expanded ? ListViewGroupCollapsedState.Collapsed : ListViewGroupCollapsedState.Expanded; + group.CollapsedState = + group.CollapsedState == ListViewGroupCollapsedState.Expanded + ? ListViewGroupCollapsedState.Collapsed + : ListViewGroupCollapsedState.Expanded; Invalidate(); return; @@ -381,11 +397,20 @@ protected override void OnMouseMove(MouseEventArgs e) int delta = _isVerticalScrollbar ? e.Y - _scrollbarDragStart.Y : e.X - _scrollbarDragStart.X; if (_isVerticalScrollbar) { - _verticalScrollOffset = Math.Max(-Height / 4, Math.Min(_verticalScrollOffset + delta * 3, Items.Sum(r => rowBoundsHeight) - Height + 30 + Height / 4)); + _verticalScrollOffset = Math.Max( + -Height / 4, + Math.Min( + _verticalScrollOffset + delta * 3, + Items.Sum(r => rowBoundsHeight) - Height + 30 + Height / 4 + ) + ); } else { - _horizontalScrollOffset = Math.Max(-Width / 4, Math.Min(_horizontalScrollOffset + delta * 3, Columns.Sum(c => c.Width) - Width + Width / 4)); + _horizontalScrollOffset = Math.Max( + -Width / 4, + Math.Min(_horizontalScrollOffset + delta * 3, Columns.Sum(c => c.Width) - Width + Width / 4) + ); } } _scrollbarDragStart = e.Location; @@ -421,4 +446,4 @@ protected override void OnMouseDoubleClick(MouseEventArgs e) x += Columns[i].Width; } } -} \ No newline at end of file +} diff --git a/SDUI/SK/SKControl.cs b/SDUI/SK/SKControl.cs index 798b110..03a82b1 100644 --- a/SDUI/SK/SKControl.cs +++ b/SDUI/SK/SKControl.cs @@ -1,9 +1,9 @@ -using SkiaSharp; -using System; +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; +using SkiaSharp; namespace SDUI.SK; @@ -12,9 +12,15 @@ public class SKControl : Control private readonly bool designMode; private Bitmap bitmap; + public SKControl() { - SetStyle(ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true); + SetStyle( + ControlStyles.ResizeRedraw + | ControlStyles.OptimizedDoubleBuffer + | ControlStyles.SupportsTransparentBackColor, + true + ); BackColor = Color.Transparent; DoubleBuffered = true; diff --git a/SDUI/SK/SKPaintSurfaceEventArgs.cs b/SDUI/SK/SKPaintSurfaceEventArgs.cs index d09b9cf..1adc252 100644 --- a/SDUI/SK/SKPaintSurfaceEventArgs.cs +++ b/SDUI/SK/SKPaintSurfaceEventArgs.cs @@ -6,4 +6,4 @@ public class SKPaintSurfaceEventArgs(SKSurface surface, SKImageInfo info) { public SKSurface Surface => surface; public SKImageInfo ImageInfo => info; -} \ No newline at end of file +}