示例#1
0
 /// <summary>
 /// Handles the <see cref="Mouse.PreviewMouseDownEvent"/>.
 /// </summary>
 private static void HandlePreviewMouseDown(DependencyObject element, MouseDevice device, MouseButton button, ref RoutedEventData data)
 {
     if (button == MouseButton.Left)
     {
         ((SliderBase)element).Focus();
     }
 }
        // Initializor=============================================
        public override void Initialize()
        {
            // Initialize the keyboard
            keyboard = Engine.Services.GetService<KeyboardDevice>();
            mouseDevice = Engine.Services.GetService<MouseDevice>();
            mouseDevice.ResetMouseAfterUpdate = false;

            // Initialize buttons
            Texture2D texture;

            hand = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\hand"),
                    new Vector2(mouseDevice.State.X, mouseDevice.State.Y), this);

            texture = Engine.Content.Load<Texture2D>("Content\\Textures\\menuReturnBtn");
            returnBtn = new Button(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 270), this);

            texture = Engine.Content.Load<Texture2D>("Content\\Textures\\menuMenuBtn");
            menuBtn = new Button(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 320), this);

            texture = Engine.Content.Load<Texture2D>("Content\\Textures\\menuQuitBtn");
            quitBtn = new Button(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 370), this);

            pauseText = new EntityText(Engine.Content.Load<SpriteFont>("Content\\Fonts\\FontAgency24"),
                new Vector2((Engine.Viewport.Width / 2)-40, 200), "PAUSE", this);

            // Initialize the black texture
            black = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\black"),
                    Vector2.Zero, this);
            black.Alpha = 0.4f;

            base.Initialize();
        }
示例#3
0
 /// <inheritdoc/>
 protected override void OnMouseEnter(MouseDevice device, ref RoutedEventData data)
 {
     if (HighlightOnMouseOver)
     {
         HighlightOpacity = 1.0;
     }
     base.OnMouseEnter(device, ref data);
 }
 protected override void Setup(Texture2D texture, Vector2 Position)
 {
     base.Setup(texture, Position);
     mouseDevice = Engine.Services.GetService<MouseDevice>();
     mouseDevice.ResetMouseAfterUpdate = false;
     buttonPosition = Position;
     cmouse = Mouse.GetState();
 }
示例#5
0
        public MouseInputBinding(UltravioletContext uv, MouseButton button)
        {
            Contract.Require(uv, nameof(uv));

            if (!uv.GetInput().IsMouseSupported())
            {
                throw new NotSupportedException();
            }

            this.mouse = uv.GetInput().GetMouse();
            this.button = button;

            this.stringRepresentation = BuildStringRepresentation();
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MouseInputBinding"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="button">The <see cref="MouseButton"/> value that represents the binding's primary button.</param>
        /// <param name="control">A value indicating whether the binding requires the Control modifier.</param>
        /// <param name="alt">A value indicating whether the binding requires the Alt modifier.</param>
        /// <param name="shift">A value indicating whether the binding requires the Shift modifier.</param>
        public MouseInputBinding(UltravioletContext uv, MouseButton button, Boolean control, Boolean alt, Boolean shift)
        {
            if (!uv.GetInput().IsMouseSupported())
            {
                throw new NotSupportedException();
            }

            this.mouse = uv.GetInput().GetMouse();
            this.button = button;
            this.control = control;
            this.alt = alt;
            this.shift = shift;

            this.stringRepresentation = BuildStringRepresentation();
        }
示例#7
0
        protected override void LoadContent()
        {
            // Setup engine. We do this in the load method
            // so that we know graphics will be ready for use
            Engine.SetupEngine(graphics);

            // Setup Inputs
            MouseDevice mouse = new MouseDevice();
            KeyboardDevice keyboard = new KeyboardDevice();

            Engine.Services.AddService(typeof(MouseDevice), mouse);
            Engine.Services.AddService(typeof(KeyboardDevice), keyboard);

            // Add MenuScreen
            Engine.AddScreen(new IntroScreen("IntroScreen"));
            Trace.WriteLine(Engine.GameScreens[0].Name);
        }
        // Initializor=============================================
        public override void Initialize()
        {
            // Initialize the keyboard
            keyboard = Engine.Services.GetService<KeyboardDevice>();
            mouseDevice = Engine.Services.GetService<MouseDevice>();
            mouseDevice.ResetMouseAfterUpdate = false;

            Texture2D texture;
            Texture2D level_finish_bg=Engine.Content.Load<Texture2D>("Content\\Textures\\level_finish_bg");

            hand = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\hand"),
                    new Vector2(mouseDevice.State.X, mouseDevice.State.Y), this);

            // Initialize the Game Text
            string level="LEVEL " + GlobalVariables.level.ToString() + " COMPLETE";
            titleText = new EntityText(Engine.Content.Load<SpriteFont>("Content\\Fonts\\FontAgency24"),
                new Vector2((Engine.Viewport.Width / 2) - 20, 200), level, this);

            string score = "Score: " + GlobalVariables.score.ToString()+" points.";
            scoreText = new EntityText(Engine.Content.Load<SpriteFont>("Content\\Fonts\\FontAgency24"),
                new Vector2((Engine.Viewport.Width / 2) - 120, 270), score, this);

            string money = "Money: " + GlobalVariables.money.ToString() + " Dirhams";
            moneyText = new EntityText(Engine.Content.Load<SpriteFont>("Content\\Fonts\\FontAgency24"),
                new Vector2((Engine.Viewport.Width / 2) - 120, 330), money, this);

            // Initialize the black texture
            texture = Engine.Content.Load<Texture2D>("Content\\Textures\\next_btn");
            nextBtn = new Button(texture, new Vector2(475, 380), this);

            background = new Entity2D(level_finish_bg,
                                Vector2.Zero, this);
            background.Alpha = 0f;
            background.Position = new Vector2((Engine.Viewport.Width / 2) - (background.Texture.Width / 2),
                                             (Engine.Viewport.Height / 2) - (background.Texture.Height / 2));

            fade = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\black"),
                    Vector2.Zero, this);
            fade.Alpha = 0.4f;

            base.Initialize();
        }
        public override void Initialize()
        {
            // Initialize the keyboard
            keyboard = Engine.Services.GetService<KeyboardDevice>();
            mouseDevice = Engine.Services.GetService<MouseDevice>();
            mouseDevice.ResetMouseAfterUpdate=false;

            // Initialize Components
            Texture2D texture;

            black = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\black"),
                                Vector2.Zero, this);

            hand = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\hand"),
                                new Vector2(mouseDevice.State.X, mouseDevice.State.Y), this);

            // Initialize Buttons
            texture = Engine.Content.Load<Texture2D>("Content\\Textures\\menuPlayBtn");
            menuPlay = new Button(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 270), this);

            //texture = Engine.Content.Load<Texture2D>("Content\\Textures\\menuOptionsBtn");
            //menuOptions = new Button(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 315), this);

            //texture = Engine.Content.Load<Texture2D>("Content\\Textures\\menuWhoBtn");
            //menuWho = new Button(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 360), this);

            texture = Engine.Content.Load<Texture2D>("Content\\Textures\\menuQuitBtn");
            menuQuit = new Button(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 325), this);

            texture = Engine.Content.Load<Texture2D>("Content\\Textures\\MenuTitle");
            menuTitle = new Entity2D(texture, new Vector2((Engine.Viewport.Width / 2) - (texture.Width / 2), 155), this);

            texture=Engine.Content.Load<Texture2D>("Content\\Textures\\MenuBall");
            menuBall = new Entity2D(texture, new Vector2(473,81), this);

            background = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\MenuBackground"), Vector2.Zero, this);

            base.Initialize();
        }
