Skip to content

Commit

Permalink
Added multiple background modes for UI-Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Mar 9, 2020
1 parent 28a467e commit 8c90558
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 12 deletions.
1 change: 1 addition & 0 deletions Arma.Studio.Data/ArmA.Studio.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<Compile Include="UI\AttachedProperties\SelectAllOnFocusAttached.cs" />
<Compile Include="UI\AttachedProperties\SelectFileNameOnFocusAttached.cs" />
<Compile Include="UI\Converters\EnumNameConverter.cs" />
<Compile Include="UI\Converters\EnumSourceConverter.cs" />
<Compile Include="UI\Converters\InvertConverter.cs" />
<Compile Include="UI\Converters\AllFalseMultiConverter.cs" />
<Compile Include="UI\Converters\AllTrueMultiConverter.cs" />
Expand Down
56 changes: 56 additions & 0 deletions Arma.Studio.Data/UI/Converters/EnumSourceConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Windows;
using System.Windows.Data;

namespace Arma.Studio.Data.UI.Converters
{
/// <summary>
/// Converts the passed <see cref="Enum"/> value to the corresponding <see cref="String"/> representing its name.
/// Requires the parameter to be the <see cref="Type"/> of the enum to convert.
/// Can convert backwards.
/// </summary>
public class EnumSourceConverter : IValueConverter
{
public static EnumSourceConverter Instance { get => _Instance; set => _Instance = value; }
private static EnumSourceConverter _Instance;

static EnumSourceConverter()
{
_Instance = new EnumSourceConverter();
}
/// <summary>
/// Converts a value
/// </summary>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>A converted value. If the method returns null, the valid null value is used.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Type t && t.IsEnum)
{
return Enum.GetValues(t);
}
return null;
}

/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value that is produced by the binding target.</param>
/// <param name="targetType">The type to convert to.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>A converted value. If the method returns null, the valid null value is used.</returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
3 changes: 3 additions & 0 deletions Arma.Studio.UiEditor/ArmA.Studio.UiEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<ItemGroup>
<EmbeddedResource Include="ParentClasses.cpp" />
</ItemGroup>
<ItemGroup>
<Resource Include="Background.jpg" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent><![CDATA[
Expand Down
Binary file added Arma.Studio.UiEditor/Background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions Arma.Studio.UiEditor/Properties/Language.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Arma.Studio.UiEditor/Properties/Language.resx
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,10 @@
<data name="LoggerName" xml:space="preserve">
<value>UI-Editor</value>
</data>
<data name="UiEditor_Background" xml:space="preserve">
<value>Background</value>
</data>
<data name="UiEditor_Background_ToolTip" xml:space="preserve">
<value>The Background displayed in the canvas area.</value>
</data>
</root>
20 changes: 20 additions & 0 deletions Arma.Studio.UiEditor/UI/CanvasManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class CanvasManager : INotifyPropertyChanged,
IOnDrop
{

public enum EBackgroundMode
{
NA,
Grid,
Arma
}

public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged([CallerMemberName]string callee = "") => this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(callee));
#region Collection: SelectedNodes (System.Collections.ObjectModel.ObservableCollection<Data.IControlElement>)
Expand Down Expand Up @@ -143,6 +150,7 @@ public CanvasManager(UiEditorDataContext owner)
this.Height = 1080;
this.Zoom = 0.5;
this.Cursor = Cursors.Arrow;
this.BackgroundMode = EBackgroundMode.Grid;
}
private readonly UiEditorDataContext Owner;

Expand Down Expand Up @@ -224,6 +232,18 @@ public double Width
}
private double _Width;
#endregion
#region Property: BackgroundMode (EBackgroundMode)
public EBackgroundMode BackgroundMode
{
get => this._BackgroundMode;
set
{
this._BackgroundMode = value;
this.RaisePropertyChanged();
}
}
private EBackgroundMode _BackgroundMode;
#endregion
#region Property: Height (System.Double)
public double Height
{
Expand Down
47 changes: 35 additions & 12 deletions Arma.Studio.UiEditor/UI/UiEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,35 @@
Cursor="{Binding CanvasManager.Cursor}">
<Canvas.Style>
<Style TargetType="Canvas">
<Setter Property="Background">
<Setter.Value>
<VisualBrush TileMode="Tile"
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<DataTrigger Binding="{Binding CanvasManager.BackgroundMode}" Value="Arma">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/Arma.Studio.UiEditor;component/Background.jpg"/>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding CanvasManager.BackgroundMode}" Value="Grid">
<Setter Property="Background">
<Setter.Value>
<VisualBrush TileMode="Tile"
Viewport="{Binding CanvasManager.GridSize, Converter={StaticResource ToRectangleConverter}}"
ViewportUnits="Absolute"
Viewbox="0,0,50,50"
ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Rectangle Stroke="#FF7F7F7F"
<VisualBrush.Visual>
<Rectangle Stroke="#FF7F7F7F"
StrokeThickness="1"
StrokeDashArray="0,50,0,50"
Fill="White"
Width="50"
Height="50"
RenderSize="50,50"/>
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding CanvasManager.ShowGrid}" Value="False">
<Setter Property="Background" Value="White"/>
</VisualBrush.Visual>
</VisualBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
Expand Down Expand Up @@ -117,6 +124,22 @@
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<Grid ToolTip="{x:Static p:Language.UiEditor_Background_ToolTip}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="4"/>
<ColumnDefinition MinWidth="64" Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{x:Static p:Language.UiEditor_Background}" Grid.Column="0" VerticalAlignment="Center"/>
<ComboBox ItemsSource="{Binding Source={x:Type local:CanvasManager+EBackgroundMode}, Converter={StaticResource EnumSourceConverter}}"
SelectedItem="{Binding CanvasManager.BackgroundMode}" Grid.Column="2">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource EnumNameConverter}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<Grid ToolTip="{x:Static p:Language.UiEditor_CanvasGridSize_ToolTip}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down
2 changes: 2 additions & 0 deletions Arma.Studio/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<asd:SingleToCollectionConverter x:Key="SingleToCollectionConverter"/>
<asd:ToCompositeCollectionMultiConverter x:Key="ToCompositeCollectionMultiConverter"/>
<asd:ToRectangleConverter x:Key="ToRectangleConverter"/>
<asd:EnumNameConverter x:Key="EnumNameConverter"/>
<asd:EnumSourceConverter x:Key="EnumSourceConverter"/>
</ResourceDictionary>
<ResourceDictionary>
<DrawingBrush x:Key="DrawingBrushStatusInformation">
Expand Down

0 comments on commit 8c90558

Please sign in to comment.