Skip to content

Commit

Permalink
Added version #.
Browse files Browse the repository at this point in the history
Fixed bug where any images loaded wouldnt be able to be edited until the program was closed.
I feel like I did something else, but I can't remember... oh well.
  • Loading branch information
7ark committed Jun 20, 2020
1 parent 09ecf47 commit 713ffbf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion RadarTimingsTester/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RadarTimingsTester"
mc:Ignorable="d"
Title="Radar Timings Tester (RTT)" Height="720" Width="1080" ResizeMode="CanMinimize">
Name="MainWin" Title="Radar Timings Tester (RTT)" Height="720" Width="1080" ResizeMode="CanMinimize">
<Grid Background="{DynamicResource {x:Static SystemColors.MenuBrushKey}}">
<Canvas x:Name="MainCanvas" MouseDown="MainCanvas_MouseDown" MouseMove="MainCanvas_MouseMove" MouseUp="MainCanvas_MouseUp" HorizontalAlignment="Left" Width="600" Height="600"/>
<Button Name="LoadMapButton" HorizontalAlignment="Right" VerticalAlignment="Top" Width="300" Height="50" Margin="0,30,75,0" FontSize="30" Click="LoadMapButton_Click">Load Map Radar</Button>
Expand Down
34 changes: 30 additions & 4 deletions RadarTimingsTester/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public override string ToString()
}
}

private readonly string VERSION = "0.4";

private bool ready = false;
private Point currentPoint = new Point();
private SolidColorBrush currentColor = new SolidColorBrush();
Expand All @@ -84,6 +86,8 @@ public MainWindow()
DrawOptions.Items.Add("Freehand");
DrawOptions.Items.Add("Waypoint");
DrawOptions.SelectedIndex = 0;

MainWin.Title = "Radar Timings Tester (RTT) [Version " + VERSION +"]";
}

private void LoadMapData(string path)
Expand Down Expand Up @@ -386,7 +390,7 @@ private void RedrawLines(bool clear = true)
private void LoadMapButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "png files (*.png)|*.png|All files (*.*)|*.*";
fileDialog.Filter = "dds files (*.dds)|*.dds|png files (*.png)|*.png|All files (*.*)|*.*";
fileDialog.RestoreDirectory = true;
if(fileDialog.ShowDialog() == true)
{
Expand All @@ -396,10 +400,32 @@ private void LoadMapButton_Click(object sender, RoutedEventArgs e)

string path = fileDialog.FileName;
string ext = System.IO.Path.GetExtension(path);
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri(path));

MainCanvas.Background = imageBrush;
//Manually load the image data into a byte[]. We do this so we can close the stream without holding onto the reference.
Stream imageStreamSource = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] bytes = new byte[imageStreamSource.Length + 10];
int toRead = (int)imageStreamSource.Length;
int alreadyRead = 0;
do
{
int n = imageStreamSource.Read(bytes, alreadyRead, 10);
alreadyRead += n;
toRead -= n;
} while (toRead > 0);
imageStreamSource.Close();

//Do that shit with whatever and make it show up. You get it.
using(var stream = new MemoryStream(bytes))
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();

ImageBrush b = new ImageBrush(bitmap);
MainCanvas.Background = b;
}

string txtPath = path.Replace("_radar" + ext, ".txt");
int layerN = 1;
Expand Down

0 comments on commit 713ffbf

Please sign in to comment.