示例#10
0
        public void OnKeyDown(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
        {
            switch (e.Key)
            {
            case Key.Escape:
                MainWindow.exit = true;
                break;

            case Key.Left:
                player.Angle = MathHelper.PiOver2;
                break;

            case Key.Right:
                player.Angle = 3 * MathHelper.PiOver2;
                break;

            case Key.Up:
                player.Angle = 0;
                break;

            case Key.Down:
                player.Angle = 3 * MathHelper.Pi;
                break;
            }
        }
示例#11
0
 internal InputManager(KeyboardDevice keyboardDevice, MouseDevice mouseDevice, JoystickDevice[] joystickDevice)
 {
     this.keyboardDevice = keyboardDevice;
     this.mouseDevice    = mouseDevice;
     this.joysticks      = joystickDevice;
 }
示例#12
0
 public void OnKeyUp(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
示例#13
0
 private bool IsInputValid(MouseDevice mouseDevice)
 {
     return(mouseDevice.MiddleButton == MouseButtonState.Pressed && Keyboard.Modifiers.HasFlag(Modifiers));
 }
 /// <summary>
 /// Invokes the <see cref="OnMouseDown"/> method.
 /// </summary>
 private static void OnMouseDownProxy(DependencyObject element, MouseDevice device, MouseButton button, RoutedEventData data)
 {
     ((UIElement)element).OnMouseDown(device, button, data);
 }
示例#15
0
        public void OnKeyUp(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
        {
            switch (e.Key)
            {
            case Key.Left:
                if (Keyboard[Key.Right])
                {
                    player.Angle = 3 * MathHelper.PiOver2;
                }
                if (Keyboard[Key.Up])
                {
                    player.Angle = 0;
                }
                if (Keyboard[Key.Down])
                {
                    player.Angle = MathHelper.Pi;
                }
                break;

            case Key.Right:
                if (Keyboard[Key.Left])
                {
                    player.Angle = MathHelper.PiOver2;
                }
                if (Keyboard[Key.Up])
                {
                    player.Angle = 0;
                }
                if (Keyboard[Key.Down])
                {
                    player.Angle = MathHelper.Pi;
                }
                break;

            case Key.Up:
                if (Keyboard[Key.Left])
                {
                    player.Angle = MathHelper.PiOver2;
                }
                if (Keyboard[Key.Right])
                {
                    player.Angle = 3 * MathHelper.PiOver2;
                }
                if (Keyboard[Key.Down])
                {
                    player.Angle = MathHelper.Pi;
                }
                break;

            case Key.Down:
                if (Keyboard[Key.Left])
                {
                    player.Angle = MathHelper.PiOver2;
                }
                if (Keyboard[Key.Right])
                {
                    player.Angle = 3 * MathHelper.PiOver2;
                }
                if (Keyboard[Key.Up])
                {
                    player.Angle = 0;
                }
                break;
            }
        }
示例#16
0
 /// <inheritdoc/>
 protected override void OnMouseMove(MouseDevice device, Double x, Double y, Double dx, Double dy, RoutedEventData data)
 {
     if (ClickMode != ClickMode.Hover)
     {
         if (IsMouseCaptured && device.IsButtonDown(MouseButton.Left))
         {
             var position = Mouse.GetPosition(this);
             IsPressed = Bounds.Contains(position);
         }
     }
     base.OnMouseMove(device, x, y, dx, dy, data);
 }
        /// <summary>
        /// Invoked by the <see cref="Mouse.MouseDoubleClickEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The mouse device.</param>
        /// <param name="button">The mouse button that was pressed or released.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnMouseDoubleClick(MouseDevice device, MouseButton button, RoutedEventData data)
        {

        }
示例#18
0
 /// <inheritdoc/>
 protected override void OnMouseMove(MouseDevice device, Double x, Double y, Double dx, Double dy, RoutedEventData data)
 {
     if (device.IsButtonDown(MouseButton.Left))
     {
         var twopi = 2.0f * (Single)Math.PI;
         var delta = twopi * (Single)(dx / ActualWidth);
         TriangleRotation = Math.Max(0, Math.Min(twopi, TriangleRotation + delta));
     }
     base.OnMouseMove(device, x, y, dx, dy, data);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 protected virtual void OnMouseMoved(MouseDevice sender, MouseEventArgs args)
 {
     Core.Extensions.RaiseEvent(MouseMoved, this, args);
 }
示例#20
0
 public MouseHorizontalWheelEventArgs(MouseDevice mouse, int timestamp, int horizontalDelta)
     : base(mouse, timestamp)
 {
     this.HorizontalDelta = horizontalDelta;
 }
示例#21
0
        public void OnUpdateFrame(FrameEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
        {
            if (!fadingOut && fadeBox.Color.A > 0)
            {
                fadeBox.Color = new Color4(0, 0, 0, fadeBox.Color.A - (float)e.Time * fadeTime);
            }

            if (fadingOut)
            {
                if (fadeBox.Color.A < 1)
                {
                    fadeBox.Color = new Color4(0, 0, 0, fadeBox.Color.A + (float)e.Time * fadeTime);
                }
                else
                {
                    if (gameWon)
                    {
                        MainWindow.state = new EndMenuState();
                        Resources.StopAllAudio();
                        //Resources.UnloadAudioBuffers();
                    }
                    else
                    {
                        Type oldAreaType = area.GetType();
                        area.Unload();
                        area = tempNewArea;
                        area.LoadContent(data);
                        player.MoveTo(area.SetPlayerStartLocation(oldAreaType));
                        GL.ClearColor(area.ClearColor);
                        fadingOut = false;
                    }
                }
            }

            player.Moving = false;

            if (Keyboard[Key.Up])
            {
                player.MoveBy(new Vector2(0, (float)(e.Time * Player.MoveSpeed)));
                player.Moving = true;
            }

            if (Keyboard[Key.Down])
            {
                player.MoveBy(new Vector2(0, -(float)(e.Time * Player.MoveSpeed)));
                player.Moving = true;
            }

            if (Keyboard[Key.Left])
            {
                player.MoveBy(new Vector2(-(float)(e.Time * Player.MoveSpeed), 0));
                player.Moving = true;
            }

            if (Keyboard[Key.Right])
            {
                player.MoveBy(new Vector2((float)(e.Time * Player.MoveSpeed), 0));
                player.Moving = true;
            }

            c.Update(e.Time);
            player.Update(e.Time);

            message = string.Empty;


            foreach (TriggerChangeArea trigger in area.AreaChangeTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    tempNewArea = trigger.Area;
                    fadingOut   = true;
                    break;
                }
            }

            foreach (TriggerButtonPress trigger in area.ButtonPressTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    trigger.Button.Activated = true;
                }

                else
                {
                    if (trigger.Button.Activated)
                    {
                        trigger.Activate();
                    }
                }
            }

            foreach (TriggerEndgame trigger in area.EndgameTrigger)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    if (Keyboard[Key.Z])
                    {
                        fadingOut = true;
                        gameWon   = true;
                    }
                    else
                    {
                        message = "Press Z to repair the ship and leave!";
                    }
                }
            }

            foreach (TriggerReading trigger in area.ReadingTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    if (Keyboard[Key.Z])
                    {
                        trigger.Activate();
                    }
                    else
                    {
                        message = "Press Z to read the note";
                    }
                }
            }

            List <TriggerDoorOpen> openedList = new List <TriggerDoorOpen>();

            foreach (TriggerDoorOpen trigger in area.DoorOpenTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    Entity ent = player.FindNameInInventory(trigger.LockCode);
                    if (ent != null)
                    {
                        if (Keyboard[Key.Z])
                        {
                            ChangeGameDataDoor(trigger.Door);
                            player.Inventory.Remove(ent);
                            area.EntList.Remove(trigger.Door);
                            ent.Unload();
                            trigger.Door.Unload();
                        }
                        else
                        {
                            message = "Press Z to open the " + trigger.Door.Name;
                        }
                    }
                }
            }


            List <TriggerPickup> pickedUpList = new List <TriggerPickup>();

            foreach (TriggerPickup trigger in area.PickupTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    if (Keyboard[Key.Z])
                    {
                        ChangeGameDataItem(trigger.Ent);
                        player.Inventory.Add(trigger.Ent);
                        area.EntList.Remove(trigger.Ent);
                        pickedUpList.Add(trigger);
                    }
                    else
                    {
                        message = "Press Z to pick up the " + trigger.Ent.Name;
                    }
                }
            }
            foreach (TriggerPickup trigger in pickedUpList)
            {
                area.PickupTriggers.Remove(trigger);
            }


            foreach (Entity ent in area.EntList)
            {
                if (PhysicsManager.IsColliding(player, ent) && ent.Solid)
                {
                    player.MoveBy(PhysicsManager.ReactCollision(player, ent));
                }
            }
            c.JumpTo(player.Position);
        }
