forked from Adrianotiger/desktopPet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
317 lines (277 loc) · 10.4 KB
/
Form1.cs
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
using DesktopPet;
using System;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace desktopPet
{
public partial class Form1 : Form
{
public const int MAX_SHEEPS = 64;
public enum DEBUG_TYPE
{
info = 1,
warning = 2,
error = 3,
}
Form2[] sheeps = new Form2[MAX_SHEEPS];
static FormDebug debug = null;
int iSheeps = 0;
Xml xml;
Animations animations;
public Form1()
{
InitializeComponent();
FormBorderStyle = FormBorderStyle.None;
xml = new Xml();
animations = new Animations(xml);
}
private void Form1_Load(object sender, EventArgs e)
{
Keys ks = ModifierKeys;
if (ks == Keys.Shift)
{
debug = new FormDebug();
debug.Show();
AddDebugInfo(DEBUG_TYPE.info, "debug window started");
}
xml.readXML();
timer1.Tag = "A";
timer1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (iSheeps < MAX_SHEEPS)
{
int iXSize = pictureBox1.Image.Width / xml.images.xImages;
int iYSize = pictureBox1.Image.Height / xml.images.yImages;
Bitmap bmpOriginal = new Bitmap(xml.images.bitmapImages);
sheeps[iSheeps] = new Form2(animations, xml);
sheeps[iSheeps].Show(iXSize, iYSize);
/*
Width = 900;
Top = 0;
Left = 0;
Height = 600;
Visible = true;
pictureBox1.Width = 640;
pictureBox1.Height = 440;
FormBorderStyle = FormBorderStyle.Sizable;
BackColor = Color.White;
Thread.Sleep(2000);
*/
AddDebugInfo(DEBUG_TYPE.info, "new pet...");
for (int i = 0; i < xml.images.xImages * xml.images.yImages; i++)
{
Rectangle cropArea = new Rectangle(0 + iXSize * (i % xml.images.xImages), 0 + iYSize * (i / xml.images.xImages), iXSize, iYSize);
Bitmap bmpImage = new Bitmap(iXSize, iYSize, bmpOriginal.PixelFormat);
using (Graphics graphics = Graphics.FromImage(bmpImage))
{
Rectangle destRectangle = new Rectangle(0, 0, iXSize, iYSize);
Rectangle sourceRectangle = new Rectangle(0 + iXSize * (i % xml.images.xImages), 0 + iYSize * (i / xml.images.xImages), iXSize, iYSize);
graphics.DrawImage(bmpOriginal, destRectangle, sourceRectangle, GraphicsUnit.Pixel);
}
sheeps[iSheeps].addImage(bmpImage);
}
AddDebugInfo(DEBUG_TYPE.info, (xml.images.xImages * xml.images.yImages).ToString() + " frames added");
sheeps[iSheeps].Play(true);
iSheeps++;
}
else
{
AddDebugInfo(DEBUG_TYPE.warning, "max PETs reached");
}
}
private void pictureBox2_MouseClick(object sender, MouseEventArgs e)
{
if (e.Y < Height / 3)
{
DialogResult res;
AddDebugInfo(DEBUG_TYPE.info, "Info pressed");
do
{
res = MessageBox.Show("Application Version 1.0 (beta 0.5)\nAdriano Petrucci\n____________________________\nAnimation pack from: " + xml.headerInfo.Author + "\nInfo: " + xml.headerInfo.Info + "\nVersion: " + xml.headerInfo.Version, xml.headerInfo.Title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
if (res == DialogResult.Retry)
{
button1_Click(sender, e);
}
else if (res == DialogResult.Abort)
{
for (int i = 0; i < iSheeps; i++)
{
sheeps[i].Sync();
}
}
} while (res == DialogResult.Retry);
}
else if (e.X < Width / 2)
{
AddDebugInfo(DEBUG_TYPE.info, "new pet pressed");
button1_Click(sender, e);
}
else
{
AddDebugInfo(DEBUG_TYPE.info, "exit application pressed");
timer1.Tag = "0";
timer1.Interval = 1200;
timer1.Enabled = true;
Opacity = 0.0;
for (int i = 0; i < iSheeps; i++)
{
sheeps[i].Kill();
}
}
}
private void pictureBox2_MouseEnter(object sender, EventArgs e)
{
if (Opacity > 0.1)
{
Opacity = 1.0;
button2.Visible = true;
}
}
private void pictureBox2_MouseLeave(object sender, EventArgs e)
{
if (Opacity > 0.8)
{
Opacity = 0.8;
new Thread(new ThreadStart(() =>
{
Thread.Sleep(1200);
try
{
Invoke(new Action(() => { if (Opacity < 1.0) button2.Visible = false; }));
}
catch (Exception) { }
})).Start();
}
}
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
string sDesc;
string sTitle;
if (e.Y < Height / 3)
{
sTitle = "Info";
toolTip1.ToolTipIcon = ToolTipIcon.Info;
sDesc = "Info about this application";
}
else if (e.X < Width / 2)
{
sTitle = "More";
toolTip1.ToolTipIcon = ToolTipIcon.None;
sDesc = "Add another one to \n your desktop";
}
else
{
sTitle = "Kill all";
toolTip1.ToolTipIcon = ToolTipIcon.Warning;
sDesc = "Close application and \n clean desktop";
}
if (toolTip1.ToolTipTitle != sTitle)
{
toolTip1.ToolTipTitle = sTitle;
toolTip1.SetToolTip(pictureBox2, sDesc);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (timer1.Tag.ToString() == "A")
{
timer1.Enabled = false;
timer1.Tag = "B";
AddDebugInfo(DEBUG_TYPE.info, "init application...");
// Set images
pictureBox2.Image = new Bitmap(xml.bitmapHome);
pictureBox2.Width = pictureBox2.Image.Width;
pictureBox2.Height = pictureBox2.Image.Height;
Width = pictureBox2.Width;
Height = pictureBox2.Height;
pictureBox1.Image = new Bitmap(xml.images.bitmapImages);
Icon = new Icon(xml.bitmapIcon);
// Set info texts
toolTip1.SetToolTip(pictureBox2, xml.headerInfo.Title);
// set home position
Top = Screen.PrimaryScreen.WorkingArea.Height - Height;
Left = Screen.PrimaryScreen.WorkingArea.Width - Width - 50;
xml.loadAnimations(animations);
button2.Visible = false;
Opacity = 1.0;
button1_Click(sender, e);
}
else if (timer1.Tag.ToString() == "0")
{
timer1.Tag = "1";
}
else
{
Close();
}
}
private void pictureBox2_Click(object sender, EventArgs e)
{
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
AddDebugInfo(DEBUG_TYPE.info, "dragging file...");
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
AddDebugInfo(DEBUG_TYPE.info, "files dragged:");
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
AddDebugInfo(DEBUG_TYPE.info, file);
for(int i=0;i<iSheeps;i++)
{
sheeps[i].Close();
sheeps[i].Dispose();
}
iSheeps = 0;
xml = new Xml();
animations = new Animations(xml);
DesktopPet.Properties.Settings.Default.xml = File.ReadAllText(file);
DesktopPet.Properties.Settings.Default.Save();
xml.readXML();
timer1.Tag = "A";
timer1.Enabled = true;
break;
}
}
public static void AddDebugInfo(DEBUG_TYPE type, string text)
{
if(debug != null)
{
debug.AddDebugInfo(type, text);
}
}
private void button2_Click(object sender, EventArgs e)
{
FormOptions formoptions = new FormOptions();
switch(formoptions.ShowDialog())
{
case DialogResult.Retry:
AddDebugInfo(DEBUG_TYPE.warning, "restoring default XML");
for (int i = 0; i < iSheeps; i++)
{
sheeps[i].Close();
sheeps[i].Dispose();
}
iSheeps = 0;
xml = new Xml();
animations = new Animations(xml);
DesktopPet.Properties.Settings.Default.xml = "";
DesktopPet.Properties.Settings.Default.Home = "";
DesktopPet.Properties.Settings.Default.Icon = "";
DesktopPet.Properties.Settings.Default.Images = "";
DesktopPet.Properties.Settings.Default.Save();
xml.readXML();
timer1.Tag = "A";
timer1.Enabled = true;
break;
}
}
}
}