Exemplo n.º 1
0
        private void OnMouseMove(float scaleX, float scaleY)
        {
            int x1, y1, x2, y2;

            GetBorders(out x1, out y1, out x2, out y2);

            bool mouseMove =
                (_mouseX != (_mouseX = (int)((Mouse.X - x1) / scaleX))) |
                (_mouseY != (_mouseY = (int)((Mouse.Y - y1) / scaleY)));

            if (mouseMove)
            {
                MouseButton  buttons = MouseButton.None;
                TkMouseState mouse   = Mouse.GetState();

                if (mouse.IsButtonDown(TkMouseButton.Left))
                {
                    buttons |= MouseButton.Left;
                }
                if (mouse.IsButtonDown(TkMouseButton.Right))
                {
                    buttons |= MouseButton.Right;
                }
                if (buttons != MouseButton.None)
                {
                    TopScreen?.MouseDrag(new ScreenEventArgs(_mouseX, _mouseY, buttons));
                }

                TopScreen?.MouseMove(new ScreenEventArgs(_mouseX, _mouseY, buttons));
            }
        }
Exemplo n.º 2
0
 void update_mouseButtonStates(ref MouseState e, OpenTK.Input.MouseState otk_e)
 {
     for (int i = 0; i < MouseState.MaxButtons; i++)
     {
         if (otk_e.IsButtonDown((OpenTK.Input.MouseButton)i))
         {
             e.EnableBit(i);
         }
     }
 }
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            OpenTK.Input.MouseState mouseState = OpenTK.Input.Mouse.GetState();

            if (mouseState.IsButtonDown(OpenTK.Input.MouseButton.Left))
            {
                xPosition -= e.Time;
            }
            if (mouseState.IsButtonDown(OpenTK.Input.MouseButton.Right))
            {
                xPosition += e.Time;
            }

            GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Matrix4 projMatrix = Matrix4.CreateOrthographicOffCenter(0, DEFAULT_WIDTH, 0, DEFAULT_HEIGHT, -1.0f, 1.0f);
            Matrix4 viewMatrix = Matrix4.Identity;

            Matrix4.CreateRotationZ((float)RotationAngle, out Matrix4 tempMatrix);
            Matrix4.CreateTranslation((float)xPosition * 200, -50.0f, 0.0f, out Matrix4 tempMatrix2);

            foreach (var obj in GameObjects)
            {
                Matrix4 mvp = tempMatrix2 * tempMatrix * obj.ModelMatrix * viewMatrix * projMatrix;

                GL.UseProgram(MainShaderProgram.ProgramId);

                GlCustomUtil.Bind3dObject(obj);

                GL.UniformMatrix4(MainShaderProgram.MatrixShaderLocation, false, ref mvp);

                GL.DrawElements(PrimitiveType.Triangles, obj.Indices.Length, DrawElementsType.UnsignedInt, 0);
                var x = GL.GetError();
            }

            SwapBuffers();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets a value indicating whether the specified mouse button is pressed on the current frame..
 /// </summary>
 /// <param name="button">The mouse button to check.</param>
 /// <returns><code>true</code> if pressed, otherwise false.</returns>
 public bool IsButtonDown(Mouse.Button button)
 {
     return(_state.IsButtonDown((OpenTK.Input.MouseButton)button));
 }
