Skip to content

Commit 42bc126

Browse files
author
RandomEngy
committed
Adding icon to Preview button.
1 parent 60e23f9 commit 42bc126

10 files changed

Lines changed: 76 additions & 10 deletions
-1.94 KB
Binary file not shown.
-2.11 KB
Binary file not shown.

VidCoder/Icons/preview.png

22.7 KB
Loading

VidCoder/VidCoder.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@
353353
<Content Include="BuiltInPresets.xml">
354354
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
355355
</Content>
356+
<Resource Include="Icons\preview.png" />
356357
<Resource Include="Icons\VidCoder.png" />
357358
<Resource Include="Icons\error.png" />
358359
<Resource Include="Icons\copy.png" />

VidCoder/View/AboutDialog.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<TextBlock HorizontalAlignment="Left" Name="versionLabel" Text="Version" VerticalAlignment="Top" />
1515
<TextBlock Text="{Binding Version}" Margin="5,0,0,0" Name="versionText" />
1616
</StackPanel>
17-
<TextBlock Height="23" HorizontalAlignment="Left" Margin="171,79,0,0" Name="textBlock3" Text="Based on HandBrake (svn3097)" VerticalAlignment="Top" />
17+
<TextBlock Height="23" HorizontalAlignment="Left" Margin="171,79,0,0" Name="textBlock3" Text="Based on HandBrake (svn3182)" VerticalAlignment="Top" />
1818
<TextBlock Height="23" HorizontalAlignment="Left" Margin="171,108,0,0" Name="textBlock2" Text="© 2010 VidCoder Developers" VerticalAlignment="Top" />
1919
<Label Content="License:" Height="28" HorizontalAlignment="Left" Margin="12,138,0,0" Name="label1" VerticalAlignment="Top" />
2020

VidCoder/View/EncodingWindow.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,13 @@
139139
Content="{Binding DeleteButtonText}"
140140
Command="{Binding DeletePresetCommand}" />
141141
</StackPanel>
142-
<Button Height="24" Margin="0,12,12,0" VerticalAlignment="Top" IsEnabled="{Binding HasSourceData}"
143-
Command="{Binding PreviewCommand}" HorizontalAlignment="Right" Width="75">Preview</Button>
142+
<Button Height="26" Margin="0,12,12,0" VerticalAlignment="Top" IsEnabled="{Binding HasSourceData}"
143+
Command="{Binding PreviewCommand}" HorizontalAlignment="Right" Width="77">
144+
<StackPanel Orientation="Horizontal">
145+
<Image Source="/Icons/preview.png" />
146+
<TextBlock Text="Preview" Margin="5,0,0,0" VerticalAlignment="Center" />
147+
</StackPanel>
148+
</Button>
144149
<!--<Label Height="23" Margin="476.523,12,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="16.434" VerticalContentAlignment="Center">#</Label>
145150
<ComboBox SelectedValue="{Binding SelectedPreview}" SelectedValuePath="Content" Height="23" Margin="490.75,12,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="36.5"
146151
IsEnabled="{Binding PreviewEnabled}">

VidCoder/View/MainWindow.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,13 @@
357357
</StackPanel>
358358
</Button>
359359
<Button
360-
Height="23" HorizontalAlignment="Right" Margin="0,50,12,0" VerticalAlignment="Top" Width="75"
361-
Command="{Binding OpenPreviewWindowCommand}">Preview</Button>
360+
Height="26" HorizontalAlignment="Right" Margin="0,50,12,0" VerticalAlignment="Top" Width="77"
361+
Command="{Binding OpenPreviewWindowCommand}">
362+
<StackPanel Orientation="Horizontal">
363+
<Image Source="/Icons/preview.png" />
364+
<TextBlock Text="Preview" Margin="5,0,0,0" VerticalAlignment="Center" />
365+
</StackPanel>
366+
</Button>
362367

363368
<Button Height="37" HorizontalAlignment="Left" Margin="6,90,0,0" VerticalAlignment="Top" Width="114"
364369
Command="{Binding AddToQueueCommand}">

VidCoder/View/PreviewWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Grid>
1818
<Grid Margin="0" Name="previewImageHolder" SizeChanged="previewImageHolder_SizeChanged" Background="Black">
1919
<Image
20-
Name="previewImage" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center"
20+
Name="previewImage" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Top"
2121
Source="{Binding PreviewSource}"
2222
Visibility="{Binding HasPreview, Converter={StaticResource VisibilityConverter}}"/>
2323
<Grid

