Ejemplo n.º 1
0
        protected virtual void Init(UiController controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(ButtonDrawable));

            float changeTime = (float)DefinitionResolver.Get <double>(controller, binding, file["ChangeTime"], 0) / 1000.0f;

            _changeSpeed = changeTime > 0 ? 1 / changeTime : 10000;

            _colorDisabled = DefinitionResolver.GetColorWrapper(controller, binding, file["ColorDisabled"]);
            _colorReleased = DefinitionResolver.GetColorWrapper(controller, binding, file["ColorReleased"]);
            _colorPushed   = DefinitionResolver.GetColorWrapper(controller, binding, file["ColorPushed"]);

            _margin = DefinitionResolver.Get <Margin>(controller, binding, file["Margin"], Margin.None);

            _opacity = (float)DefinitionResolver.Get <double>(controller, binding, file["Opacity"], 1);

            if (file["Special"] != null)
            {
                _specialState = DefinitionResolver.Get <bool>(controller, binding, file["Special"], false);
            }
            else
            {
                _specialState = null;
            }

            if (file["Checked"] != null)
            {
                _checkedState = DefinitionResolver.Get <bool>(controller, binding, file["Checked"], false);
            }
            else
            {
                _checkedState = null;
            }
        }
Ejemplo n.º 2
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiText));

            FontName    = file["Font"] as string;
            FontSize    = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0);
            FontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], 0);
            LineHeight  = DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100);
            Justify     = DefinitionResolver.Get <bool>(Controller, Binding, file["Justify"], false);

            _indent    = DefinitionResolver.Get <Length>(Controller, Binding, file["Indent"], Length.Zero);
            _lineWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["LineWidth"], Length.Stretch);

            Text = DefinitionResolver.GetString(Controller, Binding, file["Text"]) ?? string.Empty;

            TextColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? UiLabel.DefaultTextColor;

            HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left);
            VerticalContentAlignment   vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top);

            TextAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);

            return(true);
        }
Ejemplo n.º 3
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiImage));

            _image         = DefinitionResolver.GetShared <Texture2D>(Controller, Binding, file["Image"], null);
            _stretch       = DefinitionResolver.Get <Stretch>(Controller, Binding, file["Stretch"], Stretch.Uniform);
            _color         = DefinitionResolver.GetColorWrapper(Controller, Binding, file["Color"]) ?? new ColorWrapper();
            _rotationSpeed = (float)DefinitionResolver.Get <double>(Controller, Binding, file["RotationSpeed"], 0);
            _scaleByUnit   = DefinitionResolver.Get <bool>(Controller, Binding, file["ScaleByUnit"], true);
            _scale         = DefinitionResolver.Get(Controller, Binding, file["Scale"], Scale.One);

            _image.ValueChanged += _image_ValueChanged;

            switch (DefinitionResolver.Get <ResampleFilter>(Controller, Binding, file["ResampleFilter"], ResampleFilter.Default))
            {
            case ResampleFilter.Point:
                _samplerState = SamplerState.PointClamp;
                break;

            case ResampleFilter.Linear:
                _samplerState = SamplerState.LinearClamp;
                break;

            case ResampleFilter.Anisotropic:
                _samplerState = SamplerState.AnisotropicClamp;
                break;
            }

            return(true);
        }
Ejemplo n.º 4
0
        bool IDefinitionClass.Init(UiController controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(QuickSeparatorLine));

            _color = DefinitionResolver.GetColorWrapper(controller, binding, file["Color"]);

            _left  = DefinitionResolver.Get <Length>(controller, binding, file["Left"], Length.Zero);
            _right = DefinitionResolver.Get <Length>(controller, binding, file["Right"], Length.Zero);

            return(true);
        }
