Ejemplo n.º 1
0
        static public void ImGui_ImplGlfw_Shutdown()
        {
            if (installedCallbacks)
            {
                Glfw.SetMouseButtonCallback(windowHandle, prevUserCallbackMousebutton);
                Glfw.SetScrollCallback(windowHandle, prevUserCallbackScroll);
                Glfw.SetKeyCallback(windowHandle, prevUserCallbackKey);
                Glfw.SetCharCallback(windowHandle, prevUserCallbackChar);
                installedCallbacks = false;
            }

            for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor.COUNT; cursor_n++)
            {
                Glfw.DestroyCursor(mouseCursors[(int)cursor_n]);
                mouseCursors[(int)cursor_n] = new Cursor(); // idk if this clearing is nessesary
            }
        }
Ejemplo n.º 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();
        }