Ejemplo n.º 1
0
        public static void OutputEnum(Effects.Property enumProperty, Formatter output)
        {
            OutputVersionConditional(enumProperty.WinVer, output);

            output.WriteLine("[version(VERSION)]");
            output.WriteLine("typedef enum " + enumProperty.TypeNameIdl);
            output.WriteLine("{");
            output.Indent();

            for (int i = 0; i < enumProperty.EnumFields.FieldsList.Count; ++i)
            {
                var enumValue = enumProperty.EnumFields.FieldsList[i];
                if (i != (enumProperty.EnumFields.FieldsList.Count - 1))
                {
                    output.WriteLine(enumValue.Name + " = " + i.ToString() + ",");
                }
                else
                {
                    output.WriteLine(enumValue.Name + " = " + i.ToString());
                }
            }
            output.Unindent();
            output.WriteLine("} " + enumProperty.TypeNameIdl + ";");

            EndVersionConditional(enumProperty.WinVer, output);
        }
Ejemplo n.º 2
0
 private static string GetPropertyMapping(Effects.Property property)
 {
     if (property.ConvertRadiansToDegrees)
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_RADIANS_TO_DEGREES");
     }
     else if (property.Name == "AlphaMode")
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_COLORMATRIX_ALPHA_MODE");
     }
     else if (property.TypeNameCpp == "Color")
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_COLOR_TO_VECTOR" + property.Type.Single(char.IsDigit));
     }
     else if (property.IsHdrAlias)
     {
         // The platform doesn't natively support HDR colors, so we set the mapping type to unknown.
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_UNKNOWN");
     }
     else if (property.TypeNameCpp == "Rect")
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_RECT_TO_VECTOR4");
     }
     else
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT");
     }
 }
Ejemplo n.º 3
0
        static string FormatPropertyValue(Effects.Property property, string value)
        {
            if (property.Type == "enum")
            {
                if (property.EnumFields.D2DEnum != null)
                {
                    bool valueFound = false;
                    foreach (EnumValue v in property.EnumFields.D2DEnum.Values)
                    {
                        if (v.ValueExpression == value)
                        {
                            value      = v.NativeName;
                            valueFound = true;
                            break;
                        }
                    }
                    System.Diagnostics.Debug.Assert(valueFound);
                }
                else
                {
                    value = property.TypeNameCpp + "::" + property.EnumFields.FieldsList[Int32.Parse(value)].Name;
                }
            }
            else if (property.Type.StartsWith("matrix") || property.Type.StartsWith("vector"))
            {
                var values = SplitVectorValue(value);

                if (property.TypeNameCpp == "Color")
                {
                    values = ConvertVectorToColor(values);
                }
                else if (property.TypeNameCpp == "Rect")
                {
                    values = ConvertVectorToRect(values);
                }

                value = property.TypeNameCpp + "{ " + string.Join(", ", values) + " }";
            }
            else if (property.Type == "float")
            {
                if (!value.Contains('.'))
                {
                    value += ".0";
                }

                value += "f";
            }
            else if (property.Type == "bool")
            {
                value = "static_cast<boolean>(" + value + ")";
            }
            else if (property.IsArray)
            {
                value = "{ " + value + " }";
            }

            return(value);
        }
Ejemplo n.º 4
0
        private static void WritePropertyInitialization(Formatter output, Effects.Property property)
        {
            // Property with type string describes
            // name/author/category/description of effect but not input type
            if (property.Type == "string" || property.IsHandCoded)
            {
                return;
            }

            string defaultValue = property.Properties.Find(internalProperty => internalProperty.Name == "Default").Value;

            string setFunction = property.IsArray ? "SetArrayProperty" : "SetBoxedProperty";

            output.WriteLine(setFunction + "<" + property.TypeNameBoxed + ">(" + property.NativePropertyName + ", " + FormatPropertyValue(property, defaultValue) + ");");
        }
Ejemplo n.º 5
0
 private static string GetPropertyMapping(Effects.Property property)
 {
     if (property.ConvertRadiansToDegrees)
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_RADIANS_TO_DEGREES");
     }
     else if (property.TypeNameCpp == "Color")
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_COLOR_TO_VECTOR" + property.Type.Single(char.IsDigit));
     }
     else if (property.TypeNameCpp == "Rect")
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_RECT_TO_VECTOR4");
     }
     else
     {
         return("GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT");
     }
 }
