From 18c25d31e853d06a0a94a2bf57eb0e8c72193153 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 16 Oct 2026 17:55:10 +0200 Subject: [PATCH 1/7] Refactor Renderer and Tiling to use pixelScale for scaling calculations --- include/Nebulite/Core/Renderer.hpp | 7 +++++-- include/Nebulite/Data/Tiling.hpp | 4 ++-- src/Nebulite/Core/Renderer.cpp | 13 +++++++------ src/Nebulite/Data/Tiling.cpp | 14 +++++++------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/Nebulite/Core/Renderer.hpp b/include/Nebulite/Core/Renderer.hpp index f924c012..37069b2f 100755 --- a/include/Nebulite/Core/Renderer.hpp +++ b/include/Nebulite/Core/Renderer.hpp @@ -498,10 +498,13 @@ class Renderer final : public Interaction::Execution::Domain { // Custom Subclasses Environment env; - // Rendering + // Scaling + // TODO: Add event trigger to re-calculate pixelScale! std::uint8_t windowScale = 1; - SDL_Window* window{}; + float pixelScale = 1.0; + // SDL-Related + SDL_Window* window{}; SDL_Renderer* renderer{}; //------------------------------------------ diff --git a/include/Nebulite/Data/Tiling.hpp b/include/Nebulite/Data/Tiling.hpp index 5ebc61cf..ab729003 100644 --- a/include/Nebulite/Data/Tiling.hpp +++ b/include/Nebulite/Data/Tiling.hpp @@ -114,7 +114,7 @@ class Tile { * @param capture The capture instance for logging errors during texture creation and rendering * @param dispPosX The display position, horizontally * @param dispPosY The display position, vertically - * @param windowScale The scaling factor of the window + * @param pixelScale The scaling factor of the tile texture */ void render( Core::Renderer& nebuliteRenderer, @@ -123,7 +123,7 @@ class Tile { Utility::Io::Capture& capture, int dispPosX, int dispPosY, - int windowScale + float pixelScale ); }; diff --git a/src/Nebulite/Core/Renderer.cpp b/src/Nebulite/Core/Renderer.cpp index 37392b5e..d8cb9718 100755 --- a/src/Nebulite/Core/Renderer.cpp +++ b/src/Nebulite/Core/Renderer.cpp @@ -108,6 +108,7 @@ void Renderer::setupDisplayValues() { auto const resX = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::resolutionX).value_or(1000); auto const resY = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::resolutionX).value_or(1000); windowScale = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::resolutionScaling).value_or(1); + pixelScale = static_cast(windowScale) * SDL_GetWindowDisplayScale(window); fps.target = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::targetFps).value_or(60); // Set in workspace @@ -685,6 +686,7 @@ void Renderer::changeWindowSize(int const w, int const h, std::uint8_t const sc // Set new scalar windowScale = scalar; + pixelScale = static_cast(windowScale) * SDL_GetWindowDisplayScale(window); // Set the new resolution in the workspace domainScope.set(Constants::KeyNames::Renderer::dispResXWindow, w * windowScale); @@ -739,12 +741,11 @@ void Renderer::moveCam(int const dX, int const dY) const { } SDL_FRect Renderer::scaleRectFromLogicalSize(SDL_FRect const& logicalRect) const { - auto const scale = static_cast(windowScale); return SDL_FRect{ - .x=logicalRect.x * scale, - .y=logicalRect.y * scale, - .w=logicalRect.w * scale, - .h=logicalRect.h * scale, + .x=logicalRect.x * pixelScale, + .y=logicalRect.y * pixelScale, + .w=logicalRect.w * pixelScale, + .h=logicalRect.h * pixelScale, }; } @@ -811,7 +812,7 @@ void Renderer::renderFrame() { capture, dispPosX, dispPosY, - windowScale + pixelScale ); }); } diff --git a/src/Nebulite/Data/Tiling.cpp b/src/Nebulite/Data/Tiling.cpp index b2de3640..a44dd653 100644 --- a/src/Nebulite/Data/Tiling.cpp +++ b/src/Nebulite/Data/Tiling.cpp @@ -118,7 +118,7 @@ void Tile::render( Utility::Io::Capture& capture, int const dispPosX, int const dispPosY, - int const windowScale + float const pixelScale ){ auto* const renderer = nebuliteRenderer.getSdlRenderer(); @@ -128,8 +128,8 @@ void Tile::render( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, - 2*windowScale*tilingInfo.w, - 2*windowScale*tilingInfo.h + static_cast(2.0f*pixelScale*static_cast(tilingInfo.w)), + static_cast(2.0f*pixelScale*static_cast(tilingInfo.h)) ); if (!texture) { capture.error.println("Failed to create render target texture."); @@ -152,10 +152,10 @@ void Tile::render( // Render tile to screen SDL_SetRenderTarget(renderer, nullptr); SDL_FRect const destRect{ - .x = static_cast(windowScale * (coordinate.x * tilingInfo.w - dispPosX)), - .y = static_cast(windowScale * (coordinate.y * tilingInfo.h - dispPosY)), - .w = static_cast(2 * windowScale * tilingInfo.w), - .h = static_cast(2 * windowScale * tilingInfo.h), + .x = pixelScale * static_cast(coordinate.x * tilingInfo.w - dispPosX), + .y = pixelScale * static_cast(coordinate.y * tilingInfo.h - dispPosY), + .w = 2.0f * pixelScale * static_cast(tilingInfo.w), + .h = 2.0f * pixelScale * static_cast(tilingInfo.h), }; if (!SDL_RenderTexture(renderer, texture, nullptr, &destRect)) { capture.error.println("Failed to render background tile texture: ", SDL_GetError()); From 38cb0e5f58f7576861732f04279c249d9ae57757 Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 17 Oct 2026 10:54:10 +0200 Subject: [PATCH 2/7] Refactor Renderer to use pixelScale for scaling calculations and handle display scale changes --- src/Nebulite/Core/Renderer.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Nebulite/Core/Renderer.cpp b/src/Nebulite/Core/Renderer.cpp index d8cb9718..eece1811 100755 --- a/src/Nebulite/Core/Renderer.cpp +++ b/src/Nebulite/Core/Renderer.cpp @@ -134,7 +134,7 @@ void Renderer::initImgui() { ImPlot::CreateContext(); // Pixel-friendly ImGui style for retro RPGs - ImGuiStyle &style = ImGui::GetStyle(); + auto& style = ImGui::GetStyle(); // Rounding style.WindowRounding = 0.0f; @@ -162,8 +162,9 @@ void Renderer::initImgui() { style.AntiAliasedFill = false; // Scaling - float const fullScale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()) * static_cast(windowScale) * 0.6f; // adjust to taste + float const fullScale = pixelScale * static_cast(windowScale) * 0.6f; // adjust to taste style.FontScaleDpi = fullScale; + style.ScaleAllSizes(SDL_GetWindowDisplayScale(window)); // Color palette: dark backgrounds, warm accent for UI (tweak hex to taste) auto constexpr layer0 = ImVec4(0.05f, 0.07f, 0.10f, 1.00f); // deep navy @@ -472,7 +473,20 @@ void Renderer::pollEvents() { events.push_back(event); // Handle quit event - if (event.type == SDL_EVENT_QUIT) { status.quit = true; } + if (event.type == SDL_EVENT_QUIT) { + status.quit = true; + } + + // Handle change in Scale + if (event.type == SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED) { + auto const newScale = SDL_GetWindowDisplayScale(window); + auto const oldScale = pixelScale / static_cast(windowScale); + auto const scaleDiff = newScale / oldScale; + auto& style = ImGui::GetStyle(); + style.ScaleAllSizes(scaleDiff); + + pixelScale = newScale * static_cast(windowScale); + } } } From 1d24284eed283e6ef82d4aae5d2b29649a387696 Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 17 Oct 2026 11:13:53 +0200 Subject: [PATCH 3/7] Add Debug module for renderer with gui scaling functionality --- .../Nebulite/Module/Domain/Renderer/Debug.hpp | 49 +++++++++++++++++++ src/Nebulite/Module/Domain/Initializer.cpp | 6 +++ src/Nebulite/Module/Domain/Renderer/Debug.cpp | 44 +++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 include/Nebulite/Module/Domain/Renderer/Debug.hpp create mode 100644 src/Nebulite/Module/Domain/Renderer/Debug.cpp diff --git a/include/Nebulite/Module/Domain/Renderer/Debug.hpp b/include/Nebulite/Module/Domain/Renderer/Debug.hpp new file mode 100644 index 00000000..4597bcc5 --- /dev/null +++ b/include/Nebulite/Module/Domain/Renderer/Debug.hpp @@ -0,0 +1,49 @@ +#ifndef NEBULITE_MODULE_DOMAIN_RENDERER_DEBUG_HPP +#define NEBULITE_MODULE_DOMAIN_RENDERER_DEBUG_HPP + +//------------------------------------------ +// Includes + +// Nebulite +#include "Nebulite/Constants/Event.hpp" +#include "Nebulite/Module/Base/DomainModule.hpp" +#include "Nebulite/Utility/Args/SegmentedStringView.hpp" + +//------------------------------------------ +namespace Nebulite::Core { +class Renderer; +} // namespace Nebulite::Core + +namespace Nebulite::Module::Domain::Renderer { +/** + * @class Nebulite::Module::Domain::Renderer::Debug + * @brief DomainModule for renderer debugging utilities. + */ +class Debug final : public Base::DomainModule { +public: + [[nodiscard]] Constants::Event updateHook() override; + void reinit() override {} + + //------------------------------------------ + // Available Functions + + [[nodiscard]] Constants::Event scale(Utility::Args::SegmentedStringView const& args) const; + + static auto constexpr scaleName = "scale"; + static auto constexpr scaleDesc = "Scales all Dear ImGui style sizes.\n" + "\n" + "Usage: imguidb scale \n"; + + //------------------------------------------ + // Categories + + static auto constexpr imguiDebugName = "imguidb"; + static auto constexpr imguiDebugDesc = "Dear ImGui debugging utilities."; + + //------------------------------------------ + // Setup + + explicit Debug(ConstructorParams const& params); +}; +} // namespace Nebulite::Module::Domain::Renderer +#endif // NEBULITE_MODULE_DOMAIN_RENDERER_DEBUG_HPP diff --git a/src/Nebulite/Module/Domain/Initializer.cpp b/src/Nebulite/Module/Domain/Initializer.cpp index ab48b49d..051bc37c 100644 --- a/src/Nebulite/Module/Domain/Initializer.cpp +++ b/src/Nebulite/Module/Domain/Initializer.cpp @@ -46,6 +46,7 @@ // Renderer #include "Nebulite/Module/Domain/Renderer/Audio.hpp" #include "Nebulite/Module/Domain/Renderer/Console.hpp" +#include "Nebulite/Module/Domain/Renderer/Debug.hpp" #include "Nebulite/Module/Domain/Renderer/General.hpp" #include "Nebulite/Module/Domain/Renderer/Input.hpp" #include "Nebulite/Module/Domain/Renderer/RenderObjectDraft.hpp" @@ -245,6 +246,11 @@ void Initializer::initRenderer(Core::Renderer* target) { Global::settings(), *target ); + target->initModule( + "Renderer Debug Functions", + Global::settings(), + *target + ); target->initModule( "Renderer Input Functions", Global::settings(), diff --git a/src/Nebulite/Module/Domain/Renderer/Debug.cpp b/src/Nebulite/Module/Domain/Renderer/Debug.cpp new file mode 100644 index 00000000..8cfdece1 --- /dev/null +++ b/src/Nebulite/Module/Domain/Renderer/Debug.cpp @@ -0,0 +1,44 @@ +//------------------------------------------ +// Includes + +// External +#include + +// Nebulite +#include "Nebulite/Constants/Event.hpp" +#include "Nebulite/Constants/StandardCapture.hpp" +#include "Nebulite/Core/Renderer.hpp" +#include "Nebulite/Module/Base/DomainModule.hpp" +#include "Nebulite/Module/Domain/Renderer/Debug.hpp" +#include "Nebulite/Utility/Args/SegmentedStringView.hpp" + +//------------------------------------------ +namespace Nebulite::Module::Domain::Renderer { + +Constants::Event Debug::updateHook() { + return Constants::Event::success; +} + +Constants::Event Debug::scale(Utility::Args::SegmentedStringView const& args) const { + if (args.size() < 2) { + return Constants::StandardCapture::Warning::Functional::tooFewArgs(domain.capture); + } + if (args.size() > 2) { + return Constants::StandardCapture::Warning::Functional::tooManyArgs(domain.capture); + } + + auto const scaleFactor = args.tryGetAs(1); + if (!scaleFactor.has_value()) { + return Constants::StandardCapture::Warning::Functional::invalidArgument(domain.capture); + } + + ImGui::GetStyle().ScaleAllSizes(scaleFactor.value()); + return Constants::Event::success; +} + +Debug::Debug(ConstructorParams const& params) : DomainModule(params) { + bindCategory(imguiDebugName, imguiDebugDesc); + bindFunction(&Debug::scale, scaleName, scaleDesc); +} + +} // namespace Nebulite::Module::Domain::Renderer From 8ae636c014e50171668a1b5c5c75cec20e60410f Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 17 Oct 2026 12:18:14 +0200 Subject: [PATCH 4/7] Refactor Renderer to improve scaling calculations and add ImGui scaling functions --- include/Nebulite/Core/Renderer.hpp | 21 ++++++++++++++- src/Nebulite/Core/Renderer.cpp | 43 +++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/include/Nebulite/Core/Renderer.hpp b/include/Nebulite/Core/Renderer.hpp index 37069b2f..65e041c5 100755 --- a/include/Nebulite/Core/Renderer.hpp +++ b/include/Nebulite/Core/Renderer.hpp @@ -264,12 +264,19 @@ class Renderer final : public Interaction::Execution::Domain { void moveCam(int dX, int dY) const; /** - * @brief Scales a rectangle from logical size to window size based on the current window scale factor. + * @brief Scales a rectangle from logical size to window size. * @param logicalRect The rect from the logical coordinate system to scale. * @return The rect in the window coordinate system */ [[nodiscard]] SDL_FRect scaleRectFromLogicalSize(SDL_FRect const& logicalRect) const ; + /** + * @brief Scales a rect from logical size to the ImGui renderer window size. + * @param logicalRect The rect from the logical coordinate system to scale. + * @return The rect in the window coordinate system + */ + [[nodiscard]] SDL_FRect scaleRectFromLogicalSizeForImgui(SDL_FRect const& logicalRect) const ; + //------------------------------------------ // Getting @@ -331,6 +338,16 @@ class Renderer final : public Interaction::Execution::Domain { */ [[nodiscard]] unsigned int getWindowScale() const noexcept { return windowScale; } + /** + * @brief Sets a debug multiplier for mouse coordinates forwarded to Dear ImGui. + */ + void setImguiMouseScale(float scale) noexcept { imguiMouseScale = scale; } + + /** + * @brief Sets a debug multiplier for Dear ImGui's SDL render pass. + */ + void setImguiRenderScale(float scale) noexcept { imguiRenderScale = scale; } + //------------------------------------------ // Texture-Related @@ -502,6 +519,8 @@ class Renderer final : public Interaction::Execution::Domain { // TODO: Add event trigger to re-calculate pixelScale! std::uint8_t windowScale = 1; float pixelScale = 1.0; + float imguiMouseScale = 1.0f; + float imguiRenderScale = 1.0f; // SDL-Related SDL_Window* window{}; diff --git a/src/Nebulite/Core/Renderer.cpp b/src/Nebulite/Core/Renderer.cpp index eece1811..36967da4 100755 --- a/src/Nebulite/Core/Renderer.cpp +++ b/src/Nebulite/Core/Renderer.cpp @@ -108,7 +108,7 @@ void Renderer::setupDisplayValues() { auto const resX = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::resolutionX).value_or(1000); auto const resY = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::resolutionX).value_or(1000); windowScale = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::resolutionScaling).value_or(1); - pixelScale = static_cast(windowScale) * SDL_GetWindowDisplayScale(window); + pixelScale = static_cast(windowScale); fps.target = Global::settings().get(Module::Domain::GlobalSpace::Settings::Key::targetFps).value_or(60); // Set in workspace @@ -162,9 +162,8 @@ void Renderer::initImgui() { style.AntiAliasedFill = false; // Scaling - float const fullScale = pixelScale * static_cast(windowScale) * 0.6f; // adjust to taste + float const fullScale = static_cast(windowScale) * 0.6f; // adjust to taste style.FontScaleDpi = fullScale; - style.ScaleAllSizes(SDL_GetWindowDisplayScale(window)); // Color palette: dark backgrounds, warm accent for UI (tweak hex to taste) auto constexpr layer0 = ImVec4(0.05f, 0.07f, 0.10f, 1.00f); // deep navy @@ -270,6 +269,7 @@ void Renderer::initSdl() { std::abort(); } SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + pixelScale = static_cast(windowScale) * SDL_GetWindowDisplayScale(window); //------------------------------------------ // UI @@ -480,11 +480,7 @@ void Renderer::pollEvents() { // Handle change in Scale if (event.type == SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED) { auto const newScale = SDL_GetWindowDisplayScale(window); - auto const oldScale = pixelScale / static_cast(windowScale); - auto const scaleDiff = newScale / oldScale; - auto& style = ImGui::GetStyle(); - style.ScaleAllSizes(scaleDiff); - + imguiRenderScale = newScale; pixelScale = newScale * static_cast(windowScale); } } @@ -497,7 +493,22 @@ void Renderer::render() { // Event polling and processing pollEvents(); for (auto const& event : events) { - ImGui_ImplSDL3_ProcessEvent(&event); + if (event.type == SDL_EVENT_MOUSE_MOTION) { + SDL_Event imguiEvent = event; + imguiEvent.motion.x *= imguiMouseScale; + imguiEvent.motion.y *= imguiMouseScale; + ImGui_ImplSDL3_ProcessEvent(&imguiEvent); + } + else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN || event.type == SDL_EVENT_MOUSE_BUTTON_UP) { + SDL_Event imguiEvent = event; + imguiEvent.button.x *= imguiMouseScale; + imguiEvent.button.y *= imguiMouseScale; + ImGui_ImplSDL3_ProcessEvent(&imguiEvent); + } + else { + ImGui_ImplSDL3_ProcessEvent(&event); + } + // Skip tab key if Imgui wants text input. Otherwise, RmlUi tries to focus some element. if (event.type == SDL_EVENT_KEY_DOWN && event.key.scancode == SDL_SCANCODE_TAB && ImGui::GetIO().WantTextInput) { @@ -542,7 +553,9 @@ void Renderer::render() { // Finalize render if (status.showFps) renderFps(); ImGui::Render(); + SDL_SetRenderScale(renderer, imguiRenderScale, imguiRenderScale); ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), renderer); + SDL_SetRenderScale(renderer, 1.0f, 1.0f); // Present frame SDL_RenderPresent(renderer); @@ -698,7 +711,7 @@ void Renderer::changeWindowSize(int const w, int const h, std::uint8_t const sc auto const currentCenterX = domainScope.get(Constants::KeyNames::Renderer::positionX).value_or(0) + domainScope.get(Constants::KeyNames::Renderer::dispResXLogical).value_or(0) / 2; auto const currentCenterY = domainScope.get(Constants::KeyNames::Renderer::positionY).value_or(0) + domainScope.get(Constants::KeyNames::Renderer::dispResYLogical).value_or(0) / 2; - // Set new scalar + // Set new scalar, recalculate pixelScale windowScale = scalar; pixelScale = static_cast(windowScale) * SDL_GetWindowDisplayScale(window); @@ -763,6 +776,16 @@ SDL_FRect Renderer::scaleRectFromLogicalSize(SDL_FRect const& logicalRect) const }; } +SDL_FRect Renderer::scaleRectFromLogicalSizeForImgui(SDL_FRect const& logicalRect) const { + auto const scalar = static_cast(windowScale); + return SDL_FRect{ + .x=logicalRect.x * scalar, + .y=logicalRect.y * scalar, + .w=logicalRect.w * scalar, + .h=logicalRect.h * scalar, + }; +} + //------------------------------------------ // Renderer::tick Functions From bc9ffa4bf527bc541ecbd61894d79cf7d8d0074c Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 17 Oct 2026 12:18:42 +0200 Subject: [PATCH 5/7] Add scaling functions for framebuffer, mouse, and render in Debug module --- .../Nebulite/Module/Domain/Renderer/Debug.hpp | 20 ++++++- src/Nebulite/Module/Domain/Renderer/Debug.cpp | 54 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/include/Nebulite/Module/Domain/Renderer/Debug.hpp b/include/Nebulite/Module/Domain/Renderer/Debug.hpp index 4597bcc5..705e8ef9 100644 --- a/include/Nebulite/Module/Domain/Renderer/Debug.hpp +++ b/include/Nebulite/Module/Domain/Renderer/Debug.hpp @@ -29,11 +29,29 @@ class Debug final : public Base::DomainModule { [[nodiscard]] Constants::Event scale(Utility::Args::SegmentedStringView const& args) const; - static auto constexpr scaleName = "scale"; + static auto constexpr scaleName = "imguidb scale"; static auto constexpr scaleDesc = "Scales all Dear ImGui style sizes.\n" "\n" "Usage: imguidb scale \n"; + [[nodiscard]] Constants::Event framebufferScale(Utility::Args::SegmentedStringView const& args) const; + static auto constexpr framebufferScaleName = "imguidb framebuffer-scale"; + static auto constexpr framebufferScaleDesc = "Overrides Dear ImGui's framebuffer scale for the current frame.\n" + "\n" + "Usage: imguidb framebuffer-scale \n"; + + [[nodiscard]] Constants::Event mouseScale(Utility::Args::SegmentedStringView const& args) const; + static auto constexpr mouseScaleName = "imguidb mouse-scale"; + static auto constexpr mouseScaleDesc = "Scales mouse coordinates forwarded to Dear ImGui.\n" + "\n" + "Usage: imguidb mouse-scale \n"; + + [[nodiscard]] Constants::Event renderScale(Utility::Args::SegmentedStringView const& args) const; + static auto constexpr renderScaleName = "imguidb render-scale"; + static auto constexpr renderScaleDesc = "Scales Dear ImGui vertices during its SDL render pass.\n" + "\n" + "Usage: imguidb render-scale \n"; + //------------------------------------------ // Categories diff --git a/src/Nebulite/Module/Domain/Renderer/Debug.cpp b/src/Nebulite/Module/Domain/Renderer/Debug.cpp index 8cfdece1..3603f47e 100644 --- a/src/Nebulite/Module/Domain/Renderer/Debug.cpp +++ b/src/Nebulite/Module/Domain/Renderer/Debug.cpp @@ -36,9 +36,63 @@ Constants::Event Debug::scale(Utility::Args::SegmentedStringView const& args) co return Constants::Event::success; } +Constants::Event Debug::framebufferScale(Utility::Args::SegmentedStringView const& args) const { + if (args.size() < 2) { + return Constants::StandardCapture::Warning::Functional::tooFewArgs(domain.capture); + } + if (args.size() > 2) { + return Constants::StandardCapture::Warning::Functional::tooManyArgs(domain.capture); + } + + auto const scaleFactor = args.tryGetAs(1); + if (!scaleFactor.has_value()) { + return Constants::StandardCapture::Warning::Functional::invalidArgument(domain.capture); + } + + ImGui::GetIO().DisplayFramebufferScale = ImVec2(scaleFactor.value(), scaleFactor.value()); + return Constants::Event::success; +} + +Constants::Event Debug::mouseScale(Utility::Args::SegmentedStringView const& args) const { + if (args.size() < 2) { + return Constants::StandardCapture::Warning::Functional::tooFewArgs(domain.capture); + } + if (args.size() > 2) { + return Constants::StandardCapture::Warning::Functional::tooManyArgs(domain.capture); + } + + auto const scaleFactor = args.tryGetAs(1); + if (!scaleFactor.has_value() || scaleFactor.value() <= 0.0f) { + return Constants::StandardCapture::Warning::Functional::invalidArgument(domain.capture); + } + + domain.setImguiMouseScale(scaleFactor.value()); + return Constants::Event::success; +} + +Constants::Event Debug::renderScale(Utility::Args::SegmentedStringView const& args) const { + if (args.size() < 2) { + return Constants::StandardCapture::Warning::Functional::tooFewArgs(domain.capture); + } + if (args.size() > 2) { + return Constants::StandardCapture::Warning::Functional::tooManyArgs(domain.capture); + } + + auto const scaleFactor = args.tryGetAs(1); + if (!scaleFactor.has_value() || scaleFactor.value() <= 0.0f) { + return Constants::StandardCapture::Warning::Functional::invalidArgument(domain.capture); + } + + domain.setImguiRenderScale(scaleFactor.value()); + return Constants::Event::success; +} + Debug::Debug(ConstructorParams const& params) : DomainModule(params) { bindCategory(imguiDebugName, imguiDebugDesc); bindFunction(&Debug::scale, scaleName, scaleDesc); + bindFunction(&Debug::framebufferScale, framebufferScaleName, framebufferScaleDesc); + bindFunction(&Debug::mouseScale, mouseScaleName, mouseScaleDesc); + bindFunction(&Debug::renderScale, renderScaleName, renderScaleDesc); } } // namespace Nebulite::Module::Domain::Renderer From a74723d016b54118a1e48e2478e7025b0915bdb4 Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 17 Oct 2026 12:19:07 +0200 Subject: [PATCH 6/7] Fix tile rendering to use scaled rectangle for ImGui text display --- src/Nebulite/Module/Domain/Renderer/Tiling.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Nebulite/Module/Domain/Renderer/Tiling.cpp b/src/Nebulite/Module/Domain/Renderer/Tiling.cpp index b059585c..03e457a2 100644 --- a/src/Nebulite/Module/Domain/Renderer/Tiling.cpp +++ b/src/Nebulite/Module/Domain/Renderer/Tiling.cpp @@ -101,9 +101,10 @@ namespace Nebulite::Module::Domain::Renderer { } // Render cost and count as text in the top-left corner of the tile + auto scaledRectImgui = domain.scaleRectFromLogicalSizeForImgui(rect); std::string const metaInfoText = "Count: " + std::to_string(objectCount) + " Cost: " + std::to_string(tileCost); ImGui::GetBackgroundDrawList()->AddText( - ImVec2(scaledRect.x+2, scaledRect.y+2), + ImVec2(scaledRectImgui.x+2, scaledRectImgui.y+2), ImColor(255, 0, 255, 255), metaInfoText.c_str() ); From 5962e28ba2bd9037fe4272eee2cd2a9ffb517317 Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 18 Oct 2026 13:06:24 +0200 Subject: [PATCH 7/7] Remove old TODO --- include/Nebulite/Core/Renderer.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/Nebulite/Core/Renderer.hpp b/include/Nebulite/Core/Renderer.hpp index 65e041c5..d3e322f7 100755 --- a/include/Nebulite/Core/Renderer.hpp +++ b/include/Nebulite/Core/Renderer.hpp @@ -516,7 +516,6 @@ class Renderer final : public Interaction::Execution::Domain { Environment env; // Scaling - // TODO: Add event trigger to re-calculate pixelScale! std::uint8_t windowScale = 1; float pixelScale = 1.0; float imguiMouseScale = 1.0f;