private Cursor MapCursor(Cursors cursorToSet)
        {
            switch (cursorToSet)
            {
            case Cursors.Arrow:
                return(Glfw.CreateStandardCursor(CursorType.Arrow));

            case Cursors.Cross:
            case Cursors.Default:
                return(Glfw.CreateStandardCursor(CursorType.Arrow));

            case Cursors.Hand:
                return(Glfw.CreateStandardCursor(CursorType.Hand));

            case Cursors.Help:
                return(Glfw.CreateStandardCursor(CursorType.Arrow));

            case Cursors.HSplit:
                return(Glfw.CreateStandardCursor(CursorType.ResizeVertical));

            case Cursors.IBeam:
                return(Glfw.CreateStandardCursor(CursorType.Beam));

            case Cursors.No:
            case Cursors.NoMove2D:
            case Cursors.NoMoveHoriz:
            case Cursors.NoMoveVert:
            case Cursors.PanEast:
            case Cursors.PanNE:
            case Cursors.PanNorth:
            case Cursors.PanNW:
            case Cursors.PanSE:
            case Cursors.PanSouth:
            case Cursors.PanSW:
            case Cursors.PanWest:
            case Cursors.SizeAll:
            case Cursors.SizeNESW:
            case Cursors.SizeNS:
                return(Glfw.CreateStandardCursor(CursorType.ResizeVertical));

            case Cursors.SizeNWSE:
            case Cursors.SizeWE:
                return(Glfw.CreateStandardCursor(CursorType.ResizeHorizontal));

            case Cursors.UpArrow:
                return(Glfw.CreateStandardCursor(CursorType.Arrow));

            case Cursors.VSplit:
                return(Glfw.CreateStandardCursor(CursorType.ResizeHorizontal));

            case Cursors.WaitCursor:
                return(Glfw.CreateStandardCursor(CursorType.Arrow));
            }

            return(Glfw.CreateStandardCursor(CursorType.Arrow));
        }
Exemple #2
0
        static void Main()
        {
            Init();

            Glfw.Window window;
            var         starCursors  = new Glfw.Cursor[CURSOR_FRAME_COUNT];
            var         currentFrame = Glfw.Cursor.None;

            Gl.Initialize();

            if (!Glfw.Init())
            {
                Environment.Exit(1);
            }

            for (int i = 0; i < CURSOR_FRAME_COUNT; i++)
            {
                starCursors[i] = CreateCursorFrame(i / (float)CURSOR_FRAME_COUNT);
                if (!starCursors[i])
                {
                    Glfw.Terminate();
                    Environment.Exit(1);
                }
            }

            Glfw.CursorType[] shapes =
            {
                Glfw.CursorType.Arrow,
                Glfw.CursorType.Beam,
                Glfw.CursorType.Crosshair,
                Glfw.CursorType.Hand,
                Glfw.CursorType.ResizeX,
                Glfw.CursorType.ResizeY
            };

            standardCursors = new Glfw.Cursor[6];

            for (int i = 0; i < standardCursors.Length; i++)
            {
                standardCursors[i] = Glfw.CreateStandardCursor(shapes[i]);

                if (!standardCursors[i])
                {
                    Glfw.Terminate();
                    Environment.Exit(1);
                }
            }

            window = Glfw.CreateWindow(640, 480, "Cursor Test");

            if (!window)
            {
                Glfw.Terminate();
                Environment.Exit(1);
            }

            Glfw.MakeContextCurrent(window);

            Glfw.GetCursorPos(window, out cursorX, out cursorY);
            Log("Cursor position: {0} {1}", cursorX, cursorY);

            Glfw.SetCursorPosCallback(window, CursorPositionCallback);
            Glfw.SetKeyCallback(window, KeyCallback);

            while (!Glfw.WindowShouldClose(window))
            {
                Gl.Clear(ClearBufferMask.ColorBufferBit);

                if (trackCursor)
                {
                    int   wnd_width, wnd_height, fb_width, fb_height;
                    float scale;

                    Glfw.GetWindowSize(window, out wnd_width, out wnd_height);
                    Glfw.GetFramebufferSize(window, out fb_width, out fb_height);

                    scale = (float)fb_width / (float)wnd_width;

                    Gl.Viewport(0, 0, fb_width, fb_height);

                    Gl.MatrixMode(MatrixMode.Projection);
                    Gl.LoadIdentity();
                    Gl.Ortho(0f, fb_width, 0f, fb_height, 0f, 1f);

                    Gl.Begin(PrimitiveType.Lines);
                    Gl.Vertex2(0f, (float)(fb_height - cursorY * scale));
                    Gl.Vertex2((float)fb_width, (float)(fb_height - cursorY * scale));
                    Gl.Vertex2((float)cursorX * scale, 0f);
                    Gl.Vertex2((float)cursorX * scale, (float)fb_height);
                    Gl.End();
                }

                Glfw.SwapBuffers(window);

                if (animateCursor)
                {
                    var i = (int)(Glfw.GetTime() * 30.0) % CURSOR_FRAME_COUNT;

                    if (currentFrame != starCursors[i])
                    {
                        Glfw.SetCursor(window, starCursors[i]);
                        currentFrame = starCursors[i];
                    }
                }
                else
                {
                    currentFrame = Glfw.Cursor.None;
                }

                if (waitEvents)
                {
                    if (animateCursor)
                    {
                        Glfw.WaitEventsTimeout(1.0 / 30.0);
                    }
                    else
                    {
                        Glfw.WaitEvents();
                    }
                }
                else
                {
                    Glfw.PollEvents();
                }
            }

            Glfw.DestroyWindow(window);

            for (int i = 0; i < CURSOR_FRAME_COUNT; i++)
            {
                Glfw.DestroyCursor(starCursors[i]);
            }

            for (int i = 0; i < standardCursors.Length; i++)
            {
                Glfw.DestroyCursor(standardCursors[i]);
            }

            Glfw.Terminate();
        }
