2021-12-07 22:47:41 +01:00
|
|
|
#include "content/views/view_tools.hpp"
|
2022-10-13 10:47:35 +02:00
|
|
|
#include <imgui_internal.h>
|
2020-11-15 00:46:38 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2020-11-15 00:46:38 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
ViewTools::ViewTools() : View("hex.builtin.view.tools.name") { }
|
2020-11-15 21:31:04 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewTools::drawContent() {
|
2023-03-21 15:33:43 +01:00
|
|
|
auto &tools = ContentRegistry::Tools::impl::getEntries();
|
2022-10-13 10:47:35 +02:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
if (ImGui::Begin(View::toWindowName("hex.builtin.view.tools.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2022-10-13 10:47:35 +02:00
|
|
|
for (auto iter = tools.begin(); iter != tools.end(); iter++) {
|
|
|
|
auto &[name, function, detached] = *iter;
|
|
|
|
|
|
|
|
if (detached) continue;
|
|
|
|
|
2021-02-13 15:15:32 +01:00
|
|
|
if (ImGui::CollapsingHeader(LangEntry(name))) {
|
2021-01-13 13:18:03 +01:00
|
|
|
function();
|
2023-01-19 16:59:59 +01:00
|
|
|
ImGui::NewLine();
|
2022-10-13 10:47:35 +02:00
|
|
|
} else {
|
|
|
|
if (ImGui::IsMouseClicked(0) && ImGui::IsItemActivated() && this->m_dragStartIterator == tools.end())
|
|
|
|
this->m_dragStartIterator = iter;
|
|
|
|
|
2023-01-01 01:01:24 +01:00
|
|
|
if (!ImGui::IsMouseDown(0))
|
|
|
|
this->m_dragStartIterator = tools.end();
|
|
|
|
|
2022-10-13 10:47:35 +02:00
|
|
|
if (!ImGui::IsItemHovered() && this->m_dragStartIterator == iter) {
|
|
|
|
detached = true;
|
|
|
|
}
|
|
|
|
|
2021-01-13 13:18:03 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-15 00:46:38 +01:00
|
|
|
}
|
|
|
|
ImGui::End();
|
2022-10-13 10:47:35 +02:00
|
|
|
|
|
|
|
for (auto iter = tools.begin(); iter != tools.end(); iter++) {
|
|
|
|
auto &[name, function, detached] = *iter;
|
|
|
|
|
|
|
|
if (!detached) continue;
|
|
|
|
|
2022-10-13 15:14:51 +02:00
|
|
|
ImGui::SetNextWindowSize(scaled(ImVec2(600, 0)));
|
2022-10-13 10:47:35 +02:00
|
|
|
if (ImGui::Begin(View::toWindowName(name).c_str(), &detached, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize)) {
|
|
|
|
function();
|
|
|
|
|
|
|
|
if (ImGui::IsWindowAppearing() && this->m_dragStartIterator == iter) {
|
|
|
|
this->m_dragStartIterator = tools.end();
|
|
|
|
|
|
|
|
// Attach the newly created window to the cursor, so it gets dragged around
|
|
|
|
GImGui->MovingWindow = ImGui::GetCurrentWindow();
|
|
|
|
GImGui->ActiveId = GImGui->MovingWindow->MoveId;
|
|
|
|
ImGui::DockContextQueueUndockWindow(GImGui, GImGui->MovingWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
2020-11-15 00:46:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|