Ejemplo n.º 5
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiLabel));

            string fontName    = file["Font"] as string;
            int    fontSize    = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0);
            int    fontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], 0);

            _font = new UiFont(fontName, fontSize, fontSpacing);

            _lineHeight = DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100);

            _textMargin = DefinitionResolver.Get <Margin>(Controller, Binding, file["TextMargin"], Margin.None);

            _rotation = DefinitionResolver.Get <TextRotation>(Controller, Binding, file["TextRotation"], TextRotation.None);

            _maxWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["MaxWidth"], new Length(pixels: int.MaxValue));

            Text = DefinitionResolver.GetSharedString(Controller, Binding, file["Text"]);

            if (Text == null)
            {
                return(false);
            }

            TextColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? DefaultTextColor;

            HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Auto);
            VerticalContentAlignment   vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Auto);

            if (horzAlign == HorizontalContentAlignment.Auto)
            {
                horzAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.HorizontalAlignment);
            }

            if (vertAlign == VerticalContentAlignment.Auto)
            {
                vertAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.VerticalAlignment);
            }

            TextAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);

            if (DefinitionResolver.Get <bool>(Controller, Binding, file["AutoSizeUpdate"], false))
            {
                Text.ValueChanged += Text_ValueChanged;
            }

            return(true);
        }
Ejemplo n.º 6
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiListBox));

            _selectionColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["SelectionColor"]);

            return(true);
        }
Ejemplo n.º 7
0
        bool IDefinitionClass.Init(UiController controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(NinePatchBackground));

            _image       = DefinitionResolver.Get <NinePatchImage>(controller, binding, file["Image"], null);
            _scaleByUnit = DefinitionResolver.Get <bool>(controller, binding, file["ScaleByUnit"], false);
            _scale       = (float)DefinitionResolver.Get <double>(controller, binding, file["Scale"], 1);
            _color       = DefinitionResolver.GetColorWrapper(controller, binding, file["Color"]) ?? new ColorWrapper();

            _margin = DefinitionResolver.Get <Margin>(controller, binding, file["Margin"], Margin.None);

            return(true);
        }
Ejemplo n.º 8
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiVerticalGradient));

            _topColor    = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TopColor"]);
            _bottomColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["BottomColor"]);

            return(true);
        }
Ejemplo n.º 9
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiHorizontalGradient));

            _leftColor  = DefinitionResolver.GetColorWrapper(Controller, Binding, file["LeftColor"]);
            _rightColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["RightColor"]);

            return(true);
        }
Ejemplo n.º 10
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiRectangle));

            _image       = DefinitionResolver.Get <NinePatchImage>(Controller, Binding, file["Image"], null);
            _scaleByUnit = DefinitionResolver.Get(Controller, Binding, file["ScaleByUnit"], false);
            _scale       = (float)DefinitionResolver.Get(Controller, Binding, file["Scale"], 1.0);
            _color       = DefinitionResolver.GetColorWrapper(Controller, Binding, file["Color"]);

            return(true);
        }
Ejemplo n.º 11
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiSeparatorLine));

            _image       = DefinitionResolver.GetShared <Texture2D>(Controller, Binding, file["Image"], null);
            _color       = DefinitionResolver.GetColorWrapper(Controller, Binding, file["Color"]) ?? new ColorWrapper();
            _scaleByUnit = DefinitionResolver.Get <bool>(Controller, Binding, file["ScaleByUnit"], true);
            _scale       = (float)DefinitionResolver.Get <double>(Controller, Binding, file["Scale"], 1);
            _vertical    = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Horizontal) == Mode.Vertical;

            return(true);
        }
Ejemplo n.º 12
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiImage));

            _image         = DefinitionResolver.GetShared <Texture2D>(Controller, Binding, file["Image"], null);
            _stretch       = DefinitionResolver.Get <Stretch>(Controller, Binding, file["Stretch"], Stretch.Uniform);
            _color         = DefinitionResolver.GetColorWrapper(Controller, Binding, file["Color"]) ?? new ColorWrapper();
            _rotationSpeed = (float)DefinitionResolver.Get <double>(Controller, Binding, file["RotationSpeed"], 0);
            _scaleByUnit   = DefinitionResolver.Get <bool>(Controller, Binding, file["ScaleByUnit"], true);
            _scale         = (float)DefinitionResolver.Get <double>(Controller, Binding, file["Scale"], 1);

            return(true);
        }