示例#22
0
 public void OnMouseDown(object sender, MouseEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
示例#23
0
        /// <inheritdoc/>
        protected override void OnMouseWheel(MouseDevice device, Double x, Double y, RoutedEventData data)
        {
            TriangleZoom = (Single)Math.Max(0, Math.Min(1, TriangleZoom + (y * 0.1f)));

            base.OnMouseWheel(device, x, y, data);
        }
示例#24
0
        protected override void update()
        {
            Paddle paddle = paddleSet.get(0);
            Ball   ball   = ballSet.get(0);

            /* EXAMPLE 1
             * Single IF Statement
             *
             * Notice how this if statement seeks to
             * determine if the game logic should continue
             * or if we should jump to the game winning code
             * in gameWin()
             */
            bool playerWonGame = areAllBlocksRemoved();

            if (playerWonGame) // The player has won when all the normal blocks are removed
            {
                gameWin();
            }

            /* EXAMPLE 2
             * Sequential, Single IF Statement Demonstration
             *
             * The above if statement is followed by a
             * second if statement in sequential order.
             * Since we omitted the "else" statement here
             * these two ifs are unrelated to one another
             * and their code blocks are not mutually exclusive
             * We'll improve this code once we reach if/else
             * statements in the lab
             */
            if (!playerWonGame)
            {
                /* TODO 5
                 * Compound Boolean Expressions using Logical AND and Logical OR
                 *
                 * Here, we'll combine the mouse and keyboard if statements into one
                 * longer, compound if statement using AND and OR.
                 *
                 * The if statement below should ask: "Is the spacebar pressed
                 * OR is BOTH the mouse onscreen AND the left button clicked?"
                 * Note that the OR is "||", the AND is "&&" and the BOTH is accomplished
                 * by adding parenthesis around MouseOnScreen() and isButtonTapped()
                 *
                 * If either of these (or both) are true, then this will execute the
                 * code you already wrote in the TODO1 section below.
                 * How is this question change if we swapped all ANDs and ORs?
                 * This would produce the question: "Is the spacebar pressed
                 * AND EITHER the mouse onscreen OR the the left button is clicked?"
                 *
                 * before: Only pressing the space key would cause the ball to spawn.
                 * after:  Now, using the mouse or the space key causes balls to spawn.
                 *
                 */

                /*      Starting code:
                 *            if (keyboard.isButtonTapped(KeyEvent.VK_SPACE)) {
                 */

                if (keyboard.isKeyTapped(Keys.Space) || (MouseDevice.MouseOnScreen() && MouseDevice.IsRightTapped())) /** SOLN */

                /*  TODO 1
                 *  Single IF Statement
                 *
                 *   Write a single If statement here that asks:
                 *
                 *  "Is the ball invisible?".  If it is invisible, then
                 *   put it on the screen near the paddle by calling "ball.spawn(paddle)".
                 *
                 *  See the EXAMPLE1 and EXAMPLE1B for a sample single IF statement.
                 *
                 *  Transform this pseuducode into the if statement below:
                 *  Step 1: if the ball is invisible, then tell the ball to spawn near the paddle.
                 *  Step 2: fill in the code gaps below to obtain working Java code
                 *
                 *   if( <your question goes here> ) {
                 *	    <your "then" code goes here to spawn the paddle near the ball>
                 *   }
                 *
                 *   before: hitting space or left-clicking does nothing in our game
                 *   after: hitting space or left-clicking spawns a ball and starts the game
                 *
                 */
                {
                    if (ball.Visible == false)  /**   SOLN */
                    {
                        ball.spawn(paddle);
                    }
                }

                /* TODO 4
                 * Use Logical AND to Enable Mouse Support for Ball Spawning
                 *
                 * Rewrite the three IF statements below as one compound IF statement using Java's logical
                 * AND operator "&&".  Start by commenting out the 3 if statements, and build your own in
                 * its place.
                 *
                 * Notice the IF statements and what they accomplish; in order, they ask the following:
                 * (1) Is the mouse is onscreen? (i.e. connected to your computer)
                 * (2) Is the mouse's left-button is pressed?
                 * (3) Is the ball already spawned? (i.e. is the ball already visible?)
                 *
                 * before: Three if statements, with one nested inside the other.
                 * after: One compound if statement to rule the spawning of the ball.
                 */
                if (MouseDevice.MouseOnScreen()) //is a mouse connected to the computer?
                {
                    if (MouseDevice.IsRightTapped())
                    {                              //is the mouse's left-button pressed?
                        if (ball.Visible == false) //is there no ball on the scree currently
                        {
                            ball.spawn(paddle);
                        }
                    }
                }

                if (MouseDevice.MouseOnScreen() && MouseDevice.IsRightTapped() && ball.Visible == true) /** SOLN */
                {
                    ball.spawn(paddle);
                }



                /*  TODO 2
                 *  Sequential, Single If statements.
                 *
                 *  These will have the form as outlined in the lab, and will ask:
                 *
                 *  "Is the user pressing the left key? If so, move the paddle left."
                 *  "Is the user pressing the right key? If so, move the paddle right."
                 *  "Is the user pressing the up key? If so, move the paddle up."
                 *  "Is the user pressing the down key? If so, move the paddle down."
                 *
                 *  Transform this pseuducode above into the if statement below:
                 *  by replacing "LEFT button" with "KeyEvent.VK_LEFT" and
                 *  by replacing "keyboard is pressing down" with "keyboard.isButtonDown()"
                 *  by replacing "Tell the paddle to move left" with "paddle.moveLeft()"
                 *
                 *	 if (keyboard is pressing down the LEFT button) {
                 *       Tell the paddle to move left
                 *   }
                 *
                 *   if (keyboard is pressing down the RIGHT button) {
                 *       Tell the paddle to move right
                 *   }
                 *
                 *   if (the keyboard is pressing UP) {
                 *      Tell the paddle to move up
                 *   }
                 *
                 *   if pressing down {
                 *      move paddle down.
                 *   }
                 *
                 *   before:
                 *   after:
                 *
                 *   Take a look at the animated gif in the lab for a pictorial example of the before and after.
                 *
                 */

                //BUG: NOTE: the mouse check must come first here, or the if's need to be joined as an if-else clause for the keyboard code to function correctly
                if (keyboard.isKeyDown(Keys.Left))        /** SOLN */
                {
                    paddle.moveLeft();
                    //mouse.setX()  //solution to bug 1001
                }
                else if (keyboard.isKeyDown(Keys.Right))  /** SOLN */
                {
                    paddle.moveRight();
                    //mouse.setY() //solution to bug 1001
                }
                if (MouseDevice.MouseOnScreen())                                        /** SOLN */
                {
                    paddle.CenterX = MouseDevice.getMouseX();
                    paddle.clampAtWorldBounds();
                }



                /* EXAMPLE 4
                 * Compound Boolean Expressions using Logical AND
                 *
                 * Notice how we check the ball first for null before we try to use it.
                 * By ordering the null check first and using the double '&', we perform a short-circuit
                 * evaulation of the clauses in the if statement.  This means that the && will
                 * block execution of the second Boolean expression if the first expression is false.
                 *
                 * This is based on the following observations:
                 * FALSE AND X is always FALSE, regardless of X.
                 * TRUE OR Y is always TRUE, regardless of Y.
                 *
                 * Also observe how reversing the expressions
                 * is a logic error and could result in NullPointerExceptions being thrown.
                 * So we can see order of boolean expressions is important inside an
                 * if statement, just like the order of the statements in an if/else chain matters as well.
                 */
                if (ball != null && ball.Visible)
                {
                    BoundCollidedStatus status = ball.collideWorldBound();
                    switch (status)
                    {
                    case BoundCollidedStatus.CollidedTop: {
                        ball.reflectTop();
                        ball.playBounceSound();
                        break;
                    }

                    case BoundCollidedStatus.CollideBottom: {
                        ball.Visible = false;
                        ball.playDieSound();

                        lifeSet.remove();

                        if (lifeSet.getCount() < 1)
                        {
                            gameLost();
                        }

                        break;
                    }

                    case BoundCollidedStatus.CollidedLeft: {
                        ball.reflectLeft();
                        ball.playBounceSound();
                        break;
                    }

                    case BoundCollidedStatus.CollidedRight: {
                        ball.reflectRight();
                        ball.playBounceSound();
                        break;
                    }

                    // Catch the case where the ball is inside the
                    // world and not hitting any bounds. A warning is
                    // given if all cases are not handled.
                    default:
                        break;
                    }

                    /* TODO Z
                     * another good single if (without it, the ball goes through the paddle!)
                     *
                     * before: The ball goes right through the paddle!
                     * after: The ball reflects off the paddle and plays a bounce sound
                     *
                     * Take a look at the animated gif in the lab for a pictorial example of the before and after.
                     */
                    if (paddle.Collided(ball))
                    {
                        paddle.reflect(ball);
                        ball.playBounceSound();
                    }


                    //ROB/KELVIN; consider undoing the import so the students know PaddleStates live inside Paddles?
                    //ROB/KELVIN Q2: unite Ball and Paddle Types/States respectively, to reduce logic to:
                    //	if(ball.getState() != paddle.getState() ) ball.setState(paddle.getState());


                    /* EXAMPLE 1B
                     * Single IF Statement
                     *
                     *  The following if statement checks to see if the paddle and ball state/types
                     *  are synchronized.  If the paddle is in a NORMAL state, the ball should be
                     *  set to a NORMAL type/state as well, which draws a standard ball (with no
                     *  fire or ice) on the screen.
                     *
                     */
                    if (paddle.getState() == Paddle.PaddleState.NORMAL)
                    {
                        ball.setType(Ball.BallType.NORMAL);
                    }

                    /* TODO Y
                     * IF-ELSE Chain
                     *
                     * Write a chain of 2 IF statements joined by an ELSE clause to determine if
                     * the ball needs to be transformed into a fireball or iceball, respectively, based
                     * on the current state of the paddle.
                     *
                     * See the example above for how this is done for the NORMAL state and NORMAL ball type
                     *
                     * before: Balls don't change to fire or ice as they should when they collide with such blocks
                     * after: Balls will visibly change appearance to match the paddle's fire or ice state.
                     *
                     * Take a look at the animated gif in the lab for a pictorial example of the before and after.
                     */
                    if (paddle.getState() == Paddle.PaddleState.FIRE)
                    {
                        ball.setType(Ball.BallType.FIRE);                                        /** SOLN */
                    }
                    else if (paddle.getState() == Paddle.PaddleState.ICE)
                    {
                        ball.setType(Ball.BallType.ICE);                                            /** SOLN */
                    }
                    //logic reduction here to see ball and paddle states are synchronized
                    /** ball.setState(paddle.getState());  REDUCE to this!  */


                    //ROB/KELVIN: where does a paddle get its state set?
                    //ROB/KELVIN: where does a ball get its state set? In response to the paddle, and in the update, right?
                    if (blockSet.isBallCollidingWithABlock(ball))
                    {
                        handleBlockBallCollision(ball, paddle);
                    }
                }
            }
        }
        /// <summary>
        /// Invoked by the <see cref="Mouse.MouseMoveEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The mouse device.</param>
        /// <param name="x">The x-coordinate of the cursor in device-independent screen coordinates.</param>
        /// <param name="y">The y-coordinate of the cursor in device-independent screen coordinates.</param>
        /// <param name="dx">The difference between the x-coordinate of the mouse's 
        /// current position and the x-coordinate of the mouse's previous position.</param>
        /// <param name="dy">The difference between the y-coordinate of the mouse's 
        /// current position and the y-coordinate of the mouse's previous position.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnMouseMove(MouseDevice device, Double x, Double y, Double dx, Double dy, RoutedEventData data)
        {

        }
示例#26
0
        /// <inheritdoc/>
        protected override void OnMouseMove(MouseDevice device, Double x, Double y, Double dx, Double dy, RoutedEventData data)
        {
            LinkUtil.UpdateLinkCursor(textLayoutCommands, this, Mouse.GetPosition(this));

            base.OnMouseMove(device, x, y, dx, dy, data);
        }
 /// <summary>
 /// Invokes the <see cref="OnMouseLeave"/> method.
 /// </summary>
 private static void OnMouseLeaveProxy(DependencyObject element, MouseDevice device, RoutedEventData data)
 {
     var uiElement = ((UIElement)element);
     uiElement.OnMouseLeave(device, data);
 }
示例#28
0
        /// <inheritdoc/>
        protected override void OnMouseLeave(MouseDevice device, RoutedEventData data)
        {
            LinkUtil.UpdateLinkCursor(textLayoutCommands, this, Mouse.GetPosition(this));

            base.OnMouseLeave(device, data);
        }
示例#29
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.Mouse.PreviewMouseUp"/>
 /// attached event for the specified element.
 /// </summary>
 internal static void RaisePreviewMouseUp(DependencyObject element, MouseDevice device, MouseButton button, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfMouseButtonEventHandler>(PreviewMouseUpEvent);
     evt?.Invoke(element, device, button, data);
 }
示例#30
0
 internal override Point GetMouseScreenPosition(MouseDevice mouseDevice)
 {
     return(mouseDevice.GetScreenPositionFromSystem());
 }
示例#31
0
 public void OnKeyDown(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
     if (e.Key == Key.Escape)
     {
         StateManager.ClearStates();
     }
 }
示例#32
0
 internal override MouseButtonState GetMouseButtonState(MouseButton mouseButton, MouseDevice mouseDevice)
 {
     return(mouseDevice.GetButtonStateFromSystem(mouseButton));
 }
示例#33
0
 public void OnMouseUp(object sender, MouseButtonEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
示例#34
0
 /// <summary>
 /// Handles the <see cref="Mouse.PreviewMouseWheelEvent"/> routed event.
 /// </summary>
 private static void HandlePreviewMouseWheel(DependencyObject element, MouseDevice device, Double x, Double y, ref RoutedEventData data)
 {
     var numericUpDown = (NumericUpDown)element;
     if (numericUpDown.PART_Input.IsKeyboardFocused)
     {
         numericUpDown.Value += y;
     }
 }
示例#35
0
        /// <inheritdoc/>
        protected override void OnMouseWheel(MouseDevice device, Double x, Double y, ref RoutedEventData data)
        {
            TriangleZoom = (Single)Math.Max(0, Math.Min(1, TriangleZoom + (y * 0.1f)));

            base.OnMouseWheel(device, x, y, ref data);
        }
示例#36
0
        /// <inheritdoc/>
        protected override void OnMouseMove(MouseDevice device, Double x, Double y, Double dx, Double dy, RoutedEventData data)
        {
            LinkUtil.UpdateLinkCursor(textLayoutCommands, this, Mouse.GetPosition(this));

            base.OnMouseMove(device, x, y, dx, dy, data);
        }
示例#37
0
 protected virtual void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
 {
 }
示例#38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FormMouseWheelEventArgs"/> class.
 /// </summary>
 /// <param name="routedEvent"></param>
 /// <param name="mouse">The mouse device associated with this event.</param>
 /// <param name="timestamp">The time when the input occurred.</param>
 /// <param name="delta">The amount the wheel has changed.</param>
 public FormMouseWheelEventArgs(RoutedEvent routedEvent, MouseDevice mouse, int timestamp, int delta) : base(routedEvent)
 {
     Delta     = delta;
     Timestamp = timestamp;
     Mouse     = mouse;
 }
示例#39
0
        /// <inheritdoc/>
        protected override void OnMouseLeave(MouseDevice device, RoutedEventData data)
        {
            LinkUtil.UpdateLinkCursor(textLayoutCommands, this, Mouse.GetPosition(this));

            base.OnMouseLeave(device, data);
        }
示例#40
0
 protected virtual void OnDrag(MouseDevice mouseDevice, double zoom)
 {
 }
示例#41
0
 /// <inheritdoc/>
 protected override void OnMouseUp(MouseDevice device, MouseButton button, RoutedEventData data)
 {
     if (button == MouseButton.Left)
     {
         LinkUtil.ExecuteTextLink(textLayoutCommands, this, data);
     }
     base.OnMouseUp(device, button, data);
 }
 public MouseController(MouseDevice mouse)
 {
     _mouse = mouse;
     //  mouseDown = mouse.ButtonDown;
 }
示例#43
0
 /// <inheritdoc/>
 protected override void OnMouseDown(MouseDevice device, MouseButton button, RoutedEventData data)
 {
     if (button == MouseButton.Left)
     {
         View.CaptureMouse(this, CaptureMode.Element);
     }
     base.OnMouseDown(device, button, data);
 }
示例#44
0
 /// <summary>
 /// When overriden in a derived class, determines whether the gesture matches the specified mouse double click input event.
 /// </summary>
 /// <param name="device">The mouse device.</param>
 /// <param name="button">The mouse button that was pressed or released.</param>
 /// <param name="data">The routed event metadata for this event invocation.</param>
 /// <returns><see langword="true"/> if the gesture matches the event; otherwise, <see langword="false"/>.</returns>
 public virtual Boolean MatchesMouseDoubleClick(MouseDevice device, MouseButton button, RoutedEventData data) => false;
示例#45
0
 /// <inheritdoc/>
 protected override void OnMouseUp(MouseDevice device, MouseButton button, RoutedEventData data)
 {
     if (button == MouseButton.Left && IsMouseCaptured)
     {
         View.ReleaseMouse();
     }
     base.OnMouseUp(device, button, data);
 }
示例#46
0
 /// <summary>
 /// When overriden in a derived class, determines whether the gesture matches the specified mouse wheel input event.
 /// </summary>
 /// <param name="device">The mouse device.</param>
 /// <param name="x">The amount that the wheel was scrolled along the x-axis.</param>
 /// <param name="y">The amount that the wheel was scrolled along the y-axis.</param>
 /// <param name="data">The routed event metadata for this event invocation.</param>
 /// <returns><see langword="true"/> if the gesture matches the event; otherwise, <see langword="false"/>.</returns>
 public virtual Boolean MatchesMouseWheel(MouseDevice device, Double x, Double y, RoutedEventData data) => false;
示例#47
0
 /// <inheritdoc/>
 protected override void OnMouseEnter(MouseDevice device, RoutedEventData data)
 {
     if (ClickMode == ClickMode.Hover)
     {
         OnClick();
         OnClickByUser();
     }
     base.OnMouseEnter(device, data);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Mouse"/> class.
 /// </summary>
 /// <param name="view">The view which owns this tracker.</param>
 /// <param name="device">The mouse device which is being tracked.</param>
 public Mouse(PresentationFoundationView view, MouseDevice device)
     : base(view)
 {
     this.device = device;
 }
示例#49
0
 /// <inheritdoc/>
 protected override void OnMouseUp(MouseDevice device, MouseButton button, RoutedEventData data)
 {
     if (button == MouseButton.Left)
     {
         HandleReleased();
         data.Handled = true;
     }
     base.OnMouseUp(device, button, data);
 }
 private bool ProcessMouseEvent(RawMouseEventArgs mouseEventArgs)
 {
     return(Dispatcher.CurrentDispatcher.Invoke(() => MouseDevice.ProcessRawEvent(mouseEventArgs), DispatcherPriority.Input));
 }
        /// <summary>
        /// Invoked by the <see cref="Mouse.MouseLeaveEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The mouse device.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnMouseLeave(MouseDevice device, RoutedEventData data)
        {

        }
示例#52
0
 public void processInput(KeyboardState keyboard, MouseDevice mouse)
 {
     // Pass on to the camera
     camera.processInput(keyboard, mouse);
 }
        /// <summary>
        /// Invoked by the <see cref="Mouse.MouseWheelEvent"/> attached routed event.
        /// </summary>
        /// <param name="device">The mouse device.</param>
        /// <param name="x">The amount that the wheel was scrolled along the x-axis.</param>
        /// <param name="y">The amount that the wheel was scrolled along the y-axis.</param>
        /// <param name="data">The routed event metadata for this event invocation.</param>
        protected virtual void OnMouseWheel(MouseDevice device, Double x, Double y, RoutedEventData data)
        {

        }
示例#54
0
 protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
 {
     this.startRootPoint     = PathFigureUtilities.GetPoint(this.PathEditorTarget.PathGeometry.Figures[pathEditContext.FigureIndex], pathEditContext.PartIndex, true);
     this.geometryToDocument = this.PathEditorTarget.GetTransformToAncestor((IViewObject)this.View.HitTestRoot);
     base.OnBegin(pathEditContext, mouseDevice);
 }
 /// <summary>
 /// Invokes the <see cref="OnMouseMove"/> method.
 /// </summary>
 private static void OnMouseMoveProxy(DependencyObject element, MouseDevice device, Double x, Double y, Double dx, Double dy, RoutedEventData data)
 {
     ((UIElement)element).OnMouseMove(device, x, y, dx, dy, data);
 }
示例#56
0
        public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
            }
            XVisualInfo template = new XVisualInfo();

            using (new XLock(this.window.Display))
            {
                if (!mode.Index.HasValue)
                {
                    throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
                }
                template.VisualID = mode.Index.Value;
                int nitems;
                this.window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(Functions.XGetVisualInfo(this.window.Display, XVisualInfoMask.ID, ref template, out nitems), typeof(XVisualInfo));
                XSetWindowAttributes attributes = new XSetWindowAttributes();
                attributes.background_pixel = IntPtr.Zero;
                attributes.border_pixel     = IntPtr.Zero;
                attributes.colormap         = Functions.XCreateColormap(this.window.Display, this.window.RootWindow, this.window.VisualInfo.Visual, 0);
                this.window.EventMask       = EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PointerMotionMask | EventMask.KeymapStateMask | EventMask.ExposureMask | EventMask.StructureNotifyMask | EventMask.FocusChangeMask | EventMask.PropertyChangeMask;
                attributes.event_mask       = (IntPtr)((long)this.window.EventMask);
                uint num = 10250U;
                this.window.WindowHandle = Functions.XCreateWindow(this.window.Display, this.window.RootWindow, x, y, width, height, 0, this.window.VisualInfo.Depth, 1, this.window.VisualInfo.Visual, (UIntPtr)num, ref attributes);
                if (this.window.WindowHandle == IntPtr.Zero)
                {
                    throw new ApplicationException("XCreateWindow call failed (returned 0).");
                }
                if (title != null)
                {
                    Functions.XStoreName(this.window.Display, this.window.WindowHandle, title);
                }
            }
            this.SetWindowMinMax((short)30, (short)30, (short)-1, (short)-1);
            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)12L;
            using (new XLock(this.window.Display))
            {
                Functions.XSetWMNormalHints(this.window.Display, this.window.WindowHandle, ref hints);
                Functions.XSetWMProtocols(this.window.Display, this.window.WindowHandle, new IntPtr[1]
                {
                    this._atom_wm_destroy
                }, 1);
            }
            this.RefreshWindowBounds(ref new XEvent()
            {
                ConfigureEvent =
                {
                    x      = x,
                    y      = y,
                    width  = width,
                    height = height
                }
            });
            this.driver      = new X11Input((IWindowInfo)this.window);
            this.mouse       = this.driver.Mouse[0];
            this.EmptyCursor = X11GLNative.CreateEmptyCursor(this.window);
            this.exists      = true;
        }
