-
Notifications
You must be signed in to change notification settings - Fork 7
/
MainWindow.xaml.cs
86 lines (67 loc) · 2.85 KB
/
MainWindow.xaml.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
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace Voxel_Fortress
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
MapMaker mapMaker = new MapMaker();
MapMaker.Images mapImages = new MapMaker.Images();
public MainWindow()
{
InitializeComponent();
}
private void heightMapButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog heightMapDialog = new OpenFileDialog();
heightMapDialog.Filter = "Image Files (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg;*.jpeg|All Files (*.*)|*.*";
if (heightMapDialog.ShowDialog() == true)
{
mapImages.imageFilename = heightMapDialog.FileName;
BitmapImage elevationMap = new BitmapImage(new Uri(heightMapDialog.FileName));
mapImages.elevationMap = MapMaker.ConvertBitmapImage(elevationMap);
elevationMapImage.Source = elevationMap;
exportButton.IsEnabled = true;
}
}
private void exportButton_Click(object sender, RoutedEventArgs e)
{
exportProgress.Value = 0;
BackgroundWorker mapExportWorker = new BackgroundWorker();
mapExportWorker.WorkerReportsProgress = true;
mapExportWorker.DoWork += mapMaker.LoadMap;
mapExportWorker.ProgressChanged += MapExportWorker_ProgressChanged;
mapExportWorker.RunWorkerCompleted += MapExportWorker_RunWorkerCompleted;
mapExportWorker.RunWorkerAsync(mapImages);
(sender as Button).IsEnabled = false;
}
private void MapExportWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
exportButton.IsEnabled = true;
}
private void MapExportWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
exportProgress.Value = e.ProgressPercentage;
exportLabel.Text = e.UserState as string;
}
private void colorMapButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog heightMapDialog = new OpenFileDialog();
heightMapDialog.Filter = "Image Files (*.png, *.bmp, *.jpg)|*.png;*.bmp;*.jpg;*.jpeg|All Files (*.*)|*.*";
if (heightMapDialog.ShowDialog() == true)
{
mapImages.imageFilename = heightMapDialog.FileName;
BitmapImage colorMap = new BitmapImage(new Uri(heightMapDialog.FileName));
mapImages.colorMap = MapMaker.ConvertBitmapImage(colorMap);
colorMapImage.Source = colorMap;
exportButton.IsEnabled = true;
}
}
}
}