示例#1
0
        public static void Update(VisualElementRenderer renderer)
        {
            ElementPositions.Clear();

            XnaMouseState state;
            try
            {
                if (!Forms.Game.IsActive)
                    return;
                state = XnaMouse.GetState();
            }
            catch (InvalidOperationException) { return; }

            var buttonState = UpdateButtonsState(state);

            var reallyOver = renderer.FlattenHierarchyReverse()
                .Where(c => !c.Model.InputTransparent && c.Model.IsEnabled)
                .Select(c => new ElementPosition { Element = c, Position = state.ToRelative(c) })
                .Where(c => c.IsPositionInside());

            var newOver = reallyOver.FirstOrDefault();
            var newOverEventArgs = newOver.Element != null? new MouseEventArgs(state.ToRelative(newOver.Element)) : null;

            if (newOver.Element != null)
            {
                foreach(var stateChange in buttonStateChange)
                {
                    if (stateChange.Value != null)
                    {
                        if (stateChange.Value == XnaButtonState.Pressed)
                        {
                            newOver.Element.HandleRaise(
                                r => new MouseButtonEventArgs(stateChange.Key, state.ToRelative(r)),
                                (r, e) => r.InterceptMouseDown(e),
                                (r, e) => r.HandleMouseDown(e));
                        }
                        else
                            newOver.Element.HandleRaise(
                                r => new MouseButtonEventArgs(stateChange.Key, state.ToRelative(r)),
                                (r, e) => r.InterceptMouseUp(e),
                                (r, e) => r.HandleMouseUp(e));
                    }
                }
            }

            if (_pressing == null)
            {
                if (newOver.Position != null)
                    newOver.Element.OnMouseOver(newOverEventArgs);

                if (_over != newOver.Element)
                {
                    if (_over != null)
                        _over.OnMouseLeave(new MouseEventArgs(state.ToRelative(_over)));
                    if (newOver.Element != null)
                        newOver.Element.OnMouseEnter(newOverEventArgs);

                    _over = newOver.Element;
                }

                if (_over != null && state.LeftButton == XnaButtonState.Pressed)
                {
                    _pressing = _over;
                }
            }
            else
            {
                var pressingEvent = new MouseEventArgs(state.ToRelative(_pressing));
                _pressing.OnMouseOver(pressingEvent);

                if (state.LeftButton == XnaButtonState.Released)
                {
                    if (newOver.Element == _pressing)
                    {
                        _pressing.RaiseClick(newOverEventArgs);
                        _pressing = null;
                    }
                    else
                    {
                        _pressing.OnMouseLeave(pressingEvent);
                        _pressing = null;

                        if (newOver.Element != null)
                            newOver.Element.OnMouseEnter(newOverEventArgs);

                        _over = newOver.Element;
                    }
                }
            }
        }
示例#2
0
        static Microsoft.Xna.Framework.Ray GetPickRay(VisualElementRenderer renderer, float x, float y)
        {
            var nearsource = new XnaVector3(x, y, 0f);
            var farsource = new XnaVector3(x, y, 1f);

            var world = XnaMatrix.Identity;

            var nearPoint = Forms.Game.GraphicsDevice.Viewport.Unproject(nearsource,
                renderer.Effect.Projection, renderer.Effect.View, world);

            var farPoint = Forms.Game.GraphicsDevice.Viewport.Unproject(farsource,
                renderer.Effect.Projection, renderer.Effect.View, world);

            // Create a ray from the near clip plane to the far clip plane.
            var direction = farPoint - nearPoint;
            direction.Normalize();
            return new Microsoft.Xna.Framework.Ray(nearPoint, direction);
        }
示例#3
0
        static XnaVector2? ToRelative(this XnaMouseState state, VisualElementRenderer renderer)
        {
            foreach (var savedPosition in ElementPositions)
            {
                if (savedPosition.Element == renderer)
                    return savedPosition.Position;
            }

            XnaVector2? position;
            var plane = new XnaPlane(new XnaVector3(0, 0, 1), 0);
            plane = plane.Transform(renderer.Effect.World);

            var ray = GetPickRay(renderer, state.X, state.Y);
            var dist = ray.Intersects(plane);
            if (dist != null)
            {
                var clickPosition = XnaVector3.Transform(ray.Position + ray.Direction * dist.Value, XnaMatrix.Invert(renderer.Effect.World));
                position = new XnaVector2(clickPosition.X, clickPosition.Y);
            }
            else position = null;

            ElementPositions.Add(new ElementPosition
            {
                Element = renderer,
                Position = position
            });
            return position;
        }
