Skip to content

Commit

Permalink
Display crosshair for image 'origin'
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Jan 2, 2020
1 parent 40c3760 commit e121832
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 33 deletions.
6 changes: 6 additions & 0 deletions HaRepacker/Configuration/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,11 @@ public class UserSettings
// Themes
[JsonProperty(PropertyName = "ThemeColor")]
public int ThemeColor = 1;//white = 1, black = 0


// Settings not shown on this page

[JsonProperty(PropertyName = "EnableCrossHairDebugInformation")]
public bool EnableCrossHairDebugInformation = true;
}
}
39 changes: 39 additions & 0 deletions HaRepacker/Converter/CheckboxToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (C) 2020 LastBattle
* https://github.com/lastbattle/Harepacker-resurrected
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace HaRepacker.Converter
{
/// <summary>
/// Converts CheckBox IsChecked to Visiblity
/// </summary>
public class CheckboxToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool? isChecked = (bool?)value;

if (isChecked == true)
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return false; // anyway
}
}
}
9 changes: 8 additions & 1 deletion HaRepacker/Converter/ImageSizeDoubleToIntegerConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
using System;
/* Copyright (C) 2020 LastBattle
* https://github.com/lastbattle/Harepacker-resurrected
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
41 changes: 41 additions & 0 deletions HaRepacker/Converter/ImageWidthOrHeightToScreenDPIConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright (C) 2020 LastBattle
* https://github.com/lastbattle/Harepacker-resurrected
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */


using HaRepacker.Utils;
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 image (x, y) width or height to the correct size according to the screen's DPI scaling factor
/// </summary>
public class ImageWidthOrHeightToScreenDPIConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double widthOrHeight = (double)value;
double realWidthOrHeightToDisplay = widthOrHeight / ScreenDPI.GetScreenScaleFactor();

return realWidthOrHeightToDisplay;
}

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

return imageWidthOrHeight;
}
}
}
36 changes: 36 additions & 0 deletions HaRepacker/Converter/PointFOriginToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (C) 2020 LastBattle
* https://github.com/lastbattle/Harepacker-resurrected
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace HaRepacker.Converter
{
/// <summary>
/// Converts PointF X and Y coordinates to homosapien-ape readable string
/// </summary>
public class PointFOriginToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
PointF point = (PointF)value;

return string.Format("X {0}, Y {1}", point.X, point.Y);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return new PointF(0,0); // anyway wtf
}
}
}
50 changes: 50 additions & 0 deletions HaRepacker/Converter/VectorOriginPointFToMarginConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright (C) 2020 LastBattle
* https://github.com/lastbattle/Harepacker-resurrected
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

using HaRepacker.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace HaRepacker.Converter
{
/// <summary>
/// Converts PointF vector origin to XAML Margin
/// </summary>
public class VectorOriginPointFToMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
PointF originValue = (PointF)value;

// get DPI.
//PresentationSource source = PresentationSource.FromVisual(this);

// converted
// its always -50, as it is 50px wide, as specified in the xaml
Thickness margin = new Thickness(originValue.X / ScreenDPI.GetScreenScaleFactor(), originValue.Y / ScreenDPI.GetScreenScaleFactor(), 0, 0); // 20,75


return margin;
}

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

// converted
PointF originValue = new PointF((float) (value_.Left * ScreenDPI.GetScreenScaleFactor()), (float) (value_.Top * ScreenDPI.GetScreenScaleFactor()));
return originValue;
}
}
}
12 changes: 6 additions & 6 deletions HaRepacker/GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,14 @@ await Task.Run(() =>
{
Program.WzMan.AddLoadedWzFileToMainPanel(wzFile, MainPanel, currentDispatcher);
}
// error opening one of the files
if (errorOpeningFile_Admin)
{
MessageBox.Show(HaRepacker.Properties.Resources.MainFileOpenFail, HaRepacker.Properties.Resources.Error);
}
}); // load complete

// error opening one of the files
if (errorOpeningFile_Admin) // got to be called after await Task.run()
{
MessageBox.Show(HaRepacker.Properties.Resources.MainFileOpenFail, HaRepacker.Properties.Resources.Error);
}

// Hide panel splash sdcreen
MainPanel.OnSetPanelLoadingCompleted();
}
Expand Down
2 changes: 1 addition & 1 deletion HaRepacker/GUI/OptionsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void okButton_Click(object sender, EventArgs e)
Warning.Error(HaRepacker.Properties.Resources.OptionsIndentError);
return;
}

Program.ConfigurationManager.UserSettings.Sort = sortBox.Checked;
Program.ConfigurationManager.UserSettings.UseApngIncompatibilityFrame = apngIncompEnable.Checked;
Program.ConfigurationManager.UserSettings.AutoAssociate = autoAssociateBox.Checked;
Expand Down
9 changes: 9 additions & 0 deletions HaRepacker/GUI/Panels/MainPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@ private void TimerImgSequence_Tick(object sender, EventArgs e)
// Set current image
canvasPropBox.Image = currentNode.Item4;

// Set origin to canvas xaml
canvasPropBox.CanvasVectorOrigin = vectorOriginSelected;

// Set tooltip text
if (i_animateCanvasNode == animate_PreLoadImages.Count)
statusBarItemLabel_Others.Text = "# " + currentNode.Item1 + ", Delay: " + currentNode.Item2 + " ms. Repeating Animate.";
Expand Down Expand Up @@ -1388,6 +1391,9 @@ private void ShowObjectValue(WzObject obj)
System.Drawing.PointF origin = canvas.GetCanvasVectorPosition();
vectorOriginSelected = origin;

