コード例 #1
0
ファイル: Viewport.cs プロジェクト: bluetsys/freeserf.net
        public override bool HandleEvent(Event.EventArgs e)
        {
            if (!Enabled || !Displayed)
            {
                return(false);
            }

            bool result = false;

            switch (e.Type)
            {
            case Event.Type.Click:
                if (e.Button == Event.Button.Left)
                {
                    result = HandleClickLeft(e.X, e.Y);
                }
                break;

            case Event.Type.Drag:
                result = HandleDrag(e.X, e.Y, e.Dx, e.Dy, e.Button);
                break;

            case Event.Type.DoubleClick:
            case Event.Type.SpecialClick:
                result = HandleDoubleClick(e.X, e.Y, e.Button);
                break;

            case Event.Type.KeyPressed:
                result = HandleKeyPressed((char)e.Dx, e.Dy);
                break;

            case Event.Type.SystemKeyPressed:
                result = HandleSystemKeyPressed((Event.SystemKey)e.Dx, e.Dy);
                break;

            default:
                break;
            }

            return(result);
        }
コード例 #2
0
        public override bool HandleEvent(Event.EventArgs e)
        {
            if (!Enabled || !Displayed)
            {
                return(false);
            }

            bool viewportActive  = Ingame && Viewport != null;
            bool viewportEnabled = Viewport != null && Viewport.Enabled;
            bool clickEvent      = e.Type == Event.Type.Click ||
                                   e.Type == Event.Type.DoubleClick ||
                                   e.Type == Event.Type.SpecialClick ||
                                   e.Type == Event.Type.Drag;

            // If the viewport is active and it is a click event
            // we will disable the viewport temporary to avoid
            // viewport mouse interaction handling with gui
            // coordinates.
            if (viewportActive && clickEvent)
            {
                Viewport.Enabled = false;
            }

            // Now test if there are gui elements that handle
            // the event.
            try
            {
                if (base.HandleEvent(e))
                {
                    // Ensure viewport enable reset
                    if (viewportEnabled)
                    {
                        Viewport.Enabled = true;
                    }

                    return(true); // handled
                }
            }
            catch (Exception ex)
            {
                throw new ExceptionFreeserf(Game, ex);
            }

            // If not handled we check for viewport mouse interaction
            if (viewportActive && clickEvent && viewportEnabled)
            {
                Viewport.Enabled = true;

                if (e.UntransformedArgs != null)
                {
                    var position = new Position(e.UntransformedArgs.X, e.UntransformedArgs.Y);
                    var delta    = new Size(e.UntransformedArgs.Dx, e.UntransformedArgs.Dy);

                    position = Gui.PositionToGame(position, RenderView); // this considers game zoom

                    if (e.Type == Event.Type.Drag)
                    {
                        delta = Gui.DeltaToGame(delta, RenderView);
                    }

                    try
                    {
                        // pass game transformed mouse data to the viewport
                        return(Viewport.HandleEvent(Event.EventArgs.Transform(e, position.X, position.Y, delta.Width, delta.Height)));
                    }
                    catch (Exception ex)
                    {
                        throw new ExceptionFreeserf(Game, ex);
                    }
                }
                else
                {
                    Debug.NotReached();
                }
            }

            return(false);
        }