aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/WindowComposition.cs
blob: 0e5a5d4a09e651bf3f367c859d1c8e31890bc789 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
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 (Exception ex)
                            {
                                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;
                    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:
                    var rnd = new Random();
                    int xOffset = 0;
                    int yOffset = 0;

                    xOffset = rnd.Next(API.CurrentSkin.ShakeMinOffset, API.CurrentSkin.ShakeMaxOffset);
                    yOffset = rnd.Next(API.CurrentSkin.ShakeMinOffset, API.CurrentSkin.ShakeMaxOffset);
                    int leftright = rnd.Next(0, 1);
                    if (API.Upgrades["fancyeffects"] == true)
                    {
                        form.Left += MouseX * xOffset;
                        form.Top += MouseY * yOffset;
                    }
                    else
                    {
                        form.Left += MouseX;
                        form.Top += MouseY;
                    }
                   
                    break;
            }
        }
    }

    public enum WindowAnimationStyle
    {
        Fade,
        Default,
        Zoom,
        ToAppLauncher
    }

    public enum WindowDragEffect
    {
        Fade,
        Default,
        Shake
    }
}