Ejemplo n.º 6
0
        static void AddValidationChecks(List <string> validationChecks, Effects.Property property, string minOrMax, string comparisonOperator)
        {
            if (property.Type.StartsWith("vector"))
            {
                // Expand out a separate "value.X >= limit" check for each component of the vector.
                int componentIndex = 0;

                foreach (var componentMinOrMax in SplitVectorValue(minOrMax))
                {
                    var componentName = "XYZW"[componentIndex++];

                    validationChecks.Add("value." + componentName + " " + comparisonOperator + " " + componentMinOrMax);
                }
            }
            else
            {
                // Simple "value >= limit" check.
                validationChecks.Add("value " + comparisonOperator + " " + FormatPropertyValue(property, minOrMax));
            }
        }
Ejemplo n.º 7
0
        private static bool IsEnumEqualD2DEnum(Effects.Property enumProperty, Enum d2dEnum, bool shouldMatchName)
        {
            // Check if names are the same
            if (FormatEnumValueString(d2dEnum.NativeName).Contains(FormatEnumValueString(enumProperty.EffectName)) || !shouldMatchName)
            {
                // Check if number of enums values are the same
                if (d2dEnum.Values.Count == enumProperty.EnumFields.FieldsList.Count)
                {
                    var d2dEnumValues = d2dEnum.Values;

                    for (int i = 0; i < enumProperty.EnumFields.FieldsList.Count; ++i)
                    {
                        if (!FormatEnumValueString(d2dEnumValues[i].NativeName).Contains(FormatEnumValueString(enumProperty.EnumFields.FieldsList[i].Displayname)))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 8
0
 private static bool IsGeneratablePropertyMapping(Effects.Property property)
 {
     return(property.Type != "string" && !property.IsHidden && !property.IsHandCoded);
 }
Ejemplo n.º 9
0
        private static void WritePropertyImplementation(Effects.Effect effect, Formatter output, Effects.Property property)
        {
            // Property with type string describes
            // name/author/category/description of effect but not input type
            if (property.Type == "string" || property.IsHandCoded || property.IsHidden)
            {
                return;
            }

            var min = property.Properties.Find(internalProperty => internalProperty.Name == "Min");
            var max = property.Properties.Find(internalProperty => internalProperty.Name == "Max");

            bool isWithUnsupported = (property.ExcludedEnumIndexes != null) && (property.ExcludedEnumIndexes.Count != 0);

            string customConversion = null;

            if (property.ConvertRadiansToDegrees)
            {
                customConversion = "ConvertRadiansToDegrees";
            }
            else if (property.ConvertColorHdrToVector3)
            {
                customConversion = "ConvertColorHdrToVector3";
            }
            else if (property.Name == "AlphaMode")
            {
                customConversion = "ConvertAlphaMode";
            }

            bool isValidation = ((min != null) || (max != null) || isWithUnsupported) && (customConversion == null);

            string implementMacro = property.IsArray ? "IMPLEMENT_EFFECT_ARRAY_PROPERTY" : "IMPLEMENT_EFFECT_PROPERTY";

            if (isValidation)
            {
                implementMacro += "_WITH_VALIDATION";
            }

            output.WriteLine(implementMacro + "(" + effect.ClassName + ",");
            output.Indent();
            output.WriteLine(property.Name + ",");
            output.WriteLine((customConversion ?? property.TypeNameBoxed) + ",");

            if (!property.IsArray)
            {
                output.WriteLine(property.TypeNameCpp + ",");
            }

            if (isValidation)
            {
                output.WriteLine(property.NativePropertyName + ",");

                var validationChecks = new List <string>();

                if (min != null)
                {
                    AddValidationChecks(validationChecks, property, min.Value, ">=");
                }

                if (max != null)
                {
                    AddValidationChecks(validationChecks, property, max.Value, "<=");
                }

                if (isWithUnsupported)
                {
                    foreach (var index in property.ExcludedEnumIndexes)
                    {
                        validationChecks.Add("value != static_cast<" + property.TypeNameCpp + ">(" + index + ")");
                    }
                }

                output.WriteLine("(" + string.Join(") && (", validationChecks) + "))");
            }
            else
            {
                output.WriteLine(property.NativePropertyName + ")");
            }

            output.Unindent();
            output.WriteLine();
        }