2020-11-10 15:26:38 +01:00
|
|
|
#include "window.hpp"
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
#include <hex.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
#include <hex/helpers/utils.hpp>
|
2021-09-03 02:33:15 +02:00
|
|
|
#include <hex/helpers/paths.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2021-09-26 21:18:25 +02:00
|
|
|
#include <hex/helpers/file.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-03-06 13:09:20 +01:00
|
|
|
#include <chrono>
|
2021-08-17 13:41:44 +02:00
|
|
|
#include <csignal>
|
2020-11-10 15:26:38 +01:00
|
|
|
#include <iostream>
|
2020-12-11 14:24:42 +01:00
|
|
|
#include <numeric>
|
2022-01-23 02:28:38 +01:00
|
|
|
#include <set>
|
2021-03-06 13:09:20 +01:00
|
|
|
#include <thread>
|
2022-01-11 20:28:57 +01:00
|
|
|
#include <assert.h>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-12-22 15:06:16 +01:00
|
|
|
#include <romfs/romfs.hpp>
|
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <imgui.h>
|
2021-03-02 13:48:23 +01:00
|
|
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <imgui_internal.h>
|
|
|
|
#include <imgui_impl_glfw.h>
|
|
|
|
#include <imgui_impl_opengl3.h>
|
|
|
|
#include <imgui_freetype.h>
|
2021-12-31 01:10:06 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2021-03-02 13:48:23 +01:00
|
|
|
#include <implot.h>
|
|
|
|
#include <implot_internal.h>
|
2021-08-17 13:41:19 +02:00
|
|
|
#include <imnodes.h>
|
|
|
|
#include <imnodes_internal.h>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-02-24 22:42:26 +01:00
|
|
|
#include <fontawesome_font.h>
|
2021-08-04 14:01:24 +02:00
|
|
|
#include <codicons_font.h>
|
2021-08-31 15:22:00 +02:00
|
|
|
#include <unifont_font.h>
|
2021-02-24 22:42:26 +01:00
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
#include "helpers/plugin_manager.hpp"
|
2021-12-07 22:47:41 +01:00
|
|
|
#include <hex/helpers/project_file_handler.hpp>
|
2021-04-20 21:46:48 +02:00
|
|
|
#include "init/tasks.hpp"
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
namespace hex {
|
|
|
|
|
2021-03-06 13:09:20 +01:00
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
void *ImHexSettingsHandler_ReadOpenFn(ImGuiContext *ctx, ImGuiSettingsHandler *, const char *) {
|
2022-01-24 20:53:17 +01:00
|
|
|
return ctx; // Unused, but the return value has to be non-null
|
2020-11-23 23:57:19 +01:00
|
|
|
}
|
2020-11-15 15:49:21 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void ImHexSettingsHandler_ReadLine(ImGuiContext *, ImGuiSettingsHandler *handler, void *, const char *line) {
|
2022-01-18 00:10:10 +01:00
|
|
|
for (auto &[name, view] : ContentRegistry::Views::getEntries()) {
|
2021-03-03 22:26:17 +01:00
|
|
|
std::string format = std::string(view->getUnlocalizedName()) + "=%d";
|
2020-12-11 14:24:42 +01:00
|
|
|
sscanf(line, format.c_str(), &view->getWindowOpenState());
|
2020-11-15 15:49:21 +01:00
|
|
|
}
|
2020-11-23 23:57:19 +01:00
|
|
|
}
|
2020-11-15 15:49:21 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void ImHexSettingsHandler_WriteAll(ImGuiContext *ctx, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buf) {
|
|
|
|
buf->reserve(buf->size() + 0x20); // Ballpark reserve
|
2020-11-15 15:49:21 +01:00
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
buf->appendf("[%s][General]\n", handler->TypeName);
|
2020-11-15 15:49:21 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
for (auto &[name, view] : ContentRegistry::Views::getEntries()) {
|
|
|
|
buf->appendf("%s=%d\n", name.c_str(), view->getWindowOpenState());
|
2020-11-15 15:49:21 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
buf->append("\n");
|
2020-11-15 15:49:21 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
Window::Window() {
|
2021-04-18 20:24:42 +02:00
|
|
|
{
|
2021-04-20 21:46:48 +02:00
|
|
|
for (const auto &[argument, value] : init::getInitArguments()) {
|
|
|
|
if (argument == "update-available") {
|
|
|
|
this->m_availableUpdate = value;
|
|
|
|
} else if (argument == "no-plugins") {
|
2022-01-24 20:53:17 +01:00
|
|
|
View::doLater([] { ImGui::OpenPopup("No Plugins"); });
|
2021-08-22 21:11:01 +02:00
|
|
|
} else if (argument == "tip-of-the-day") {
|
|
|
|
this->m_tipOfTheDay = value;
|
|
|
|
|
|
|
|
this->m_showTipOfTheDay = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1);
|
|
|
|
if (this->m_showTipOfTheDay)
|
2022-01-24 20:53:17 +01:00
|
|
|
View::doLater([] { ImGui::OpenPopup("hex.welcome.tip_of_the_day"_lang); });
|
2021-04-18 20:24:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-17 15:46:26 +02:00
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
this->initGLFW();
|
|
|
|
this->initImGui();
|
2021-11-28 11:57:52 +01:00
|
|
|
this->setupNativeWindow();
|
2021-01-31 00:04:33 +01:00
|
|
|
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::subscribe<EventSettingsChanged>(this, [this]() {
|
2021-02-10 18:17:09 +01:00
|
|
|
{
|
2021-02-16 23:42:35 +01:00
|
|
|
auto theme = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color");
|
2021-11-11 18:59:44 +01:00
|
|
|
|
|
|
|
if (theme.is_number())
|
|
|
|
EventManager::post<RequestChangeTheme>(theme.get<int>());
|
2021-02-10 18:17:09 +01:00
|
|
|
}
|
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
{
|
2021-02-16 23:42:35 +01:00
|
|
|
auto language = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.language");
|
|
|
|
|
2021-06-18 20:09:36 +02:00
|
|
|
if (language.is_string()) {
|
2021-03-06 12:40:29 +01:00
|
|
|
LangEntry::loadLanguage(static_cast<std::string>(language));
|
2021-06-18 20:09:36 +02:00
|
|
|
} else {
|
|
|
|
// If no language is specified, fall back to English.
|
|
|
|
LangEntry::loadLanguage("en-US");
|
|
|
|
}
|
2021-01-30 23:02:03 +01:00
|
|
|
}
|
|
|
|
|
2021-03-06 13:09:20 +01:00
|
|
|
{
|
|
|
|
auto targetFps = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps");
|
|
|
|
|
|
|
|
if (targetFps.is_number())
|
|
|
|
this->m_targetFps = targetFps;
|
|
|
|
}
|
2021-04-12 21:08:36 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
if (ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.launched", 0) == 1)
|
|
|
|
this->m_layoutConfigured = true;
|
|
|
|
else
|
|
|
|
ContentRegistry::Settings::write("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.launched", 1);
|
|
|
|
}
|
2021-01-30 23:02:03 +01:00
|
|
|
});
|
|
|
|
|
2021-09-16 22:23:51 +02:00
|
|
|
EventManager::subscribe<RequestChangeTheme>(this, [this](u32 theme) {
|
|
|
|
if (this->m_bannerTexture.valid())
|
|
|
|
ImGui::UnloadImage(this->m_bannerTexture);
|
|
|
|
|
|
|
|
switch (theme) {
|
2022-01-24 20:53:17 +01:00
|
|
|
default:
|
|
|
|
case 1: /* Dark theme */
|
2021-12-22 15:06:16 +01:00
|
|
|
{
|
2021-09-16 22:23:51 +02:00
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
ImGui::StyleCustomColorsDark();
|
|
|
|
ImPlot::StyleColorsDark();
|
2021-12-22 15:06:16 +01:00
|
|
|
|
|
|
|
auto banner = romfs::get("banner_dark.png");
|
2022-01-24 20:53:17 +01:00
|
|
|
this->m_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8 *>(banner.data()), banner.size());
|
2021-12-22 15:06:16 +01:00
|
|
|
|
2021-09-16 22:23:51 +02:00
|
|
|
break;
|
2021-12-22 15:06:16 +01:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
case 2: /* Light theme */
|
2021-12-22 15:06:16 +01:00
|
|
|
{
|
2021-09-16 22:23:51 +02:00
|
|
|
ImGui::StyleColorsLight();
|
|
|
|
ImGui::StyleCustomColorsLight();
|
|
|
|
ImPlot::StyleColorsLight();
|
2021-12-22 15:06:16 +01:00
|
|
|
|
|
|
|
auto banner = romfs::get("banner_light.png");
|
2022-01-24 20:53:17 +01:00
|
|
|
this->m_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8 *>(banner.data()), banner.size());
|
2021-12-22 15:06:16 +01:00
|
|
|
|
2021-09-16 22:23:51 +02:00
|
|
|
break;
|
2021-12-22 15:06:16 +01:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
case 3: /* Classic theme */
|
2021-12-22 15:06:16 +01:00
|
|
|
{
|
2021-09-16 22:23:51 +02:00
|
|
|
ImGui::StyleColorsClassic();
|
|
|
|
ImGui::StyleCustomColorsClassic();
|
|
|
|
ImPlot::StyleColorsClassic();
|
2021-12-22 15:06:16 +01:00
|
|
|
|
|
|
|
auto banner = romfs::get("banner_dark.png");
|
2022-01-24 20:53:17 +01:00
|
|
|
this->m_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8 *>(banner.data()), banner.size());
|
2021-12-22 15:06:16 +01:00
|
|
|
|
2021-09-16 22:23:51 +02:00
|
|
|
break;
|
2021-12-22 15:06:16 +01:00
|
|
|
}
|
2021-09-16 22:23:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::GetStyle().Colors[ImGuiCol_DockingEmptyBg] = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
|
|
|
|
ImGui::GetStyle().Colors[ImGuiCol_TitleBg] = ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg];
|
|
|
|
ImGui::GetStyle().Colors[ImGuiCol_TitleBgActive] = ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg];
|
|
|
|
ImGui::GetStyle().Colors[ImGuiCol_TitleBgCollapsed] = ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg];
|
|
|
|
|
|
|
|
if (!this->m_bannerTexture.valid()) {
|
|
|
|
log::fatal("Failed to load banner texture!");
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
EventManager::subscribe<EventFileLoaded>(this, [](const auto &path) {
|
2021-04-13 08:41:59 +02:00
|
|
|
SharedData::recentFilePaths.push_front(path);
|
2021-02-01 19:03:45 +01:00
|
|
|
|
|
|
|
{
|
2022-01-16 01:51:31 +01:00
|
|
|
std::list<fs::path> uniques;
|
2021-04-13 08:41:59 +02:00
|
|
|
for (auto &file : SharedData::recentFilePaths) {
|
2021-02-01 19:03:45 +01:00
|
|
|
|
|
|
|
bool exists = false;
|
|
|
|
for (auto &unique : uniques) {
|
|
|
|
if (file == unique)
|
|
|
|
exists = true;
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
if (!exists && !file.empty())
|
2021-02-01 19:03:45 +01:00
|
|
|
uniques.push_back(file);
|
|
|
|
|
|
|
|
if (uniques.size() > 5)
|
|
|
|
break;
|
|
|
|
}
|
2021-04-13 08:41:59 +02:00
|
|
|
SharedData::recentFilePaths = uniques;
|
2021-02-01 19:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::vector<std::string> recentFilesVector;
|
2022-01-16 01:51:31 +01:00
|
|
|
for (const auto &recentPath : SharedData::recentFilePaths)
|
|
|
|
recentFilesVector.push_back(recentPath.string());
|
2021-02-01 19:03:45 +01:00
|
|
|
|
2021-02-13 15:15:32 +01:00
|
|
|
ContentRegistry::Settings::write("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files", recentFilesVector);
|
2021-02-01 19:03:45 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
EventManager::subscribe<EventFileUnloaded>(this, [] {
|
2021-09-08 15:18:24 +02:00
|
|
|
EventManager::post<RequestChangeWindowTitle>("");
|
|
|
|
});
|
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
EventManager::subscribe<RequestCloseImHex>(this, [this](bool noQuestions) {
|
2021-02-01 19:03:45 +01:00
|
|
|
glfwSetWindowShouldClose(this->m_window, true);
|
2021-08-21 13:55:21 +02:00
|
|
|
|
|
|
|
if (!noQuestions)
|
|
|
|
EventManager::post<EventWindowClosing>(this->m_window);
|
2021-02-01 19:03:45 +01:00
|
|
|
});
|
|
|
|
|
2021-03-29 22:44:23 +02:00
|
|
|
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](std::string windowTitle) {
|
2021-08-17 13:41:44 +02:00
|
|
|
std::string title = "ImHex";
|
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
if (ImHexApi::Provider::isValid()) {
|
2021-09-08 15:18:24 +02:00
|
|
|
if (!windowTitle.empty())
|
|
|
|
title += " - " + windowTitle;
|
|
|
|
|
|
|
|
if (ProjectFile::hasUnsavedChanges())
|
|
|
|
title += " (*)";
|
|
|
|
}
|
2021-08-17 13:41:44 +02:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
this->m_windowTitle = title;
|
2021-08-17 13:41:44 +02:00
|
|
|
glfwSetWindowTitle(this->m_window, title.c_str());
|
|
|
|
});
|
|
|
|
|
2021-08-17 22:54:09 +02:00
|
|
|
constexpr auto CrashBackupFileName = "crash_backup.hexproj";
|
|
|
|
|
|
|
|
EventManager::subscribe<EventAbnormalTermination>(this, [CrashBackupFileName](int signal) {
|
2021-08-18 23:12:54 +02:00
|
|
|
if (!ProjectFile::hasUnsavedChanges())
|
|
|
|
return;
|
|
|
|
|
2021-08-17 13:41:44 +02:00
|
|
|
for (const auto &path : hex::getPath(ImHexPath::Config)) {
|
2022-01-13 14:33:30 +01:00
|
|
|
if (ProjectFile::store((fs::path(path) / CrashBackupFileName).string()))
|
2021-08-17 13:41:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-03-29 22:44:23 +02:00
|
|
|
});
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
EventManager::subscribe<RequestOpenPopup>(this, [this](auto name) {
|
2021-09-26 21:18:25 +02:00
|
|
|
this->m_popupsToOpen.push_back(name);
|
|
|
|
});
|
|
|
|
|
2021-08-17 22:54:09 +02:00
|
|
|
for (const auto &path : hex::getPath(ImHexPath::Config)) {
|
2022-01-13 14:33:30 +01:00
|
|
|
if (auto filePath = fs::path(path) / CrashBackupFileName; fs::exists(filePath)) {
|
2021-08-17 22:54:09 +02:00
|
|
|
this->m_safetyBackupPath = filePath;
|
2022-01-24 20:53:17 +01:00
|
|
|
View::doLater([] { ImGui::OpenPopup("hex.safety_backup.title"_lang); });
|
2021-08-17 22:54:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 15:15:32 +01:00
|
|
|
for (const auto &path : ContentRegistry::Settings::read("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files"))
|
2021-04-13 08:41:59 +02:00
|
|
|
SharedData::recentFilePaths.push_back(path);
|
2021-08-17 13:41:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
auto signalHandler = [](int signalNumber) {
|
|
|
|
EventManager::post<EventAbnormalTermination>(signalNumber);
|
2021-08-21 00:52:11 +02:00
|
|
|
|
2022-01-11 20:28:57 +01:00
|
|
|
if (std::uncaught_exceptions() > 0) {
|
|
|
|
log::fatal("Uncaught exception thrown!");
|
|
|
|
}
|
|
|
|
|
2021-11-09 19:14:25 +01:00
|
|
|
// Let's not loop on this...
|
|
|
|
std::signal(signalNumber, nullptr);
|
2022-01-11 20:28:57 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
#if defined(DEBUG)
|
|
|
|
assert(false);
|
|
|
|
#else
|
|
|
|
std::raise(signalNumber);
|
|
|
|
#endif
|
2021-08-17 13:41:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
std::signal(SIGTERM, signalHandler);
|
|
|
|
std::signal(SIGSEGV, signalHandler);
|
2022-01-24 20:53:17 +01:00
|
|
|
std::signal(SIGINT, signalHandler);
|
|
|
|
std::signal(SIGILL, signalHandler);
|
2021-08-17 13:41:44 +02:00
|
|
|
std::signal(SIGABRT, signalHandler);
|
2022-01-24 20:53:17 +01:00
|
|
|
std::signal(SIGFPE, signalHandler);
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2021-12-22 15:06:16 +01:00
|
|
|
auto imhexLogo = romfs::get("logo.png");
|
2022-01-24 20:53:17 +01:00
|
|
|
this->m_logoTexture = ImGui::LoadImageFromMemory(reinterpret_cast<const ImU8 *>(imhexLogo.data()), imhexLogo.size());
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2021-09-12 13:59:23 +02:00
|
|
|
ContentRegistry::Settings::store();
|
2021-08-21 13:55:21 +02:00
|
|
|
EventManager::post<EventSettingsChanged>();
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window() {
|
2022-01-18 00:10:10 +01:00
|
|
|
this->exitImGui();
|
|
|
|
this->exitGLFW();
|
2021-01-30 23:02:03 +01:00
|
|
|
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::unsubscribe<EventSettingsChanged>(this);
|
|
|
|
EventManager::unsubscribe<EventFileLoaded>(this);
|
2021-09-08 15:18:24 +02:00
|
|
|
EventManager::unsubscribe<EventFileUnloaded>(this);
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::unsubscribe<RequestCloseImHex>(this);
|
2021-03-29 22:44:23 +02:00
|
|
|
EventManager::unsubscribe<RequestChangeWindowTitle>(this);
|
2021-09-08 15:18:24 +02:00
|
|
|
EventManager::unsubscribe<EventAbnormalTermination>(this);
|
2021-09-16 22:23:51 +02:00
|
|
|
EventManager::unsubscribe<RequestChangeTheme>(this);
|
2021-09-26 21:18:25 +02:00
|
|
|
EventManager::unsubscribe<RequestOpenPopup>(this);
|
2021-07-29 00:39:58 +02:00
|
|
|
|
|
|
|
ImGui::UnloadImage(this->m_bannerTexture);
|
2021-08-18 22:36:46 +02:00
|
|
|
ImGui::UnloadImage(this->m_logoTexture);
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::loop() {
|
2021-03-06 13:09:20 +01:00
|
|
|
this->m_lastFrameTime = glfwGetTime();
|
2020-11-10 15:26:38 +01:00
|
|
|
while (!glfwWindowShouldClose(this->m_window)) {
|
2021-12-16 23:48:52 +01:00
|
|
|
if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED)) {
|
2021-06-07 18:14:40 +02:00
|
|
|
glfwWaitEvents();
|
2021-12-16 23:48:52 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
double timeout = (1.0 / 5.0) - (glfwGetTime() - this->m_lastFrameTime);
|
2021-12-04 23:16:15 +01:00
|
|
|
timeout = timeout > 0 ? timeout : 0;
|
2021-12-16 23:48:52 +01:00
|
|
|
glfwWaitEventsTimeout(ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) || !SharedData::runningTasks.empty() ? 0 : timeout);
|
|
|
|
}
|
|
|
|
|
2020-11-23 22:23:06 +01:00
|
|
|
|
2021-06-07 18:14:40 +02:00
|
|
|
this->frameBegin();
|
|
|
|
this->frame();
|
2020-11-10 15:26:38 +01:00
|
|
|
this->frameEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::frameBegin() {
|
2021-03-06 13:09:20 +01:00
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGuiViewport *viewport = ImGui::GetMainViewport();
|
2021-08-21 00:52:11 +02:00
|
|
|
ImGui::SetNextWindowPos(viewport->WorkPos);
|
|
|
|
ImGui::SetNextWindowSize(viewport->WorkSize);
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui::SetNextWindowViewport(viewport->ID);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
2021-08-21 00:52:11 +02:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
2020-11-30 00:03:12 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-01-21 17:48:24 +01:00
|
|
|
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
if (ImGui::Begin("DockSpace", nullptr, windowFlags)) {
|
2022-01-22 22:03:19 +01:00
|
|
|
auto drawList = ImGui::GetWindowDrawList();
|
2021-08-21 00:52:11 +02:00
|
|
|
ImGui::PopStyleVar();
|
2022-01-22 22:03:19 +01:00
|
|
|
auto sidebarPos = ImGui::GetCursorPos();
|
|
|
|
auto sidebarWidth = ContentRegistry::Interface::getSidebarItems().empty() ? 0 : 30_scaled;
|
|
|
|
|
|
|
|
ImGui::SetCursorPosX(sidebarWidth);
|
|
|
|
|
|
|
|
auto footerHeight = ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().FramePadding.y * 2 + 1_scaled;
|
|
|
|
auto dockSpaceSize = ImVec2(SharedData::windowSize.x - sidebarWidth, ImGui::GetContentRegionAvail().y - footerHeight);
|
|
|
|
|
|
|
|
SharedData::dockSpaceId = ImGui::DockSpace(ImGui::GetID("MainDock"), dockSpaceSize);
|
|
|
|
|
|
|
|
drawList->AddRectFilled(ImGui::GetWindowPos(), ImGui::GetWindowPos() + ImGui::GetWindowSize() - ImVec2(dockSpaceSize.x, footerHeight - ImGui::GetStyle().FramePadding.y - 1_scaled), ImGui::GetColorU32(ImGuiCol_MenuBarBg));
|
2021-02-18 12:09:19 +01:00
|
|
|
|
|
|
|
ImGui::Separator();
|
2021-08-21 00:52:11 +02:00
|
|
|
ImGui::SetCursorPosX(8);
|
2021-02-18 12:09:19 +01:00
|
|
|
for (const auto &callback : ContentRegistry::Interface::getFooterItems()) {
|
2022-01-22 22:03:19 +01:00
|
|
|
auto prevIdx = drawList->_VtxCurrentIdx;
|
2021-02-18 12:09:19 +01:00
|
|
|
callback();
|
2022-01-22 22:03:19 +01:00
|
|
|
auto currIdx = drawList->_VtxCurrentIdx;
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-02-18 12:09:19 +01:00
|
|
|
// Only draw separator if something was actually drawn
|
|
|
|
if (prevIdx != currIdx) {
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
|
|
|
ImGui::SameLine();
|
|
|
|
}
|
|
|
|
}
|
2021-02-11 23:09:45 +01:00
|
|
|
|
2022-01-22 22:03:19 +01:00
|
|
|
{
|
|
|
|
ImGui::SetCursorPos(sidebarPos);
|
|
|
|
|
2022-01-22 22:37:52 +01:00
|
|
|
static i32 openWindow = -1;
|
2022-01-22 22:03:19 +01:00
|
|
|
u32 index = 0;
|
|
|
|
ImGui::PushID("SideBarWindows");
|
|
|
|
for (const auto &[icon, callback] : ContentRegistry::Interface::getSidebarItems()) {
|
|
|
|
ImGui::SetCursorPosY(sidebarPos.y + sidebarWidth * index);
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_MenuBarBg));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabActive));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetColorU32(ImGuiCol_ScrollbarGrabHovered));
|
|
|
|
|
|
|
|
ImGui::BeginDisabled(!ImHexApi::Provider::isValid());
|
|
|
|
{
|
|
|
|
if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) {
|
|
|
|
if (openWindow == index)
|
|
|
|
openWindow = -1;
|
|
|
|
else
|
|
|
|
openWindow = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
|
|
|
|
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
|
|
|
|
bool open = openWindow == index;
|
|
|
|
if (open) {
|
|
|
|
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 2_scaled, 0));
|
|
|
|
ImGui::SetNextWindowSize(ImVec2(250_scaled, dockSpaceSize.y + ImGui::GetStyle().FramePadding.y + 2_scaled));
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1);
|
|
|
|
if (ImGui::Begin("Window", &open, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar)) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
}
|
|
|
|
|
2021-08-21 00:52:11 +02:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
|
|
|
if (ImGui::BeginMainMenuBar()) {
|
2021-02-18 12:09:19 +01:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
auto menuBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
|
|
|
|
ImGui::SetCursorPosX(5);
|
|
|
|
ImGui::Image(this->m_logoTexture, ImVec2(menuBarHeight, menuBarHeight));
|
|
|
|
|
2022-01-23 20:45:51 +01:00
|
|
|
for (const auto &[priority, menuItem] : ContentRegistry::Interface::getMainMenuItems()) {
|
|
|
|
if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) {
|
2021-08-18 22:36:46 +02:00
|
|
|
ImGui::EndMenu();
|
2020-11-28 22:01:50 +01:00
|
|
|
}
|
2022-01-18 00:10:10 +01:00
|
|
|
}
|
2020-11-11 09:22:55 +01:00
|
|
|
|
2022-01-23 02:28:38 +01:00
|
|
|
std::set<std::string> encounteredMenus;
|
|
|
|
for (auto &[priority, menuItem] : ContentRegistry::Interface::getMenuItems()) {
|
|
|
|
if (ImGui::BeginMenu(LangEntry(menuItem.unlocalizedName))) {
|
|
|
|
auto [iter, inserted] = encounteredMenus.insert(menuItem.unlocalizedName);
|
|
|
|
if (!inserted)
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
menuItem.callback();
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2022-01-18 00:10:10 +01:00
|
|
|
}
|
2020-11-11 09:22:55 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
this->drawTitleBar();
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
ImGui::EndMainMenuBar();
|
2021-08-21 00:52:11 +02:00
|
|
|
}
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
// Draw toolbar
|
|
|
|
if (ImGui::BeginMenuBar()) {
|
|
|
|
|
|
|
|
for (const auto &callback : ContentRegistry::Interface::getToolbarItems()) {
|
|
|
|
callback();
|
|
|
|
ImGui::SameLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenuBar();
|
2020-11-23 23:57:19 +01:00
|
|
|
}
|
2020-11-11 14:41:44 +01:00
|
|
|
|
2021-09-21 02:29:54 +02:00
|
|
|
if (!ImHexApi::Provider::isValid()) {
|
2021-08-18 22:36:46 +02:00
|
|
|
static char title[256];
|
2021-01-27 01:10:13 +01:00
|
|
|
ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock"));
|
|
|
|
if (ImGui::Begin(title)) {
|
2022-01-11 23:48:18 +01:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10_scaled, 10_scaled));
|
2021-07-29 00:39:58 +02:00
|
|
|
if (ImGui::BeginChild("Welcome Screen", ImVec2(0, 0), false, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoScrollWithMouse)) {
|
2021-01-27 01:10:13 +01:00
|
|
|
this->drawWelcomeScreen();
|
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
2021-02-21 13:49:03 +01:00
|
|
|
} else if (!this->m_layoutConfigured) {
|
|
|
|
this->m_layoutConfigured = true;
|
2021-04-12 21:08:36 +02:00
|
|
|
this->resetLayout();
|
2021-01-27 01:10:13 +01:00
|
|
|
}
|
|
|
|
|
2021-12-10 16:09:55 +01:00
|
|
|
this->beginNativeWindowFrame();
|
2022-01-22 22:03:19 +01:00
|
|
|
|
|
|
|
drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth - 2, 0), ImGui::GetWindowPos() + ImGui::GetWindowSize() - ImVec2(dockSpaceSize.x + 2, footerHeight - ImGui::GetStyle().FramePadding.y - 2), ImGui::GetColorU32(ImGuiCol_Separator));
|
|
|
|
drawList->AddLine(ImGui::GetWindowPos() + ImVec2(sidebarWidth, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetWindowPos() + ImVec2(ImGui::GetWindowSize().x, ImGui::GetCurrentWindow()->MenuBarHeight()), ImGui::GetColorU32(ImGuiCol_Separator));
|
2020-11-11 14:41:44 +01:00
|
|
|
}
|
2020-11-23 23:57:19 +01:00
|
|
|
ImGui::End();
|
2021-08-21 00:52:11 +02:00
|
|
|
ImGui::PopStyleVar(2);
|
2021-04-21 23:31:51 +02:00
|
|
|
|
2021-08-22 21:11:01 +02:00
|
|
|
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
|
|
|
|
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size / 3, ImGuiCond_Appearing);
|
|
|
|
if (ImGui::BeginPopup("hex.welcome.tip_of_the_day"_lang)) {
|
|
|
|
ImGui::Header("hex.welcome.tip_of_the_day"_lang, true);
|
|
|
|
|
2022-01-15 14:14:53 +01:00
|
|
|
ImGui::TextFormattedWrapped("{}", this->m_tipOfTheDay.c_str());
|
2021-08-22 21:11:01 +02:00
|
|
|
ImGui::NewLine();
|
|
|
|
|
2021-09-08 16:40:44 +02:00
|
|
|
bool dontShowAgain = !this->m_showTipOfTheDay;
|
|
|
|
if (ImGui::Checkbox("hex.common.dont_show_again"_lang, &dontShowAgain)) {
|
|
|
|
this->m_showTipOfTheDay = !dontShowAgain;
|
2021-08-22 21:11:01 +02:00
|
|
|
ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", this->m_showTipOfTheDay);
|
2021-09-08 16:40:44 +02:00
|
|
|
}
|
2021-08-22 21:11:01 +02:00
|
|
|
|
|
|
|
ImGui::SameLine((ImGui::GetMainViewport()->Size / 3 - ImGui::CalcTextSize("hex.common.close"_lang) - ImGui::GetStyle().FramePadding).x);
|
|
|
|
|
|
|
|
if (ImGui::Button("hex.common.close"_lang))
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2021-04-21 23:31:51 +02:00
|
|
|
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
|
|
|
|
if (ImGui::BeginPopupModal("No Plugins", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) {
|
|
|
|
ImGui::TextUnformatted("No ImHex plugins loaded (including the built-in plugin)!");
|
|
|
|
ImGui::TextUnformatted("Make sure you at least got the builtin plugin in your plugins folder.");
|
|
|
|
ImGui::TextUnformatted("To find out where your plugin folder is, check ImHex' Readme.");
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2021-08-17 22:54:09 +02:00
|
|
|
|
|
|
|
// Popup for if there is a safety backup present because ImHex crashed
|
|
|
|
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
|
|
|
|
if (ImGui::BeginPopupModal("hex.safety_backup.title"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove)) {
|
|
|
|
ImGui::TextUnformatted("hex.safety_backup.desc"_lang);
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
|
|
|
if (ImGui::Button("hex.safety_backup.restore"_lang, ImVec2(width / 3, 0))) {
|
|
|
|
ProjectFile::load(this->m_safetyBackupPath.string());
|
|
|
|
ProjectFile::markDirty();
|
|
|
|
|
|
|
|
ProjectFile::clearProjectFilePath();
|
2022-01-13 14:33:30 +01:00
|
|
|
fs::remove(this->m_safetyBackupPath);
|
2021-08-17 22:54:09 +02:00
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX(width / 9 * 5);
|
|
|
|
if (ImGui::Button("hex.safety_backup.delete"_lang, ImVec2(width / 3, 0))) {
|
2022-01-13 14:33:30 +01:00
|
|
|
fs::remove(this->m_safetyBackupPath);
|
2021-08-17 22:54:09 +02:00
|
|
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
2021-09-26 21:18:25 +02:00
|
|
|
|
2021-09-27 15:04:30 +02:00
|
|
|
this->m_popupsToOpen.remove_if([](const auto &name) {
|
|
|
|
if (ImGui::IsPopupOpen(name.c_str()))
|
|
|
|
return true;
|
2021-09-26 21:18:25 +02:00
|
|
|
else
|
2021-09-27 15:04:30 +02:00
|
|
|
ImGui::OpenPopup(name.c_str());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2022-01-18 00:10:10 +01:00
|
|
|
|
|
|
|
EventManager::post<EventFrameBegin>();
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:14:40 +02:00
|
|
|
void Window::frame() {
|
|
|
|
for (const auto &call : View::getDeferedCalls())
|
|
|
|
call();
|
|
|
|
View::getDeferedCalls().clear();
|
|
|
|
|
2021-12-12 21:46:48 +01:00
|
|
|
View::drawCommonInterfaces();
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
for (auto &[name, view] : ContentRegistry::Views::getEntries()) {
|
2021-12-12 21:46:48 +01:00
|
|
|
ImGui::GetCurrentContext()->NextWindowData.ClearFlags();
|
|
|
|
|
2021-06-07 18:14:40 +02:00
|
|
|
view->drawAlwaysVisible();
|
|
|
|
|
|
|
|
if (!view->shouldProcess())
|
|
|
|
continue;
|
|
|
|
|
2021-12-12 21:46:48 +01:00
|
|
|
if (view->isAvailable()) {
|
2022-01-16 00:48:35 +01:00
|
|
|
ImGui::SetNextWindowSizeConstraints(scaled(view->getMinSize()), scaled(view->getMaxSize()));
|
2021-12-12 21:46:48 +01:00
|
|
|
view->drawContent();
|
|
|
|
}
|
2021-12-12 00:41:44 +01:00
|
|
|
|
2021-12-31 01:10:06 +01:00
|
|
|
if (view->getWindowOpenState()) {
|
2022-01-18 00:10:10 +01:00
|
|
|
auto window = ImGui::FindWindowByName(view->getName().c_str());
|
2022-01-11 20:29:06 +01:00
|
|
|
bool hasWindow = window != nullptr;
|
2021-12-23 15:11:38 +01:00
|
|
|
bool focused = false;
|
|
|
|
|
2022-01-11 20:29:06 +01:00
|
|
|
|
|
|
|
if (hasWindow && !(window->Flags & ImGuiWindowFlags_Popup)) {
|
2022-01-18 00:10:10 +01:00
|
|
|
ImGui::Begin(View::toWindowName(name).c_str());
|
2021-12-31 11:01:22 +01:00
|
|
|
|
2022-01-29 21:48:59 +01:00
|
|
|
focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
|
2021-12-23 15:11:38 +01:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &io = ImGui::GetIO();
|
|
|
|
for (const auto &key : this->m_pressedKeys) {
|
|
|
|
ShortcutManager::process(view, io.KeyCtrl, io.KeyAlt, io.KeyShift, io.KeySuper, focused, key);
|
|
|
|
}
|
|
|
|
}
|
2021-06-07 18:14:40 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
this->m_pressedKeys.clear();
|
2021-06-07 18:14:40 +02:00
|
|
|
}
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
void Window::frameEnd() {
|
2022-01-18 00:10:10 +01:00
|
|
|
EventManager::post<EventFrameEnd>();
|
|
|
|
|
2021-12-10 16:09:55 +01:00
|
|
|
this->endNativeWindowFrame();
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui::Render();
|
2020-11-17 13:58:50 +01:00
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
int displayWidth, displayHeight;
|
|
|
|
glfwGetFramebufferSize(this->m_window, &displayWidth, &displayHeight);
|
|
|
|
glViewport(0, 0, displayWidth, displayHeight);
|
2020-11-10 15:26:38 +01:00
|
|
|
glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
GLFWwindow *backup_current_context = glfwGetCurrentContext();
|
2020-11-23 15:51:40 +01:00
|
|
|
ImGui::UpdatePlatformWindows();
|
|
|
|
ImGui::RenderPlatformWindowsDefault();
|
|
|
|
glfwMakeContextCurrent(backup_current_context);
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
glfwSwapBuffers(this->m_window);
|
2021-03-06 13:09:20 +01:00
|
|
|
|
2021-10-23 12:59:13 +02:00
|
|
|
if (this->m_targetFps <= 200)
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(u64((this->m_lastFrameTime + 1 / this->m_targetFps - glfwGetTime()) * 1000)));
|
|
|
|
|
2021-03-06 13:09:20 +01:00
|
|
|
this->m_lastFrameTime = glfwGetTime();
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 01:10:13 +01:00
|
|
|
void Window::drawWelcomeScreen() {
|
2021-02-18 12:09:19 +01:00
|
|
|
const auto availableSpace = ImGui::GetContentRegionAvail();
|
2021-01-27 12:04:42 +01:00
|
|
|
|
2021-08-31 15:22:00 +02:00
|
|
|
ImGui::Image(this->m_bannerTexture, this->m_bannerTexture.size() / (2 * (1.0F / SharedData::globalScale)));
|
2021-07-29 00:39:58 +02:00
|
|
|
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::Indent();
|
2021-07-29 00:39:58 +02:00
|
|
|
if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, 0))) {
|
|
|
|
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 3);
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
2022-01-15 14:14:53 +01:00
|
|
|
ImGui::TextFormattedWrapped("A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.");
|
2021-07-29 00:39:58 +02:00
|
|
|
|
2021-12-08 22:18:59 +01:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 6);
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-07-29 00:39:58 +02:00
|
|
|
|
|
|
|
|
2021-08-22 22:11:55 +02:00
|
|
|
ImGui::UnderlinedText("hex.welcome.header.start"_lang);
|
2022-01-11 23:48:18 +01:00
|
|
|
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
|
2021-01-27 12:04:42 +01:00
|
|
|
{
|
2021-08-04 14:01:24 +02:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_NEW_FILE, "hex.welcome.start.create_file"_lang))
|
2021-07-27 21:07:36 +02:00
|
|
|
EventManager::post<RequestOpenWindow>("Create File");
|
2021-08-04 14:01:24 +02:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_GO_TO_FILE, "hex.welcome.start.open_file"_lang))
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<RequestOpenWindow>("Open File");
|
2021-08-04 14:01:24 +02:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_NOTEBOOK, "hex.welcome.start.open_project"_lang))
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<RequestOpenWindow>("Open Project");
|
2021-12-07 22:47:41 +01:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_TELESCOPE, "hex.welcome.start.open_other"_lang))
|
|
|
|
ImGui::OpenPopup("hex.welcome.start.popup.open_other"_lang);
|
|
|
|
}
|
|
|
|
|
2021-12-08 22:18:59 +01:00
|
|
|
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + ImGui::GetCursorPos());
|
2021-12-07 22:47:41 +01:00
|
|
|
if (ImGui::BeginPopup("hex.welcome.start.popup.open_other"_lang)) {
|
2021-12-08 22:18:59 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
for (const auto &unlocalizedProviderName : ContentRegistry::Provider::getEntries()) {
|
|
|
|
if (ImGui::Hyperlink(LangEntry(unlocalizedProviderName))) {
|
|
|
|
EventManager::post<RequestCreateProvider>(unlocalizedProviderName, nullptr);
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
2021-01-27 12:04:42 +01:00
|
|
|
}
|
2021-02-19 13:22:12 +01:00
|
|
|
|
2021-04-18 20:24:42 +02:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 9);
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-08-22 22:11:55 +02:00
|
|
|
ImGui::UnderlinedText("hex.welcome.start.recent"_lang);
|
2022-01-11 23:48:18 +01:00
|
|
|
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
|
2021-01-27 12:04:42 +01:00
|
|
|
{
|
2021-04-13 08:41:59 +02:00
|
|
|
if (!SharedData::recentFilePaths.empty()) {
|
|
|
|
for (auto &path : SharedData::recentFilePaths) {
|
2022-01-13 14:33:30 +01:00
|
|
|
if (ImGui::BulletHyperlink(fs::path(path).filename().string().c_str())) {
|
2021-09-08 15:18:24 +02:00
|
|
|
EventManager::post<RequestOpenFile>(path);
|
2021-02-01 19:03:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 12:04:42 +01:00
|
|
|
}
|
2021-02-19 13:22:12 +01:00
|
|
|
|
2021-04-18 20:24:42 +02:00
|
|
|
if (!this->m_availableUpdate.empty()) {
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
|
|
|
ImGui::TableNextColumn();
|
2021-08-22 22:11:55 +02:00
|
|
|
ImGui::UnderlinedText("hex.welcome.header.update"_lang);
|
2021-04-18 20:24:42 +02:00
|
|
|
{
|
|
|
|
if (ImGui::DescriptionButton("hex.welcome.update.title"_lang, hex::format("hex.welcome.update.desc"_lang, this->m_availableUpdate).c_str(), ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
|
|
|
hex::openWebpage("hex.welcome.update.link"_lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 21:38:52 +01:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 6);
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::TableNextColumn();
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGui::UnderlinedText("hex.welcome.header.help"_lang);
|
2022-01-11 23:48:18 +01:00
|
|
|
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
|
2021-01-27 12:04:42 +01:00
|
|
|
{
|
2021-08-04 14:01:24 +02:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_GITHUB, "hex.welcome.help.repo"_lang)) hex::openWebpage("hex.welcome.help.repo.link"_lang);
|
|
|
|
if (ImGui::IconHyperlink(ICON_VS_ORGANIZATION, "hex.welcome.help.gethelp"_lang)) hex::openWebpage("hex.welcome.help.gethelp.link"_lang);
|
2021-12-20 21:38:52 +01:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_COMMENT_DISCUSSION, "hex.welcome.help.discord"_lang)) hex::openWebpage("hex.welcome.help.discord.link"_lang);
|
2021-01-27 12:04:42 +01:00
|
|
|
}
|
|
|
|
|
2021-04-18 20:24:42 +02:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
2021-02-19 13:22:12 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-08-22 22:11:55 +02:00
|
|
|
ImGui::UnderlinedText("hex.welcome.header.plugins"_lang);
|
2021-02-19 13:22:12 +01:00
|
|
|
{
|
2021-04-20 21:46:48 +02:00
|
|
|
const auto &plugins = PluginManager::getPlugins();
|
2021-02-19 13:22:12 +01:00
|
|
|
|
2021-04-21 23:31:51 +02:00
|
|
|
if (!plugins.empty()) {
|
2022-01-23 23:28:56 +01:00
|
|
|
if (ImGui::BeginTable("plugins", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit, ImVec2((ImGui::GetContentRegionAvail().x * 5) / 6, ImGui::GetTextLineHeightWithSpacing() * 5))) {
|
2021-02-19 13:22:12 +01:00
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2022-01-23 23:28:56 +01:00
|
|
|
ImGui::TableSetupColumn("hex.welcome.plugins.plugin"_lang, ImGuiTableColumnFlags_WidthStretch, 0.2);
|
|
|
|
ImGui::TableSetupColumn("hex.welcome.plugins.author"_lang, ImGuiTableColumnFlags_WidthStretch, 0.2);
|
|
|
|
ImGui::TableSetupColumn("hex.welcome.plugins.desc"_lang, ImGuiTableColumnFlags_WidthStretch, 0.6);
|
|
|
|
ImGui::TableSetupColumn("##loaded", ImGuiTableColumnFlags_WidthFixed, ImGui::GetTextLineHeight());
|
2021-02-19 13:22:12 +01:00
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
ImGuiListClipper clipper;
|
|
|
|
clipper.Begin(plugins.size());
|
|
|
|
|
|
|
|
while (clipper.Step()) {
|
|
|
|
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
2022-01-23 23:28:56 +01:00
|
|
|
const auto &plugin = plugins[i];
|
|
|
|
|
2021-02-19 13:22:12 +01:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
2022-01-23 23:28:56 +01:00
|
|
|
ImGui::TextUnformatted(plugin.getPluginName().c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(plugin.getPluginAuthor().c_str());
|
2021-02-19 13:22:12 +01:00
|
|
|
ImGui::TableNextColumn();
|
2022-01-23 23:28:56 +01:00
|
|
|
ImGui::TextUnformatted(plugin.getPluginDescription().c_str());
|
2021-02-19 13:22:12 +01:00
|
|
|
ImGui::TableNextColumn();
|
2022-01-23 23:28:56 +01:00
|
|
|
ImGui::TextUnformatted(plugin.isLoaded() ? ICON_VS_CHECK : ICON_VS_CLOSE);
|
2021-02-19 13:22:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clipper.End();
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2021-07-29 00:39:58 +02:00
|
|
|
if (ImGui::BeginTable("Welcome Right", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, 0))) {
|
2021-04-18 20:24:42 +02:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-08-22 22:11:55 +02:00
|
|
|
ImGui::UnderlinedText("hex.welcome.header.customize"_lang);
|
2021-01-27 12:04:42 +01:00
|
|
|
{
|
2021-02-18 12:09:19 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.welcome.customize.settings.title"_lang, "hex.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
2021-04-18 20:24:42 +02:00
|
|
|
EventManager::post<RequestOpenWindow>("Settings");
|
2021-01-27 12:04:42 +01:00
|
|
|
}
|
2021-04-18 20:24:42 +02:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-08-22 22:11:55 +02:00
|
|
|
ImGui::UnderlinedText("hex.welcome.header.learn"_lang);
|
2021-01-27 12:04:42 +01:00
|
|
|
{
|
2021-02-18 12:09:19 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.welcome.learn.latest.title"_lang, "hex.welcome.learn.latest.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
2021-02-11 23:09:45 +01:00
|
|
|
hex::openWebpage("hex.welcome.learn.latest.link"_lang);
|
2021-02-18 12:09:19 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.welcome.learn.pattern.title"_lang, "hex.welcome.learn.pattern.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
2021-02-11 23:09:45 +01:00
|
|
|
hex::openWebpage("hex.welcome.learn.pattern.link"_lang);
|
2021-02-18 12:09:19 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.welcome.learn.plugins.title"_lang, "hex.welcome.learn.plugins.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
2021-02-11 23:09:45 +01:00
|
|
|
hex::openWebpage("hex.welcome.learn.plugins.link"_lang);
|
2021-01-27 12:04:42 +01:00
|
|
|
}
|
|
|
|
|
2021-02-18 12:09:19 +01:00
|
|
|
auto extraWelcomeScreenEntries = ContentRegistry::Interface::getWelcomeScreenEntries();
|
|
|
|
if (!extraWelcomeScreenEntries.empty()) {
|
2021-04-18 20:24:42 +02:00
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
2021-02-18 12:09:19 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-08-22 22:11:55 +02:00
|
|
|
ImGui::UnderlinedText("hex.welcome.header.various"_lang);
|
2021-02-18 12:09:19 +01:00
|
|
|
{
|
|
|
|
for (const auto &callback : extraWelcomeScreenEntries)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
2021-01-27 01:10:13 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
void Window::resetLayout() const {
|
2021-02-21 13:49:03 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
if (auto &layouts = ContentRegistry::Interface::getLayouts(); !layouts.empty()) {
|
|
|
|
auto &[name, function] = layouts[0];
|
2021-02-21 13:49:03 +01:00
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
function(ContentRegistry::Interface::getDockSpaceId());
|
|
|
|
}
|
2021-02-21 13:49:03 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 08:56:49 +01:00
|
|
|
void Window::initGLFW() {
|
2022-01-24 20:53:17 +01:00
|
|
|
glfwSetErrorCallback([](int error, const char *desc) {
|
2021-06-20 21:22:31 +02:00
|
|
|
log::error("GLFW Error [{}] : {}", error, desc);
|
2020-11-11 14:41:44 +01:00
|
|
|
});
|
|
|
|
|
2022-01-13 14:34:27 +01:00
|
|
|
if (!glfwInit()) {
|
|
|
|
log::fatal("Failed to initialize GLFW!");
|
|
|
|
std::abort();
|
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
|
|
|
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
|
|
|
#elif defined(OS_MACOS)
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
|
|
#endif
|
2020-11-10 15:26:38 +01:00
|
|
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
2020-11-11 14:41:44 +01:00
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
2021-04-21 20:06:48 +02:00
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
2021-11-28 11:57:52 +01:00
|
|
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
2020-11-30 00:03:12 +01:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
this->m_windowTitle = "ImHex";
|
2022-01-11 23:48:18 +01:00
|
|
|
this->m_window = glfwCreateWindow(1280_scaled, 720_scaled, this->m_windowTitle.c_str(), nullptr, nullptr);
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2021-06-07 18:14:40 +02:00
|
|
|
glfwSetWindowUserPointer(this->m_window, this);
|
2020-11-23 23:57:19 +01:00
|
|
|
|
2022-01-13 14:34:27 +01:00
|
|
|
if (this->m_window == nullptr) {
|
|
|
|
log::fatal("Failed to create window!");
|
|
|
|
std::abort();
|
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
|
|
|
|
glfwMakeContextCurrent(this->m_window);
|
|
|
|
glfwSwapInterval(1);
|
|
|
|
|
2021-11-28 11:57:52 +01:00
|
|
|
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
|
|
|
if (monitor != nullptr) {
|
|
|
|
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
|
|
|
if (mode != nullptr) {
|
|
|
|
int monitorX, monitorY;
|
|
|
|
glfwGetMonitorPos(monitor, &monitorX, &monitorY);
|
|
|
|
|
|
|
|
int windowWidth, windowHeight;
|
|
|
|
glfwGetWindowSize(this->m_window, &windowWidth, &windowHeight);
|
|
|
|
|
|
|
|
glfwSetWindowPos(this->m_window, monitorX + (mode->width - windowWidth) / 2, monitorY + (mode->height - windowHeight) / 2);
|
|
|
|
}
|
|
|
|
}
|
2021-11-28 01:17:48 +01:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
{
|
|
|
|
int x = 0, y = 0;
|
|
|
|
glfwGetWindowPos(this->m_window, &x, &y);
|
|
|
|
SharedData::windowPos = ImVec2(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int width = 0, height = 0;
|
|
|
|
glfwGetWindowSize(this->m_window, &width, &height);
|
|
|
|
glfwSetWindowSize(this->m_window, width, height);
|
|
|
|
SharedData::windowSize = ImVec2(width, height);
|
|
|
|
}
|
2020-12-16 22:43:07 +01:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
glfwSetWindowPosCallback(this->m_window, [](GLFWwindow *window, int x, int y) {
|
|
|
|
SharedData::windowPos = ImVec2(x, y);
|
2020-12-16 22:43:07 +01:00
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return;
|
2021-06-07 18:14:40 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
|
2021-08-18 22:36:46 +02:00
|
|
|
win->frameBegin();
|
|
|
|
win->frame();
|
|
|
|
win->frameEnd();
|
|
|
|
});
|
2020-12-16 22:43:07 +01:00
|
|
|
|
|
|
|
glfwSetWindowSizeCallback(this->m_window, [](GLFWwindow *window, int width, int height) {
|
2021-01-12 23:28:41 +01:00
|
|
|
SharedData::windowSize = ImVec2(width, height);
|
2021-06-07 18:14:40 +02:00
|
|
|
|
2021-08-21 13:55:21 +02:00
|
|
|
if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return;
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
|
2021-06-07 18:14:40 +02:00
|
|
|
win->frameBegin();
|
|
|
|
win->frame();
|
|
|
|
win->frameEnd();
|
2020-12-16 22:43:07 +01:00
|
|
|
});
|
|
|
|
|
2020-11-11 14:41:44 +01:00
|
|
|
glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) {
|
2021-03-26 21:40:35 +01:00
|
|
|
auto keyName = glfwGetKeyName(key, scancode);
|
|
|
|
if (keyName != nullptr)
|
|
|
|
key = std::toupper(keyName[0]);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
|
2021-12-23 15:11:38 +01:00
|
|
|
|
2021-01-21 15:02:49 +01:00
|
|
|
if (action == GLFW_PRESS) {
|
|
|
|
auto &io = ImGui::GetIO();
|
2021-12-23 15:11:38 +01:00
|
|
|
|
|
|
|
win->m_pressedKeys.push_back(key);
|
2021-01-21 15:02:49 +01:00
|
|
|
io.KeysDown[key] = true;
|
2022-01-24 20:53:17 +01:00
|
|
|
io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0;
|
2021-01-21 15:02:49 +01:00
|
|
|
io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0;
|
2022-01-24 20:53:17 +01:00
|
|
|
io.KeyAlt = (mods & GLFW_MOD_ALT) != 0;
|
|
|
|
} else if (action == GLFW_RELEASE) {
|
2021-01-21 15:02:49 +01:00
|
|
|
auto &io = ImGui::GetIO();
|
|
|
|
io.KeysDown[key] = false;
|
2022-01-24 20:53:17 +01:00
|
|
|
io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0;
|
2021-01-21 15:02:49 +01:00
|
|
|
io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0;
|
2022-01-24 20:53:17 +01:00
|
|
|
io.KeyAlt = (mods & GLFW_MOD_ALT) != 0;
|
2021-01-21 15:02:49 +01:00
|
|
|
}
|
2020-11-11 14:41:44 +01:00
|
|
|
});
|
|
|
|
|
2020-11-17 13:58:50 +01:00
|
|
|
glfwSetDropCallback(this->m_window, [](GLFWwindow *window, int count, const char **paths) {
|
|
|
|
if (count != 1)
|
|
|
|
return;
|
|
|
|
|
2021-09-26 21:17:46 +02:00
|
|
|
for (u32 i = 0; i < count; i++) {
|
|
|
|
auto path = std::filesystem::path(paths[i]);
|
|
|
|
|
2022-01-13 14:34:27 +01:00
|
|
|
bool handled = false;
|
|
|
|
for (const auto &[extensions, handler] : ContentRegistry::FileHandler::getEntries()) {
|
|
|
|
for (const auto &extension : extensions) {
|
|
|
|
if (path.extension() == extension) {
|
|
|
|
if (!handler(path))
|
|
|
|
View::showMessagePopup("hex.message.file_handler_failed"_lang);
|
|
|
|
|
|
|
|
handled = true;
|
2021-09-26 21:17:46 +02:00
|
|
|
break;
|
2021-09-30 12:29:03 +02:00
|
|
|
}
|
2021-09-26 21:17:46 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-13 14:34:27 +01:00
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
EventManager::post<RequestOpenFile>(path.string());
|
2021-09-26 21:17:46 +02:00
|
|
|
}
|
2020-11-17 13:58:50 +01:00
|
|
|
});
|
|
|
|
|
2020-11-30 00:03:12 +01:00
|
|
|
glfwSetWindowCloseCallback(this->m_window, [](GLFWwindow *window) {
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<EventWindowClosing>(window);
|
2020-11-30 00:03:12 +01:00
|
|
|
});
|
|
|
|
|
2022-01-11 23:48:18 +01:00
|
|
|
glfwSetWindowSizeLimits(this->m_window, 720_scaled, 480_scaled, GLFW_DONT_CARE, GLFW_DONT_CARE);
|
2021-11-28 11:57:52 +01:00
|
|
|
|
|
|
|
glfwShowWindow(this->m_window);
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::initImGui() {
|
|
|
|
IMGUI_CHECKVERSION();
|
2021-02-03 00:56:33 +01:00
|
|
|
|
2021-08-31 15:22:00 +02:00
|
|
|
GImGui = ImGui::CreateContext(SharedData::fontAtlas);
|
2021-03-02 13:48:23 +01:00
|
|
|
GImPlot = ImPlot::CreateContext();
|
2021-08-17 13:39:46 +02:00
|
|
|
GImNodes = ImNodes::CreateContext();
|
2021-02-03 00:56:33 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
2020-11-23 15:51:40 +01:00
|
|
|
|
2021-08-21 00:52:11 +02:00
|
|
|
style.Alpha = 1.0F;
|
|
|
|
style.WindowRounding = 0.0F;
|
|
|
|
|
2021-02-18 17:10:56 +01:00
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableKeyboard;
|
2022-01-24 20:53:17 +01:00
|
|
|
#if !defined(OS_LINUX)
|
2021-08-18 22:36:46 +02:00
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
2022-01-24 20:53:17 +01:00
|
|
|
#endif
|
2021-02-18 17:10:56 +01:00
|
|
|
|
2021-08-31 15:22:00 +02:00
|
|
|
for (auto &entry : SharedData::fontAtlas->ConfigData)
|
|
|
|
io.Fonts->ConfigData.push_back(entry);
|
2021-02-18 17:10:56 +01:00
|
|
|
|
2022-01-11 16:02:05 +01:00
|
|
|
io.ConfigViewportsNoTaskBarIcon = false;
|
2022-01-24 20:53:17 +01:00
|
|
|
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB;
|
|
|
|
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
|
|
|
|
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
|
|
|
|
io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
|
|
|
|
io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
|
|
|
|
io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP;
|
|
|
|
io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN;
|
|
|
|
io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
|
|
|
|
io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
|
|
|
|
io.KeyMap[ImGuiKey_Insert] = GLFW_KEY_INSERT;
|
|
|
|
io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
|
|
|
|
io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
|
|
|
|
io.KeyMap[ImGuiKey_Space] = GLFW_KEY_SPACE;
|
|
|
|
io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
|
|
|
|
io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
|
2021-01-21 15:02:49 +01:00
|
|
|
io.KeyMap[ImGuiKey_KeyPadEnter] = GLFW_KEY_KP_ENTER;
|
2022-01-24 20:53:17 +01:00
|
|
|
io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
|
|
|
|
io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
|
|
|
|
io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
|
|
|
|
io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
|
|
|
|
io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
|
|
|
|
io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
|
2020-11-23 15:51:40 +01:00
|
|
|
|
2021-08-17 13:39:46 +02:00
|
|
|
ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick);
|
|
|
|
ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkCreationOnSnap);
|
|
|
|
|
|
|
|
{
|
|
|
|
static bool always = true;
|
|
|
|
ImNodes::GetIO().LinkDetachWithModifierClick.Modifier = &always;
|
|
|
|
}
|
|
|
|
|
2021-02-25 00:17:41 +01:00
|
|
|
io.UserData = new ImGui::ImHexCustomData();
|
|
|
|
|
2021-08-31 15:22:00 +02:00
|
|
|
style.ScaleAllSizes(SharedData::globalScale);
|
2020-12-11 14:24:42 +01:00
|
|
|
|
2021-08-31 15:22:00 +02:00
|
|
|
{
|
|
|
|
GLsizei width, height;
|
|
|
|
u8 *fontData;
|
|
|
|
|
|
|
|
io.Fonts->GetTexDataAsRGBA32(&fontData, &width, &height);
|
|
|
|
|
|
|
|
// Create new font atlas
|
|
|
|
GLuint tex;
|
|
|
|
glGenTextures(1, &tex);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA8, GL_UNSIGNED_INT, fontData);
|
|
|
|
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(tex));
|
2021-03-01 08:56:49 +01:00
|
|
|
}
|
2020-12-11 14:24:42 +01:00
|
|
|
|
2020-11-23 15:51:40 +01:00
|
|
|
style.WindowMenuButtonPosition = ImGuiDir_None;
|
2020-11-23 22:14:11 +01:00
|
|
|
style.IndentSpacing = 10.0F;
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2020-11-15 15:49:21 +01:00
|
|
|
// Install custom settings handler
|
|
|
|
ImGuiSettingsHandler handler;
|
|
|
|
handler.TypeName = "ImHex";
|
|
|
|
handler.TypeHash = ImHashStr("ImHex");
|
|
|
|
handler.ReadOpenFn = ImHexSettingsHandler_ReadOpenFn;
|
|
|
|
handler.ReadLineFn = ImHexSettingsHandler_ReadLine;
|
|
|
|
handler.WriteAllFn = ImHexSettingsHandler_WriteAll;
|
2022-01-24 20:53:17 +01:00
|
|
|
handler.UserData = this;
|
2021-02-18 17:10:56 +01:00
|
|
|
ImGui::GetCurrentContext()->SettingsHandlers.push_back(handler);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-03-01 08:56:49 +01:00
|
|
|
static std::string iniFileName;
|
|
|
|
for (const auto &dir : hex::getPath(ImHexPath::Config)) {
|
|
|
|
if (std::filesystem::exists(dir)) {
|
2022-01-13 14:33:30 +01:00
|
|
|
iniFileName = (dir / "interface.ini").string();
|
2021-03-01 08:56:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
io.IniFilename = iniFileName.c_str();
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui_ImplGlfw_InitForOpenGL(this->m_window, true);
|
2021-04-21 20:06:48 +02:00
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui_ImplOpenGL3_Init("#version 150");
|
2021-08-21 00:52:11 +02:00
|
|
|
|
|
|
|
for (const auto &plugin : PluginManager::getPlugins())
|
|
|
|
plugin.setImGuiContext(ImGui::GetCurrentContext());
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
void Window::exitGLFW() {
|
2020-11-10 15:26:38 +01:00
|
|
|
glfwDestroyWindow(this->m_window);
|
|
|
|
glfwTerminate();
|
|
|
|
}
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
void Window::exitImGui() {
|
2022-01-24 20:53:17 +01:00
|
|
|
delete static_cast<ImGui::ImHexCustomData *>(ImGui::GetIO().UserData);
|
2021-02-25 00:17:41 +01:00
|
|
|
|
2021-08-17 13:39:46 +02:00
|
|
|
ImNodes::PopAttributeFlag();
|
|
|
|
ImNodes::PopAttributeFlag();
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
2021-08-17 13:39:46 +02:00
|
|
|
ImNodes::DestroyContext();
|
2021-03-02 13:48:23 +01:00
|
|
|
ImPlot::DestroyContext();
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui::DestroyContext();
|
|
|
|
}
|
|
|
|
|
2021-06-18 20:09:36 +02:00
|
|
|
}
|