Пример #1
0
        static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
        {
            // Update buttons
            ImGuiIOPtr io = ImGui.GetIO();

            for (int i = 0; i < io.MouseDown.Count; i++)
            {
                // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
                io.MouseDown[i]     = mouseJustPressed[i] || Glfw.GetMouseButton(windowHandle, (MouseButton)i) != 0;
                mouseJustPressed[i] = false;
            }

            // Update mouse position
            Vector2 mouse_pos_backup = io.MousePos;

            io.MousePos = new Vector2(-float.MaxValue, -float.MaxValue);

            //const bool focused = true; // Emscripten

            bool focused = Glfw.GetWindowAttribute(windowHandle, WindowAttribute.Focused);

            if (focused)
            {
                if (io.WantSetMousePos)
                {
                    Glfw.SetCursorPosition(windowHandle, (double)mouse_pos_backup.X, (double)mouse_pos_backup.Y);
                }
                else
                {
                    double mouse_x, mouse_y;
                    Glfw.GetCursorPosition(windowHandle, out mouse_x, out mouse_y);
                    io.MousePos = new Vector2((float)mouse_x, (float)mouse_y);
                }
            }
        }
Пример #2
0
        public void update()
        {
            float ratio = 1.0f;

            if (Glfw.GetKey(_window, Keys.LeftControl) == InputState.Press)
            {
                ratio = 0.1f;
            }

            if (Glfw.GetKey(_window, Keys.LeftShift) == InputState.Press)
            {
                ratio = 2f;
            }

            if (Glfw.GetKey(_window, Keys.W) == InputState.Press)
            {
                position += orientation * 0.05f * ratio;
            }

            if (Glfw.GetKey(_window, Keys.S) == InputState.Press)
            {
                position -= orientation * 0.05f * ratio;
            }

            if (Glfw.GetKey(_window, Keys.A) == InputState.Press)
            {
                position += _sideOrientation * 0.05f * ratio;
            }

            if (Glfw.GetKey(_window, Keys.D) == InputState.Press)
            {
                position -= _sideOrientation * 0.05f * ratio;
            }

            dvec2 mouseOffset = new dvec2();

            Glfw.GetCursorPosition(_window, out mouseOffset.x, out mouseOffset.y);
            mouseOffset -= _winCenter;

            if (Math.Abs(mouseOffset.x + mouseOffset.y) < 0.01f)
            {
                return;
            }

            rotate((float)-mouseOffset.y / 10.0f, (float)-mouseOffset.x / 10.0f);
            Glfw.SetCursorPosition(_window, _winCenter.x, _winCenter.y);
        }
Пример #3
0
        public static void AjustCurve(ref BezierCurve curve, int surfacehieght)
        {
            InputState a = Glfw.GetMouseButton(window, MouseButton.Left);

            switch (a)
            {
            case InputState.Press:

                double x, y;
                Glfw.GetCursorPosition(window, out x, out y);
                y = -y + surfacehieght;

                if (!LeftMouseIsHeld)
                {
                    holdingpiece = findpoint(new SKPoint((float)x, (float)y), ref curve);
                }


                if (holdingpiece)
                {
                    if (isTouch)
                    {
                        selected.touch = new SKPoint((float)x, (float)y);
                    }
                    else
                    {
                        selected.intersect = new SKPoint((float)x, (float)y);
                    }
                }

                //Console.WriteLine(x.ToString()+" "+y.ToString()+" "+ holdingpiece.ToString()+" "+LeftMouseIsHeld+" "+curve.Count);
                LeftMouseIsHeld = true;
                break;

            case InputState.Release:
                holdingpiece    = false;
                LeftMouseIsHeld = false;
                break;
            }
        }