예제 #1
0
파일: UiImage.cs 프로젝트: prepare/Sitana
        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);
        }
예제 #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(UiExpandingBorder));

            _expanded = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Expanded"], true);

            _expandWidth  = DefinitionResolver.Get <Length>(Controller, Binding, file["ExpandedWidth"], PositionParameters.Width);
            _expandHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["ExpandedHeight"], PositionParameters.Height);

            _expandSpeed = DefinitionResolver.Get <int>(Controller, Binding, file["ExpandTime"], 0);

            _expandedValue = _expanded.Value ? 1 : 0;

            RegisterDelegate("CollapseFinished", file["CollapseFinished"]);
            RegisterDelegate("ExpandFinished", file["ExpandFinished"]);
            RegisterDelegate("ExpandStarted", file["ExpandStarted"]);

            if (_expandSpeed > 0)
            {
                _expandSpeed = 1000 / _expandSpeed;
            }
            else
            {
                _expandSpeed = 10000;
            }

            _expanded.ValueChanged += _expanded_ValueChanged;
            return(true);
        }
예제 #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(UiStackPanel));

            StackMode             = DefinitionResolver.Get(Controller, Binding, file["Mode"], Mode.Vertical);
            _spacing              = DefinitionResolver.Get(Controller, Binding, file["Spacing"], Length.Zero);
            _padding              = DefinitionResolver.Get(Controller, Binding, file["Padding"], Length.Zero);
            _notifyParentOnResize = DefinitionResolver.Get(Controller, Binding, file["NotifyParentOnResize"], true);

            _wrap = DefinitionResolver.Get(Controller, Binding, file["Wrap"], false);

            _horizontalContentAlignment = DefinitionResolver.Get(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left);
            _verticalContentAlignment   = DefinitionResolver.Get(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top);

            _expanded = DefinitionResolver.GetShared(Controller, Binding, file["Expanded"], true);

            _expandSpeed   = DefinitionResolver.Get(Controller, Binding, file["ExpandTime"], 0);
            _collapseSpeed = DefinitionResolver.Get(Controller, Binding, file["CollapseTime"], (int)_expandSpeed);

            _expandedValue = _expanded.Value ? 1 : 0;

            if (_expandSpeed > 0)
            {
                _expandSpeed = 1000 / _expandSpeed;
            }
            else
            {
                _expandSpeed = 10000;
            }

            if (_collapseSpeed > 0)
            {
                _collapseSpeed = 1000 / _collapseSpeed;
            }
            else
            {
                _collapseSpeed = 10000;
            }

            RegisterDelegate("CollapseFinished", file["CollapseFinished"]);
            RegisterDelegate("ExpandFinished", file["ExpandFinished"]);
            RegisterDelegate("ExpandStarted", file["ExpandStarted"]);

            TryInitChildren(definition);


            _expanded.ValueChanged += _expanded_ValueChanged;

            return(true);
        }
예제 #4
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(UiView));

            _zoom = DefinitionResolver.GetShared <int>(Controller, Binding, file["Zoom"], 1);

            return(true);
        }
예제 #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(UiCheckBox));

            Checked = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Checked"], false);

            return(true);
        }
예제 #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(UiRadioButton));

            SelectedValue = DefinitionResolver.GetShared <int>(Controller, Binding, file["SelectedValue"], -1);
            Value         = DefinitionResolver.Get <int>(Controller, Binding, file["Value"], 0);

            return(true);
        }
예제 #7
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(UiEditBoxBase));

            Hint = DefinitionResolver.GetSharedString(Controller, Binding, file["Hint"]) ?? new SharedString();

            _maxLength           = DefinitionResolver.Get(Controller, Binding, file["MaxLength"], int.MaxValue);
            _inputType           = DefinitionResolver.Get(Controller, Binding, file["InputType"], TextInputType.NormalText);
            _lostFocusCancels    = DefinitionResolver.Get(Controller, Binding, file["CancelOnLostFocus"], false);
            _focusedShared       = DefinitionResolver.GetShared(Controller, Binding, file["IsFocused"], false);
            _focusedShared.Value = false;

            string filter = DefinitionResolver.GetString(Controller, Binding, file["Filter"]);

            if (!filter.IsNullOrEmpty())
            {
                _filter = new List <char>(filter.ToCharArray());
            }

            _focusedShared.ValueChanged += (bool focused) =>
            {
                if (focused)
                {
                    CurrentlyFocused = this;
                }
                else if (CurrentlyFocused == this)
                {
                    CurrentlyFocused = null;
                }
            };

            if (_inputType == TextInputType.Password)
            {
                _password = new SharedString();
            }

            RegisterDelegate("TextApply", file["TextApply"]);
            RegisterDelegate("TextChanged", file["TextChanged"]);
            RegisterDelegate("TextCancel", file["TextCancel"]);

            RegisterDelegate("LostFocus", file["LostFocus"]);
            RegisterDelegate("Return", file["Return"]);

            return(true);
        }
