diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a3e277..bcfa43c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.11.4) +set(BLT_GRAPHICS_VERSION 0.11.5) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/examples/basic/basic.cpp b/examples/basic/basic.cpp index 5d6b2d3..b022a7d 100644 --- a/examples/basic/basic.cpp +++ b/examples/basic/basic.cpp @@ -25,7 +25,7 @@ blt::gfx::resource_manager resources; blt::gfx::batch_renderer_2d renderer_2d(resources); blt::gfx::first_person_camera camera; -void init(const blt::gfx::window_context& context) +void init(const blt::gfx::window_data&) { using namespace blt::gfx; @@ -35,9 +35,9 @@ void init(const blt::gfx::window_context& context) renderer_2d.create(); } -void update(const blt::gfx::window_context& context, std::int32_t width, std::int32_t height) +void update(const blt::gfx::window_data& data) { - global_matrices.update_perspectives(width, height, 90, 0.1, 2000); + global_matrices.update_perspectives(data.width, data.height, 90, 0.1, 2000); camera.update(); camera.update_view(global_matrices); diff --git a/include/blt/gfx/window.h b/include/blt/gfx/window.h index fdf2b12..66c1765 100644 --- a/include/blt/gfx/window.h +++ b/include/blt/gfx/window.h @@ -28,50 +28,63 @@ namespace blt::gfx struct window_data { - std::string title; - std::int32_t width; - std::int32_t height; - std::function init; - std::function update; - - window_context context{}; - std::int32_t sync_interval = 0; - - window_data(std::string title, std::function init, - std::function update, std::int32_t width = 640, - std::int32_t height = 480): - title(std::move(title)), width(width), height(height), init(std::move(init)), update(std::move(update)) - {} - - window_data& setHeight(int32_t new_height) - { - window_data::height = new_height; - return *this; - } - - window_data& setWidth(int32_t new_width) - { - window_data::width = new_width; - return *this; - } - - window_data& setTitle(const std::string& title_str) - { - window_data::title = title_str; - return *this; - } - - window_data& setContext(const window_context& ctx) - { - context = ctx; - return *this; - } - - window_data& setSyncInterval(std::int32_t sync) - { - sync_interval = sync; - return *this; - } + private: + std::function init; + std::function update; + public: + std::string title; + std::int32_t width; + std::int32_t height; + + window_context context{}; + std::int32_t sync_interval = 0; + + window_data(std::string title, std::function init, std::function update, + std::int32_t width = 640, std::int32_t height = 480): + title(std::move(title)), width(width), height(height), init(std::move(init)), update(std::move(update)) + {} + + inline void call_init() const + { + init(*this); + } + + inline void call_update() const + { + update(*this); + } + + window_data& setWindowSize(int32_t new_width, int32_t new_height); + + window_data& setHeight(int32_t new_height) + { + setWindowSize(width, new_height); + return *this; + } + + window_data& setWidth(int32_t new_width) + { + setWindowSize(new_width, height); + return *this; + } + + window_data& setTitle(const std::string& title_str) + { + window_data::title = title_str; + return *this; + } + + window_data& setContext(const window_context& ctx) + { + context = ctx; + return *this; + } + + window_data& setSyncInterval(std::int32_t sync) + { + sync_interval = sync; + return *this; + } }; void init(window_data data); diff --git a/src/blt/gfx/window.cpp b/src/blt/gfx/window.cpp index 623b46f..c93b9df 100644 --- a/src/blt/gfx/window.cpp +++ b/src/blt/gfx/window.cpp @@ -164,7 +164,7 @@ namespace blt::gfx ImGui::NewFrame(); /* -- Call user update function -- */ - data.update(data.context, window_state.width, window_state.height); + data.call_update(); /* -- Render the ImGUI frame -- */ ImGui::Render(); @@ -249,7 +249,7 @@ namespace blt::gfx #endif /* -- Call User Provided post-window-init function -- */ - data.init(data.context); + data.call_init(); #ifdef __EMSCRIPTEN__ /* @@ -389,4 +389,12 @@ namespace blt::gfx { return window_state.inputManager.key_pressed; } + + window_data& window_data::setWindowSize(int32_t new_width, int32_t new_height) + { + width = new_width; + height = new_height; + glfwSetWindowSize(window_state.window, width, height); + return *this; + } }