From 19545aa4463abd4389fa6fc5e5460e42e25fd923 Mon Sep 17 00:00:00 2001 From: touky Date: Thu, 24 Nov 2016 00:43:27 -0500 Subject: [PATCH] imgui extension + tileset imGui docking extension tweak tileset new getters --- src/lolimgui.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++------ src/lolimgui.h | 21 +++++++++++++----- src/tileset.cpp | 10 +++++++++ src/tileset.h | 2 ++ 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/lolimgui.cpp b/src/lolimgui.cpp index 175a7630..ca9d9006 100644 --- a/src/lolimgui.cpp +++ b/src/lolimgui.cpp @@ -21,22 +21,66 @@ using namespace lol; //Imgui extension --------------------------------------------------------------------------------- namespace ImGui { - IMGUI_API void SetNextWindowSizeAndDock(const ImVec2& size, ImGuiSetDock dock, ImGuiSetCond cond) + IMGUI_API void SetNextWindowDockingAndSize(const ImVec2& size, ImGuiSetDock dock, const ImVec2& padding, ImGuiSetCond cond) { - vec2 video_size = vec2(Video::GetSize()); - ImVec2 pos = ImVec2(); + SetNextWindowDockingAndSize(size, dock, ImVec4(vec2(padding).xyxy), cond); + } + IMGUI_API void SetNextWindowDockingAndSize(const ImVec2& size, ImGuiSetDock dock, const ImVec4& padding, ImGuiSetCond cond) + { + vec4 pdg = padding; + vec2 vsz = vec2(Video::GetSize()); + vec2 ctr = pdg.xy + (((vsz - pdg.zw) - pdg.xy) * .5f); + vec2 pos = vec2(); switch (dock) { - case ImGuiSetDock_TopLeft: pos = ImVec2(0, 0); break; - case ImGuiSetDock_TopRight: pos = ImVec2(video_size.x - size.x, 0); break; - case ImGuiSetDock_BottomLeft: pos = ImVec2(0, video_size.y - size.y); break; - case ImGuiSetDock_BottomRight: pos = ImVec2(video_size.x - size.x, video_size.y - size.y); break; + case ImGuiSetDock_Center: pos = vec2(ctr.x - (size.x * .5f), ctr.y - (size.y * .5f)); break; + case ImGuiSetDock_Top: pos = vec2(ctr.x - (size.x * .5f), pdg.y); break; + case ImGuiSetDock_TopRight: pos = vec2(vsz.x - (size.x + pdg.z), pdg.y); break; + case ImGuiSetDock_Right: pos = vec2(vsz.x - (size.x + pdg.z), ctr.y - (size.y * .5f)); break; + case ImGuiSetDock_BottomRight: pos = vec2(vsz.x - (size.x + pdg.z), vsz.y - (size.y + pdg.w)); break; + case ImGuiSetDock_Bottom: pos = vec2(ctr.x - (size.x * .5f), vsz.y - (size.y + pdg.w)); break; + case ImGuiSetDock_BottomLeft: pos = vec2(pdg.x, vsz.y - (size.y + pdg.w)); break; + case ImGuiSetDock_Left: pos = vec2(pdg.x, ctr.y - (size.y * .5f)); break; + case ImGuiSetDock_TopLeft: pos = vec2(pdg.x, pdg.y); break; } ImGui::SetNextWindowPos(pos, cond); ImGui::SetNextWindowSize(size, cond); } + + IMGUI_API void SetNextWindowDocking(ImGuiSetDock dock, const ImVec2& padding, ImGuiSetCond cond) + { + SetNextWindowDocking(dock, ImVec4(vec2(padding).xyxy), cond); + } + IMGUI_API void SetNextWindowDocking(ImGuiSetDock dock, const ImVec4& padding, ImGuiSetCond cond) + { + vec2 vsz = vec2(Video::GetSize()); + vec2 size = vec2(); + vec2 pos = vec2(); + vec4 pdg = padding; + + switch (dock) + { + case ImGuiSetDock_Center: size = vsz - vec2(pdg.x + pdg.z, pdg.y + pdg.w); break; + case ImGuiSetDock_Top: size = vec2(vsz.x - (pdg.x + pdg.z), vsz.y *.5f - pdg.y); break; + case ImGuiSetDock_TopRight: size = vec2(vsz.x *.5f - pdg.z, vsz.y *.5f - pdg.y); break; + case ImGuiSetDock_Right: size = vec2(vsz.x *.5f - pdg.z, vsz.y - (pdg.y + pdg.w)); break; + case ImGuiSetDock_BottomRight: size = vec2(vsz.x *.5f - pdg.z, vsz.y *.5f - pdg.w); break; + case ImGuiSetDock_Bottom: size = vec2(vsz.x - (pdg.x + pdg.z), vsz.y *.5f - pdg.w); break; + case ImGuiSetDock_BottomLeft: size = vec2(vsz.x *.5f - pdg.x, vsz.y *.5f - pdg.w); break; + case ImGuiSetDock_Left: size = vec2(vsz.x *.5f - pdg.x, vsz.y - (pdg.y + pdg.w)); break; + case ImGuiSetDock_TopLeft: size = vec2(vsz.x *.5f - pdg.x, vsz.y *.5f - pdg.y); break; + } + + SetNextWindowDockingAndSize(size, dock, padding, cond); + } + + IMGUI_API float GetMainMenuBarHeight() + { + ImGuiContext& g = *GImGui; + return g.FontBaseSize + g.Style.FramePadding.y * 2.0f; + } } //LolImGui ---------------------------------------------------------------------------------------- diff --git a/src/lolimgui.h b/src/lolimgui.h index 780c049d..3b82c4c9 100644 --- a/src/lolimgui.h +++ b/src/lolimgui.h @@ -19,7 +19,7 @@ #define IM_VEC4_CLASS_EXTRA ImVec4(const lol::vec4 &v) { x = v.x; y = v.y; z = v.z; w = v.w; } \ ImVec4(const lol::ivec4 &v) : ImVec4(lol::vec4(v)) { } \ - operator lol::vec4() { return lol::vec4(x, y, z, w); } \ + operator lol::vec4() const { return lol::vec4(x, y, z, w); } \ operator lol::ivec4() const { return lol::ivec4(lol::vec4(x, y, z, w)); } #include "imgui.h" @@ -32,15 +32,24 @@ typedef int ImGuiSetDock; // condition flags for Set*() // e enum ImGuiSetDock_ { - ImGuiSetDock_TopLeft = 0, - ImGuiSetDock_TopRight = 1, - ImGuiSetDock_BottomLeft = 2, - ImGuiSetDock_BottomRight = 3, + ImGuiSetDock_Center, + ImGuiSetDock_Top, + ImGuiSetDock_TopRight, + ImGuiSetDock_Right, + ImGuiSetDock_BottomRight, + ImGuiSetDock_Bottom, + ImGuiSetDock_BottomLeft, + ImGuiSetDock_Left, + ImGuiSetDock_TopLeft, }; namespace ImGui { - IMGUI_API void SetNextWindowSizeAndDock(const ImVec2& size, ImGuiSetDock dock, ImGuiSetCond cond = 0); + IMGUI_API void SetNextWindowDockingAndSize(const ImVec2& size, ImGuiSetDock dock, const ImVec2& padding, ImGuiSetCond cond = 0); + IMGUI_API void SetNextWindowDockingAndSize(const ImVec2& size, ImGuiSetDock dock, const ImVec4& padding = ImVec4(0, 0, 0, 0), ImGuiSetCond cond = 0); + IMGUI_API void SetNextWindowDocking(ImGuiSetDock dock, const ImVec2& padding, ImGuiSetCond cond = 0); + IMGUI_API void SetNextWindowDocking(ImGuiSetDock dock, const ImVec4& padding = ImVec4(0, 0, 0, 0), ImGuiSetCond cond = 0); + IMGUI_API float GetMainMenuBarHeight(); } //LolImGui ---------------------------------------------------------------------------------------- diff --git a/src/tileset.cpp b/src/tileset.cpp index 473e6441..fb952d2d 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -162,6 +162,16 @@ ivec2 TileSet::GetTileSize(int tileid) const return m_tileset_data->m_tiles[tileid].m1.extent(); } +ibox2 TileSet::GetTilePixel(int tileid) const +{ + return m_tileset_data->m_tiles[tileid].m1; +} + +box2 TileSet::GetTileTexel(int tileid) const +{ + return m_tileset_data->m_tiles[tileid].m2; +} + //Palette --------------------------------------------------------------------- void TileSet::SetPalette(TileSet* palette) { diff --git a/src/tileset.h b/src/tileset.h index 4e6b2e63..5855c5e2 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -62,6 +62,8 @@ public: void define_tile(ivec2 count); int GetTileCount() const; ivec2 GetTileSize(int tileid) const; + ibox2 GetTilePixel(int tileid) const; + box2 GetTileTexel(int tileid) const; void SetPalette(TileSet* palette); TileSet* GetPalette();