예제 #1
0
        public virtual void Initialize(WidgetArgs args)
        {
            // Parse the YAML equations to find the widget bounds
            var parentBounds = (Parent == null)
                                ? new Rectangle(0, 0, Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height)
                                : Parent.Bounds;

            var substitutions = args.ContainsKey("substitutions") ?
                                new Dictionary <string, int>((Dictionary <string, int>)args["substitutions"]) :
                                new Dictionary <string, int>();

            substitutions.Add("WINDOW_RIGHT", Game.Renderer.Resolution.Width);
            substitutions.Add("WINDOW_BOTTOM", Game.Renderer.Resolution.Height);
            substitutions.Add("PARENT_RIGHT", parentBounds.Width);
            substitutions.Add("PARENT_LEFT", parentBounds.Left);
            substitutions.Add("PARENT_TOP", parentBounds.Top);
            substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
            var width  = Evaluator.Evaluate(Width, substitutions);
            var height = Evaluator.Evaluate(Height, substitutions);

            substitutions.Add("WIDTH", width);
            substitutions.Add("HEIGHT", height);

            Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
                                   Evaluator.Evaluate(Y, substitutions),
                                   width,
                                   height);
        }
예제 #2
0
        public virtual void Initialize(WidgetArgs args)
        {
            // Parse the YAML equations to find the widget bounds
            var parentBounds = (Parent == null)
                                ? new Rectangle(0, 0, Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height)
                                : Parent.Bounds;

            var substitutions = args.ContainsKey("substitutions") ?
                                new Dictionary <string, int>((Dictionary <string, int>)args["substitutions"]) :
                                new Dictionary <string, int>();

            substitutions.Add("WINDOW_RIGHT", Game.Renderer.Resolution.Width);
            substitutions.Add("WINDOW_BOTTOM", Game.Renderer.Resolution.Height);
            substitutions.Add("PARENT_RIGHT", parentBounds.Width);
            substitutions.Add("PARENT_LEFT", parentBounds.Left);
            substitutions.Add("PARENT_TOP", parentBounds.Top);
            substitutions.Add("PARENT_BOTTOM", parentBounds.Height);

            var readOnlySubstitutions = new ReadOnlyDictionary <string, int>(substitutions);
            var width = Width != null?Width.Evaluate(readOnlySubstitutions) : 0;

            var height = Height != null?Height.Evaluate(readOnlySubstitutions) : 0;

            substitutions.Add("WIDTH", width);
            substitutions.Add("HEIGHT", height);

            var x = X != null?X.Evaluate(readOnlySubstitutions) : 0;

            var y = Y != null?Y.Evaluate(readOnlySubstitutions) : 0;

            Bounds = new Rectangle(x, y, width, height);
        }