From ebcdbeb172bc8874b7898a01acad29560ad5d068 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Sat, 5 Apr 2025 21:07:51 -0400 Subject: [PATCH] graphics --- CMakeLists.txt | 2 +- include/blt/gfx/renderer/batch_2d_renderer.h | 41 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76b31e0..9540d7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.25) include(FetchContent) -set(BLT_GRAPHICS_VERSION 2.0.8) +set(BLT_GRAPHICS_VERSION 2.0.9) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/renderer/batch_2d_renderer.h b/include/blt/gfx/renderer/batch_2d_renderer.h index 48648ef..9b752d8 100644 --- a/include/blt/gfx/renderer/batch_2d_renderer.h +++ b/include/blt/gfx/renderer/batch_2d_renderer.h @@ -32,11 +32,29 @@ namespace blt::gfx { + enum class anchor_t + { + TOP_LEFT, + TOP_RIGHT, + BOTTOM_LEFT, + BOTTOM_RIGHT, + CENTER, }; + struct rectangle2d_t { vec2f pos, size; f32 rotation = 0; + rectangle2d_t(const anchor_t anchor, const f32 x, const f32 y, const f32 width, const f32 height): pos(x, y), size(width, height) + { + update_based_on_anchor(anchor); + } + + rectangle2d_t(const anchor_t anchor, const vec2f pos, const vec2f size): pos(pos), size(size) + { + update_based_on_anchor(anchor); + } + rectangle2d_t(const f32 x, const f32 y, const f32 width, const f32 height, const f32 rotation): pos(x, y), size(width, height), rotation(rotation) {} @@ -49,6 +67,29 @@ namespace blt::gfx rectangle2d_t(const vec2f pos, const vec2f size): pos(pos), size(size) {} + + void update_based_on_anchor(const anchor_t anchor) + { + switch (anchor) + { + case anchor_t::TOP_LEFT: + pos += vec2f(size.x() / 2.0f, -size.y() / 2.0f); + break; + case anchor_t::TOP_RIGHT: + pos += vec2f(-size.x() / 2.0f, -size.y() / 2.0f); + break; + case anchor_t::BOTTOM_LEFT: + // size = vec2f(size.x() / 2.0f, size.y() / 2.0f); + pos += vec2f(size.x() / 2.0f, size.y() / 2.0f); + + break; + case anchor_t::BOTTOM_RIGHT: + pos += vec2f(-size.x() / 2.0f, size.y() / 2.0f); + break; + case anchor_t::CENTER: + break; + } + } }; struct line2d_t