// Set origin to canvas xaml
canvasPropBox.CanvasVectorOrigin = origin;

canvasPropBox.Visibility = Visibility.Visible;
}
else if (obj is WzUOLProperty)
Expand All @@ -1403,6 +1409,9 @@ private void ShowObjectValue(WzObject obj)
// origin
System.Drawing.PointF origin = ((WzCanvasProperty)linkValue).GetCanvasVectorPosition();
vectorOriginSelected = origin;

// Set origin to canvas xaml
canvasPropBox.CanvasVectorOrigin = origin;
}

// Value
Expand Down
105 changes: 81 additions & 24 deletions HaRepacker/GUI/Panels/SubPanels/ImageRenderViewer.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
xmlns:converter="clr-namespace:HaRepacker.Converter"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">

<UserControl.Resources>
<converter:ImageSizeDoubleToIntegerConverter x:Key="imageSizeConverter" />
<converter:VectorOriginPointFToMarginConverter x:Key="vectorOriginConverter" />
<converter:CheckboxToVisibilityConverter x:Key="checkboxToVisibilityConverter"/>
<converter:ImageWidthOrHeightToScreenDPIConverter x:Key="imageWidthOrHeightToScreenDPIConverter"/>
<converter:PointFOriginToStringConverter x:Key="pointFOriginToStringConverter"/>
</UserControl.Resources>

<Grid>
Expand All @@ -18,37 +22,90 @@
<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.Row="0">
<!-- Image and borders-->
<Grid Width="{Binding ImageWidth}"
Height="{Binding ImageHeight}"
VerticalAlignment="Top" HorizontalAlignment="Left" Margin="80,50,0,0">

<Border BorderBrush="Red" BorderThickness="0.5" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border.RenderTransform>
<ScaleTransform
ScaleX="{Binding ElementName=ZoomSlider, Path='Value'}"
ScaleY="{Binding ElementName=ZoomSlider, Path='Value'}"/>
</Border.RenderTransform>

<Grid>
<!-- Source="pack://siteoforigin:,,,/Resources/ladyboss_test_attack2_0.png" -->
<!-- Source="{Binding Image}" -->
<Image x:Name="canvasPropBox"
Source="{Binding Image}"
Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center"
/>

<!-- Crosshair for vector origin-->
<!-- Margin="{Binding CanvasVectorOrigin, Converter={StaticResource vectorOriginConverter}}"
-->
<Grid x:Name="gridCrossHair"
Visibility="{Binding ElementName=checkbox_crosshair, Path=IsChecked, Converter={StaticResource checkboxToVisibilityConverter}}"
HorizontalAlignment="Left" VerticalAlignment="Bottom"
Margin="{Binding CanvasVectorOrigin, Converter={StaticResource vectorOriginConverter}}" >

<!-- Grid to compensate for the crosshair length-->
<!-- Crosshair must always only be 1/2 of the image width and height-->
<Grid Margin="-5,0,0,-5">
<Grid Width="0.5" Height="10" Background="Red"/>
<Grid Height="0.5" Width="10" Background="Red"/>
</Grid>
</Grid>
</Grid>
</Border>
</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>
<!-- Image width-->
<StackPanel Visibility="{Binding ElementName=checkbox_crosshair, Path=IsChecked, Converter={StaticResource checkboxToVisibilityConverter}}"
Margin="0,80,0,0" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Width: " FontSize="10"/>
<TextBlock Text="{Binding ImageWidth, Converter={StaticResource imageSizeConverter}}" FontSize="10"/>
<TextBlock Text="px " Margin="3,0,0,0" FontSize="10"/>
</StackPanel>
</StackPanel>

<!-- Image height -->
<StackPanel Visibility="{Binding ElementName=checkbox_crosshair, Path=IsChecked, Converter={StaticResource checkboxToVisibilityConverter}}"
Margin="80,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Height: " FontSize="10"/>
<TextBlock Text="{Binding ImageHeight, Converter={StaticResource imageSizeConverter}}" FontSize="10"/>
<TextBlock Text="px " Margin="3,0,0,0" FontSize="10"/>
</StackPanel>
</StackPanel>

<!-- Checkbox to enable crosshair or not-->
<Grid VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,80,10,0">
<CheckBox x:Name="checkbox_crosshair" Content="Enable Cross Hair"
Checked="checkbox_crosshair_Checked" Unchecked="checkbox_crosshair_Checked"/>
</Grid>

<!-- Displays the origin-->
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Left"
Visibility="{Binding ElementName=checkbox_crosshair, Path=IsChecked, Converter={StaticResource checkboxToVisibilityConverter}}"
Orientation="Horizontal" Margin="0,70,0,0">
<TextBlock Text="Image origin = " Margin="70,0,0,0" FontSize="10"/>
<TextBlock Text="{Binding CanvasVectorOrigin, Converter={StaticResource pointFOriginToStringConverter}}" Margin="3,0,0,0" FontSize="10"/>
</StackPanel>
</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" />
Minimum="0.1"
Maximum="10"
Value="3"
TickFrequency="0.05"
SmallChange="0.05"
LargeChange="0.1" />
</Grid>
</Grid>
</UserControl>
Loading

0 comments on commit e121832

Please sign in to comment.