protected virtual void CalculateMatrix()
{
//If we are a child of another UIElement, start with our container's Matrix.
//Otherwise, assume our matrix is IDENTITY (aka no scale & positioned at 0,0)
if (_Parent != null)
{
_Mtx = _Parent.Matrix.CloneMatrix();
_ScaleParent = _Parent.Scale;
}
else
{
_ScaleParent = Vector2.One;
_Mtx = Matrix2D.IDENTITY;
}
//Translate by our x and y coordinates
_Mtx.Translate(_X, _Y);
//Scale by our scaleX and scaleY values
_Mtx.Scale(_ScaleX, _ScaleY);
//Work out the absolute scale factor for this UIElement
_Scale = _Mtx.ExtractScaleVector();
//Because Matrix has changed, that means the inverted matrix is now invalid.
//Make this null so that next time its requested it gets recalculated
_InvertedMtx = null;
//Matrix is no longer dirty :)
_MtxDirty = false;
//We cache mouse target positions, because our coordinates have changed these are no longer valid.
_HitTestCache.Clear();
}