Program Listing for File window.hpp

Return to documentation for file (inexor/vulkan-renderer/wrapper/windows/window.hpp)

#pragma once

#include <GLFW/glfw3.h>

#include <array>
#include <cstdint>
#include <string>

namespace inexor::vulkan_renderer::wrapper::windows {

enum class Mode { WINDOWED, FULLSCREEN, WINDOWED_FULLSCREEN };

class Window {
private:
    std::uint32_t m_width;
    std::uint32_t m_height;
    Mode m_mode;
    GLFWwindow *m_window{nullptr};

public:
    Window(const std::string &title, std::uint32_t width, std::uint32_t height, bool visible, bool resizable,
           Mode mode);

    ~Window();

    [[nodiscard]] std::array<int, 2> get_framebuffer_size() const {
        int width = 0;
        int height = 0;
        glfwGetFramebufferSize(m_window, &width, &height);
        return {width, height};
    }

    [[nodiscard]] std::uint32_t height() const {
        return m_height;
    }

    [[nodiscard]] Mode mode() const {
        return m_mode;
    }

    static void poll();

    void set_cursor_position_callback(GLFWcursorposfun cursor_pos_callback);

    void set_mouse_button_callback(GLFWmousebuttonfun mouse_button_callback);

    void set_mouse_scroll_callback(GLFWscrollfun mouse_scroll_callback);

    void set_keyboard_button_callback(GLFWkeyfun keyboard_button_callback);

    void set_resize_callback(GLFWframebuffersizefun frame_buffer_resize_callback);

    void set_title(const std::string &title);

    // @note Since GLFW is a C-style API, we can't use a class method as callback for window resize.
    void set_user_ptr(void *user_ptr);

    bool should_close();

    void show();

    [[nodiscard]] std::uint32_t width() const {
        return m_width;
    }

    [[nodiscard]] auto window() const {
        return m_window;
    }

    void wait_for_focus();
};

} // namespace inexor::vulkan_renderer::wrapper::windows