forked from IcySon55/OPL-Theme-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
783 lines (680 loc) · 21.9 KB
/
Main.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
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using OPL_Theme_Editor.Properties;
namespace OPL_Theme_Editor
{
public partial class frmMain : Form
{
private Theme _theme = null;
private bool _fileOpen = false;
private bool _hasChanges = false;
private FileInfo _openFile = null;
private bool _imported = false;
private Control _selected = null;
private enum Tabs
{
General,
Database,
Class,
List,
Form,
Validation
}
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
// Load Settings
Text = Settings.Default.ApplicationName;
Icon = Resources.ps2;
WindowState = Settings.Default.Maximized ? FormWindowState.Maximized : FormWindowState.Normal;
if (Settings.Default.WindowLocation != null)
Location = Settings.Default.WindowLocation;
PopulateRecentlyOpenedFiles();
}
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
// Save Settings
Settings.Default.Maximized = WindowState == FormWindowState.Maximized;
Settings.Default.WindowLocation = Location;
Settings.Default.Save();
}
private void DoubleBuffer(DataGridView dgv, bool doubleBuffered)
{
dgv.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(dgv, doubleBuffered, null);
}
private void PopulateRecentlyOpenedFiles()
{
if (Settings.Default.RecentlyOpenedFiles == null)
Settings.Default.RecentlyOpenedFiles = new System.Collections.Specialized.StringCollection();
while (Settings.Default.RecentlyOpenedFiles.Count > 10)
Settings.Default.RecentlyOpenedFiles.RemoveAt(Settings.Default.RecentlyOpenedFiles.Count - 1);
tsbOpen.DropDownItems.Clear();
tsmRecent.DropDownItems.Clear();
for (int i = 0; i < Settings.Default.RecentlyOpenedFiles.Count; i++)
{
string rof = Settings.Default.RecentlyOpenedFiles[i];
string index = (i + 1).ToString();
string shortcut = "D" + index.Substring(index.Length - 1, 1);
ToolStripMenuItem itemMenuBar = new ToolStripMenuItem();
itemMenuBar.Name = "recentlyOpenedFileMenu" + i;
itemMenuBar.Text = index + " " + PathUtil.CompactPathFromLeft(rof, 48);
itemMenuBar.Click += new EventHandler(tsmRecentFile_Click);
itemMenuBar.Tag = rof;
itemMenuBar.ShortcutKeys = Keys.Alt ^ (Keys)Enum.Parse(typeof(Keys), shortcut);
tsmRecent.DropDownItems.Add(itemMenuBar);
ToolStripMenuItem itemToolStrip = new ToolStripMenuItem();
itemToolStrip.Name = "recentlyOpenedFileButton" + i;
itemToolStrip.Text = index + " " + PathUtil.CompactPathFromLeft(rof, 48);
itemToolStrip.Click += new EventHandler(tsmRecentFile_Click);
itemToolStrip.Tag = rof;
itemToolStrip.ShortcutKeys = Keys.Alt ^ (Keys)Enum.Parse(typeof(Keys), shortcut);
tsbOpen.DropDownItems.Add(itemToolStrip);
}
if (Settings.Default.RecentlyOpenedFiles.Count == 0)
{
ToolStripMenuItem itemMenuBar = new ToolStripMenuItem();
itemMenuBar.Name = "recentlyOpenedFileMenuNone";
itemMenuBar.Text = "No recently opened files...";
itemMenuBar.Click += new EventHandler(tsmRecentFile_Click);
itemMenuBar.Enabled = false;
tsmRecent.DropDownItems.Add(itemMenuBar);
ToolStripMenuItem itemToolStrip = new ToolStripMenuItem();
itemToolStrip.Name = "recentlyOpenedFileButtonNone";
itemToolStrip.Text = "No recently opened files...";
itemToolStrip.Click += new EventHandler(tsmRecentFile_Click);
itemToolStrip.Enabled = false;
tsbOpen.DropDownItems.Add(itemToolStrip);
}
Settings.Default.Save();
}
#region Menu and Toolbar
// New
private void tsmNew_Click(object sender, EventArgs e)
{
ConfirmNew();
}
private void tsbNew_Click(object sender, EventArgs e)
{
tsmNew_Click(sender, e);
}
// Open
private void tsmOpen_Click(object sender, EventArgs e)
{
ConfirmOpen();
}
private void tsbOpen_Click(object sender, EventArgs e)
{
tsmOpen_Click(sender, e);
}
private void tsmRecentFile_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
OpenTheme((string)item.Tag);
}
// Import
private void tsmImport_Click(object sender, EventArgs e)
{
ConfirmImport();
}
private void tsbImport_Click(object sender, EventArgs e)
{
tsmImport_Click(sender, e);
}
// Save
private void tsmSave_Click(object sender, EventArgs e)
{
SaveTheme();
}
private void tsbSave_Click(object sender, EventArgs e)
{
tsmSave_Click(sender, e);
}
// Save As
private void tsmSaveAs_Click(object sender, EventArgs e)
{
SaveTheme(true);
}
private void tsbSaveAs_Click(object sender, EventArgs e)
{
tsmSaveAs_Click(sender, e);
}
// Add
private void tsmAdd_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
private void tsbAdd_Click(object sender, EventArgs e)
{
tsmAdd_Click(sender, e);
}
// Delete
private void tsmDelete_Click(object sender, EventArgs e)
{
UpdateForm();
}
private void tsbDelete_Click(object sender, EventArgs e)
{
tsmDelete_Click(sender, e);
}
// Properties
// About
private void tsmAbout_Click(object sender, EventArgs e)
{
frmAbout about = new frmAbout();
about.ShowDialog();
}
private void tsbAbout_Click(object sender, EventArgs e)
{
tsmAbout_Click(sender, e);
}
// Exit
private void tsmExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
#endregion
private void ConfirmNew()
{
DialogResult dr = DialogResult.No;
if (_fileOpen && _hasChanges)
{
dr = MessageBox.Show("You have unsaved changes in " + FileName() + ". Save changes before creating a new theme?", "Unsaved Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
}
switch (dr)
{
case DialogResult.Yes:
dr = SaveTheme();
if (dr == DialogResult.OK) NewTheme();
break;
case DialogResult.No:
NewTheme();
break;
case DialogResult.Cancel:
break;
}
}
private void ConfirmOpen()
{
DialogResult dr = DialogResult.No;
if (_fileOpen && _hasChanges)
{
dr = MessageBox.Show("You have unsaved changes in " + FileName() + ". Save changes before opening another theme?", "Unsaved Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
}
switch (dr)
{
case DialogResult.Yes:
dr = SaveTheme();
if (dr == DialogResult.OK) OpenTheme();
break;
case DialogResult.No:
OpenTheme();
break;
case DialogResult.Cancel:
break;
}
}
private void ConfirmImport()
{
DialogResult dr = DialogResult.No;
if (_fileOpen && _hasChanges)
{
dr = MessageBox.Show("You have unsaved changes in " + FileName() + ". Save changes before opening another theme?", "Unsaved Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
}
switch (dr)
{
case DialogResult.Yes:
dr = SaveTheme();
if (dr == DialogResult.OK) ImportTheme();
break;
case DialogResult.No:
ImportTheme();
break;
case DialogResult.Cancel:
break;
}
}
private void NewTheme()
{
_openFile = null;
_theme = new Theme();
_fileOpen = true;
_hasChanges = false;
LoadTheme();
UpdateForm();
}
private void OpenTheme(string filename = "")
{
ofdOpen.InitialDirectory = Settings.Default.InitialDirectory;
ofdOpen.Filter = "XML Themes|*.thm|All Files|*.*";
string path = filename;
DialogResult dr = DialogResult.OK;
if (filename == string.Empty)
{
dr = ofdOpen.ShowDialog();
path = ofdOpen.FileName;
}
if (dr == DialogResult.OK)
{
try
{
if (!File.Exists(path))
throw new FileNotFoundException(path + " was not found.", path);
_openFile = new FileInfo(path);
_theme = Theme.Load(_openFile.FullName);
_fileOpen = true;
_hasChanges = false;
// Recently Opened Files
if (!Settings.Default.RecentlyOpenedFiles.Contains(_openFile.FullName))
{
Settings.Default.RecentlyOpenedFiles.Insert(0, _openFile.FullName);
}
else
{
Settings.Default.RecentlyOpenedFiles.Remove(_openFile.FullName);
Settings.Default.RecentlyOpenedFiles.Insert(0, _openFile.FullName);
}
Settings.Default.InitialDirectory = new DirectoryInfo(_openFile.FullName).FullName;
PopulateRecentlyOpenedFiles();
LoadTheme();
}
catch (FileNotFoundException)
{
if (Settings.Default.RecentlyOpenedFiles.Contains(path))
{
Settings.Default.RecentlyOpenedFiles.Remove(path);
PopulateRecentlyOpenedFiles();
MessageBox.Show(path + " no longer exists and has been removed from the Recently Opened Files list.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception)
{
_fileOpen = false;
_hasChanges = false;
}
finally
{
UpdateForm();
}
}
}
private DialogResult ImportTheme(string filename = "")
{
ofdOpen.InitialDirectory = Settings.Default.InitialDirectory;
ofdOpen.Filter = "CFG Themes|*.cfg|All Files|*.*";
string path = filename;
DialogResult dr = DialogResult.OK;
if (filename == string.Empty)
{
dr = ofdOpen.ShowDialog();
path = ofdOpen.FileName;
}
if (dr == DialogResult.OK)
{
try
{
if (!File.Exists(path))
throw new FileNotFoundException(path + " was not found.", path);
using (StreamReader sr = new StreamReader(File.OpenRead(path), Encoding.UTF8))
{
Theme theme = new Theme();
string colonValue = "(?<=.*:).*";
string equalValue = "(?<=.*=).*";
bool inItem = false;
Item item = new Item();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.StartsWith("#"))
{
if (!inItem)
{
if (line.StartsWith("# Theme Name:") || line.StartsWith("# Name:"))
theme.Name = Regex.Match(line, colonValue).Value.Trim();
else if (line.StartsWith("# Author:"))
theme.Author = Regex.Match(line, colonValue).Value.Trim();
else if (line.StartsWith("# Version:"))
theme.Version = Regex.Match(line, colonValue).Value.Trim();
else if (line.StartsWith("# Site:"))
theme.Site = Regex.Match(line, colonValue).Value.Trim();
else
theme.Notes += line.TrimStart('#').Trim() + "\r\n";
}
else
{
// Item Comments
item.Comment += line.TrimStart('#').Trim() + "\r\n";
}
}
// Theme Settings
else if (line.StartsWith("bg_color="))
theme.BackgroundColor = Regex.Match(line, equalValue).Value.Trim();
else if (line.StartsWith("sel_text_color="))
theme.BackgroundColor = Regex.Match(line, equalValue).Value.Trim();
else if (line.StartsWith("settings_text_color="))
theme.BackgroundColor = Regex.Match(line, equalValue).Value.Trim();
else if (line.StartsWith("text_color="))
theme.BackgroundColor = Regex.Match(line, equalValue).Value.Trim();
else if (line.StartsWith("ui_text_color="))
theme.BackgroundColor = Regex.Match(line, equalValue).Value.Trim();
else if (line.StartsWith("default_font="))
theme.BackgroundColor = Regex.Match(line, equalValue).Value.Trim();
// Page
else if (line.StartsWith("main"))
{
item = new Item();
theme.MainItems.Add(item);
inItem = true;
}
else if (line.StartsWith("info"))
{
item = new Item();
theme.InfoItems.Add(item);
inItem = true;
}
else if (line.Trim().StartsWith("type"))
{
ItemType type = ItemType.Background;
Enum.TryParse<ItemType>(Regex.Match(line, equalValue).Value.Trim(), out type);
item.Type = type;
}
else if (line.Trim().StartsWith("x"))
item.X = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("y"))
item.Y = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("width"))
item.Height = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("height"))
item.Width = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("attribute"))
item.Attribute = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("pattern"))
item.Pattern = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("default"))
item.DefaultImage = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("color"))
item.Color = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("aligned"))
item.Aligned = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("display"))
item.Display = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay="))
item.Overlay.Image = Regex.Match(line, equalValue).Value.Trim();
else if (line.Trim().StartsWith("overlay_ulx"))
item.Overlay.UpperLeftX = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay_uly"))
item.Overlay.UpperLeftY = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay_urx"))
item.Overlay.UpperRightX = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay_ury"))
item.Overlay.UpperRightY = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay_llx"))
item.Overlay.LowerLeftX = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay_lly"))
item.Overlay.LowerLeftY = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay_lrx"))
item.Overlay.LowerRightX = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
else if (line.Trim().StartsWith("overlay_lry"))
item.Overlay.LowerRightY = Int32.Parse(Regex.Match(line, equalValue).Value.Trim());
}
_openFile = new FileInfo(path);
_imported = true;
_theme = theme;
_fileOpen = true;
_hasChanges = false;
// Clean up negative values
foreach (Item itm in theme.MainItems)
{
int temp = 0;
switch(itm.Type)
{
case ItemType.LoadingIcon:
Image img = Image.FromFile(_openFile.DirectoryName + @"\load0.png");
if (Int32.TryParse(itm.X, out temp))
if (temp < 0)
itm.X = (pnlMain.Width + temp - img.Width).ToString();
if (Int32.TryParse(itm.Y, out temp))
if (temp < 0)
itm.Y = (pnlMain.Height + temp - img.Height).ToString();
itm.Width = img.Width.ToString();
itm.Height = img.Height.ToString();
break;
case ItemType.ItemIcon:
itm.Width = "64";
itm.Height = "64";
break;
case ItemType.ItemCover:
//image = _openFile.DirectoryName + @"\" + itm.Overlay.Image + ".png";
break;
case ItemType.HintText:
if (Int32.TryParse(itm.X, out temp))
if (temp < 0)
itm.X = (pnlMain.Width + temp).ToString();
if (Int32.TryParse(itm.Y, out temp))
if (temp < 0)
itm.Y = (pnlMain.Height + temp).ToString();
break;
}
}
LoadTheme();
}
Settings.Default.InitialDirectory = new DirectoryInfo(_openFile.FullName).FullName;
}
catch (Exception)
{
_fileOpen = false;
_hasChanges = false;
}
finally
{
UpdateForm();
}
}
return dr;
}
private DialogResult SaveTheme(bool saveAs = false)
{
DialogResult dr = DialogResult.OK;
if (_openFile == null || _imported || saveAs)
{
sfdSave.InitialDirectory = Settings.Default.InitialDirectory;
dr = sfdSave.ShowDialog();
}
if ((_openFile == null || _imported || saveAs) && dr == DialogResult.OK)
{
_openFile = new FileInfo(sfdSave.FileName);
Settings.Default.InitialDirectory = new DirectoryInfo(sfdSave.FileName).FullName;
Settings.Default.Save();
}
if (dr == DialogResult.OK)
{
_theme.Save(_openFile.FullName);
if (!Settings.Default.RecentlyOpenedFiles.Contains(_openFile.FullName))
{
Settings.Default.RecentlyOpenedFiles.Insert(0, _openFile.FullName);
}
else
{
Settings.Default.RecentlyOpenedFiles.Remove(_openFile.FullName);
Settings.Default.RecentlyOpenedFiles.Insert(0, _openFile.FullName);
}
PopulateRecentlyOpenedFiles();
_imported = false;
_hasChanges = false;
UpdateForm();
}
return dr;
}
// Form Population
private void LoadTheme()
{
List<Control> items = new List<Control>();
pnlMain.Controls.Clear();
lstItems.Items.Clear();
foreach (Item item in _theme.MainItems)
{
// Background
if (item.Type == ItemType.Background)
{
string backgroundPath = _openFile.DirectoryName + @"\" + item.DefaultImage + ".png";
SelectablePictureBox pb = new SelectablePictureBox();
if (File.Exists(backgroundPath))
{
Image img = Image.FromFile(backgroundPath);
pb.BackgroundImage = img;
pb.BackgroundImageLayout = ImageLayout.Stretch;
}
pb.SetBounds(0, 0, 640, 480);
pb.Tag = item;
item.Tag = pb;
items.Add(pb);
lstItems.Items.Add(item);
pb.GotFocus += new EventHandler(Item_GotFocus);
pb.LostFocus += new EventHandler(Item_LostFocus);
}
// Item Cover
else if (item.Type == ItemType.ItemCover)
{
string testGame = "SLUS_211.13";
string itemCoverPath = _openFile.DirectoryName + @"\..\..\art\" + testGame + "_COV.jpg";
ResizeablePictureBox pb = new ResizeablePictureBox(ResizeModes.Move);
if (File.Exists(itemCoverPath))
{
Image img = Image.FromFile(itemCoverPath);
pb.BackgroundImage = img;
pb.BackgroundImageLayout = ImageLayout.Stretch;
pb.SetBounds(Int(item.X), Int(item.Y), img.Width, img.Height);
}
pb.Tag = item;
item.Tag = pb;
items.Add(pb);
lstItems.Items.Add(item);
pb.GotFocus += new EventHandler(Item_GotFocus);
pb.LostFocus += new EventHandler(Item_LostFocus);
pb.ResizeOccurred += new ResizeablePictureBox.ResizeOccurredEventHandler(MoveResizeCompleted);
pb.MouseMoved += new ResizeablePictureBox.MouseMovedEventHandler(HandleMouseMove);
}
// Loading Icon
else if (item.Type == ItemType.LoadingIcon)
{
string backgroundPath = _openFile.DirectoryName + @"\load0.png";
ResizeablePictureBox pb = new ResizeablePictureBox(ResizeModes.Move);
if (File.Exists(backgroundPath))
{
Image img = Image.FromFile(backgroundPath);
pb.BackgroundImage = img;
pb.BackgroundImageLayout = ImageLayout.Stretch;
pb.SetBounds(Int(item.X), Int(item.Y), Int(item.Width), Int(item.Height));
}
pb.Tag = item;
item.Tag = pb;
items.Add(pb);
lstItems.Items.Add(item);
pb.GotFocus += new EventHandler(Item_GotFocus);
pb.LostFocus += new EventHandler(Item_LostFocus);
}
// Fallback
else
{
SelectablePictureBox pb = new SelectablePictureBox();
Image img = Properties.Resources.grid;
pb.Opacity = 0.5f;
pb.BackgroundImage = img;
pb.BackgroundImageLayout = ImageLayout.Tile;
pb.SetBounds(Int(item.X), Int(item.Y), Math.Max(Int(item.Width), 32), Math.Max(Int(item.Height), 32));
pb.Tag = item;
item.Tag = pb;
items.Add(pb);
lstItems.Items.Add(item);
pb.GotFocus += new EventHandler(Item_GotFocus);
pb.LostFocus += new EventHandler(Item_LostFocus);
}
}
// Add controls to the form
items.Reverse();
foreach (Control pb in items)
{
pnlMain.Controls.Add(pb);
}
}
private int Int(string value)
{
int temp = 0;
Int32.TryParse(value, out temp);
return temp;
}
protected void Item_GotFocus(object sender, EventArgs e)
{
Control ctrl = (Control)sender;
lstItems.SelectedItem = ctrl.Tag;
}
protected void Item_LostFocus(object sender, EventArgs e)
{
//Control ctrl = (Control)sender;
//lstItems.SelectedItem = ctrl.Tag;
}
protected void MoveResizeCompleted(Control control)
{
Item item = (Item)control.Tag;
item.X = control.Location.X.ToString();
item.Y = control.Location.Y.ToString();
//lstItems.Items[lstItems.SelectedIndex] = lstItems.SelectedItem;
}
private void lstItems_SelectedIndexChanged(object sender, EventArgs e)
{
((Item)lstItems.Items[lstItems.SelectedIndex]).Tag.Focus();
}
private Item NewItem()
{
Item item = new Item();
item.Comment = "New Item";
return item;
}
// Utilities
private string FileName()
{
return _openFile == null ? "Untitled" : _openFile.Name;
}
private string ThemeName()
{
return _openFile == null ? " (Untitled)" : " (" + _theme.Name + ")";
}
private void UpdateForm()
{
bool _itemSelected = false;
// Form Caption
Text = Settings.Default.ApplicationName + " - " + FileName() + (_hasChanges ? "*" : string.Empty) + ThemeName();
// Enable
tsmSave.Enabled = _fileOpen;
tsbSave.Enabled = _fileOpen;
tsmSaveAs.Enabled = _fileOpen;
tsbSaveAs.Enabled = _fileOpen;
tsbAdd.Enabled = _fileOpen;
tsbDelete.Enabled = _fileOpen && _itemSelected;
tsbProperties.Enabled = _fileOpen && _itemSelected;
}
private void HandleMouseMove(int x, int y, int width, int height, int eX, int eY)
{
lblDimensions.Text = "Dimensions:\r\n";
lblDimensions.Text += "X: " + x + "\r\n";
lblDimensions.Text += "Y: " + y + "\r\n";
lblDimensions.Text += "W: " + width + "\r\n";
lblDimensions.Text += "H: " + height + "\r\n";
lblDimensions.Text += "eX: " + eX + "\r\n";
lblDimensions.Text += "eY: " + eY;
}
#region Change Detection
#endregion
}
}