-
-
Save ice1000/865c7666d13b945628254aa00bd9d62d to your computer and use it in GitHub Desktop.
Rotating text and icon demo for dear imgui
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "imgui_internal.h" | |
int rotation_start_index; | |
auto ImRotateStart() -> void { | |
rotation_start_index = ImGui::GetWindowDrawList()->VtxBuffer.Size; | |
} | |
auto ImRotationCenter() -> ImVec2 { | |
ImVec2 l{FLT_MAX, FLT_MAX}, u{-FLT_MAX, -FLT_MAX}; // bounds | |
const auto& buf = ImGui::GetWindowDrawList()->VtxBuffer; | |
for (int i = rotation_start_index; i < buf.Size; i++) | |
l = ImMin(l, buf[i].pos), u = ImMax(u, buf[i].pos); | |
return {(l.x + u.x) / 2, (l.y + u.y) / 2}; // or use _ClipRectStack? | |
} | |
void ImRotateEnd(float rad, ImVec2 center = ImRotationCenter()) { | |
float s = ImSin(rad), c = ImCos(rad); | |
center = ImRotate(center, s, c) - center; | |
auto& buf = ImGui::GetWindowDrawList()->VtxBuffer; | |
for (int i = rotation_start_index; i < buf.Size; i++) | |
buf[i].pos = ImRotate(buf[i].pos, s, c) - center; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment