3 using System.Collections.Generic;
5 using System.Windows.Controls;
6 using System.Windows.Data;
8 using SiliconStudio.Core.Mathematics;
10 namespace SiliconStudio.Presentation.Controls
14 private static readonly Dictionary<DependencyProperty, int> PropertyToIndex;
15 private bool interlock;
20 public static readonly DependencyProperty MatrixProperty = DependencyProperty.Register(
"Matrix", typeof(
Matrix), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(
default(
Matrix), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMatrixPropertyChanged, null,
false, UpdateSourceTrigger.Explicit));
25 public static readonly DependencyProperty M11Property = DependencyProperty.Register(
"M11", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
30 public static readonly DependencyProperty M12Property = DependencyProperty.Register(
"M12", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
35 public static readonly DependencyProperty M13Property = DependencyProperty.Register(
"M13", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
40 public static readonly DependencyProperty M14Property = DependencyProperty.Register(
"M14", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
45 public static readonly DependencyProperty M21Property = DependencyProperty.Register(
"M21", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
50 public static readonly DependencyProperty M22Property = DependencyProperty.Register(
"M22", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
55 public static readonly DependencyProperty M23Property = DependencyProperty.Register(
"M23", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
60 public static readonly DependencyProperty M24Property = DependencyProperty.Register(
"M24", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
65 public static readonly DependencyProperty M31Property = DependencyProperty.Register(
"M31", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
70 public static readonly DependencyProperty M32Property = DependencyProperty.Register(
"M32", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
75 public static readonly DependencyProperty M33Property = DependencyProperty.Register(
"M33", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
80 public static readonly DependencyProperty M34Property = DependencyProperty.Register(
"M34", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
85 public static readonly DependencyProperty M41Property = DependencyProperty.Register(
"M41", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
90 public static readonly DependencyProperty M42Property = DependencyProperty.Register(
"M42", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
95 public static readonly DependencyProperty M43Property = DependencyProperty.Register(
"M43", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
100 public static readonly DependencyProperty M44Property = DependencyProperty.Register(
"M44", typeof(
float), typeof(
MatrixEditor),
new FrameworkPropertyMetadata(.0f, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnElementValuePropertyChanged));
104 PropertyToIndex =
new Dictionary<DependencyProperty, int> {
105 { M11Property, 0 }, { M12Property, 1 }, { M13Property, 2 }, { M14Property, 3 },
106 { M21Property, 4 }, { M22Property, 5 }, { M23Property, 6 }, { M24Property, 7 },
107 { M31Property, 8 }, { M32Property, 9 }, { M33Property, 10 }, { M34Property, 11 },
108 { M41Property, 12 }, { M42Property, 13 }, { M43Property, 14 }, { M44Property, 15 },
114 public Matrix Matrix {
get {
return (
Matrix)GetValue(MatrixProperty); } set { SetValue(MatrixProperty, value); } }
119 public float M11 {
get {
return (
float)GetValue(M11Property); } set { SetValue(M11Property, value); } }
124 public float M12 {
get {
return (
float)GetValue(M12Property); } set { SetValue(M12Property, value); } }
129 public float M13 {
get {
return (
float)GetValue(M13Property); } set { SetValue(M13Property, value); } }
134 public float M14 {
get {
return (
float)GetValue(M14Property); } set { SetValue(M14Property, value); } }
139 public float M21 {
get {
return (
float)GetValue(M21Property); } set { SetValue(M21Property, value); } }
144 public float M22 {
get {
return (
float)GetValue(M22Property); } set { SetValue(M22Property, value); } }
149 public float M23 {
get {
return (
float)GetValue(M23Property); } set { SetValue(M23Property, value); } }
154 public float M24 {
get {
return (
float)GetValue(M24Property); } set { SetValue(M24Property, value); } }
159 public float M31 {
get {
return (
float)GetValue(M31Property); } set { SetValue(M31Property, value); } }
164 public float M32 {
get {
return (
float)GetValue(M32Property); } set { SetValue(M32Property, value); } }
169 public float M33 {
get {
return (
float)GetValue(M33Property); } set { SetValue(M33Property, value); } }
174 public float M34 {
get {
return (
float)GetValue(M34Property); } set { SetValue(M34Property, value); } }
179 public float M41 {
get {
return (
float)GetValue(M41Property); } set { SetValue(M41Property, value); } }
184 public float M42 {
get {
return (
float)GetValue(M42Property); } set { SetValue(M42Property, value); } }
189 public float M43 {
get {
return (
float)GetValue(M43Property); } set { SetValue(M43Property, value); } }
194 public float M44 {
get {
return (
float)GetValue(M44Property); } set { SetValue(M44Property, value); } }
199 private void OnMatrixValueChanged()
204 foreach (var dependencyProperty
in PropertyToIndex)
206 SetCurrentValue(dependencyProperty.Key,
Matrix[dependencyProperty.Value]);
211 UpdateBinding(MatrixProperty);
218 private void OnElementValueChanged(DependencyPropertyChangedEventArgs e)
223 var array =
new float[16];
224 foreach (var dependencyProperty
in PropertyToIndex)
226 array[dependencyProperty.Value] = e.Property == dependencyProperty.Key ? (float)e.NewValue :
Matrix[dependencyProperty.Value];
233 UpdateBinding(e.Property);
240 private void UpdateBinding(DependencyProperty dependencyProperty)
242 BindingExpression expression = GetBindingExpression(dependencyProperty);
243 if (expression != null)
244 expression.UpdateSource();
252 private static void OnMatrixPropertyChanged(
DependencyObject sender, DependencyPropertyChangedEventArgs e)
254 var editor = (MatrixEditor)sender;
255 editor.OnMatrixValueChanged();
263 private static void OnElementValuePropertyChanged(
DependencyObject sender, DependencyPropertyChangedEventArgs e)
265 var editor = (MatrixEditor)sender;
266 editor.OnElementValueChanged(e);
Represents a 4x4 mathematical matrix.