Skip to content

Commit

Permalink
Gui: add helpers for rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
32th-System committed Jul 4, 2023
1 parent 759610e commit 1846352
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions thprac/src/thprac/thprac_gui_components.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
#include "thprac_gui_components.h"
#include "imgui_internal.h"
#include <Shlwapi.h>

namespace THPrac
{
int rotation_start_index;
void ImRotateStart()
{
rotation_start_index = ImGui::GetWindowDrawList()->VtxBuffer.Size;
}

ImVec2 ImRotationCenter()
{
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 ImVec2((l.x + u.x) / 2, (l.y + u.y) / 2); // or use _ClipRectStack?
}

ImVec2 operator-(const ImVec2& l, const ImVec2& r) { return { l.x - r.x, l.y - r.y }; }

void ImRotateEnd(float rad, ImVec2 center)
{
float s = sin(rad), c = cos(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;
}

namespace Gui
{
bool GuiNavFocus::mGlobalDisable = false;
Expand Down
3 changes: 3 additions & 0 deletions thprac/src/thprac/thprac_gui_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "utils/utils.h"

namespace THPrac {
void ImRotateStart();
ImVec2 ImRotationCenter();
void ImRotateEnd(float rad, ImVec2 center = ImRotationCenter());
namespace Gui {
class GameGuiWnd {
public:
Expand Down

0 comments on commit 1846352

Please sign in to comment.