| 36 | namespace oid::host { |
| 37 | |
| 38 | class GlfwHostBackend final : public HostBackend { |
| 39 | public: |
| 40 | // Monitor work area (screen coordinates, e.g. glfwGetMonitorWorkarea) |
| 41 | // used by window_visible_on() below. |
| 42 | struct MonitorRect { |
| 43 | int x; |
| 44 | int y; |
| 45 | int w; |
| 46 | int h; |
| 47 | }; |
| 48 | |
| 49 | ~GlfwHostBackend() override; |
| 50 | |
| 51 | bool initialize(const char* title, int width, int height) override; |
| 52 | void poll_events() override; |
| 53 | [[nodiscard]] bool should_close() const override; |
| 54 | [[nodiscard]] FramebufferSize framebuffer_size() const override; |
| 55 | void begin_frame() override; |
| 56 | void end_frame() override; |
| 57 | void shutdown() override; |
| 58 | |
| 59 | [[nodiscard]] GLFWwindow* window() const { |
| 60 | return window_; |
| 61 | } |
| 62 | |
| 63 | // Current window size/position in screen coordinates (glfwGetWindowSize |
| 64 | // / glfwGetWindowPos); {0, 0} when there is no window yet. |
| 65 | [[nodiscard]] std::pair<int, int> window_size() const; |
| 66 | [[nodiscard]] std::pair<int, int> window_position() const; |
| 67 | |
| 68 | // Moves the window (glfwSetWindowPos); no-op when there is no window. |
| 69 | void set_window_position(int x, int y); |
| 70 | |
| 71 | // Every connected monitor's work area (glfwGetMonitors + |
| 72 | // glfwGetMonitorWorkarea), for window_visible_on() below. Public: called |
| 73 | // by main_imgui at startup to decide whether a saved window position is |
| 74 | // still reachable, not just internally by this class. |
| 75 | [[nodiscard]] std::vector<MonitorRect> monitors() const; |
| 76 | |
| 77 | // Pure, testable: does the window rect (x, y, w, h) overlap any monitor |
| 78 | // work area? Used to discard a saved window position that would place |
| 79 | // the window fully off-screen (e.g. a since-unplugged monitor). |
| 80 | [[nodiscard]] static bool window_visible_on( |
| 81 | int x, int y, int w, int h, const std::vector<MonitorRect>& monitors); |
| 82 | |
| 83 | private: |
| 84 | GLFWwindow* window_{nullptr}; |
| 85 | }; |
| 86 | |
| 87 | } // namespace oid::host |
| 88 |
nothing calls this directly
no outgoing calls
no test coverage detected