VidCoder/View/PreviewWindow.xaml.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,21 @@ public partial class PreviewWindow : Window
2222
{
2323
private PreviewViewModel viewModel;
2424

25+
// DPI factors for the OS. Used to scale back down the images so they display at native resolution.
26+
// Normal DPI: 1.0
27+
// 120 DPI: 1.25
28+
// 144 DPI: 1.5
29+
private double dpiXFactor, dpiYFactor;
30+
2531
public PreviewWindow()
2632
{
2733
InitializeComponent();
2834

35+
// Get system DPI
36+
Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice;
37+
this.dpiXFactor = m.M11;
38+
this.dpiYFactor = m.M22;
39+
2940
this.previewControls.Opacity = 0.0;
3041
this.DataContextChanged += new DependencyPropertyChangedEventHandler(PreviewWindow_DataContextChanged);
3142
}
@@ -60,6 +71,14 @@ protected override void OnSourceInitialized(EventArgs e)
6071
this.Left = workArea.Left + widthRemaining / 2 + 676;
6172
this.Top = workArea.Top + heightRemaining / 2;
6273
}
74+
75+
// Initialize window size to fit 853x480 at native resolution.
76+
double targetImageWidth = 480.0 * (16.0 / 9.0);
77+
double targetImageHeight = 480.0;
78+
79+
// Add some for the window borders and scale to DPI
80+
this.Width = (targetImageWidth + 16.0) / this.dpiXFactor;
81+
this.Height = (targetImageHeight + 34.0) / this.dpiYFactor;
6382
}
6483
else
6584
{
@@ -76,8 +95,12 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
7695
private void RefreshImageSize()
7796
{
7897
PreviewViewModel previewVM = this.DataContext as PreviewViewModel;
79-
double width = previewVM.PreviewWidth;
80-
double height = previewVM.PreviewHeight;
98+
double widthPixels = previewVM.PreviewWidth;
99+
double heightPixels = previewVM.PreviewHeight;
100+
101+
// Convert pixels to WPF length units: we want to keep native image resolution.
102+
double width = widthPixels / this.dpiXFactor;
103+
double height = heightPixels / this.dpiYFactor;
81104

82105
double availableWidth = this.previewImageHolder.ActualWidth;
83106
double availableHeight = this.previewImageHolder.ActualHeight;
@@ -86,6 +109,15 @@ private void RefreshImageSize()
86109
{
87110
this.previewImage.Width = width;
88111
this.previewImage.Height = height;
112+
113+
double left = (availableWidth - width) / 2;
114+
double top = (availableHeight - height) / 2;
115+
116+
// Round to nearest pixel
117+
left = Math.Floor(left * this.dpiXFactor) / this.dpiXFactor;
118+
top = Math.Floor(top * this.dpiYFactor) / this.dpiYFactor;
119+
120+
this.previewImage.Margin = new Thickness(left, top, 0, 0);
89121
return;
90122
}
91123

@@ -96,15 +128,31 @@ private void RefreshImageSize()
96128
{
97129
// If the image is shorter than the space available and is touching the sides
98130
double scalingFactor = availableWidth / width;
131+
double resizedHeight = height * scalingFactor;
99132
this.previewImage.Width = availableWidth;
100-
this.previewImage.Height = height * scalingFactor;
133+
this.previewImage.Height = resizedHeight;
134+
135+
double top = (availableHeight - resizedHeight) / 2;
136+
137+
// Round to nearest pixel
138+
top = Math.Floor(top * this.dpiYFactor) / this.dpiYFactor;
139+
140+
this.previewImage.Margin = new Thickness(0, top, 0, 0);
101141
}
102142
else
103143
{
104144
// If the image is taller than the space available and is touching the top and bottom
105145
double scalingFactor = availableHeight / height;
106-
this.previewImage.Width = width * scalingFactor;
146+
double resizedWidth = width * scalingFactor;
147+
this.previewImage.Width = resizedWidth;
107148
this.previewImage.Height = availableHeight;
149+
150+
double left = (availableWidth - resizedWidth) / 2;
151+
152+
// Round to nearest pixel
153+
left = Math.Floor(left * this.dpiXFactor) / this.dpiXFactor;
154+
155+
this.previewImage.Margin = new Thickness(left, 0, 0, 0);
108156
}
109157
}
110158

VidCoder/ViewModel/PreviewViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ public int SelectedPreview
149149
}
150150
}
151151

152+
/// <summary>
153+
/// Gets or sets the width of the preview image in pixels.
154+
/// </summary>
152155
public double PreviewWidth { get; set; }
156+
157+
/// <summary>
158+
/// Gets or sets the height of the preview image in pixels.
159+
/// </summary>
153160
public double PreviewHeight { get; set; }
154161

155162
public int SliderMax

0 commit comments

Comments
 (0)