Skip to content

Commit

Permalink
Added the ability to zoom on image
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Jan 1, 2020
1 parent 17dbf20 commit f52755d
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 76 deletions.
30 changes: 30 additions & 0 deletions HaRepacker/Converter/ImageSizeDoubleToIntegerConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace HaRepacker.Converter
{
/// <summary>
/// Converts the double value of an image size to integer
/// </summary>
public class ImageSizeDoubleToIntegerConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double value_ = (double)value;

return (int)value_;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// cant really convert back here anyway
double value_ = (double)value;

return (int)value_;
}
}
}
87 changes: 35 additions & 52 deletions HaRepacker/GUI/Panels/MainPanel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,70 +278,53 @@

<localSubPanels:SoundPlayer x:Name="mp3Player" Visibility="Collapsed"/>

<Grid x:Name="Grid_ImageDisplay" Margin="10">

<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!-- <Grid Grid.Row="0" x:Name="Grid_ImageOpenGLRender" Visibility="Collapsed">
<DockPanel>
<sharpGL:OpenGLControl x:Name="openGLControl" DrawFPS="True"
OpenGLInitialized="OpenGLControl_OpenGLInitialized"
Resized="OpenGLControl_Resized"
OpenGLDraw="OpenGLControl_OpenGLDraw"
>
</sharpGL:OpenGLControl>
</DockPanel>
</Grid>-->

<Grid Grid.Row="0" x:Name="Grid_ImageRender">
<Image x:Name="canvasPropBox" Stretch="None" Margin="300,100,0,0"
VerticalAlignment="Center" HorizontalAlignment="Center" Source="pack://siteoforigin:,,,/Resources/8800000_attack_10.png">
</Image>

<Grid x:Name="grid_planVisibility">
<Grid x:Name="cartesianPlaneX" Height="2" Background="Gray" Visibility="Collapsed">
<Grid Background="White" Height="1"/>
</Grid>
<Grid x:Name="cartesianPlaneY" Width="2" Background="Gray" Visibility="Collapsed">
<Grid Background="White" Width="1"/>
</Grid>

<Grid Grid.Row="0" x:Name="Grid_ImageRender" Margin="10">
<localSubPanels:ImageRenderViewer x:Name="canvasPropBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

</localSubPanels:ImageRenderViewer>

<Grid x:Name="grid_planVisibility">
<Grid x:Name="cartesianPlaneX" Height="2" Background="Gray" Visibility="Collapsed">
<Grid Background="White" Height="1"/>
</Grid>
<Grid x:Name="cartesianPlaneY" Width="2" Background="Gray" Visibility="Collapsed">
<Grid Background="White" Width="1"/>
</Grid>
</Grid>

<!-- plane UI. Put this above the image -->
<!-- Not done yet -->
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20"
<!-- plane UI. Put this above the image -->
<!-- Not done yet -->
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20"
Visibility="Collapsed">
<CheckBox x:Name="cartesianPlane_checkBox" Content="Plane"
<CheckBox x:Name="cartesianPlane_checkBox" Content="Plane"
Checked="cartesianPlane_checkBox_CheckUnchecked" Unchecked="cartesianPlane_checkBox_CheckUnchecked"/>
<ComboBox x:Name="planePosition_comboBox" Width="100" SelectedIndex="0"
<ComboBox x:Name="planePosition_comboBox" Width="100" SelectedIndex="0"
SelectionChanged="planePosition_comboBox_SelectionChanged">
<ComboBoxItem Content="Center" Tag="Center"/>
<ComboBoxItem Content="Top" Tag="Top"/>
<ComboBoxItem Content="Bottom" Tag="Bottom"/>
<ComboBoxItem Content="Left" Tag="Left"/>
<ComboBoxItem Content="Right" Tag="Right"/>
<ComboBoxItem Content="Top-Left" Tag="Top-Left"/>
<ComboBoxItem Content="Top-Right" Tag="Top-Right"/>
<ComboBoxItem Content="Bottom-Left" Tag="Bottom-Left"/>
<ComboBoxItem Content="Bottom-Right" Tag="Bottom-Right"/>
</ComboBox>
</StackPanel>
</Grid>
<ComboBoxItem Content="Center" Tag="Center"/>
<ComboBoxItem Content="Top" Tag="Top"/>
<ComboBoxItem Content="Bottom" Tag="Bottom"/>
<ComboBoxItem Content="Left" Tag="Left"/>
<ComboBoxItem Content="Right" Tag="Right"/>
<ComboBoxItem Content="Top-Left" Tag="Top-Left"/>
<ComboBoxItem Content="Top-Right" Tag="Top-Right"/>
<ComboBoxItem Content="Bottom-Left" Tag="Bottom-Left"/>
<ComboBoxItem Content="Bottom-Right" Tag="Bottom-Right"/>
</ComboBox>
</StackPanel>
</Grid>

