Skip to content

Commit

Permalink
Added image support to controlStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Mar 9, 2020
1 parent 44fe93e commit 28a467e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
1 change: 1 addition & 0 deletions Arma.Studio.UiEditor/ArmA.Studio.UiEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="Data\ControlXListBox.cs" />
<Compile Include="Data\ControlXSlider.cs" />
<Compile Include="Data\InterfaceSize.cs" />
<Compile Include="UI\Converters\ControlTextImageConverter.cs" />
<Compile Include="UI\Converters\SizeExToFontSizeMultiConverter.cs" />
<Compile Include="UI\EEditorMouseMode.cs" />
<Compile Include="UI\CanvasManager.cs" />
Expand Down
17 changes: 13 additions & 4 deletions Arma.Studio.UiEditor/Data/ControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,25 @@ public bool IsDeletable
/// Initial fade of the control
/// </summary>
[ArmaName("fade", Group = PropGroup_Visual)]
public double Opacity
public double Fade
{
get => this._Opacity;
get => this._Fade;
set
{
this._Opacity = value;
this._Fade = value;
this.RaisePropertyChanged();
this.RaisePropertyChanged(nameof(Opacity));
}
}
private double _Fade;
public double Opacity
{
get => 1 - this._Fade;
set
{
this.Fade = 1 - value;
}
}
private double _Opacity;
#endregion
#region Property: Url {url} (System.String)
/// <summary>
Expand Down
11 changes: 9 additions & 2 deletions Arma.Studio.UiEditor/Data/ControlStatic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<DataTemplate DataType="{x:Type local:ControlStatic}">
<DataTemplate.Resources>
<converters:SizeExToFontSizeMultiConverter x:Key="SizeExToFontSizeMultiConverter"/>
<converters:ControlTextImageConverter x:Key="ControlTextImageConverter"/>
</DataTemplate.Resources>
<Grid>
<Grid.ToolTip>
Expand Down Expand Up @@ -34,7 +35,7 @@
</Style>
</Grid.Style>
<Rectangle Width="{Binding Width}"
Height="{Binding Height}">
Height="{Binding Height}">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding BackgroundColor}"/>
</Rectangle.Fill>
Expand Down Expand Up @@ -62,7 +63,13 @@
</Style>
</TextBlock.Style>
</TextBlock>
<Image Source="{Binding Text}">
<Image Source="{Binding Text, Converter={StaticResource ControlTextImageConverter}}"
Width="{Binding Width}"
Height="{Binding Height}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Stretch="Fill"
StretchDirection="Both">
<Image.Style>
<Style TargetType="Image">
<Setter Property="Visibility" Value="Collapsed"/>
Expand Down
45 changes: 45 additions & 0 deletions Arma.Studio.UiEditor/UI/Converters/ControlTextImageConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Arma.Studio.Data;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace Arma.Studio.UiEditor.UI.Converters
{
public class ControlTextImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string str)
{
str = str.TrimStart('\\', '/', ' ', '\t');
var pbo = (Application.Current as IApp).MainWindow.FileManagement.FirstOrDefault((it) => str.StartsWith(it.FullPath, StringComparison.InvariantCultureIgnoreCase) || str.StartsWith(it.Prefix, StringComparison.InvariantCultureIgnoreCase));
if (pbo is null)
{
return null;
}
if (str.StartsWith(pbo.Prefix))
{
return System.IO.Path.Combine(pbo.FullPath, str.Substring(pbo.Prefix.Length).TrimStart('\\', '/', ' ', '\t'));
}
else
{
return str;
}
}
else
{
return value;
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

0 comments on commit 28a467e

Please sign in to comment.