Skip to content

Commit 225c2cd

Browse files
committed
Update v2.3
1 parent 3135ba8 commit 225c2cd

14 files changed

Lines changed: 307 additions & 27 deletions

EmptyKeys.UserInterface.Designer/EmptyKeys.UserInterface.Designer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="EventTrigger.cs" />
7272
<Compile Include="GeneratedBindingsMode.cs" />
7373
<Compile Include="GeneratedBindings.cs" />
74+
<Compile Include="ImageButton.cs" />
7475
<Compile Include="Input\GamepadBinding.cs" />
7576
<Compile Include="Input\GamepadGesture.cs" />
7677
<Compile Include="Input\GamepadInput.cs" />
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Media;
9+
using System.Windows.Media.Imaging;
10+
11+
namespace EmptyKeys.UserInterface.Designer
12+
{
13+
/// <summary>
14+
/// Implements button with image
15+
/// </summary>
16+
public class ImageButton : Button
17+
{
18+
private static readonly Type typeOfThis = typeof(ImageButton);
19+
private static DependencyObjectType dependencyType;
20+
21+
/// <summary>
22+
/// The image normal property
23+
/// </summary>
24+
public static readonly DependencyProperty ImageNormalProperty =
25+
DependencyProperty.Register("ImageNormal", typeof(BitmapImage), typeOfThis,
26+
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure));
27+
28+
/// <summary>
29+
/// Gets or sets the image normal.
30+
/// </summary>
31+
/// <value>
32+
/// The image normal.
33+
/// </value>
34+
public BitmapImage ImageNormal
35+
{
36+
get { return (BitmapImage)GetValue(ImageNormalProperty); }
37+
set { SetValue(ImageNormalProperty, value); }
38+
}
39+
40+
/// <summary>
41+
/// The image pressed property
42+
/// </summary>
43+
public static readonly DependencyProperty ImagePressedProperty =
44+
DependencyProperty.Register("ImagePressed", typeof(BitmapImage), typeOfThis,
45+
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure));
46+
47+
/// <summary>
48+
/// Gets or sets the image pressed.
49+
/// </summary>
50+
/// <value>
51+
/// The image pressed.
52+
/// </value>
53+
public BitmapImage ImagePressed
54+
{
55+
get { return (BitmapImage)GetValue(ImagePressedProperty); }
56+
set { SetValue(ImagePressedProperty, value); }
57+
}
58+
59+
/// <summary>
60+
/// The image hover property
61+
/// </summary>
62+
public static readonly DependencyProperty ImageHoverProperty =
63+
DependencyProperty.Register("ImageHover", typeof(BitmapImage), typeOfThis,
64+
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure));
65+
66+
/// <summary>
67+
/// Gets or sets the image hover.
68+
/// </summary>
69+
/// <value>
70+
/// The image hover.
71+
/// </value>
72+
public BitmapImage ImageHover
73+
{
74+
get { return (BitmapImage)GetValue(ImageHoverProperty); }
75+
set { SetValue(ImageHoverProperty, value); }
76+
}
77+
78+
/// <summary>
79+
/// The image disabled property
80+
/// </summary>
81+
public static readonly DependencyProperty ImageDisabledProperty =
82+
DependencyProperty.Register("ImageDisabled", typeof(BitmapImage), typeOfThis,
83+
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure));
84+
85+
/// <summary>
86+
/// Gets or sets the image disabled.
87+
/// </summary>
88+
/// <value>
89+
/// The image disabled.
90+
/// </value>
91+
public BitmapImage ImageDisabled
92+
{
93+
get { return (BitmapImage)GetValue(ImageDisabledProperty); }
94+
set { SetValue(ImageDisabledProperty, value); }
95+
}
96+
97+
/*
98+
/// <summary>
99+
/// The image focused property
100+
/// </summary>
101+
public static readonly DependencyProperty ImageFocusedProperty =
102+
DependencyProperty.Register("ImageFocused", typeof(BitmapImage), typeOfThis,
103+
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure));
104+
105+
/// <summary>
106+
/// Gets or sets the image focused.
107+
/// </summary>
108+
/// <value>
109+
/// The image focused.
110+
/// </value>
111+
public BitmapImage ImageFocused
112+
{
113+
get { return (BitmapImage)GetValue(ImageFocusedProperty); }
114+
set { SetValue(ImageFocusedProperty, value); }
115+
}
116+
*/
117+
118+
/// <summary>
119+
/// The image stretch property
120+
/// </summary>
121+
public static readonly DependencyProperty ImageStretchProperty =
122+
DependencyProperty.Register("ImageStretch", typeof(Stretch), typeOfThis,
123+
new FrameworkPropertyMetadata(Stretch.Uniform, FrameworkPropertyMetadataOptions.AffectsMeasure));
124+
125+
/// <summary>
126+
/// Gets or sets the image stretch.
127+
/// </summary>
128+
/// <value>
129+
/// The image stretch.
130+
/// </value>
131+
public Stretch ImageStretch
132+
{
133+
get { return (Stretch)GetValue(ImageStretchProperty); }
134+
set { SetValue(ImageStretchProperty, value); }
135+
}
136+
137+
/// <summary>
138+
/// Initializes the <see cref="ImageButton"/> class.
139+
/// </summary>
140+
static ImageButton()
141+
{
142+
}
143+
144+
/// <summary>
145+
/// Initializes a new instance of the <see cref="ImageButton"/> class.
146+
/// </summary>
147+
public ImageButton()
148+
: base()
149+
{
150+
}
151+
}
152+
}