Ejemplo n.º 13
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiRichView));

            string defaultFont        = file["Font"] as string;
            int    defaultFontSize    = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0);
            int    defaultFontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], int.MaxValue);

            for (int idx = 0; idx < (int)FontType.Count; ++idx)
            {
                FontType type    = (FontType)idx;
                string   font    = string.Format("{0}.Font", type);
                string   spacing = string.Format("{0}.FontSpacing", type);
                string   resize  = string.Format("{0}.FontResize", type);

                string fontName    = file[font] as string;
                int    fontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file[spacing], defaultFontSpacing == int.MaxValue ? 0 : defaultFontSpacing);
                int    fontResize  = DefinitionResolver.Get <int>(Controller, Binding, file[resize], 0);

                if (fontName == null)
                {
                    fontName = defaultFont;
                }

                FontFace fontObj = FontManager.Instance.FindFont(fontName);

                if (defaultFont == null)
                {
                    defaultFont = fontName;
                }

                if (defaultFontSpacing == int.MaxValue)
                {
                    defaultFontSpacing = fontSpacing;
                }

                _fonts[idx] = new FontInfo()
                {
                    Font        = fontObj,
                    FontSpacing = (float)fontSpacing / 1000.0f,
                    FontResize  = fontResize
                };
            }

            for (int idx = 0; idx < (int)SizeType.Count; ++idx)
            {
                SizeType type = (SizeType)idx;
                string   size = string.Format("{0}.FontSize", type);

                int fontSize = DefinitionResolver.Get <int>(Controller, Binding, file[size], defaultFontSize);

                if (defaultFontSize == 0)
                {
                    defaultFontSize = fontSize;
                }

                _sizes[idx] = fontSize;
            }

            _bulletText = DefinitionResolver.GetString(Controller, Binding, file["BulletText"]) ?? "* ";
            //_bulletText = _bulletText.Replace(" ", ((char)0xa0).ToString());

            _horizontalRulerHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["HorizontalRulerHeight"], new Length(0, 0, 1));
            _indentSize            = DefinitionResolver.Get <Length>(Controller, Binding, file["Indent"], Length.Zero);
            _paragraphSpacing      = DefinitionResolver.Get <Length>(Controller, Binding, file["ParagraphSpacing"], Length.Zero);
            _imageNotLoaded        = DefinitionResolver.Get <Texture2D>(Controller, Binding, file["ImageNotLoaded"], AdvancedDrawBatch.OnePixelWhiteTexture);
            _lineHeight            = (float)DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100) / 100.0f;
            _justify = DefinitionResolver.Get <bool>(Controller, Binding, file["Justify"], false);

            _linkResolver = DefinitionResolver.Get <ILinkResolver>(Controller, Binding, file["LinkResolver"], this);

            _baseLineCorrection = DefinitionResolver.Get <bool>(Controller, Binding, file["EnableBaseLineCorrection"], false);

            Type processorType = file["Processor"] as Type;

            if (processorType != null)
            {
                _richProcessor = Activator.CreateInstance(processorType) as IRichProcessor;
            }

            Text = DefinitionResolver.GetString(Controller, Binding, file["Text"]);

            _colorNormal          = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? UiLabel.DefaultTextColor;
            _colorClickable       = DefinitionResolver.GetColorWrapper(Controller, Binding, file["LinkColor"]) ?? UiLabel.DefaultTextColor;
            _colorClickableActive = DefinitionResolver.GetColorWrapper(Controller, Binding, file["ActiveLinkColor"]) ?? _colorClickable;
            _colorRuler           = DefinitionResolver.GetColorWrapper(Controller, Binding, file["HorizontalRulerColor"]) ?? UiLabel.DefaultTextColor;

            HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left);
            VerticalContentAlignment   vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top);

            _textAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);

            _clickMargin = DefinitionResolver.Get <Length>(Controller, Binding, file["ClickMargin"], Length.Zero);

            RegisterDelegate("UrlClick", file["UrlClick"]);

            EnabledGestures = (GestureType.Down | GestureType.Up | GestureType.Move | GestureType.Tap);

            return(true);
        }
