From 6b7b965d82896a0454812603ec89bf76963e8157 Mon Sep 17 00:00:00 2001
From: Markus Palme <MarkusPalme@gmx.de>
Date: Sat, 28 Oct 2006 16:04:32 +0000
Subject: [PATCH] added spinner control to widgets library

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1987 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
---
 .../ICSharpCode.SharpDevelop.Widgets.csproj   |  1 +
 .../Project/SpinnerControl.cs                 | 92 +++++++++++++++++++
 2 files changed, 93 insertions(+)
 create mode 100644 src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SpinnerControl.cs

diff --git a/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj b/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj
index ba21d34502..5247a67087 100644
--- a/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj
+++ b/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj
@@ -63,6 +63,7 @@
     <Compile Include="SideBar\SideBar.cs" />
     <Compile Include="SideBar\SideTab.cs" />
     <Compile Include="SideBar\SideTabItem.cs" />
+    <Compile Include="SpinnerControl.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Configuration" />
diff --git a/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SpinnerControl.cs b/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SpinnerControl.cs
new file mode 100644
index 0000000000..3ac0b993dd
--- /dev/null
+++ b/src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SpinnerControl.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Windows.Forms;
+using System.Drawing;
+
+namespace ICSharpCode.SharpDevelop.Widgets
+{
+	public class SpinnerControl : UserControl
+	{
+		private int lines   = 8;
+		private int current = 0;
+        private Timer timer;
+
+		public SpinnerControl()
+		{
+            SetStyle(ControlStyles.UserPaint, true);
+            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
+            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
+		}
+
+		public int Lines
+        {
+			get
+            {
+                return lines;
+            }
+			set
+            {
+				this.lines = value;
+			}
+		}
+
+		public void Start()
+		{
+			timer = new Timer();
+            timer.Interval = 100;
+            timer.Tick += new EventHandler(timer_Tick);
+            timer.Start();
+		}
+
+        void timer_Tick(object sender, EventArgs e)
+        {
+            if (this.current >= this.lines - 1)
+            {
+                this.current = 0;
+            }
+            else
+            {
+                this.current++;
+            }
+            Invalidate();
+        }
+
+		public void Stop ()
+		{
+            timer.Stop();
+		}
+
+        protected override void OnPaint(PaintEventArgs e)
+        {
+            double x, y;
+            double radius;
+            double half;
+            int i;
+
+            x = Width / 2;
+            y = Height / 2;
+            radius = Math.Min(Width / 2, Height / 2) - 5;
+            half = lines / 2;
+
+            for (i = 0; i < lines; i++)
+            {
+                double inset = 0.7 * radius;
+                double t = (double)((i + lines - current) % lines) / lines;
+
+                Color c = Color.FromArgb((int)(t * 255), 0, 0, 0);
+                Pen pen = new Pen(c);
+                pen.Width = 2;
+
+                PointF start = new PointF((float)(x + (radius - inset) * Math.Cos(i * Math.PI / half)),
+                           (float)(y + (radius - inset) * Math.Sin(i * Math.PI / half)));
+
+                PointF end = new PointF((float)(x + radius * Math.Cos(i * Math.PI / half)),
+                           (float)(y + radius * Math.Sin(i * Math.PI / half)));
+
+                e.Graphics.DrawLine(pen, start, end);
+                pen.Dispose();
+            }
+
+            base.OnPaint(e);
+        }
+	}
+}