Skip to content

Commit aebc99f

Browse files
Transform (#7)
* Transform buttons prototype * Transform button tooltips * Transform work in progress * Flip tool; VS cleanup * Revert "Flip tool; VS cleanup" This reverts commit 98193fd. * Flip tool * VS cleanup * Rotate tool * Rotation title fix * Center tool * Merge fix * Crop tool; resize models
1 parent 911688b commit aebc99f

24 files changed

+830
-12
lines changed

Pixed/Controls/TooltipButton.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Pixed.Controls
2+
{
3+
internal class TooltipButton
4+
{
5+
public string ButtonText { get; set; } = string.Empty;
6+
public string ButtonDescription { get; set; } = string.Empty;
7+
}
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<UserControl x:Class="Pixed.Controls.TooltipWith2Buttons"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Pixed.Controls"
7+
mc:Ignorable="d"
8+
d:DesignHeight="450" d:DesignWidth="800">
9+
<StackPanel Background="Black">
10+
<TextBlock FontWeight="Bold" FontSize="14" Margin="0,0,0,5" Text="{Binding Title, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith2Buttons}}" Foreground="White"></TextBlock>
11+
<WrapPanel>
12+
<Border Padding="2" BorderBrush="#999" BorderThickness="1" Margin="0,0,5,0">
13+
<TextBlock Text="{Binding ButtonText1, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith2Buttons}}" FontSize="10" Foreground="White"/>
14+
</Border>
15+
<TextBlock FontSize="12" Foreground="White" Text="{Binding ButtonTextHelper1, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith2Buttons}}"/>
16+
</WrapPanel>
17+
<WrapPanel>
18+
<Border Padding="2" BorderBrush="#999" BorderThickness="1" Margin="0,0,5,0">
19+
<TextBlock Text="{Binding ButtonText2, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith2Buttons}}" FontSize="10" Foreground="White"/>
20+
</Border>
21+
<TextBlock FontSize="12" Foreground="White" Text="{Binding ButtonTextHelper2, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith2Buttons}}"/>
22+
</WrapPanel>
23+
</StackPanel>
24+
</UserControl>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace Pixed.Controls
5+
{
6+
/// <summary>
7+
/// Interaction logic for TooltipWith2Buttons.xaml
8+
/// </summary>
9+
public partial class TooltipWith2Buttons : UserControl
10+
{
11+
public string Title
12+
{
13+
get { return (string)GetValue(TitleProperty); }
14+
set { SetValue(TitleProperty, value); }
15+
}
16+
17+
public string ButtonText1
18+
{
19+
get { return (string)GetValue(ButtonText1Property); }
20+
set { SetValue(ButtonText1Property, value); }
21+
}
22+
23+
public string ButtonTextHelper1
24+
{
25+
get { return (string)GetValue(ButtonTextHelper1Property); }
26+
set { SetValue(ButtonTextHelper1Property, value); }
27+
}
28+
29+
public string ButtonText2
30+
{
31+
get { return (string)GetValue(ButtonText2Property); }
32+
set { SetValue(ButtonText2Property, value); }
33+
}
34+
35+
public string ButtonTextHelper2
36+
{
37+
get { return (string)GetValue(ButtonTextHelper2Property); }
38+
set { SetValue(ButtonTextHelper2Property, value); }
39+
}
40+
41+
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(TooltipWith2Buttons), new PropertyMetadata("Title"));
42+
public static readonly DependencyProperty ButtonText1Property = DependencyProperty.Register("ButtonText1", typeof(string), typeof(TooltipWith2Buttons), new PropertyMetadata("ButtonText1"));
43+
public static readonly DependencyProperty ButtonTextHelper1Property = DependencyProperty.Register("ButtonTextHelper1", typeof(string), typeof(TooltipWith2Buttons), new PropertyMetadata("ButtonTextHelper1"));
44+
public static readonly DependencyProperty ButtonText2Property = DependencyProperty.Register("ButtonText2", typeof(string), typeof(TooltipWith2Buttons), new PropertyMetadata("ButtonText2"));
45+
public static readonly DependencyProperty ButtonTextHelper2Property = DependencyProperty.Register("ButtonTextHelper2", typeof(string), typeof(TooltipWith2Buttons), new PropertyMetadata("ButtonTextHelper2"));
46+
public TooltipWith2Buttons()
47+
{
48+
InitializeComponent();
49+
}
50+
}
51+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<UserControl x:Class="Pixed.Controls.TooltipWith3Buttons"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Pixed.Controls"
7+
mc:Ignorable="d"
8+
d:DesignHeight="450" d:DesignWidth="800">
9+
<StackPanel Background="Black">
10+
<TextBlock FontWeight="Bold" FontSize="14" Margin="0,0,0,5" Text="{Binding Title, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith3Buttons}}" Foreground="White"></TextBlock>
11+
<WrapPanel>
12+
<Border Padding="2" BorderBrush="#999" BorderThickness="1" Margin="0,0,5,0">
13+
<TextBlock Text="{Binding ButtonText1, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith3Buttons}}" FontSize="10" Foreground="White"/>
14+
</Border>
15+
<TextBlock FontSize="12" Foreground="White" Text="{Binding ButtonTextHelper1, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith3Buttons}}"/>
16+
</WrapPanel>
17+
<WrapPanel>
18+
<Border Padding="2" BorderBrush="#999" BorderThickness="1" Margin="0,0,5,0">
19+
<TextBlock Text="{Binding ButtonText2, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith3Buttons}}" FontSize="10" Foreground="White"/>
20+
</Border>
21+
<TextBlock FontSize="12" Foreground="White" Text="{Binding ButtonTextHelper2, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith3Buttons}}"/>
22+
</WrapPanel>
23+
<WrapPanel>
24+
<Border Padding="2" BorderBrush="#999" BorderThickness="1" Margin="0,0,5,0">
25+
<TextBlock Text="{Binding ButtonText3, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith3Buttons}}" FontSize="10" Foreground="White"/>
26+
</Border>
27+
<TextBlock FontSize="12" Foreground="White" Text="{Binding ButtonTextHelper3, RelativeSource={RelativeSource FindAncestor, AncestorType=local:TooltipWith3Buttons}}"/>
28+
</WrapPanel>
29+
</StackPanel>
30+
</UserControl>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace Pixed.Controls
5+
{
6+
/// <summary>
7+
/// Interaction logic for TooltipWith3Buttons.xaml
8+
/// </summary>
9+
public partial class TooltipWith3Buttons : UserControl
10+
{
11+
public string Title
12+
{
13+
get { return (string)GetValue(TitleProperty); }
14+
set { SetValue(TitleProperty, value); }
15+
}
16+
17+
public string ButtonText1
18+
{
19+
get { return (string)GetValue(ButtonText1Property); }
20+
set { SetValue(ButtonText1Property, value); }
21+
}
22+
23+
public string ButtonTextHelper1
24+
{
25+
get { return (string)GetValue(ButtonTextHelper1Property); }
26+
set { SetValue(ButtonTextHelper1Property, value); }
27+
}
28+
29+
public string ButtonText2
30+
{
31+
get { return (string)GetValue(ButtonText2Property); }
32+
set { SetValue(ButtonText2Property, value); }
33+
}
34+
35+
public string ButtonTextHelper2
36+
{
37+
get { return (string)GetValue(ButtonTextHelper2Property); }
38+
set { SetValue(ButtonTextHelper2Property, value); }
39+
}
40+
41+
public string ButtonText3
42+
{
43+
get { return (string)GetValue(ButtonText3Property); }
44+
set { SetValue(ButtonText3Property, value); }
45+
}
46+
47+
public string ButtonTextHelper3
48+
{
49+
get { return (string)GetValue(ButtonTextHelper3Property); }
50+
set { SetValue(ButtonTextHelper3Property, value); }
51+
}
52+
53+
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(TooltipWith3Buttons), new PropertyMetadata("Title"));
54+
public static readonly DependencyProperty ButtonText1Property = DependencyProperty.Register("ButtonText1", typeof(string), typeof(TooltipWith3Buttons), new PropertyMetadata("ButtonText1"));
55+
public static readonly DependencyProperty ButtonTextHelper1Property = DependencyProperty.Register("ButtonTextHelper1", typeof(string), typeof(TooltipWith3Buttons), new PropertyMetadata("ButtonTextHelper1"));
56+
public static readonly DependencyProperty ButtonText2Property = DependencyProperty.Register("ButtonText2", typeof(string), typeof(TooltipWith3Buttons), new PropertyMetadata("ButtonText2"));
57+
public static readonly DependencyProperty ButtonTextHelper2Property = DependencyProperty.Register("ButtonTextHelper2", typeof(string), typeof(TooltipWith3Buttons), new PropertyMetadata("ButtonTextHelper2"));
58+
public static readonly DependencyProperty ButtonText3Property = DependencyProperty.Register("ButtonText3", typeof(string), typeof(TooltipWith3Buttons), new PropertyMetadata("ButtonText3"));
59+
public static readonly DependencyProperty ButtonTextHelper3Property = DependencyProperty.Register("ButtonTextHelper3", typeof(string), typeof(TooltipWith3Buttons), new PropertyMetadata("ButtonTextHelper3"));
60+
public TooltipWith3Buttons()
61+
{
62+
InitializeComponent();
63+
}
64+
}
65+
}

Pixed/MainWindow.xaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,44 @@
188188
<Border BorderThickness="2" BorderBrush="#888" Margin="8">
189189
<StackPanel>
190190
<TextBlock Text="Transform" Height="32" Foreground="White" FontSize="15px" Padding="4" FontWeight="Bold"/>
191+
<UniformGrid Rows="1" Columns="4" Width="184" Height="46">
192+
<Button Style="{StaticResource ToolButton}" Command="{Binding ToolFlipCommand}" Content="../Resources/Icons/transform/tool-flip.png" Grid.Column="0" Grid.Row="0">
193+
<Button.ToolTip>
194+
<ToolTip Background="Black" BorderThickness="0">
195+
<controls:TooltipWith3Buttons Title="Flip horizontaly"
196+
ButtonText1="Alt" ButtonTextHelper1="Flip vertically"
197+
ButtonText2="Ctrl" ButtonTextHelper2="Apply to all layers"
198+
ButtonText3="Shift" ButtonTextHelper3="Apply to all frames"/>
199+
</ToolTip>
200+
</Button.ToolTip>
201+
</Button>
202+
<Button Style="{StaticResource ToolButton}" Command="{Binding ToolRotateCommand}" Content="../Resources/Icons/transform/tool-rotate.png" Grid.Column="1" Grid.Row="0">
203+
<Button.ToolTip>
204+
<ToolTip Background="Black" BorderThickness="0">
205+
<controls:TooltipWith3Buttons Title="Counter-clockwise rotation"
206+
ButtonText1="Alt" ButtonTextHelper1="Clockwise rotation"
207+
ButtonText2="Ctrl" ButtonTextHelper2="Apply to all layers"
208+
ButtonText3="Shift" ButtonTextHelper3="Apply to all frames"/>
209+
</ToolTip>
210+
</Button.ToolTip>
211+
</Button>
212+
<Button Style="{StaticResource ToolButton}" Command="{Binding ToolCenterCommand}" Content="../Resources/Icons/transform/tool-center.png" Grid.Column="2" Grid.Row="0">
213+
<Button.ToolTip>
214+
<ToolTip Background="Black" BorderThickness="0">
215+
<controls:TooltipWith2Buttons Title="Align image to the center"
216+
ButtonText1="Ctrl" ButtonTextHelper1="Apply to all layers"
217+
ButtonText2="Shift" ButtonTextHelper2="Apply to all frames"/>
218+
</ToolTip>
219+
</Button.ToolTip>
220+
</Button>
221+
<Button Style="{StaticResource ToolButton}" Command="{Binding ToolCropCommand}" Content="../Resources/Icons/transform/tool-crop.png" Grid.Column="3" Grid.Row="0">
222+
<Button.ToolTip>
223+
<ToolTip Background="Black" BorderThickness="0">
224+
<controls:SimpleTooltip Title="Crop to fit the content or the selection. Applies to all frames and layers!"/>
225+
</ToolTip>
226+
</Button.ToolTip>
227+
</Button>
228+
</UniformGrid>
191229
</StackPanel>
192230
</Border>
193231

Pixed/Models/Frame.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ public Frame(int width, int height)
4949
AddLayer(new Layer(width, height));
5050
}
5151

