Skip to content

Commit 5120e16

Browse files
committed
add new image dialog (so set canvas size)
1 parent fc79984 commit 5120e16

File tree

4 files changed

+85
-11
lines changed

4 files changed

+85
-11
lines changed

PixelArtTool/MainWindow.xaml.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,17 @@ void Start()
177177
ResetCurrentBrightnessPreview(currentColor);
178178

179179
// set pixel box size based on resolution
180-
//rectPixelPos.Width = 16 * (16 / canvasResolutionX);
181-
//rectPixelPos.Height = 16 * (16 / canvasResolutionY);
182-
// r 8 = 32
183-
// r 16 = 16
184-
// r 32 = 8
180+
rectPixelPos.Width = 16 * (16 / (float)canvasResolutionX);
181+
rectPixelPos.Height = 16 * (16 / (float)canvasResolutionY);
185182

186183
// hide some objects (that are visible at start to keep it easy to edit form)
187184
lineSymmetryXpositionA.Visibility = Visibility.Hidden;
188185
lineSymmetryXpositionB.Visibility = Visibility.Hidden;
186+
187+
// clear undos
188+
undoStack.Clear();
189+
redoStack.Clear();
190+
currentUndoItem = null;
189191
}
190192

191193

@@ -655,12 +657,34 @@ void WindowMouseWheel(object sender, MouseWheelEventArgs e)
655657

656658
private void OnClearButton(object sender, RoutedEventArgs e)
657659
{
658-
RegisterUndo();
659-
ClearImage(canvasBitmap, emptyRect, emptyPixels, emptyStride);
660-
UpdateOutline();
661-
// reset title
662-
window.Title = windowTitle;
663-
saveFile = null;
660+
// show dialog for new resolution
661+
NewImageDialog dlg = new NewImageDialog();
662+
dlg.Owner = this;
663+
var result = dlg.ShowDialog();
664+
switch (result)
665+
{
666+
case true:
667+
RegisterUndo();
668+
ClearImage(canvasBitmap, emptyRect, emptyPixels, emptyStride);
669+
UpdateOutline();
670+
// reset title
671+
window.Title = windowTitle;
672+
saveFile = null;
673+
//Console.WriteLine(dlg.sliderResolution.Value);
674+
675+
canvasResolutionX = (int)dlg.sliderResolution.Value;
676+
canvasResolutionY = (int)dlg.sliderResolution.Value;
677+
678+
// re-init everything!!??
679+
Start();
680+
681+
break;
682+
case false: // cancelled
683+
break;
684+
default:
685+
Console.WriteLine("Unknown error..");
686+
break;
687+
}
664688
}
665689

666690
// if unsaved, this is same as save as.., if already saved, then overwrite current

PixelArtTool/NewImageDialog.xaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Window
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:PixelArtTool"
7+
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="PixelArtTool.NewImageDialog"
8+
mc:Ignorable="d"
9+
Title="New Image" Height="201" Width="281"
10+
ResizeMode="NoResize"
11+
ShowInTaskbar="False"
12+
WindowStartupLocation="CenterOwner"
13+
>
14+
<Grid>
15+
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4">
16+
<Label Content="Resolution *Use only 8x8, 16x16, 32x32, 64x64"/>
17+
<TextBlock Text="{Binding ElementName=sliderResolution, Path=Value, StringFormat={}{0:#}}" HorizontalAlignment="Center" FontWeight="Bold"/>
18+
<Slider x:Name="sliderResolution" Minimum="8" Maximum="64" SmallChange="8" TickFrequency="8" LargeChange="8" TickPlacement="Both" Value="16" AutoToolTipPlacement="TopLeft" IsSnapToTickEnabled="True"/>
19+
<Button x:Name="okButton" IsDefault="True" Content="OK" Click="OnOkButtonClick"/>
20+
<Button x:Name="cancelButton" IsCancel="True" Content="Cancel"/>
21+
</StackPanel>
22+
</Grid>
23+
</Window>

PixelArtTool/NewImageDialog.xaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Windows;
2+
3+
namespace PixelArtTool
4+
{
5+
/// <summary>
6+
/// Interaction logic for Window1.xaml
7+
/// </summary>
8+
public partial class NewImageDialog : Window
9+
{
10+
public NewImageDialog()
11+
{
12+
InitializeComponent();
13+
}
14+
15+
private void OnOkButtonClick(object sender, RoutedEventArgs e)
16+
{
17+
this.DialogResult = true;
18+
}
19+
}
20+
}

PixelArtTool/PixelArtTool.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<Generator>MSBuild:Compile</Generator>
6060
<SubType>Designer</SubType>
6161
</ApplicationDefinition>
62+
<Compile Include="NewImageDialog.xaml.cs">
63+
<DependentUpon>NewImageDialog.xaml</DependentUpon>
64+
</Compile>
6265
<Page Include="MainWindow.xaml">
6366
<Generator>MSBuild:Compile</Generator>
6467
<SubType>Designer</SubType>
@@ -73,6 +76,10 @@
7376
<DependentUpon>MainWindow.xaml</DependentUpon>
7477
<SubType>Code</SubType>
7578
</Compile>
79+
<Page Include="NewImageDialog.xaml">
80+
<SubType>Designer</SubType>
81+
<Generator>MSBuild:Compile</Generator>
82+
</Page>
7683
</ItemGroup>
7784
<ItemGroup>
7885
<Compile Include="Properties\AssemblyInfo.cs">

0 commit comments

Comments
 (0)