Exemple #1
0
    private static void DestroyWindow(ImGuiViewport *viewport)
    {
        ViewportData *viewportData = (ViewportData *)viewport->PlatformUserData;

        if (viewportData is not null)
        {
            if (viewportData->WindowOwned)
            {
                PlatformBackend backend = GetPlatformBackend();

                // Release any keys that were pressed in the window being destroyed and are still held down,
                // because we will not receive any release events after window is destroyed.
                for (int i = 0; i < backend.KeyOwnerWindows.Length; i++)
                {
                    if (backend.KeyOwnerWindows[i] == viewportData->Window)
                    {
                        KeyCallbackManaged(viewportData->Window, (Keys)i, 0, InputAction.Release, 0);
                    }                                                                                 // Later params are only used for main viewport, on which this function is never called.
                }

                GLFW.DestroyWindow(viewportData->Window);
            }

            viewportData->Window = null;
            ViewportData.Free(viewportData);
        }

        viewport->PlatformUserData = viewport->PlatformHandle = null;
    }
Exemple #2
0
    private static void CreateWindow(ImGuiViewport *viewport)
    {
        PlatformBackend backend      = GetPlatformBackend();
        ViewportData *  viewportData = ViewportData.Allocate();

        viewport->PlatformUserData = viewportData;

        GLFW.WindowHint(WindowHintBool.Visible, false);
        GLFW.WindowHint(WindowHintBool.Focused, false);
        GLFW.WindowHint(WindowHintBool.FocusOnShow, false);
        GLFW.WindowHint(WindowHintBool.Decorated, !viewport->Flags.HasFlag(ImGuiViewportFlags.NoDecoration));
        GLFW.WindowHint(WindowHintBool.Floating, viewport->Flags.HasFlag(ImGuiViewportFlags.TopMost));

        *viewportData = new ViewportData()
        {
            Window      = GLFW.CreateWindow((int)viewport->Size.X, (int)viewport->Size.Y, "No Title Yet", null, backend.Window),
            WindowOwned = true,
        };

        viewport->PlatformHandle = viewportData->Window;

        if (OperatingSystem.IsWindows())
        {
            viewport->PlatformHandleRaw = (void *)GLFW.GetWin32Window(viewportData->Window);
        }

        GLFW.SetWindowPos(viewportData->Window, (int)viewport->Pos.X, (int)viewport->Pos.Y);

        // Install GLFW callbacks for secondary viewports
        GlfwNative.glfwSetWindowFocusCallback(viewportData->Window, &WindowFocusCallback);
        GlfwNative.glfwSetCursorEnterCallback(viewportData->Window, &CursorEnterCallback);
        GlfwNative.glfwSetCursorPosCallback(viewportData->Window, &CursorPosCallback);
        GlfwNative.glfwSetMouseButtonCallback(viewportData->Window, &MouseButtonCallback);
        GlfwNative.glfwSetScrollCallback(viewportData->Window, &ScrollCallback);
        GlfwNative.glfwSetKeyCallback(viewportData->Window, &KeyCallback);
        GlfwNative.glfwSetCharCallback(viewportData->Window, &CharCallback);
        GlfwNative.glfwSetWindowCloseCallback(viewportData->Window, &WindowCloseCallback);
        GlfwNative.glfwSetWindowPosCallback(viewportData->Window, &WindowPosCallback);
        GlfwNative.glfwSetWindowSizeCallback(viewportData->Window, &WindowSizeCallback);
        GLFW.MakeContextCurrent(viewportData->Window);
        GLFW.SwapInterval(0);
    }