private static void ApplySet(Value value, RenderableData renderData, ref Matrix4x4 matrix) { int count = value.Count; for (int i = 0; i < count; i++) { // Get the child value: Value childValue = value[i]; // Get it as a transformation: Css.Functions.Transformation transformation = childValue as Css.Functions.Transformation; if (transformation != null) { // Apply to matrix: matrix *= transformation.CalculateMatrix(renderData); } else if (childValue.Type == ValueType.Set) { // This occurs if they used an awkward combo of ' ' and ,. // No problems though - it's supported :) ApplySet(childValue, renderData, ref matrix); } } }
/// <summary>Sets the defaults for one or more transform functions.</summary> private void SetDefaults(Css.Value set) { // Get as a function: Css.Functions.Transformation tf = set as Css.Functions.Transformation; if (tf != null) { tf.SetDefaults(); return; } // Should be a set: if (set is Css.ValueSet) { for (int i = 0; i < set.Count; i++) { // Get as a function: tf = set[i] as Css.Functions.Transformation; if (tf != null) { tf.SetDefaults(); } } } }
/// <summary>Computes a Matrix4x4 from a valid transform value.</summary> public static Matrix4x4 Compute(Css.Value value, RenderableData renderData) { Matrix4x4 matrix = Matrix4x4.identity; if (value == null) { return(matrix); } // For each function in value, combine into matrix. // We either have a set of [TransformFunction]'s or a transform function Css.Functions.Transformation transformation = value as Css.Functions.Transformation; if (transformation != null) { // Single value. matrix = transformation.CalculateMatrix(renderData); } else if (value.Type == ValueType.Set) { // Set of transformation functions: ApplySet(value, renderData, ref matrix); } return(matrix); }