Пример #1
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            TryInitChildren(definition);

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

            if (file["SelectedIndex"] is MethodName || file["SelectedIndex"] is FieldName)
            {
                object value = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["SelectedIndex"]);

                if (value is SharedValue <int> )
                {
                    _sharedSelectedIndex = value as SharedValue <int>;
                    _selectedIndex       = _sharedSelectedIndex.Value;
                }

                if (value is int)
                {
                    _selectedIndex = (int)value;
                }
            }
            else
            {
                _selectedIndex = DefinitionResolver.Get <int>(Controller, Binding, file["SelectedIndex"], 0);
            }

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

            double speed = DefinitionResolver.Get <double>(Controller, Binding, file["TransitionTime"], 500) / 1000.0;

            _transitionSpeed = (float)(speed > 0 ? 1 / speed : float.MaxValue);

            DefinitionFile transitionEffectFile = file["ShowTransitionEffectNext"] as DefinitionFile;

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

            transitionEffectFile = file["HideTransitionEffectNext"] as DefinitionFile;

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

            transitionEffectFile = file["ShowTransitionEffectPrev"] as DefinitionFile;

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

            transitionEffectFile = file["HideTransitionEffectPrev"] as DefinitionFile;

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

            transitionEffectFile = file["ShowTransitionEffect"] as DefinitionFile;

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

                if (_transitionEffectShowNext == null)
                {
                    _transitionEffectShowNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }
            }

            transitionEffectFile = file["HideTransitionEffect"] as DefinitionFile;

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

                if (_transitionEffectHideNext == null)
                {
                    _transitionEffectHideNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }
            }

            if (_transitionEffectHideNext == null)
            {
                if (_transitionEffectShowNext != null)
                {
                    _transitionEffectHideNext = _transitionEffectShowNext.Reverse();
                }
            }

            if (_transitionEffectHidePrev == null)
            {
                if (_transitionEffectShowPrev != null)
                {
                    _transitionEffectHidePrev = _transitionEffectShowPrev.Reverse();
                }
            }

            if (_children.Count > 0)
            {
                _current = _children[_selectedIndex];
            }

            _previous = null;

            return(true);
        }
Пример #2
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);
        }
Пример #3
0
        protected override void Draw(ref Parameters.UiViewDrawParameters parameters)
        {
            float opacity = parameters.Opacity;

            if (opacity == 0)
            {
                return;
            }

            DrawBackground(ref parameters);

            if (_clipChildren)
            {
                parameters.DrawBatch.PushClip(ScreenBounds);
            }

            for (int idx = 0; idx < 2; ++idx)
            {
                UiView view       = idx == 0 ? _previous : _current;
                float  transition = _transition;

                if (idx == 0)
                {
                    transition = 1 - transition;
                }

                if (view != null)
                {
                    UiViewDrawParameters drawParams = parameters;

                    drawParams.Opacity = opacity;

                    TransitionEffect transitionEffect = FindTransition(idx == 0);

                    if (transitionEffect != null)
                    {
                        float  opacity2;
                        Matrix transform;

                        drawParams.Transition = transition;

                        transitionEffect.Get(transition, ScreenBounds, view.ScreenBounds, out transform, out opacity2);

                        drawParams.Opacity *= opacity2;

                        drawParams.DrawBatch.PushTransform(transform);

                        view.ViewDraw(ref drawParams);

                        drawParams.DrawBatch.PopTransform();
                    }
                    else
                    {
                        view.ViewDraw(ref drawParams);
                    }
                }
            }

            if (_clipChildren)
            {
                parameters.DrawBatch.PopClip();
            }

            if (_transition > 0)
            {
                AppMain.RedrawNextFrame();
            }
        }
Пример #4
0
        public void ViewDraw(ref UiViewDrawParameters parameters)
        {
            _isViewDisplayed = Visible && Math.Abs(parameters.Transition) < 0.000001;

            if (DisplayVisibility == 0)
            {
                return;
            }

            TransitionEffect transitionEffect         = null;
            TransitionEffect transitionEffectShowHide = null;

            switch (parameters.TransitionMode)
            {
            case TransitionMode.Show:
                transitionEffect = _parentShowTransitionEffect;
                break;

            case TransitionMode.Hide:
                transitionEffect = _parentHideTransitionEffect;
                break;

            case TransitionMode.None:
                transitionEffectShowHide = DisplayVisibility == 1 ? null : (Visible ? _showTransitionEffect : _hideTransitionEffect);
                break;
            }

            if (transitionEffect != null || transitionEffectShowHide != null)
            {
                UiViewDrawParameters drawParameters = parameters;

                float  opacity;
                Matrix transform;

                Matrix targetTransform = Matrix.Identity;
                float  targetOpacity   = 1;

                if (transitionEffect != null)
                {
                    transitionEffect.Get(parameters.Transition, parameters.TransitionRectangle, ScreenBounds, out transform, out opacity);
                    targetOpacity   *= opacity;
                    targetTransform *= transform;
                }

                if (transitionEffectShowHide != null)
                {
                    transitionEffectShowHide.Get(1 - DisplayVisibility, Parent != null ? Parent.ScreenBounds : ScreenBounds, ScreenBounds, out transform, out opacity);
                    targetOpacity   *= opacity;
                    targetTransform *= transform;
                }

                drawParameters.DrawBatch.PushTransform(targetTransform);
                drawParameters.Opacity *= (float)Opacity.Value * targetOpacity;

                Draw(ref drawParameters);

                drawParameters.DrawBatch.PopTransform();
            }
            else
            {
                UiViewDrawParameters drawParameters = parameters;
                drawParameters.Opacity *= DisplayVisibility * (float)Opacity.Value;

                Draw(ref drawParameters);
            }
        }