示例#57
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.Mouse.MouseLeave"/>
 /// attached event for the specified element.
 /// </summary>
 internal static void RaiseMouseLeave(DependencyObject element, MouseDevice device, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfMouseEventHandler>(MouseLeaveEvent);
     evt?.Invoke(element, device, data);
 }
示例#58
0
        public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
        {
            _platform = platform;
            _popup    = popupParent != null;
            _x11      = platform.Info;
            _mouse    = new MouseDevice();
            _touch    = new TouchDevice();
            _keyboard = platform.KeyboardDevice;

            var glfeature             = AvaloniaLocator.Current.GetService <IPlatformOpenGlInterface>();
            XSetWindowAttributes attr = new XSetWindowAttributes();
            var valueMask             = default(SetWindowValuemask);

            attr.backing_store = 1;
            attr.bit_gravity   = Gravity.NorthWestGravity;
            attr.win_gravity   = Gravity.NorthWestGravity;
            valueMask         |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel
                                 | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore
                                 | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

            if (_popup)
            {
                attr.override_redirect = 1;
                valueMask |= SetWindowValuemask.OverrideRedirect;
            }

            XVisualInfo?visualInfo = null;

            // OpenGL seems to be do weird things to it's current window which breaks resize sometimes
            _useRenderWindow = glfeature != null;

            var glx = glfeature as GlxPlatformOpenGlInterface;

            if (glx != null)
            {
                visualInfo = *glx.Display.VisualInfo;
            }
            else if (glfeature == null)
            {
                visualInfo = _x11.TransparentVisualInfo;
            }

            var egl = glfeature as EglPlatformOpenGlInterface;

            var visual = IntPtr.Zero;
            var depth  = 24;

            if (visualInfo != null)
            {
                visual        = visualInfo.Value.visual;
                depth         = (int)visualInfo.Value.depth;
                attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0);
                valueMask    |= SetWindowValuemask.ColorMap;
            }

            int defaultWidth = 0, defaultHeight = 0;

            if (!_popup && Screen != null)
            {
                var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity)
                              .FirstOrDefault(m => m.Bounds.Contains(Position));

                if (monitor != null)
                {
                    // Emulate Window 7+'s default window size behavior.
                    defaultWidth  = (int)(monitor.WorkingArea.Width * 0.75d);
                    defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d);
                }
            }

            // check if the calculated size is zero then compensate to hardcoded resolution
            defaultWidth  = Math.Max(defaultWidth, 300);
            defaultHeight = Math.Max(defaultHeight, 200);

            _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, defaultWidth, defaultHeight, 0,
                                    depth,
                                    (int)CreateWindowArgs.InputOutput,
                                    visual,
                                    new UIntPtr((uint)valueMask), ref attr);

            if (_useRenderWindow)
            {
                _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, defaultWidth, defaultHeight, 0, depth,
                                              (int)CreateWindowArgs.InputOutput,
                                              visual,
                                              new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                                 SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);
            }
            else
            {
                _renderHandle = _handle;
            }

            Handle    = new PlatformHandle(_handle, "XID");
            _realSize = new PixelSize(defaultWidth, defaultHeight);
            platform.Windows[_handle] = OnEvent;
            XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
                                     | XEventMask.ResizeRedirectMask
                                     | XEventMask.PointerMotionHintMask;

            if (platform.XI2 != null)
            {
                ignoredMask |= platform.XI2.AddWindow(_handle, this);
            }
            var mask = new IntPtr(0xffffff ^ (int)ignoredMask);

            XSelectInput(_x11.Display, _handle, mask);
            var protocols = new[]
            {
                _x11.Atoms.WM_DELETE_WINDOW
            };

            XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length);
            XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
                            32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1);

            if (platform.Options.WmClass != null)
            {
                SetWmClass(platform.Options.WmClass);
            }

            var surfaces = new List <object>
            {
                new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle,
                                          depth, () => RenderScaling)
            };

            if (egl != null)
            {
                surfaces.Insert(0,
                                new EglGlPlatformSurface(egl,
                                                         new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
            }
            if (glx != null)
            {
                surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext,
                                                            new SurfaceInfo(this, _x11.Display, _handle, _renderHandle)));
            }

            Surfaces = surfaces.ToArray();
            UpdateMotifHints();
            UpdateSizeHints(null);

            _transparencyHelper = new TransparencyHelper(_x11, _handle, platform.Globals);
            _transparencyHelper.SetTransparencyRequest(WindowTransparencyLevel.None);

            CreateIC();

            XFlush(_x11.Display);
            if (_popup)
            {
                PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(popupParent, MoveResize));
            }
            if (platform.Options.UseDBusMenu)
            {
                NativeMenuExporter = DBusMenuExporter.TryCreateTopLevelNativeMenu(_handle);
            }
            NativeControlHost = new X11NativeControlHost(_platform, this);
            InitializeIme();
        }
