From a36001212fb52dc55168aa21f1700e122326bade Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 27 Aug 2015 18:45:43 +0100 Subject: [PATCH] ImDrawData: added ScaleClipRects() helper (#287) --- imgui.h | 1 + imgui_draw.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/imgui.h b/imgui.h index 336fb7f04..9dd0d0733 100644 --- a/imgui.h +++ b/imgui.h @@ -1142,6 +1142,7 @@ struct ImDrawData // Functions void DeIndexAllBuffers(); // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering! + void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution. }; struct ImFontConfig diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 0d3e411bd..a4f6e4da3 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -833,6 +833,20 @@ void ImDrawData::DeIndexAllBuffers() } } +// Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution. +void ImDrawData::ScaleClipRects(const ImVec2& scale) +{ + for (int i = 0; i < CmdListsCount; i++) + { + ImDrawList* cmd_list = CmdLists[i]; + for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) + { + ImDrawCmd* cmd = &cmd_list->CmdBuffer[cmd_i]; + cmd->ClipRect = ImVec4(cmd->ClipRect.x * scale.x, cmd->ClipRect.y * scale.y, cmd->ClipRect.z * scale.x, cmd->ClipRect.w * scale.y); + } + } +} + //----------------------------------------------------------------------------- // ImFontAtlias //-----------------------------------------------------------------------------