示例#4
0
 public void RegisterEffect(Effect effect)
 {
     VisualElementRenderer <VisualElement> .RegisterEffect(effect, View);
 }
示例#5
0
 void IEffectControlProvider.RegisterEffect(Effect effect)
 {
     VisualElementRenderer <VisualElement> .RegisterEffect(effect, this, NativeView);
 }
 public CameraViewRenderer(Context context)
     : base(context)
 {
     motionEventHelper     = new MotionEventHelper();
     visualElementRenderer = new VisualElementRenderer(this);
 }
示例#7
0
 /// <summary>Draws the expander button.</summary>
 /// <param name="graphics">The graphics to draw on.</param>
 /// <param name="rectangle">The button rectangle.</param>
 /// <param name="color">The button color.</param>
 /// <param name="state">The expanded toggle.</param>
 public static void Draw(Graphics graphics, Rectangle rectangle, Color color, bool state)
 {
     VisualElementRenderer.RenderTriangle(graphics, rectangle, color, state ? Alignment.Vertical.Up : Alignment.Vertical.Down);
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                if (GetStyle(ControlStyles.AllPaintingInWmPaint))
                {
                    OnPaintBackground(e);
                }

                MinimumSize = new Size(0, GetPreferredSize(Size.Empty).Height);

                Rectangle    _clientRectangle    = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
                GraphicsPath controlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(_clientRectangle, _border);
                Color        backColorState      = ColorState.BackColorState(_backColor, Enabled, MouseState);

                e.Graphics.SetClip(controlGraphicsPath);
                VisualBackgroundRenderer.DrawBackground(e.Graphics, backColorState, BackgroundImage, MouseState, _clientRectangle, _border);
                VisualBorderRenderer.DrawBorderStyle(e.Graphics, _border, controlGraphicsPath, _mouseState);
                Rectangle arrowRectangle = new Rectangle(Width - _arrowSize.Width - 5, (Height / 2) - (_arrowSize.Height / 2), _arrowSize.Width, _arrowSize.Height);

                if (_image != null)
                {
                    e.Graphics.DrawImage(_image, new Rectangle(arrowRectangle.Left - _image.Width - 2, (Height / 2) - (_image.Height / 2), _imageSize.Width, _imageSize.Height));
                }

                VisualElementRenderer.RenderTriangle(e.Graphics, _arrowColor, _arrowDisabledColor, Enabled, _dropDownImage, arrowRectangle, Alignment.Vertical.Down);

                var       _check            = 0;
                Rectangle checkBoxRectangle = new Rectangle(3, (Height / 2) - 6, 12, 12);

                if (ShowCheckBox)
                {
                    _check = 15;

                    if (Checked)
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.CheckedNormal);
                    }
                    else
                    {
                        CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.UncheckedNormal);
                    }
                }

                Size textSize = TextManager.MeasureText(Text, Font);

                Rectangle textBoxRectangle = new Rectangle(2 + _check, (Height / 2) - (textSize.Height / 2), textSize.Width, textSize.Height);
                TextRenderer.DrawText(e.Graphics, Text, Font, textBoxRectangle, ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);

                if (_showFocus && _focused)
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
                }

                e.Graphics.ResetClip();
            }
            catch
            {
                Invalidate();
            }
        }
        public void SetPage(Page newRoot)
        {
            if (newRoot == Application.MainPage && (_renderer != null || newRoot == null))
                return;

            if (_renderer != null)
                _renderer.Dispose();

            if (newRoot == null)
            {
                Application.MainPage = null;
                _renderer = null;
                return;
            }

            Application.MainPage = newRoot;
            Application.MainPage.Platform = this;
            _renderer = VisualElementRenderer.Create(Application.MainPage);
        }
 public override ERect GetPlatformContentGeometry()
 {
     return(VisualElementRenderer?.GetNativeContentGeometry() ?? new ERect());
 }
 public override void PlatformArrange(Rect frame)
 {
     base.PlatformArrange(frame);
     VisualElementRenderer.UpdateLayout();
 }
 void IEffectControlProvider.RegisterEffect(Effect effect) => VisualElementRenderer <VisualElement> .RegisterEffect(effect, View);