diff --git a/PDGServer_WPF/App.xaml.cs b/PDGServer_WPF/App.xaml.cs
index 06ee999..a2b6928 100644
--- a/PDGServer_WPF/App.xaml.cs
+++ b/PDGServer_WPF/App.xaml.cs
@@ -57,7 +57,7 @@ namespace RBG_Server
}
- void LoadStream(Stream source, string path, bool isSprite)
+ public void LoadStream(Stream source, string path, bool isSprite)
{
long srcStart = source.Position;
byte[] vs = new byte[6]; // First 6 bytes is the gif specifier
diff --git a/PDGServer_WPF/ConnectionPage.xaml b/PDGServer_WPF/ConnectionPage.xaml
index f2d28f3..e25e0ca 100644
--- a/PDGServer_WPF/ConnectionPage.xaml
+++ b/PDGServer_WPF/ConnectionPage.xaml
@@ -13,7 +13,7 @@
-
+
@@ -50,7 +50,7 @@
-
+
diff --git a/PDGServer_WPF/ConnectionPage.xaml.cs b/PDGServer_WPF/ConnectionPage.xaml.cs
index 1386f56..9137b2c 100644
--- a/PDGServer_WPF/ConnectionPage.xaml.cs
+++ b/PDGServer_WPF/ConnectionPage.xaml.cs
@@ -1,4 +1,5 @@
-using RBG_Server;
+using Microsoft.Win32;
+using RBG_Server;
using System;
using System.Collections.Generic;
using System.IO;
@@ -247,6 +248,103 @@ namespace RBG_Server_WPF
// *************** Server Connection Logic *******************
// ************************************************************
#region server connection logic
+ private static readonly SolidColorBrush borderBrush = new(Color.FromRgb(255, 0, 0));
+
+
+ private void BrowseButton_Click(object sender, RoutedEventArgs e)
+ {
+ OpenFileDialog ofd = new();
+ ofd.Filter = "Image Files|*.png;*.jpg";
+ if (ofd.ShowDialog() == true)
+ {
+ ImageSourceTextBox.Text = ofd.FileName;
+ UpdateImage().Start();
+ }
+ }
+ ///
+ /// Update the image when the text box looses focus
+ ///
+ ///
+ ///
+ private void ImageSourceTextBox_LostFocus(object sender, RoutedEventArgs e)
+ {
+ UpdateImage().Start();
+ }
+
+ private Task UpdateImage()
+ {
+ try
+ {
+ CommunicationHandler host = App.Context.GameCommunicationHandler;
+ using FileStream fs = File.OpenRead(ImageSourceTextBox.Text);
+ using MemoryStream ms = new();
+
+ fs.CopyTo(ms);
+ // Calc mips
+ ms.Position = 0;
+ App.Context.LoadStream(ms, Name, false);
+ ms.Position = 0;
+ BitmapImage gameBoardImage = new();
+ gameBoardImage.BeginInit();
+ gameBoardImage.StreamSource = ms;
+ gameBoardImage.EndInit();
+ PreviewImage.Source = gameBoardImage;
+ RedrawGrid();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ }
+ return Task.CompletedTask;
+ }
+
+ ///
+ /// Draws the overlay grid, clearing existing elements if necessary
+ ///
+ private void RedrawGrid()
+ {
+
+ PreviewImageOverlay.RowDefinitions.Clear();
+ PreviewImageOverlay.ColumnDefinitions.Clear();
+ PreviewImageOverlay.Children.Clear();
+ for (int i = 0; i < NumberOfColumns.Value; i++)
+ {
+ PreviewImageOverlay.ColumnDefinitions.Add(new ColumnDefinition());
+ }
+ for (int i = 0; i < NumberOfRows.Value; i++)
+ {
+ PreviewImageOverlay.RowDefinitions.Add(new RowDefinition());
+ }
+ // Draw the overlay
+ Rectangle overlay = new();
+ overlay.Fill = new SolidColorBrush(Color.FromArgb(128, 0, 128, 255));
+ _ = PreviewImageOverlay.Children.Add(overlay);
+ Grid.SetRow(overlay, (int)ZoomBoxStartRow.Value);
+ Grid.SetColumn(overlay, (int)ZoomBoxStartColumn.Value);
+ Grid.SetRowSpan(overlay, (int)ZoomBoxSpan.Value);
+ Grid.SetColumnSpan(overlay, (int)ZoomBoxSpan.Value);
+ // Draw the starting position
+ overlay = new();
+ overlay.Fill = new SolidColorBrush(Color.FromArgb(64, 0, 255, 128));
+ _ = PreviewImageOverlay.Children.Add(overlay);
+ Grid.SetRow(overlay, (int)StartingRow.Value);
+ Grid.SetColumn(overlay, (int)StartingColumn.Value);
+ // Draw grids onto the preview image
+ for (int v = 0; v < PreviewImageOverlay.RowDefinitions.Count; v++)
+ {
+ for (int u = 0; u < PreviewImageOverlay.ColumnDefinitions.Count; u++)
+ {
+ Border border = new();
+ border.BorderBrush = borderBrush;
+ border.BorderThickness = new Thickness(2);
+ _ = PreviewImageOverlay.Children.Add(border);
+ Grid.SetRow(border, v);
+ Grid.SetColumn(border, u);
+ }
+ }
+ }
+
+
#endregion
}