52+
public static Frame FromLayers(ObservableCollection<Layer> layers)
53+
{
54+
Frame frame = new Frame(layers[0].Width, layers[0].Height);
55+
frame.Layers.Clear();
56+
57+
foreach(var layer in layers)
58+
{
59+
frame.AddLayer(layer);
60+
}
61+
62+
return frame;
63+
}
64+
5265
public Frame Clone()
5366
{
5467
Frame frame = new Frame(Width, Height);
@@ -117,9 +130,9 @@ public Bitmap Render()
117130
return render;
118131
}
119132

120-
public bool PointInside(int x, int y)
133+
public bool ContainsPixel(int x, int y)
121134
{
122-
return x >= 0 && y >= 0 && x < Width && y < Height;
135+
return _layers[_selectedLayer].ContainsPixel(x, y);
123136
}
124137

125138
public void MoveLayerUp(bool toTop)

Pixed/Models/Layer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,10 @@ public Bitmap Render()
150150
_needRerender = false;
151151
return bitmap;
152152
}
153+
154+
public bool ContainsPixel(int x, int y)
155+
{
156+
return x >= 0 && y >= 0 && x < Width && y < Height;
157+
}
153158
}
154159
}

Pixed/Models/PixedModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@ internal class PixedModel
1010
private int _historyIndex = -1;
1111

1212
public ObservableCollection<Frame> Frames => _frames;
13+
public int Width => Frames[0].Width;
14+
public int Height => Frames[0].Height;
1315

1416
public PixedModel()
1517
{
1618
_frames = [];
1719
_history = [];
1820
}
1921

22+
public static PixedModel FromFrames(ObservableCollection<Frame> frames)
23+
{
24+
PixedModel model = new PixedModel();
25+
26+
foreach(var frame in frames)
27+
{
28+
model.Frames.Add(frame);
29+
}
30+
31+
return model;
32+
}
33+
2034
public void AddHistory(HistoryEntry entry)
2135
{
2236
_history.Add(entry);

Pixed/Selection/BaseSelection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void FillSelectionFromFrame(Frame frame)
3535
{
3636
var pixel = Pixels[i];
3737

38-
if (!frame.PointInside(pixel.X, pixel.Y))
38+
if (!frame.ContainsPixel(pixel.X, pixel.Y))
3939
{
4040
continue;
4141
}

0 commit comments

Comments
 (0)