- March 24, 2007
- 12,073
- 7,459
- Home Country
-
Germany
- Moderator
- #1
While I was experimenting with converted svg->xaml graphics I noticed some missing MPF elements.
One of this is "MatrixTransform".
Here my first try to implement this feature, based on other existing transforms:
Then it's registered in Registration.cs:
Is this the right way to handle this? Dp I have to use "String" for "Matrix" element?
The object gets created, but "Matrix" is not set during my tests.
Morpheus
One of this is "MatrixTransform".
Code:
<RadialGradientBrush.Transform>
<!--radialGradient-->
<MatrixTransform Matrix="1, 0, 0, 0.916055, -70.7146, 48.8309"/>
</RadialGradientBrush.Transform>
Here my first try to implement this feature, based on other existing transforms:
Code:
#region Copyright (C) 2007-2011 Team MediaPortal
/*
Copyright (C) 2007-2011 Team MediaPortal
https://www.team-mediaportal.com
This file is part of MediaPortal 2
MediaPortal 2 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MediaPortal 2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MediaPortal 2. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Globalization;
using MediaPortal.Core.General;
using MediaPortal.Utilities.DeepCopy;
namespace MediaPortal.UI.SkinEngine.Controls.Transforms
{
public class MatrixTransform : Transform
{
#region Protected fields
protected AbstractProperty _matrixStringProperty;
#endregion
#region Ctor
public MatrixTransform()
{
Init();
Attach();
}
public override void Dispose()
{
base.Dispose();
Detach();
}
void Init()
{
_matrixStringProperty = new SProperty(typeof(string), string.Empty);
}
void Attach()
{
_matrixStringProperty.Attach(OnPropertyChanged);
}
void Detach()
{
_matrixStringProperty.Detach(OnPropertyChanged);
}
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
{
Detach();
base.DeepCopy(source, copyManager);
MatrixTransform t = (MatrixTransform) source;
Matrix = t.Matrix;
Attach();
}
#endregion
public AbstractProperty MatrixProperty
{
get { return _matrixStringProperty; }
}
public string Matrix
{
get { return (string) _matrixStringProperty.GetValue(); }
set { _matrixStringProperty.SetValue(value); CreateMatrix(); }
}
void CreateMatrix()
{
_matrix = SlimDX.Matrix.Identity;
string[] matrixParts = Matrix.Split(',');
if (matrixParts.Length == 6)
{
ParseToFloat(ref _matrix.M11, matrixParts[0]);
ParseToFloat(ref _matrix.M12, matrixParts[1]);
ParseToFloat(ref _matrix.M21, matrixParts[2]);
ParseToFloat(ref _matrix.M22, matrixParts[3]);
ParseToFloat(ref _matrix.M41, matrixParts[4]);
ParseToFloat(ref _matrix.M42, matrixParts[5]);
_needUpdate = false;
}
}
static void ParseToFloat(ref float target, string value)
{
target = float.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
}
}
}
Then it's registered in Registration.cs:
Code:
_objectClassRegistrations.Add("MatrixTransform", typeof(SkinEngine.Controls.Transforms.MatrixTransform));
Is this the right way to handle this? Dp I have to use "String" for "Matrix" element?
The object gets created, but "Matrix" is not set during my tests.
Morpheus