Exemplo n.º 5
0
        public static void CheckEvents()
        {
            SakuraGameWindow.ProcessEvents();


            bool __isWinFocused = SakuraGameWindow.getFocused();

            OpenTK.Input.KeyboardState keyboard = OpenTK.Input.Keyboard.GetState();
            GamePadData gamePadData             = GamePad.__gamePadData;

            gamePadData.ButtonsPrev = gamePadData.Buttons;
            gamePadData.ButtonsDown = 0;
            gamePadData.Buttons     = 0;
            gamePadData.ButtonsUp   = 0;

            if (__isWinFocused)
            {
                if (keyboard.IsKeyDown(OpenTK.Input.Key.Escape))
                {
                    System.Environment.Exit(0);
                }
                //
                if (keyboard.IsKeyDown(OpenTK.Input.Key.Left))
                {
                    if (!__isKeyLeftDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Left;
                    }
                    __isKeyLeftDown      = true;
                    gamePadData.Buttons |= GamePadButtons.Left;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.Right))
                {
                    if (!__isKeyRightDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Right;
                    }
                    __isKeyRightDown     = true;
                    gamePadData.Buttons |= GamePadButtons.Right;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.Up))
                {
                    if (!__isKeyUpDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Up;
                    }
                    __isKeyUpDown        = true;
                    gamePadData.Buttons |= GamePadButtons.Up;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.Down))
                {
                    if (!__isKeyDownDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Down;
                    }
                    __isKeyDownDown      = true;
                    gamePadData.Buttons |= GamePadButtons.Down;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.A))
                {
                    if (!__isKeyADown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Square;
                    }
                    __isKeyADown         = true;
                    gamePadData.Buttons |= GamePadButtons.Square;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.W))
                {
                    if (!__isKeyWDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Triangle;
                    }
                    __isKeyWDown         = true;
                    gamePadData.Buttons |= GamePadButtons.Triangle;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.D))
                {
                    if (!__isKeyDDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Circle;
                        gamePadData.ButtonsDown |= GamePadButtons.Back;
                    }
                    __isKeyDDown         = true;
                    gamePadData.Buttons |= GamePadButtons.Circle;
                    gamePadData.Buttons |= GamePadButtons.Back;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.S))
                {
                    if (!__isKeySDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Cross;
                        gamePadData.ButtonsDown |= GamePadButtons.Enter;
                    }
                    __isKeySDown         = true;
                    gamePadData.Buttons |= GamePadButtons.Cross;
                    gamePadData.Buttons |= GamePadButtons.Enter;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.X))
                {
                    if (!__isKeyXDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Start;
                    }
                    __isKeyXDown         = true;
                    gamePadData.Buttons |= GamePadButtons.Start;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.Z))
                {
                    if (!__isKeyZDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.Select;
                    }
                    __isKeyZDown         = true;
                    gamePadData.Buttons |= GamePadButtons.Select;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.Q))
                {
                    if (!__isKeyQDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.L;
                    }
                    __isKeyQDown         = true;
                    gamePadData.Buttons |= GamePadButtons.L;
                }
                if (keyboard.IsKeyDown(OpenTK.Input.Key.E))
                {
                    if (!__isKeyEDown)
                    {
                        gamePadData.ButtonsDown |= GamePadButtons.R;
                    }
                    __isKeyEDown         = true;
                    gamePadData.Buttons |= GamePadButtons.R;
                }



                if (keyboard.IsKeyUp(OpenTK.Input.Key.Left))
                {
                    if (__isKeyLeftDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Left;
                    }
                    __isKeyLeftDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.Right))
                {
                    if (__isKeyRightDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Right;
                    }
                    __isKeyRightDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.Up))
                {
                    if (__isKeyUpDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Up;
                    }
                    __isKeyUpDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.Down))
                {
                    if (__isKeyDownDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Down;
                    }
                    __isKeyDownDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.A))
                {
                    if (__isKeyADown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Square;
                    }
                    __isKeyADown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.W))
                {
                    if (__isKeyWDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Triangle;
                    }
                    __isKeyWDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.D))
                {
                    if (__isKeyDDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Circle;
                        gamePadData.ButtonsUp |= GamePadButtons.Back;
                    }
                    __isKeyDDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.S))
                {
                    if (__isKeySDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Cross;
                        gamePadData.ButtonsUp |= GamePadButtons.Enter;
                    }
                    __isKeySDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.X))
                {
                    if (__isKeyXDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Start;
                    }
                    __isKeyXDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.Z))
                {
                    if (__isKeyZDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.Select;
                    }
                    __isKeyZDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.Q))
                {
                    if (__isKeyQDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.L;
                    }
                    __isKeyQDown = false;
                }
                if (keyboard.IsKeyUp(OpenTK.Input.Key.E))
                {
                    if (__isKeyEDown)
                    {
                        gamePadData.ButtonsUp |= GamePadButtons.R;
                    }
                    __isKeyEDown = false;
                }
            }
            else
            {
                __isKeyLeftDown  = false;
                __isKeyRightDown = false;
                __isKeyUpDown    = false;
                __isKeyDownDown  = false;
                __isKeyADown     = false;
                __isKeyWDown     = false;
                __isKeyDDown     = false;
                __isKeySDown     = false;
                __isKeyXDown     = false;
                __isKeyZDown     = false;
                __isKeyQDown     = false;
                __isKeyEDown     = false;
            }


            Touch.__data.Clear();
            if (__isWinFocused)
            {
                //OpenTK.Input.MouseState mouse = OpenTK.Input.Mouse.GetState();
                OpenTK.Input.MouseState mouse = OpenTK.Input.Mouse.GetCursorState();
                OpenTK.Point            pt    = SakuraGameWindow.PointToClient(new OpenTK.Point(mouse.X, mouse.Y));
                float winW = SakuraGameWindow.getWidth();
                float winH = SakuraGameWindow.getHeight();
                if (mouse.IsButtonUp(OpenTK.Input.MouseButton.Left))
                {
                    if (__isMouseLeftDown == true)
                    {
                        TouchData touchData = new TouchData();
                        touchData.ID     = 0;
                        touchData.Status = TouchStatus.Up;
                        touchData.X      = (winW > 0 ? (float)pt.X / winW : 0) - 0.5f;
                        touchData.Y      = (winH > 0 ? (float)pt.Y / winH : 0) - 0.5f;
                        Touch.__data.Add(touchData);
                        //Debug.WriteLine("down:" + pt.X + "," + pt.Y);
                    }
                    __isMouseLeftDown = false;
                }
                //OpenTK.WindowState wState = MyGameWindow.getWindowState();
                //wState != OpenTK.WindowState.Minimized
                if (mouse.IsButtonDown(OpenTK.Input.MouseButton.Left))
                {
                    if (__isMouseLeftDown == false)
                    {
                        TouchData touchData = new TouchData();
                        touchData.ID     = 0;
                        touchData.Status = TouchStatus.Down;
                        touchData.X      = (winW > 0 ? (float)pt.X / winW : 0) - 0.5f;
                        touchData.Y      = (winH > 0 ? (float)pt.Y / winH : 0) - 0.5f;
                        Touch.__data.Add(touchData);
                    }
                    else
                    {
                        TouchData touchData = new TouchData();
                        touchData.ID     = 0;
                        touchData.Status = TouchStatus.Move;
                        touchData.X      = (winW > 0 ? (float)pt.X / winW : 0) - 0.5f;
                        touchData.Y      = (winH > 0 ? (float)pt.Y / winH : 0) - 0.5f;
                        Touch.__data.Add(touchData);
                    }
                    __isMouseLeftDown = true;
                }
            }
            else
            {
                __isMouseLeftDown = false;
            }

#if false
            double delta = __timer.Elapsed.TotalMilliseconds;
            double frame = 1000.0 / 24.0;
            if (delta < frame)
            {
                int free = (int)(frame - delta);
                Thread.Sleep(free);
                //Debug.WriteLine("Sleep: " + free);
            }
            __timer.Restart();
#endif
        }