Ejemplo n.º 14
0
        protected virtual bool Init(object controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiView));

            Type controllerType = file["Controller"] as Type;

            _controller = controller as UiController;

            if (controllerType != null)
            {
                var newController = Activator.CreateInstance(controllerType) as UiController;

                if (newController != null)
                {
                    newController.Parent = _controller;
                    Controller           = newController;
                }
            }

            Binding = binding;

            object bindParameter = file["Binding"];

            if (bindParameter != null)
            {
                Object bind = DefinitionResolver.GetValueFromMethodOrField(Controller, binding, bindParameter);

                if (bind != null)
                {
                    Binding = bind;
                }
            }

            Id = DefinitionResolver.GetString(Controller, Binding, file["Id"]);

            if (file["Hidden"] != null && file["Visible"] == null)
            {
                _visiblityFlag   = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Hidden"], false);
                _visibleIsHidden = true;
            }
            else
            {
                _visiblityFlag = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Visible"], true);
            }

            Tag = DefinitionResolver.GetSharedString(Controller, Binding, file["Tag"]);

            Opacity = DefinitionResolver.GetShared <double>(Controller, Binding, file["Opacity"], 1);

            DisplayVisibility = Visible ? 1 : 0;

            _modal = DefinitionResolver.Get <bool>(Controller, Binding, file["Modal"], false);

            RegisterDelegate("ViewRemoved", file["ViewRemoved"]);
            RegisterDelegate("ViewAdded", file["ViewAdded"]);
            RegisterDelegate("ViewActivated", file["ViewActivated"]);
            RegisterDelegate("ViewDeactivated", file["ViewDeactivated"]);
            RegisterDelegate("ViewResized", file["ViewResized"]);

            _minWidth  = DefinitionResolver.Get <Length>(Controller, Binding, file["MinWidth"], Length.Zero);
            _minHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["MinHeight"], Length.Zero);

            _showSpeed = (float)Math.Max(
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1),
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowTime"], -1));

            if (_showSpeed < 0)
            {
                _showSpeed = DefaultShowTime;
            }

            _showSpeed /= 1000.0f;

            _showSpeed = _showSpeed > 0 ? 1 / _showSpeed : float.MaxValue;

            _hideSpeed = (float)Math.Max(
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1),
                DefinitionResolver.Get <double>(Controller, Binding, file["HideTime"], -1));

            if (_hideSpeed < 0)
            {
                _hideSpeed = DefaultHideTime;
            }

            _hideSpeed /= 1000.0f;

            _hideSpeed = _hideSpeed > 0 ? 1 / _hideSpeed : float.MaxValue;

            CreatePositionParameters(Controller, Binding, definition);

            DefinitionFile backgroundDrawable = file["BackgroundDrawable"] as DefinitionFile;

            Color defaultBackgroundColor = Color.Transparent;

            if (backgroundDrawable != null)
            {
                BackgroundDrawable = backgroundDrawable.CreateInstance(Controller, Binding) as IBackgroundDrawable;

                if (BackgroundDrawable != null)
                {
                    defaultBackgroundColor = Color.White;
                }
            }

            _backgroundColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["BackgroundColor"]) ?? new ColorWrapper(defaultBackgroundColor);

            DefinitionFile showTransitionEffectFile       = file["ShowTransitionEffect"] as DefinitionFile;
            DefinitionFile hideTransitionEffectFile       = file["HideTransitionEffect"] as DefinitionFile;
            DefinitionFile parentShowTransitionEffectFile = file["ParentShowTransitionEffect"] as DefinitionFile;
            DefinitionFile parentHideTransitionEffectFile = file["ParentHideTransitionEffect"] as DefinitionFile;

            if (showTransitionEffectFile != null)
            {
                _showTransitionEffect = showTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (hideTransitionEffectFile != null)
            {
                _hideTransitionEffect = hideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (parentShowTransitionEffectFile != null)
            {
                _parentShowTransitionEffect = parentShowTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (parentHideTransitionEffectFile != null)
            {
                _parentHideTransitionEffect = parentHideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            return(true);
        }