示例#59
0
 /// <summary>
 /// Raises the <see cref="E:TwistedLogik.Ultraviolet.UI.Presentation.Input.Mouse.PreviewMouseWheel"/>
 /// attached event for the specified element.
 /// </summary>
 internal static void RaisePreviewMouseWheel(DependencyObject element, MouseDevice device, Double x, Double y, RoutedEventData data)
 {
     var evt = EventManager.GetInvocationDelegate<UpfMouseWheelEventHandler>(PreviewMouseWheelEvent);
     evt?.Invoke(element, device, x, y, data);
 }
示例#60
0
        public void OnUpdateFrame(FrameEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
        {
            if (fadingIn)
            {
                fadePercent -= (float)e.Time;
                if (fadePercent <= 0)
                {
                    fadingIn = false;
                }
            }

            if (fadingOut)
            {
                fadePercent += (float)e.Time;
                if (fadePercent >= 1)
                {
                    StateManager.PopState();
                    if (level + 1 > maxLevel)
                    {
                        StateManager.PushState(new MenuState("You escaped!", "\n\n\nPlay again?"));
                    }
                    else
                    {
                        StateManager.PushState(new GameState(level + 1));
                    }
                }
            }

            float time = (float)e.Time;
            bool  up = Keyboard[Key.W], left = Keyboard[Key.A], down = Keyboard[Key.S], right = Keyboard[Key.D];

            player.Update(time);

            Entity prevCollidedWith = lastCollidedWith;

            lastCollidedWith = null;

            Vector2 realPrevPos     = player.Position;

            if (up && left)
            {
                player.MoveUpLeft(time);
            }
            else if (up && right)
            {
                player.MoveUpRight(time);
            }
            else if (down && left)
            {
                player.MoveDownLeft(time);
            }
            else if (down && right)
            {
                player.MoveDownRight(time);
            }
            else if (up)
            {
                player.MoveUp(time);
            }
            else if (left)
            {
                player.MoveLeft(time);
            }
            else if (down)
            {
                player.MoveDown(time);
            }
            else if (right)
            {
                player.MoveRight(time);
            }
            else
            {
                lastCollidedWith = prevCollidedWith;                 //if no key was pressed, restore the old one. HACK
                player.moving    = false;
            }

            if (map.IsColliding(player.BoundingBox))
            {
                player.Position = realPrevPos;
            }

            foreach (var ent in entities)
            {
                if (ent is Pickaxe)
                {
                    ((Pickaxe)ent).AIUpdate(player);
                }

                if (ent is Goblin)
                {
                    ((Goblin)ent).AIUpdate(player);
                }
            }

            for (int i = entities.Count - 1; i >= 0; i--)
            {
                Entity ent = entities[i];

                ent.Update(time);
                if (map.IsColliding(ent.BoundingBox))
                {
                    ent.ResetPos();
                }

                if (PhysicsManager.IsColliding(player.BoundingBox, ent.BoundingBox))
                {
                    lastCollidedWith = ent;

                    if (ent is Generator)
                    {
                        player.Position = realPrevPos;
                    }
                    else if (ent is Lift)
                    {
                        if (((Lift)ent).enabled)
                        {
                            ((Lift)ent).source.Play();
                            fadingOut = true;
                        }
                    }
                    else if (ent is Pickaxe)
                    {
                        if (((Pickaxe)ent).active)
                        {
                            entities.Remove(ent);
                            player.health--;
                        }
                    }
                    else if (ent is Goblin)
                    {
                        entities.Remove(ent);
                        player.health -= 2;
                    }
                    else if (ent is Endgame)
                    {
                        fadingOut = true;
                    }
                }
            }

            if (Keyboard[Key.E] && lastCollidedWith != null)
            {
                if (lastCollidedWith is Generator)
                {
                    ((Generator)lastCollidedWith).Used = true;
                    player.drawShadow = false;
                    lift.Enable();
                }
            }

            camera.Position          = player.Position;
            AudioManager.ListenerPos = new Vector3(player.Position);

            if (generator != null && generator.Used)
            {
                for (int i = entities.Count - 1; i >= 0; i--)
                {
                    var ent = entities[i];
                    if (ent is Goblin)
                    {
                        entities.Remove(ent);
                    }
                    if (ent is Pickaxe)
                    {
                        ((Pickaxe)ent).active = false;
                    }
                }
            }

            if (player.health <= 0)
            {
                StateManager.PopState();
                StateManager.PushState(loseState);
            }
        }