EmptyKeys.UserInterface.Designer/Themes/Generic.xaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,31 @@
4444
</Setter.Value>
4545
</Setter>
4646
</Style>
47+
48+
<ControlTemplate x:Key="ImageButtonTemplate" TargetType="{x:Type local:ImageButton}">
49+
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" >
50+
<StackPanel Orientation="Horizontal" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
51+
<Image Name="PART_Image" Source="{TemplateBinding ImageNormal}" />
52+
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"
53+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
54+
</StackPanel>
55+
</Border>
56+
<ControlTemplate.Triggers>
57+
<Trigger Property="IsMouseOver" Value="true">
58+
<Setter TargetName="PART_Image" Property="Source" Value="{Binding ImageHover, RelativeSource={RelativeSource TemplatedParent}}" />
59+
</Trigger>
60+
<Trigger Property="IsPressed" Value="true">
61+
<Setter TargetName="PART_Image" Property="Source" Value="{Binding ImagePressed, RelativeSource={RelativeSource TemplatedParent}}" />
62+
</Trigger>
63+
<Trigger Property="IsEnabled" Value="false">
64+
<Setter TargetName="PART_Image" Property="Source" Value="{Binding ImageDisabled, RelativeSource={RelativeSource TemplatedParent}}" />
65+
</Trigger>
66+
</ControlTemplate.Triggers>
67+
</ControlTemplate>
68+
69+
<Style TargetType="{x:Type local:ImageButton}">
70+
<Setter Property="VerticalContentAlignment" Value="Center"/>
71+
<Setter Property="HorizontalContentAlignment" Value="Center"/>
72+
<Setter Property="Template" Value="{StaticResource ImageButtonTemplate}" />
73+
</Style>
4774
</ResourceDictionary>

GlobalAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313

1414
[assembly: NeutralResourcesLanguage("en")]
1515

16-
[assembly: AssemblyVersion("2.2.0.0")]
17-
[assembly: AssemblyFileVersion("2.2.0.0")]
16+
[assembly: AssemblyVersion("2.3.0.0")]
17+
[assembly: AssemblyFileVersion("2.3.0.0")]

