Skip to content

Commit b68ff74

Browse files
authored
Merge pull request #776 from johncbaur/VIX-3796
VIX-3796 Add the ability to select preview background image
2 parents 689a9e1 + 63c8ea6 commit b68ff74

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/Vixen.Application/SetupDisplay/ViewModels/SetupDisplayViewModel.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
using VixenModules.App.Props.Models.Arch;
2727
using VixenModules.App.Props.Models.Tree;
28+
using VixenModules.Preview.VixenPreview.OpenGL;
2829

2930
using Window = System.Windows.Window;
3031

@@ -87,6 +88,9 @@ public SetupDisplayViewModel()
8788
// Initialize the command to center the OpenGL preview
8889
CenterPreview = new RelayCommand(ExecuteCenterPreview);
8990

91+
// Initialize the select background image command
92+
SelectBackgroundImage = new RelayCommand(SelectBackground);
93+
9094
// Create the collection of view model rotations
9195
Rotations = new();
9296

@@ -123,6 +127,11 @@ public SetupDisplayViewModel()
123127
/// </summary>
124128
public ICommand CenterPreview { get; private set; }
125129

130+
/// <summary>
131+
/// Command for selecting the background image for the preview.
132+
/// </summary>
133+
public ICommand SelectBackgroundImage { get; private set; }
134+
126135
/// <summary>
127136
/// Gets or sets the SelectedProp value.
128137
/// </summary>
@@ -158,6 +167,32 @@ public ObservableCollection<AxisRotationViewModel> Rotations
158167

159168
#region Private Methods
160169

170+
/// <summary>
171+
/// Selects the background image.
172+
/// </summary>
173+
private void SelectBackground()
174+
{
175+
// Create the Microsoft Open File Dialog
176+
OpenFileDialog dialog = new OpenFileDialog { Title = "Select a Background", Filter = "JPG Files (*.jpg)|*.jpg" };
177+
178+
// Display the File Selection Dialog
179+
DialogResult? result = dialog.ShowDialog();
180+
181+
// If the user selected a file then...
182+
if (result == DialogResult.OK)
183+
{
184+
// If the background class exists then...
185+
if (DisplayPreviewDrawingEngine.Background != null)
186+
{
187+
// Dispose of the previous background
188+
DisplayPreviewDrawingEngine.Background.Dispose();
189+
}
190+
191+
// Assign the background image to the drawing engine
192+
DisplayPreviewDrawingEngine.Background = new PropPreviewBackground(dialog.FileName, 1.0f);
193+
}
194+
}
195+
161196
/// <summary>
162197
/// Adds the currently selected prop to the preview.
163198
/// </summary>
1.22 KB
Loading

src/Vixen.Application/SetupDisplay/Views/SetupDisplayWindow.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,13 @@
161161
</Grid>
162162
</TabItem>
163163
<TabItem Header="Preview 1">
164-
<glWpfControl:GLWpfControl
164+
<DockPanel>
165+
<ToolBar DockPanel.Dock="Top">
166+
<Button Command="{Binding SelectBackgroundImage}">
167+
<Image Source="BackgroundImage.png" Width="32" Height="32"/>
168+
</Button>
169+
</ToolBar>
170+
<glWpfControl:GLWpfControl
165171
x:Name="OpenTkControlPreview"
166172
Render="OpenTkControlPreview_OnRender"
167173
SizeChanged="OpenTkControlPreview_SizeChanged"
@@ -178,6 +184,7 @@
178184
</ContextMenu>
179185
</glWpfControl:GLWpfControl.ContextMenu>
180186
</glWpfControl:GLWpfControl>
187+
</DockPanel>
181188
</TabItem>
182189
</TabControl>
183190
</Grid>

src/Vixen.Application/Vixen.Application.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<ItemGroup>
2020
<None Remove="NLog.config" />
21+
<None Remove="SetupDisplay\Views\BackgroundImage.png" />
2122
</ItemGroup>
2223

2324
<ItemGroup>
@@ -98,4 +99,10 @@
9899
<Folder Include="SetupDisplay\Services\" />
99100
</ItemGroup>
100101

102+
<ItemGroup>
103+
<Resource Include="SetupDisplay\Views\BackgroundImage.png">
104+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
105+
</Resource>
106+
</ItemGroup>
107+
101108
</Project>

0 commit comments

Comments
 (0)