<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Right"
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Right"
Margin="10">
<Button Height="30" Width="150" Content="Animate (F5)" x:Name="button_animateSelectedCanvas"
<Button Height="30" Width="100" Content="Animate (F5)" BorderBrush="Transparent" x:Name="button_animateSelectedCanvas"
Click="button_animateSelectedCanvas_Click_1"/>
<Button Height="30" Width="150" Content="Change Image" x:Name="changeImageButton"
<Button Height="30" Width="100" Content="Change Image" BorderBrush="Transparent" x:Name="changeImageButton"
Click="changeImageButton_Click"/>
<Button Height="30" Width="150" Content="Change Sound" x:Name="changeSoundButton"
<Button Height="30" Width="100" Content="Change Sound" BorderBrush="Transparent" x:Name="changeSoundButton"
Click="changeSoundButton_Click"/>
<Button Height="30" Width="150" Content="Save Sound" x:Name="saveSoundButton"
<Button Height="30" Width="100" Content="Save Sound" BorderBrush="Transparent" x:Name="saveSoundButton"
Click="saveSoundButton_Click"/>
<Button Height="30" Width="150" Content="Save Image" x:Name="saveImageButton"
<Button Height="30" Width="100" Content="Save Image" BorderBrush="Transparent" x:Name="saveImageButton"
Click="saveImageButton_Click"/>
</StackPanel>
</Grid>
Expand Down
48 changes: 24 additions & 24 deletions HaRepacker/GUI/Panels/MainPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ private void UpdateCartesianPlanePosition(System.Drawing.PointF vectorSelected)
if (vectorSelected == null || isLoading || cartesianPlaneX == null || cartesianPlaneY == null)
return;

double xCenter = Grid_ImageDisplay.ActualWidth / 2d;
double yCenter = Grid_ImageDisplay.ActualWidth / 2d;
double xCenter = Grid_ImageRender.ActualWidth / 2d;
double yCenter = Grid_ImageRender.ActualWidth / 2d;
double imageWidth = canvasPropBox.ActualWidth;
double imageHeight = canvasPropBox.ActualHeight;