UIGenerator/BindingGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ public void GenerateFile(string outputFile)
376376
}
377377
finally
378378
{
379+
string directory = Path.GetDirectoryName(outputFile);
380+
if (!Directory.Exists(directory))
381+
{
382+
Directory.CreateDirectory(directory);
383+
}
384+
379385
using (StreamWriter outfile = new StreamWriter(outputFile))
380386
{
381387
outfile.Write(generatedCode);

UIGenerator/CodeComHelper.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private static CodeExpression GenerateImageBrush(CodeMemberMethod method, string
493493
BitmapImage bitmap = image.ImageSource as BitmapImage;
494494
if (bitmap != null)
495495
{
496-
GenerateBitmapImageField(method, brushExpr, bitmap.UriSource, variableName + "_bm", "ImageSource");
496+
GenerateBitmapImageField(method, brushExpr, image, bitmap.UriSource, variableName + "_bm", ImageBrush.ImageSourceProperty);
497497
}
498498

499499
if (BindingOperations.IsDataBound(image, ImageBrush.ImageSourceProperty))
@@ -533,16 +533,20 @@ private static void GenerateRect(CodeMemberMethod method, CodeExpression brushEx
533533
/// </summary>
534534
/// <param name="method">The method.</param>
535535
/// <param name="fieldReference">The field reference.</param>
536+
/// <param name="source">The source.</param>
536537
/// <param name="uriSource">The URI source.</param>
537538
/// <param name="variableName">Name of the variable.</param>
538-
/// <param name="sourceProperty">The asset property.</param>
539-
public static void GenerateBitmapImageField(CodeMemberMethod method, CodeExpression fieldReference, Uri uriSource, string variableName, string sourceProperty)
539+
/// <param name="property">The property.</param>
540+
public static void GenerateBitmapImageField(CodeMemberMethod method, CodeExpression fieldReference, DependencyObject source, Uri uriSource, string variableName, DependencyProperty property)
540541
{
541-
GenerateBitmapImageValue(method, uriSource, variableName);
542+
if (IsValidForFieldGenerator(source.ReadLocalValue(property)))
543+
{
544+
GenerateBitmapImageValue(method, uriSource, variableName);
542545

543-
method.Statements.Add(new CodeAssignStatement(
544-
new CodeFieldReferenceExpression(fieldReference, sourceProperty),
545-
new CodeVariableReferenceExpression(variableName)));
546+
method.Statements.Add(new CodeAssignStatement(
547+
new CodeFieldReferenceExpression(fieldReference, property.Name),
548+
new CodeVariableReferenceExpression(variableName)));
549+
}
546550
}
547551

548552
/// <summary>

UIGenerator/EmptyKeys.UserInterface.Generator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<Compile Include="Types\Controls\CanvasGeneratorType.cs" />
7878
<Compile Include="Types\Controls\GroupBoxGeneratorType.cs" />
7979
<Compile Include="Types\Controls\HeaderedItemsControlGeneratorType.cs" />
80+
<Compile Include="Types\Controls\ImageButtonGeneratorType.cs" />
8081
<Compile Include="Types\Controls\Primitives\PopupGeneratorType.cs" />
8182
<Compile Include="Types\Controls\Primitives\TabPanelGeneratorType.cs" />
8283
<Compile Include="Types\Controls\RadioButtonGeneratorType.cs" />

UIGenerator/FontGenerator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,14 @@ public void GenerateFontAssets(string path, RenderMode renderMode)
109109
string fileContent = string.Empty;
110110
string extension = ".spritefont";
111111
if (renderMode == RenderMode.Xenko)
112-
{
112+
{
113113
assetName = assetName.Replace(".", "-");
114114
string assetGuid = Guid.NewGuid().ToString();
115-
fileContent = string.Format(template, fontName, fontSize.ToString(CultureInfo.InvariantCulture), fontStyle, assetGuid);
115+
string fontSourceGuid = Guid.NewGuid().ToString();
116+
string fontTypeGuid = Guid.NewGuid().ToString();
117+
string charRegionGuid = Guid.NewGuid().ToString();
118+
string version = "{Xenko: 1.7.0-beta04}";
119+
fileContent = string.Format(template, fontName, info.FontSize.ToString(CultureInfo.InvariantCulture), fontStyle, assetGuid, fontSourceGuid, fontTypeGuid, charRegionGuid, version);
116120
extension = ".xkfnt";
117121
}
118122
else

UIGenerator/TypeGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ public TypeGenerator()
219219

220220
IGeneratorType seriesPoint = new SeriesPointGeneratorType();
221221
Generators.Add(seriesPoint.XamlType, seriesPoint);
222+
223+
IGeneratorType imageButton = new ImageButtonGeneratorType();
224+
Generators.Add(imageButton.XamlType, imageButton);
222225
}
223226

224227
/// <summary>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.CodeDom;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Media;
9+
using System.Windows.Media.Imaging;
10+
using EmptyKeys.UserInterface.Designer;
11+
12+
namespace EmptyKeys.UserInterface.Generator.Types.Controls
13+
{
14+
/// <summary>
15+
/// Implements Image Button generator
16+
/// </summary>
17+
/// <seealso cref="EmptyKeys.UserInterface.Generator.Types.ButtonGeneratorType" />
18+
public class ImageButtonGeneratorType : ButtonGeneratorType
19+
{
20+
/// <summary>
21+
/// Gets the type of the xaml.
22+
/// </summary>
23+
/// <value>
24+
/// The type of the xaml.
25+
/// </value>
26+
public override Type XamlType
27+
{
28+
get
29+
{
30+
return typeof(ImageButton);
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Generates code
36+
/// </summary>
37+
/// <param name="source">The dependence object</param>
38+
/// <param name="classType">Type of the class.</param>
39+
/// <param name="initMethod">The initialize method.</param>
40+
/// <param name="generateField"></param>
41+
/// <returns></returns>
42+
public override CodeExpression Generate(DependencyObject source, CodeTypeDeclaration classType, CodeMemberMethod initMethod, bool generateField)
43+
{
44+
CodeExpression fieldReference = base.Generate(source, classType, initMethod, generateField);
45+
CodeComHelper.GenerateEnumField<Stretch>(initMethod, fieldReference, source, ImageButton.ImageStretchProperty);
46+
47+
ImageButton imageButton = source as ImageButton;
48+
BitmapImage bitmap = imageButton.ImageNormal as BitmapImage;
49+
if (bitmap != null)
50+
{
51+
CodeComHelper.GenerateBitmapImageField(initMethod, fieldReference, source, bitmap.UriSource, imageButton.Name + "_normal_bm", ImageButton.ImageNormalProperty);
52+
}
53+
54+
bitmap = imageButton.ImageDisabled as BitmapImage;
55+
if (bitmap != null)
56+
{
57+
CodeComHelper.GenerateBitmapImageField(initMethod, fieldReference, source, bitmap.UriSource, imageButton.Name + "_disabled_bm", ImageButton.ImageDisabledProperty);
58+
}
59+
60+
bitmap = imageButton.ImageHover as BitmapImage;
61+
if (bitmap != null)
62+
{
63+
CodeComHelper.GenerateBitmapImageField(initMethod, fieldReference, source, bitmap.UriSource, imageButton.Name + "_hover_bm", ImageButton.ImageHoverProperty);
64+
}
65+
66+
bitmap = imageButton.ImagePressed as BitmapImage;
67+
if (bitmap != null)
68+
{
69+
CodeComHelper.GenerateBitmapImageField(initMethod, fieldReference, source, bitmap.UriSource, imageButton.Name + "_pressed_bm", ImageButton.ImagePressedProperty);
70+
}
71+
72+
return fieldReference;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)