예제 #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(UiSlider));

            _vertical = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Horizontal) == Mode.Vertical;

            _maxValue = DefinitionResolver.GetShared <int>(Controller, Binding, file["MaxValue"], 100);
            _minValue = DefinitionResolver.GetShared <int>(Controller, Binding, file["MinValue"], 0);
            _value    = DefinitionResolver.GetShared <int>(Controller, Binding, file["Value"], 0);

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

            List <DefinitionFile> drawableFiles = file["ThumbDrawables"] as List <DefinitionFile>;

            if (drawableFiles != null)
            {
                foreach (var def in drawableFiles)
                {
                    ButtonDrawable drawable = def.CreateInstance(Controller, Binding) as ButtonDrawable;

                    if (drawable != null)
                    {
                        _thumbDrawables.Add(drawable);
                    }
                }
            }

            drawableFiles = file["TrackDrawables"] as List <DefinitionFile>;

            if (drawableFiles != null)
            {
                foreach (var def in drawableFiles)
                {
                    ButtonDrawable drawable = def.CreateInstance(Controller, Binding) as ButtonDrawable;

                    if (drawable != null)
                    {
                        _trackDrawables.Add(drawable);
                    }
                }
            }

            return(true);
        }
예제 #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(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);
        }
예제 #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(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);
        }
예제 #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(UiModalLayout));

            _touchOutsideToHide = DefinitionResolver.Get(Controller, Binding, file["TouchOutsideToHide"], false);

            _visiblityFlag = DefinitionResolver.GetShared(Controller, binding, file["Visible"], false);

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

            if (!Visible)
            {
                DisplayVisibility = 0;
            }

            return(true);
        }
예제 #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(UiStackPanel));

            StackMode             = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Vertical);
            _spacing              = DefinitionResolver.Get <Length>(Controller, Binding, file["Spacing"], Length.Zero);
            _padding              = DefinitionResolver.Get <Length>(Controller, Binding, file["Padding"], Length.Zero);
            _notifyParentOnResize = DefinitionResolver.Get <bool>(Controller, Binding, file["NotifyParentOnResize"], true);

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

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

            _expanded = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Expanded"], true);

            _expandSpeed   = DefinitionResolver.Get <int>(Controller, Binding, file["ExpandTime"], 0);
            _expandedValue = _expanded.Value ? 1 : 0;

            if (_expandSpeed > 0)
            {
                _expandSpeed = 1000 / _expandSpeed;
            }
            else
            {
                _expandSpeed = 10000;
            }

            InitChildren(Controller, Binding, definition);

            return(true);
        }
예제 #13
0
파일: UiButton.cs 프로젝트: prepare/Sitana
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

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

            Icon = DefinitionResolver.GetShared <Texture2D>(Controller, Binding, file["Icon"], null);

            if (Icon == null)
            {
                Icon = new SharedValue <Texture2D>();
            }

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

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

            if (_text == null)
            {
                _text = new SharedString();
            }

            if (file["Hold"] != null)
            {
                RegisterDelegate("Hold", file["Hold"]);
                _processHold = true;
            }

            RegisterDelegate("Release", file["Release"]);
            RegisterDelegate("Push", file["Push"]);

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

            List <DefinitionFile> drawableFiles = file["Drawables"] as List <DefinitionFile>;

            if (file["Disabled"] != null && file["Enabled"] == null)
            {
                _enabledFlag       = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Disabled"], false);
                _enabledFlagInvert = true;
            }
            else
            {
                _enabledFlag       = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Enabled"], true);
                _enabledFlagInvert = false;
            }

            if (drawableFiles != null)
            {
                foreach (var def in drawableFiles)
                {
                    ButtonDrawable drawable = def.CreateInstance(Controller, Binding) as ButtonDrawable;

                    if (drawable != null)
                    {
                        _drawables.Add(drawable);
                    }
                }
            }

            _pushSound    = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["PushSound"], null);
            _releaseSound = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["ReleaseSound"], null);
            _actionSound  = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["ActionSound"], null);

            ButtonMode = DefinitionResolver.Get <UiButtonMode>(Controller, Binding, file["Mode"], UiButtonMode.Release);

            _repeatStart    = (float)DefinitionResolver.Get <int>(Controller, Binding, file["RepeatStart"], 0) / 1000f;
            _repeatInterval = (float)DefinitionResolver.Get <int>(Controller, Binding, file["RepeatInterval"], 0) / 1000f;

            return(true);
        }
예제 #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);
        }