2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/views/view.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <imgui.h>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/helpers/shared_data.hpp>
|
2021-01-04 00:19:56 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2021-03-03 22:26:17 +01:00
|
|
|
View::View(std::string unlocalizedName) : m_unlocalizedViewName(unlocalizedName) { }
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
void View::drawMenu() { }
|
2021-04-16 19:43:54 +02:00
|
|
|
bool View::handleShortcut(bool keys[512], bool ctrl, bool shift, bool alt) { return false; }
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-02-03 00:56:33 +01:00
|
|
|
bool View::isAvailable() {
|
|
|
|
return SharedData::currentProvider != nullptr && SharedData::currentProvider->isAvailable();
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
std::vector<std::function<void()>>& View::getDeferedCalls() {
|
2021-01-12 23:28:41 +01:00
|
|
|
return SharedData::deferredCalls;
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::drawCommonInterfaces() {
|
2021-03-03 22:26:17 +01:00
|
|
|
if (ImGui::BeginPopupModal("hex.common.error"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
2021-01-31 00:05:07 +01:00
|
|
|
ImGui::Text("%s", SharedData::errorPopupMessage.c_str());
|
2020-12-22 18:10:01 +01:00
|
|
|
ImGui::NewLine();
|
2021-01-31 00:05:07 +01:00
|
|
|
ImGui::Separator();
|
2021-03-03 22:26:17 +01:00
|
|
|
if (ImGui::Button("hex.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape))
|
2020-12-22 18:10:01 +01:00
|
|
|
ImGui::CloseCurrentPopup();
|
2021-01-31 00:05:07 +01:00
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2021-04-18 20:24:42 +02:00
|
|
|
|
|
|
|
if (ImGui::BeginPopupModal("hex.common.fatal"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
|
|
|
ImGui::Text("%s", SharedData::errorPopupMessage.c_str());
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::Button("hex.common.okay"_lang) || ImGui::IsKeyDown(ImGuiKey_Escape)) {
|
2021-08-21 13:55:21 +02:00
|
|
|
ImHexApi::Common::closeImHex();
|
2021-04-18 20:24:42 +02:00
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void View::showErrorPopup(const std::string &errorMessage) {
|
2021-01-13 23:08:41 +01:00
|
|
|
SharedData::errorPopupMessage = errorMessage;
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-03-03 22:26:17 +01:00
|
|
|
View::doLater([] { ImGui::OpenPopup("hex.common.error"_lang); });
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void View::showFatalPopup(const std::string &errorMessage) {
|
2021-04-18 20:24:42 +02:00
|
|
|
SharedData::errorPopupMessage = errorMessage;
|
|
|
|
|
|
|
|
View::doLater([] { ImGui::OpenPopup("hex.common.fatal"_lang); });
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
bool View::hasViewMenuItemEntry() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImVec2 View::getMinSize() {
|
|
|
|
return ImVec2(480, 720);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImVec2 View::getMaxSize() {
|
|
|
|
return ImVec2(FLT_MAX, FLT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool& View::getWindowOpenState() {
|
|
|
|
return this->m_windowOpen;
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
const std::string& View::getUnlocalizedName() const {
|
2021-03-03 22:26:17 +01:00
|
|
|
return this->m_unlocalizedViewName;
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 13:23:50 +01:00
|
|
|
void View::discardNavigationRequests() {
|
|
|
|
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
|
|
|
|
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void View::doLater(std::function<void()> &&function) {
|
2021-01-12 23:28:41 +01:00
|
|
|
SharedData::deferredCalls.push_back(function);
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
void View::confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn) {
|
2020-12-22 18:10:01 +01:00
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
2021-09-08 15:18:24 +02:00
|
|
|
if (ImGui::Button(textLeft.c_str(), ImVec2(width / 3, 0)))
|
2020-12-22 18:10:01 +01:00
|
|
|
leftButtonFn();
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX(width / 9 * 5);
|
2021-09-08 15:18:24 +02:00
|
|
|
if (ImGui::Button(textRight.c_str(), ImVec2(width / 3, 0)))
|
2020-12-22 18:10:01 +01:00
|
|
|
rightButtonFn();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|