-
Notifications
You must be signed in to change notification settings - Fork 4
/
MainForm.cs
141 lines (116 loc) · 4.61 KB
/
MainForm.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
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using LeafletPano.Properties;
namespace LeafletPano
{
public partial class MainForm : Form
{
private Tiler tiler;
public MainForm()
{
InitializeComponent();
colorPanel.BackColor = Settings.Default.BackgroundColor;
if (string.IsNullOrEmpty(Properties.Settings.Default.InitialPath))
Initfile(Application.StartupPath + "\\DemoData\\Rothenburg.jpg");
else
Initfile(Properties.Settings.Default.InitialPath);
}
private void startButton_Click(object sender, EventArgs e)
{
tiler.MinLevel = (int)numericUpDown2.Value;
tiler.MaxLevel = (int)numericUpDown3.Value;
tiler.BackgroundColor = colorPanel.BackColor;
startButton.Enabled = false;
tiler.CreateTiles();
}
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (s.Length == 1)
Initfile(s[0]);
}
private void Initfile(string filePath)
{
textBox1.Text = filePath;
if (tiler != null)
{
tiler.SendFeedback -= new EventHandler<SendFeedbackEventArgs>(tiler_SendFeedback);
tiler.Completed -= new EventHandler<CompletedEventArgs>(tiler_Completed);
tiler.Dispose();
tiler = null;
}
tiler = new Tiler(textBox1.Text);
tiler.SendFeedback += new EventHandler<SendFeedbackEventArgs>(tiler_SendFeedback);
tiler.Completed += new EventHandler<CompletedEventArgs>(tiler_Completed);
label5.Text = string.Format("{0}x{1}", tiler.SourceImage.Width, tiler.SourceImage.Height);
var tileImg = new Bitmap(256, 256);
using (var graphcis = Graphics.FromImage(tileImg))
{
int width, height;
if (tiler.SourceImage.Width > tiler.SourceImage.Height)
{
width = 256;
height = 256 * tiler.SourceImage.Height / tiler.SourceImage.Width;
}
else
{
height = 256;
width = 256 * tiler.SourceImage.Width / tiler.SourceImage.Height;
}
graphcis.FillRectangle(new SolidBrush(colorPanel.BackColor), 0, 0, 256, 256);
graphcis.DrawImage(tiler.SourceImage, new Rectangle(0, 0, width, height),
new Rectangle(0, 0, tiler.SourceImage.Width, tiler.SourceImage.Height),
GraphicsUnit.Pixel);
}
pictureBox2.Image = tileImg;
numericUpDown1.Value = tiler.OrgLevel;
numericUpDown2.Value = tiler.MinLevel;
numericUpDown3.Value = tiler.MaxLevel;
}
void tiler_Completed(object sender, CompletedEventArgs e)
{
System.Diagnostics.Process.Start(e.HtmlFile);
startButton.Enabled = true;
}
void tiler_SendFeedback(object sender, SendFeedbackEventArgs e)
{
label4.Text = string.Format("{0} / {1} / {2}", e.Level, e.X, e.Y);
pictureBox1.Image = e.Image;
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.All;
else
e.Effect = DragDropEffects.None;
}
private void button1_Click(object sender, EventArgs e)
{
var cd = new ColorDialog();
cd.Color = Properties.Settings.Default.BackgroundColor;
if (cd.ShowDialog() == DialogResult.OK)
colorPanel.BackColor = cd.Color;
cd.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
var fd = new OpenFileDialog();
if (fd.ShowDialog() == DialogResult.OK)
this.textBox1.Text = fd.FileName;
fd.Dispose();
Initfile(this.textBox1.Text);
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Settings.Default.BackgroundColor = colorPanel.BackColor;
Settings.Default.InitialPath = textBox1.Text;
Settings.Default.Save();
}
private void textBox1_Leave(object sender, EventArgs e)
{
Initfile(this.textBox1.Text);
}
}
}