Exemple #3
0
        static bool ImGui_ImplGlfw_Init(Window window, bool installCallbacks)
        {
            windowHandle = window;
            time         = 0.0f;

            ImGuiIOPtr io = ImGui.GetIO();

            io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors;
            io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos;
            //io.BackendPlatformName = "imgui_impl_glfw";

            io.KeyMap[(int)ImGuiKey.Tab]         = (int)Keys.Tab;
            io.KeyMap[(int)ImGuiKey.LeftArrow]   = (int)Keys.Left;
            io.KeyMap[(int)ImGuiKey.RightArrow]  = (int)Keys.Right;
            io.KeyMap[(int)ImGuiKey.UpArrow]     = (int)Keys.Up;
            io.KeyMap[(int)ImGuiKey.DownArrow]   = (int)Keys.Down;
            io.KeyMap[(int)ImGuiKey.PageUp]      = (int)Keys.PageUp;
            io.KeyMap[(int)ImGuiKey.PageDown]    = (int)Keys.PageDown;
            io.KeyMap[(int)ImGuiKey.Home]        = (int)Keys.Home;
            io.KeyMap[(int)ImGuiKey.End]         = (int)Keys.End;
            io.KeyMap[(int)ImGuiKey.Insert]      = (int)Keys.Insert;
            io.KeyMap[(int)ImGuiKey.Delete]      = (int)Keys.Delete;
            io.KeyMap[(int)ImGuiKey.Backspace]   = (int)Keys.Backspace;
            io.KeyMap[(int)ImGuiKey.Space]       = (int)Keys.Space;
            io.KeyMap[(int)ImGuiKey.Enter]       = (int)Keys.Enter;
            io.KeyMap[(int)ImGuiKey.Escape]      = (int)Keys.Escape;
            io.KeyMap[(int)ImGuiKey.KeyPadEnter] = (int)Keys.NumpadEnter;
            io.KeyMap[(int)ImGuiKey.A]           = (int)Keys.A;
            io.KeyMap[(int)ImGuiKey.C]           = (int)Keys.C;
            io.KeyMap[(int)ImGuiKey.V]           = (int)Keys.V;
            io.KeyMap[(int)ImGuiKey.X]           = (int)Keys.X;
            io.KeyMap[(int)ImGuiKey.Y]           = (int)Keys.Y;
            io.KeyMap[(int)ImGuiKey.Z]           = (int)Keys.Z;

//            io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
//            io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
//            io.ClipboardUserData = g_Window;
//#if defined(_WIN32)
//            io.ImeWindowHandle = (void*)glfwGetWin32Window(g_Window);
//#endif

            ErrorCallback prev_error_callback = Glfw.SetErrorCallback(null);

            mouseCursors[(int)ImGuiMouseCursor.Arrow]     = Glfw.CreateStandardCursor(CursorType.Arrow);
            mouseCursors[(int)ImGuiMouseCursor.TextInput] = Glfw.CreateStandardCursor(CursorType.Beam);
            mouseCursors[(int)ImGuiMouseCursor.ResizeNS]  = Glfw.CreateStandardCursor(CursorType.ResizeVertical);
            mouseCursors[(int)ImGuiMouseCursor.ResizeEW]  = Glfw.CreateStandardCursor(CursorType.ResizeHorizontal);
            mouseCursors[(int)ImGuiMouseCursor.Hand]      = Glfw.CreateStandardCursor(CursorType.Hand);

            // if GLFW_HAS_NEW_CURSORS
            //mouseCursors[(int)ImGuiMouseCursor.ResizeAll] = GLFW.Glfw.CreateStandardCursor(GLFW.CursorType. GLFW_RESIZE_ALL_CURSOR);
            //mouseCursors[(int)ImGuiMouseCursor.ResizeNESW] = GLFW.Glfw.CreateStandardCursor(GLFW.CursorType. GLFW_RESIZE_NESW_CURSOR);
            //mouseCursors[(int)ImGuiMouseCursor.ResizeNWSE] = GLFW.Glfw.CreateStandardCursor(GLFW.CursorType. GLFW_RESIZE_NWSE_CURSOR);
            //mouseCursors[(int)ImGuiMouseCursor.NotAllowed] = GLFW.Glfw.CreateStandardCursor(GLFW.CursorType. GLFW_NOT_ALLOWED_CURSOR);

            mouseCursors[(int)ImGuiMouseCursor.ResizeAll]  = Glfw.CreateStandardCursor(CursorType.Arrow);
            mouseCursors[(int)ImGuiMouseCursor.ResizeNESW] = Glfw.CreateStandardCursor(CursorType.Arrow);
            mouseCursors[(int)ImGuiMouseCursor.ResizeNWSE] = Glfw.CreateStandardCursor(CursorType.Arrow);
            mouseCursors[(int)ImGuiMouseCursor.NotAllowed] = Glfw.CreateStandardCursor(CursorType.Arrow);

            Glfw.SetErrorCallback(prev_error_callback);

            prevUserCallbackMousebutton = null;
            prevUserCallbackScroll      = null;
            prevUserCallbackKey         = null;
            prevUserCallbackChar        = null;
            if (installCallbacks)
            {
                installedCallbacks          = true;
                prevUserCallbackMousebutton = Glfw.SetMouseButtonCallback(windowHandle, mousebuttonCallbackHolder = ImGui_ImplGlfw_MouseButtonCallback);
                prevUserCallbackScroll      = Glfw.SetScrollCallback(windowHandle, scrollCallbackHolder = ImGui_ImplGlfw_ScrollCallback);
                prevUserCallbackKey         = Glfw.SetKeyCallback(windowHandle, keyCallbackHolder = ImGui_ImplGlfw_KeyCallback);
                prevUserCallbackChar        = Glfw.SetCharCallback(windowHandle, charCallbackHolder = ImGui_ImplGlfw_CharCallback);
            }

            return(true);
        }
Exemple #4
0
 public void SetCursor(CursorType cursorType)
 {
     Glfw.SetCursor(this.window.nativeWindow, Glfw.CreateStandardCursor(CursorType.Hand));
 }