aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/SkinEngine/WindowComposition.cs
diff options
context:
space:
mode:
authorMichaelTheShifter <[email protected]>2016-06-25 08:10:03 -0400
committerMichaelTheShifter <[email protected]>2016-06-25 08:10:03 -0400
commit84f689b91a73e512b035df40bbcf556b008a3b81 (patch)
treeda1020b2b5866c7ce300ac7b9c97112fe80fa1b3 /source/WindowsFormsApplication1/SkinEngine/WindowComposition.cs
parent6707e2076a63dafab686fd533c95fb8ceb6c23fa (diff)
downloadshiftos-c-_theultimatehacker-84f689b91a73e512b035df40bbcf556b008a3b81.tar.gz
shiftos-c-_theultimatehacker-84f689b91a73e512b035df40bbcf556b008a3b81.tar.bz2
shiftos-c-_theultimatehacker-84f689b91a73e512b035df40bbcf556b008a3b81.zip
Sort source code into folders.
It feels better to know what's responsible for what... Plus I removed some un-needed C# stuff.
Diffstat (limited to 'source/WindowsFormsApplication1/SkinEngine/WindowComposition.cs')
-rw-r--r--source/WindowsFormsApplication1/SkinEngine/WindowComposition.cs390
1 files changed, 390 insertions, 0 deletions
diff --git a/source/WindowsFormsApplication1/SkinEngine/WindowComposition.cs b/source/WindowsFormsApplication1/SkinEngine/WindowComposition.cs
new file mode 100644
index 0000000..18fe2d1
--- /dev/null
+++ b/source/WindowsFormsApplication1/SkinEngine/WindowComposition.cs
@@ -0,0 +1,390 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ShiftOS
+{
+ public class WindowComposition
+ {
+ private static bool _CanClose = true;
+ public static bool ShuttingDown = false;
+ public static bool SafeToAddControls = true;
+
+ public static bool CanClose
+ {
+ get
+ {
+ return _CanClose;
+ }
+ }
+
+ public static void WindowsEverywhere(Form formToInfect)
+ {
+ var t = new Timer();
+ t.Interval = 100;
+ int yvel = 1;
+ int xvel = 1;
+ t.Tick += (object s, EventArgs a) =>
+ {
+ if (Viruses.InfectedWith("windowseverywhere"))
+ {
+ formToInfect.Left += xvel * 10;
+ formToInfect.Top += yvel * 10;
+
+ if (formToInfect.Top >= API.CurrentSession.Height - formToInfect.Height)
+ {
+ yvel = -1;
+ }
+ if (formToInfect.Top <= 0)
+ {
+ yvel = 1;
+ }
+ if (formToInfect.Left >= API.CurrentSession.Width - formToInfect.Width)
+ {
+ xvel = -1;
+ }
+ if (formToInfect.Left <= 0)
+ {
+ xvel = 1;
+ }
+ }
+ };
+ t.Start();
+ }
+
+ public static void ScaleWidget(Control ctrl, int width, int height)
+ {
+ ctrl.Size = new Size(0, 0);
+ var t = new Timer();
+ t.Interval = 25;
+ t.Tick += (object s, EventArgs a) =>
+ {
+ if(ctrl.Width <= width)
+ {
+
+ }
+ };
+ }
+
+ public static void ShowForm(Form formToShow, WindowAnimationStyle style)
+ {
+ var t = new Timer();
+ switch(style)
+ {
+ case WindowAnimationStyle.Fade:
+ var bw = new BackgroundWorker();
+ bw.DoWork += (object se, DoWorkEventArgs ea) =>
+ {
+ //The form's handle has not been created so we just invoke
+ //the action on the desktop thread.
+ API.CurrentSession.Invoke(new Action(() =>
+ {
+ try {
+ formToShow.Opacity = 0;
+ formToShow.Show();
+ formToShow.Left = (Screen.PrimaryScreen.Bounds.Width - formToShow.Width) / 2;
+ formToShow.Top = (Screen.PrimaryScreen.Bounds.Height - formToShow.Height) / 2;
+ }
+ catch
+ {
+
+ }
+ }));
+ t.Interval = API.CurrentSkin.WindowFadeTime;
+ t.Tick += (object s, EventArgs a) =>
+ {
+ if (API.Upgrades["fancyeffects"] == true)
+ {
+ API.CurrentSession.Invoke(new Action(() =>
+ {
+
+ if (formToShow.Opacity < 1)
+ {
+ formToShow.Opacity += Convert.ToDouble(API.CurrentSkin.WindowFadeSpeed);
+ formToShow.Refresh();
+
+ }
+ else
+ {
+ t.Stop();
+ }
+ }));
+ }
+ else
+ {
+ API.CurrentSession.Invoke(new Action(() =>
+ {
+ formToShow.Opacity = 1;
+ }));
+ }
+ };
+ API.CurrentSession.Invoke(new Action(() =>
+ {
+ t.Start();
+ }));
+ };
+ bw.RunWorkerAsync();
+ break;
+ default:
+ var bwork = new BackgroundWorker();
+ bwork.DoWork += (object s, DoWorkEventArgs a) =>
+ {
+ API.CurrentSession.Invoke(new Action(() =>
+ {
+ formToShow.Show();
+ formToShow.Left = (Screen.PrimaryScreen.Bounds.Width - formToShow.Width) / 2;
+ formToShow.Top = (Screen.PrimaryScreen.Bounds.Height - formToShow.Height) / 2;
+
+ formToShow.Show();
+ }));
+
+ };
+ bwork.RunWorkerAsync();
+ break;
+
+ }
+ }
+
+ public static void CloseForm(Form formToClose, PanelButton pbtn, WindowAnimationStyle style)
+ {
+ var t = new Timer();
+ switch(style)
+ {
+ case WindowAnimationStyle.Fade:
+ _CanClose = false;
+ t.Interval = API.CurrentSkin.WindowFadeTime;
+ t.Tick += (object s, EventArgs a) =>
+ {
+ if (API.Upgrades["fancyeffects"] == true)
+ {
+ try
+ {
+
+ if (formToClose.Opacity > 0)
+ {
+ formToClose.Invoke(new Action(() =>
+ {
+ formToClose.Opacity -= Convert.ToDouble(API.CurrentSkin.WindowFadeSpeed);
+ formToClose.Refresh();
+ }));
+ }
+ else
+ {
+ API.PanelButtons.Remove(pbtn);
+ API.CurrentSession.SetupPanelButtons();
+ API.UpdateWindows();
+ formToClose.Dispose();
+ t.Stop();
+ }
+ }
+ catch
+ {
+ formToClose = null;
+ }
+ }
+ else
+ {
+ API.PanelButtons.Remove(pbtn);
+ API.CurrentSession.SetupPanelButtons();
+ API.UpdateWindows();
+ formToClose.Dispose();
+ t.Stop();
+
+ }
+ };
+ t.Start();
+ break;
+ case WindowAnimationStyle.Zoom:
+ _CanClose = false;
+ t.Interval = 1;
+ int w = formToClose.Width;
+ int h = formToClose.Height;
+ int maxw = w / 2;
+ int maxh = h / 2;
+ t.Tick += (object s, EventArgs a) =>
+ {
+ if (API.Upgrades["fancyeffects"] == true)
+ {
+ formToClose.MinimumSize = new Size(maxw, maxh);
+ formToClose.Opacity -= 0.1;
+ formToClose.Left += 50;
+ formToClose.Top += 50;
+
+ formToClose.Width -= 50;
+ formToClose.Height -= 50;
+ if (formToClose.Size == formToClose.MinimumSize)
+ {
+ API.PanelButtons.Remove(pbtn);
+ API.CurrentSession.SetupPanelButtons();
+ API.UpdateWindows();
+ formToClose.Dispose();
+ t.Stop();
+ }
+ }
+ else
+ {
+ API.PanelButtons.Remove(pbtn);
+ API.CurrentSession.SetupPanelButtons();
+ API.UpdateWindows();
+ formToClose.Dispose();
+ t.Stop();
+
+ }
+ };
+ t.Start();
+ break;
+ case WindowAnimationStyle.ToAppLauncher:
+ _CanClose = false;
+ t.Interval = 1;
+ int w2 = formToClose.Width;
+ int h2 = formToClose.Height;
+ int maxw2 = w2 / 2;
+ int maxh2 = h2 / 2;
+ t.Tick += (object s, EventArgs a) =>
+ {
+ formToClose.MinimumSize = new Size(maxw2, maxh2);
+ formToClose.Opacity -= 0.1;
+ if (API.Upgrades["fancyeffects"] == true)
+ {
+ switch (API.CurrentSkin.desktoppanelposition)
+ {
+ case "Bottom":
+ formToClose.Left += 50;
+ formToClose.Top += 50;
+ break;
+ case "Top":
+ formToClose.Left -= 50;
+ formToClose.Top -= 50;
+ break;
+
+ }
+
+ formToClose.Width -= 50;
+ formToClose.Height -= 50;
+ if (formToClose.Size == formToClose.MinimumSize)
+ {
+ API.PanelButtons.Remove(pbtn);
+ API.CurrentSession.SetupPanelButtons();
+ API.UpdateWindows();
+ formToClose.Dispose();
+ t.Stop();
+ }
+ }
+ else
+ {
+ API.PanelButtons.Remove(pbtn);
+ API.CurrentSession.SetupPanelButtons();
+ API.UpdateWindows();
+ formToClose.Dispose();
+ t.Stop();
+
+ }
+ };
+ t.Start();
+ break;
+ default:
+ API.PanelButtons.Remove(pbtn);
+ API.CurrentSession.SetupPanelButtons();
+ API.UpdateWindows();
+ formToClose.Dispose();
+ //Room for more animations, but just close the form if none is selected.
+ break;
+ }
+ }
+
+ public static void AnimateDragWindow(Form form, WindowDragEffect effect, bool Dragging)
+ {
+ var t = new Timer();
+ switch(effect)
+ {
+ case WindowDragEffect.Fade:
+ t.Interval = API.CurrentSkin.DragFadeInterval;
+ t.Tick += (object s, EventArgs a) =>
+ {
+ if (API.Upgrades["fancyeffects"] == true)
+ {
+ if (Dragging == true)
+ {
+ if (form.Opacity >= API.CurrentSkin.DragFadeLevel)
+ {
+ form.Opacity -= API.CurrentSkin.DragFadeSpeed;
+ }
+ else
+ {
+ t.Stop();
+ }
+ }
+ else
+ {
+ if (form.Opacity < 1)
+ {
+ form.Opacity += API.CurrentSkin.DragFadeSpeed;
+ }
+ else
+ {
+ t.Stop();
+ }
+ }
+ }
+ };
+ t.Start();
+ break;
+
+ }
+ }
+
+ public static void AnimateDragWindow(Form form, WindowDragEffect effect, bool Dragging, int MouseX, int MouseY)
+ {
+ var t = new Timer();
+ switch(effect)
+ {
+
+ case WindowDragEffect.Shake:
+ Shake(form, MouseX, MouseY);
+ break;
+ }
+ }
+
+ //Copyright - Adonis S. Deliannis
+ public static void Shake(Form form, int mouseX, int mouseY)
+ {
+ Point mouse = form.PointToScreen(new Point(mouseX, mouseY));
+ int xDist = mouse.X - form.Location.X;
+ int yDist = mouse.Y - form. Location.Y;
+ int X = xDist;
+ int Y = yDist;
+ Random r = new Random();
+ int JiggleCount = 0;
+ int Z = 15;
+
+ while (JiggleCount < 1000)
+ {
+ form.Location = new Point(r.Next(X - Z, X + Z), r.Next(Y - Z, Y + Z));
+ JiggleCount++;
+ }
+
+ JiggleCount = 0;
+ form.Location = new Point(X, Y);
+ }
+ }
+
+ public enum WindowAnimationStyle
+ {
+ Fade,
+ Default,
+ Zoom,
+ ToAppLauncher
+ }
+
+ public enum WindowDragEffect
+ {
+ Fade,
+ Default,
+ Shake
+ }
+}