-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
151 lines (131 loc) · 4.53 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows;
using Level_Editor.Framework.File_Management;
using Level_Editor.Framework.Tools;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
namespace Level_Editor
{
public partial class EditForm : Form
{
private BitmapSettings bitmapSettings;
private Timer canvasTimer;
private Timer mouseTimer;
private int mouseX;
private int mouseY;
public EditForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.CenterToScreen();
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
this.MinimizeBox = false;
this.MaximizeBox = false;
this.DoubleBuffered = true;
this.Paint += EditForm_Paint;
this.MouseUp += EditForm_MouseUp;
this.MouseDown += EditForm_MouseDown;
this.MouseMove += EditForm_MouseMove;
this.MouseClick += EditForm_MouseClick;
colorComboBox.Items.Add("None");
colorComboBox.Items.AddRange(ColorSelection.GetListofColors());
canvasTimer = new Timer();
canvasTimer.Interval = 1000 / 60;
canvasTimer.Tick += CanvasTimer_Tick;
canvasTimer.Start();
mouseTimer = new Timer();
mouseTimer.Interval = 1000 / 60;
mouseTimer.Enabled = false;
mouseTimer.Tick += MouseTimer_Tick;
}
private void EditForm_MouseMove(object sender, MouseEventArgs e)
{
mouseX = e.X;
mouseY = e.Y;
}
private void MouseTimer_Tick(object sender, EventArgs e)
{
FileResource.level.CellClicked(mouseX, mouseY);
}
private void EditForm_MouseUp(object sender, MouseEventArgs e)
{
mouseTimer.Enabled = false;
}
private void EditForm_MouseDown(object sender, MouseEventArgs e)
{
mouseTimer.Enabled = true;
}
private void EditForm_MouseClick(object sender, MouseEventArgs e)
{
if(FileResource.level != null)
{
FileResource.level.CellClicked(e.X, e.Y);
}
}
private void EditForm_Paint(object sender, PaintEventArgs e)
{
if(FileResource.level != null)
{
FileResource.level.Render(e.Graphics);
}
}
private void CanvasTimer_Tick(object sender, EventArgs e)
{
this.Invalidate();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
FileResource.SaveFile();
}
private void createToolStripMenuItem_Click(object sender, EventArgs e)
{
if(bitmapSettings == null || bitmapSettings.IsDisposed)
{
bitmapSettings = new BitmapSettings();
if (!bitmapSettings.Visible && bitmapSettings != null)
{
bitmapSettings.Owner = this;
bitmapSettings.Show();
}
}
}
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
FileResource.LoadFile();
}
private void colorComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (colorComboBox.SelectedText.Equals("None"))
{
ColorSelection.selectedColor = Color.Empty;
}
else
{
ColorSelection.selectedColor = ColorSelection.ConvertStringToColor(colorComboBox.SelectedItem.ToString());
}
RGBLabel.Text = "[R =" +
ColorSelection.selectedColor.R + " " +
", G =" +
ColorSelection.selectedColor.G + " " +
", B =" +
ColorSelection.selectedColor.B + " " +
"]";
}
private void resetBtn_Click(object sender, EventArgs e)
{
FileResource.level.ResetCanvas();
}
}
}