Expand All @@ -630,65 +630,65 @@ private void UpdateCartesianPlanePosition(System.Drawing.PointF vectorSelected)
switch (Program.ConfigurationManager.UserSettings.PlanePosition)
{
case "Top":
canvasPropBox.VerticalAlignment = VerticalAlignment.Top;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Center;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Top;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Center;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Top;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Center;
break;
case "Bottom":
canvasPropBox.VerticalAlignment = VerticalAlignment.Bottom;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Center;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Bottom;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Center;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Bottom;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Center;
break;
case "Right":
canvasPropBox.VerticalAlignment = VerticalAlignment.Center;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Right;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Right;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Center;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Right;
break;
case "Left":
canvasPropBox.VerticalAlignment = VerticalAlignment.Center;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Left;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Center;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Left;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Center;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Left;
break;
case "Top-Left":
canvasPropBox.VerticalAlignment = VerticalAlignment.Top;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Left;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Top;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Left;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Top;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Left;
break;
case "Top-Right":
canvasPropBox.VerticalAlignment = VerticalAlignment.Top;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Right;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Top;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Right;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Top;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Right;
break;
case "Bottom-Left":
canvasPropBox.VerticalAlignment = VerticalAlignment.Bottom;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Left;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Bottom;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Left;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Bottom;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Left;
break;
case "Bottom-Right":
canvasPropBox.VerticalAlignment = VerticalAlignment.Bottom;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Right;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Bottom;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Right;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Bottom;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Right;
break;
case "Center":
default:
canvasPropBox.VerticalAlignment = VerticalAlignment.Center;
canvasPropBox.HorizontalAlignment = HorizontalAlignment.Center;
//canvasPropBox.VerticalAlignment = VerticalAlignment.Center;
//canvasPropBox.HorizontalAlignment = HorizontalAlignment.Center;

cartesianPlaneX.VerticalAlignment = VerticalAlignment.Center;
cartesianPlaneY.HorizontalAlignment = HorizontalAlignment.Center;
Expand Down Expand Up @@ -844,7 +844,7 @@ private void TimerImgSequence_Tick(object sender, EventArgs e)
vectorOriginSelected = currentNode.Item3;

// Set current image
canvasPropBox.Source = currentNode.Item4;
canvasPropBox.Image = currentNode.Item4;

// Set tooltip text
if (i_animateCanvasNode == animate_PreLoadImages.Count)
Expand Down Expand Up @@ -1135,7 +1135,7 @@ private void changeImageButton_Click(object sender, RoutedEventArgs e)

// Updates
selectedWzCanvas.ParentImage.Changed = true;
canvasPropBox.Source = new BitmapImage(new Uri(dialog.FileName));
canvasPropBox.Image = new BitmapImage(new Uri(dialog.FileName));

// Add undo actions
//UndoRedoMan.AddUndoBatch(actions);
Expand Down Expand Up @@ -1377,10 +1377,10 @@ private void ShowObjectValue(WzObject obj)
{
System.Drawing.Image img = canvas.GetLinkedWzCanvasBitmap();
if (img != null)
canvasPropBox.Source = BitmapToImageSource.ToWpfBitmap((System.Drawing.Bitmap)img);
canvasPropBox.Image = BitmapToImageSource.ToWpfBitmap((System.Drawing.Bitmap)img);
}
else
canvasPropBox.Source = BitmapToImageSource.ToWpfBitmap(canvas.GetBitmap());
canvasPropBox.Image = BitmapToImageSource.ToWpfBitmap(canvas.GetBitmap());

// origin
System.Drawing.PointF origin = canvas.GetCanvasVectorPosition();
Expand All @@ -1395,7 +1395,7 @@ private void ShowObjectValue(WzObject obj)
if (linkValue is WzCanvasProperty)
{
canvasPropBox.Visibility = Visibility.Visible;
canvasPropBox.Source = BitmapToImageSource.ToWpfBitmap(linkValue.GetBitmap());
canvasPropBox.Image = BitmapToImageSource.ToWpfBitmap(linkValue.GetBitmap());
saveImageButton.Visibility = Visibility.Visible;

// origin
Expand Down
54 changes: 54 additions & 0 deletions HaRepacker/GUI/Panels/SubPanels/ImageRenderViewer.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<UserControl x:Class="HaRepacker.GUI.Panels.SubPanels.ImageRenderViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:HaRepacker.GUI.Panels.SubPanels"
xmlns:converter="clr-namespace:HaRepacker.Converter"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">

<UserControl.Resources>
<converter:ImageSizeDoubleToIntegerConverter x:Key="imageSizeConverter" />
</UserControl.Resources>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>

<Grid x:Name="grid_Picture" Grid.Row="0">
<!-- small details about the photo at the top right-->
<Grid x:Name="grid_pictureInfo" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10"
Background="#FFEDEDED" Opacity="0.6">
<StackPanel Orientation="Vertical" Margin="10">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Size: "/>
<TextBlock Text="{Binding ImageWidth, Converter={StaticResource imageSizeConverter}}"/>
<TextBlock Text=" x " Margin="3,0,3,0"/>
<TextBlock Text="{Binding ImageHeight, Converter={StaticResource imageSizeConverter}}"/>
</StackPanel>
</StackPanel>
</Grid>

<Grid Height="{Binding ElementName=ZoomSlider, Path='Value'}"
Width="{Binding ElementName=ZoomSlider, Path='Value'}">
<!-- Source="pack://siteoforigin:,,,/Resources/8800000_attack_10.png" -->
<Image x:Name="canvasPropBox" Source="{Binding Image}">
</Image>
</Grid>
</Grid>

<Grid x:Name="grid_zoom" Grid.Row="1" VerticalAlignment="Bottom">
<Slider Name="ZoomSlider"
Margin="10,0,10,0"
Minimum="50"
Maximum="1000"
Value="200"
TickFrequency="100"
SmallChange="10"
LargeChange="50" />
</Grid>
</Grid>
</UserControl>
Loading

0 comments on commit f52755d

Please sign in to comment.