2020-11-10 15:26:38 +01:00
|
|
|
#include "window.hpp"
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
#include <hex.hpp>
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-03-06 13:09:20 +01:00
|
|
|
#include <chrono>
|
2020-11-10 15:26:38 +01:00
|
|
|
#include <iostream>
|
2020-12-11 14:24:42 +01:00
|
|
|
#include <numeric>
|
2021-02-11 23:09:45 +01:00
|
|
|
#include <typeinfo>
|
2021-03-06 13:09:20 +01:00
|
|
|
#include <thread>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
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-01-27 12:04:42 +01:00
|
|
|
#include <imgui_imhex_extensions.h>
|
2021-03-02 13:48:23 +01:00
|
|
|
#include <implot.h>
|
|
|
|
#include <implot_internal.h>
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-02-24 22:42:26 +01:00
|
|
|
#include <fontawesome_font.h>
|
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
#include "helpers/plugin_manager.hpp"
|
|
|
|
#include "init/tasks.hpp"
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
#include <glad/glad.h>
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
|
|
|
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 *) {
|
|
|
|
return ctx; // Unused, but the return value has to be non-null
|
|
|
|
}
|
2020-11-15 15:49:21 +01:00
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
void ImHexSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler *handler, void *, const char* line) {
|
2021-01-12 16:50:15 +01:00
|
|
|
for (auto &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
|
|
|
|
2020-11-23 23:57:19 +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
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
for (auto &view : ContentRegistry::Views::getEntries()) {
|
2021-04-12 21:08:36 +02:00
|
|
|
buf->appendf("%s=%d\n", view->getUnlocalizedName().data(), 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-03-09 19:32:04 +01:00
|
|
|
SharedData::currentProvider = nullptr;
|
2021-01-12 16:50:15 +01:00
|
|
|
|
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") {
|
2021-04-21 23:31:51 +02:00
|
|
|
View::doLater([]{ ImGui::OpenPopup("No Plugins"); });
|
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-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-03-06 12:40:29 +01:00
|
|
|
if (theme.is_number()) {
|
|
|
|
switch (static_cast<int>(theme)) {
|
2021-02-16 23:42:35 +01:00
|
|
|
default:
|
|
|
|
case 0: /* Dark theme */
|
|
|
|
ImGui::StyleColorsDark();
|
2021-02-25 00:17:41 +01:00
|
|
|
ImGui::StyleCustomColorsDark();
|
2021-03-02 13:48:23 +01:00
|
|
|
ImPlot::StyleColorsDark();
|
2021-02-16 23:42:35 +01:00
|
|
|
break;
|
|
|
|
case 1: /* Light theme */
|
|
|
|
ImGui::StyleColorsLight();
|
2021-02-25 00:17:41 +01:00
|
|
|
ImGui::StyleCustomColorsLight();
|
2021-03-02 13:48:23 +01:00
|
|
|
ImPlot::StyleColorsLight();
|
2021-02-16 23:42:35 +01:00
|
|
|
break;
|
|
|
|
case 2: /* Classic theme */
|
|
|
|
ImGui::StyleColorsClassic();
|
2021-02-25 00:17:41 +01:00
|
|
|
ImGui::StyleCustomColorsClassic();
|
2021-03-02 13:48:23 +01:00
|
|
|
ImPlot::StyleColorsClassic();
|
2021-02-16 23:42:35 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ImGui::GetStyle().Colors[ImGuiCol_DockingEmptyBg] = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
|
2021-02-10 18:17:09 +01: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-03-27 11:36:36 +01:00
|
|
|
EventManager::subscribe<EventFileLoaded>(this, [this](const std::string &path){
|
2021-04-13 08:41:59 +02:00
|
|
|
SharedData::recentFilePaths.push_front(path);
|
2021-02-01 19:03:45 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
std::list<std::string> 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
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;
|
2021-04-13 08:41:59 +02:00
|
|
|
std::copy(SharedData::recentFilePaths.begin(), SharedData::recentFilePaths.end(), std::back_inserter(recentFilesVector));
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::subscribe<RequestCloseImHex>(this, [this]() {
|
2021-02-01 19:03:45 +01:00
|
|
|
glfwSetWindowShouldClose(this->m_window, true);
|
|
|
|
});
|
|
|
|
|
2021-03-29 22:44:23 +02:00
|
|
|
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](std::string windowTitle) {
|
|
|
|
if (windowTitle.empty())
|
|
|
|
glfwSetWindowTitle(this->m_window, "ImHex");
|
|
|
|
else
|
|
|
|
glfwSetWindowTitle(this->m_window, ("ImHex - " + windowTitle).c_str());
|
|
|
|
});
|
|
|
|
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<EventSettingsChanged>();
|
2021-02-01 19:03:45 +01: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);
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window() {
|
2021-03-09 19:32:04 +01:00
|
|
|
delete SharedData::currentProvider;
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
this->deinitImGui();
|
|
|
|
this->deinitGLFW();
|
2021-01-30 23:02:03 +01:00
|
|
|
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::unsubscribe<EventSettingsChanged>(this);
|
|
|
|
EventManager::unsubscribe<EventFileLoaded>(this);
|
|
|
|
EventManager::unsubscribe<RequestCloseImHex>(this);
|
2021-03-29 22:44:23 +02:00
|
|
|
EventManager::unsubscribe<RequestChangeWindowTitle>(this);
|
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-06-07 18:14:40 +02:00
|
|
|
if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED))
|
|
|
|
glfwWaitEvents();
|
2021-07-27 21:50:49 +02:00
|
|
|
else
|
|
|
|
glfwWaitEventsTimeout(this->m_lastFrameTime - glfwGetTime() + 1 / 5.0);
|
2020-12-22 18:10:01 +01:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-11 14:24:42 +01:00
|
|
|
bool Window::setFont(const std::filesystem::path &path) {
|
|
|
|
if (!std::filesystem::exists(path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto &io = ImGui::GetIO();
|
|
|
|
|
|
|
|
// If we have a custom font, then rescaling is unnecessary and will make it blurry
|
|
|
|
io.FontGlobalScale = 1.0f;
|
|
|
|
|
|
|
|
// Load font data & build atlas
|
|
|
|
std::uint8_t *px;
|
|
|
|
int w, h;
|
2021-02-14 11:51:05 +01:00
|
|
|
|
|
|
|
ImVector<ImWchar> ranges;
|
|
|
|
ImFontGlyphRangesBuilder glyphRangesBuilder;
|
2021-02-24 22:42:26 +01:00
|
|
|
|
2021-02-14 11:51:05 +01:00
|
|
|
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesDefault());
|
|
|
|
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesJapanese());
|
|
|
|
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesChineseFull());
|
|
|
|
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesCyrillic());
|
|
|
|
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesKorean());
|
|
|
|
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesThai());
|
|
|
|
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesVietnamese());
|
|
|
|
glyphRangesBuilder.BuildRanges(&ranges);
|
|
|
|
|
2021-02-24 22:42:26 +01:00
|
|
|
ImWchar fontAwesomeRange[] = {
|
|
|
|
ICON_MIN_FA, ICON_MAX_FA,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
ImFontConfig cfg;
|
|
|
|
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
|
|
|
|
cfg.SizePixels = 13.0f * this->m_fontScale;
|
|
|
|
|
|
|
|
io.Fonts->AddFontFromFileTTF(path.string().c_str(), std::floor(14.0f * this->m_fontScale), &cfg, ranges.Data); // Needs conversion to char for Windows
|
|
|
|
cfg.MergeMode = true;
|
|
|
|
|
|
|
|
io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 13.0f * this->m_fontScale, &cfg, fontAwesomeRange);
|
|
|
|
|
2020-12-11 14:24:42 +01:00
|
|
|
ImGuiFreeType::BuildFontAtlas(io.Fonts, ImGuiFreeType::Monochrome);
|
|
|
|
io.Fonts->GetTexDataAsRGBA32(&px, &w, &h);
|
|
|
|
|
|
|
|
// 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, w, h, 0, GL_RGBA8, GL_UNSIGNED_INT, px);
|
|
|
|
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(tex));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
|
|
|
ImGui::SetNextWindowPos(viewport->GetWorkPos());
|
|
|
|
ImGui::SetNextWindowSize(viewport->GetWorkSize());
|
|
|
|
ImGui::SetNextWindowViewport(viewport->ID);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
2020-11-30 00:03:12 +01:00
|
|
|
|
|
|
|
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking
|
|
|
|
| ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse
|
|
|
|
| ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize
|
2021-02-18 12:09:19 +01:00
|
|
|
| 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)) {
|
|
|
|
ImGui::PopStyleVar(2);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-02-18 12:09:19 +01:00
|
|
|
ImGui::DockSpace(ImGui::GetID("MainDock"), ImVec2(0.0f, ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - 1));
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
for (const auto &callback : ContentRegistry::Interface::getFooterItems()) {
|
|
|
|
auto prevIdx = ImGui::GetWindowDrawList()->_VtxCurrentIdx;
|
|
|
|
callback();
|
|
|
|
auto currIdx = ImGui::GetWindowDrawList()->_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
|
|
|
|
2021-02-18 12:09:19 +01:00
|
|
|
if (ImGui::BeginMenuBar()) {
|
|
|
|
|
|
|
|
for (const auto& menu : { "hex.menu.file"_lang, "hex.menu.edit"_lang, "hex.menu.view"_lang, "hex.menu.help"_lang })
|
2020-11-23 23:57:19 +01:00
|
|
|
if (ImGui::BeginMenu(menu)) ImGui::EndMenu();
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BeginMenu("hex.menu.view"_lang)) {
|
2021-01-12 16:50:15 +01:00
|
|
|
for (auto &view : ContentRegistry::Views::getEntries()) {
|
2021-01-31 00:04:33 +01:00
|
|
|
if (view->hasViewMenuItemEntry())
|
2021-03-03 22:26:17 +01:00
|
|
|
ImGui::MenuItem((LangEntry(view->getUnlocalizedName()) + " " + "hex.menu.view"_lang).c_str(), "", &view->getWindowOpenState());
|
2020-11-28 22:01:50 +01:00
|
|
|
}
|
2020-11-23 23:57:19 +01:00
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2020-11-11 09:22:55 +01:00
|
|
|
|
2021-01-12 16:50:15 +01:00
|
|
|
for (auto &view : ContentRegistry::Views::getEntries()) {
|
2020-12-22 18:10:01 +01:00
|
|
|
view->drawMenu();
|
2020-11-23 23:57:19 +01:00
|
|
|
}
|
2020-11-11 11:56:37 +01:00
|
|
|
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BeginMenu("hex.menu.view"_lang)) {
|
2021-06-07 18:13:54 +02:00
|
|
|
#if defined(DEBUG)
|
|
|
|
ImGui::Separator();
|
2021-02-11 23:09:45 +01:00
|
|
|
ImGui::MenuItem("hex.menu.view.demo"_lang, "", &this->m_demoWindowOpen);
|
2020-11-23 23:57:19 +01:00
|
|
|
#endif
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
2020-11-11 09:22:55 +01:00
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
#if defined(DEBUG)
|
2021-04-21 23:31:51 +02:00
|
|
|
ImGui::SameLine();
|
2021-06-07 18:13:54 +02:00
|
|
|
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - 2 * ImGui::GetFontSize());
|
|
|
|
ImGui::TextUnformatted(ICON_FA_BUG);
|
|
|
|
#endif
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2020-11-23 23:57:19 +01:00
|
|
|
ImGui::EndMenuBar();
|
|
|
|
}
|
2020-11-11 14:41:44 +01:00
|
|
|
|
2021-02-21 13:49:03 +01:00
|
|
|
if (SharedData::currentProvider == nullptr) {
|
2021-01-27 01:10:13 +01:00
|
|
|
char title[256];
|
|
|
|
ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock"));
|
|
|
|
if (ImGui::Begin(title)) {
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10 * this->m_globalScale, 10 * this->m_globalScale));
|
2021-01-27 14:26:24 +01:00
|
|
|
if (ImGui::BeginChild("Welcome Screen", ImVec2(0, 0), false, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoDecoration)) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-11 14:41:44 +01:00
|
|
|
}
|
2020-11-23 23:57:19 +01:00
|
|
|
ImGui::End();
|
2021-04-21 23:31:51 +02:00
|
|
|
|
|
|
|
// Popup for when no plugins were loaded. Intentionally left untranslated because localization isn't available
|
|
|
|
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();
|
|
|
|
}
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:14:40 +02:00
|
|
|
void Window::frame() {
|
|
|
|
bool pressedKeys[512] = { false };
|
|
|
|
|
|
|
|
std::copy_n(ImGui::GetIO().KeysDown, 512, this->m_prevKeysDown);
|
|
|
|
for (u16 i = 0; i < 512; i++)
|
|
|
|
pressedKeys[i] = ImGui::GetIO().KeysDown[i] && !this->m_prevKeysDown[i];
|
|
|
|
|
|
|
|
for (const auto &call : View::getDeferedCalls())
|
|
|
|
call();
|
|
|
|
View::getDeferedCalls().clear();
|
|
|
|
|
|
|
|
for (auto &view : ContentRegistry::Views::getEntries()) {
|
|
|
|
view->drawAlwaysVisible();
|
|
|
|
|
|
|
|
if (!view->shouldProcess())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto minSize = view->getMinSize();
|
|
|
|
minSize.x *= this->m_globalScale;
|
|
|
|
minSize.y *= this->m_globalScale;
|
|
|
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints(minSize, view->getMaxSize());
|
|
|
|
view->drawContent();
|
|
|
|
view->handleShortcut(pressedKeys, ImGui::GetIO().KeyCtrl, ImGui::GetIO().KeyShift, ImGui::GetIO().KeyAlt);
|
|
|
|
}
|
|
|
|
|
|
|
|
View::drawCommonInterfaces();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (this->m_demoWindowOpen) {
|
|
|
|
ImGui::ShowDemoWindow(&this->m_demoWindowOpen);
|
|
|
|
ImPlot::ShowDemoWindow(&this->m_demoWindowOpen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
void Window::frameEnd() {
|
|
|
|
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());
|
|
|
|
|
2020-11-23 15:51:40 +01:00
|
|
|
GLFWwindow* backup_current_context = glfwGetCurrentContext();
|
|
|
|
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-07-27 21:50:49 +02:00
|
|
|
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
|
|
|
ImGui::UnderlinedText("hex.welcome.header.main"_lang, ImGui::GetStyleColorVec4(ImGuiCol_Text));
|
2021-01-27 12:04:42 +01:00
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
2021-02-18 12:09:19 +01:00
|
|
|
const auto availableSpace = ImGui::GetContentRegionAvail();
|
2021-01-27 12:04:42 +01:00
|
|
|
|
|
|
|
ImGui::Indent();
|
|
|
|
if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) {
|
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-02-18 12:09:19 +01:00
|
|
|
ImGui::TextUnformatted("hex.welcome.header.start"_lang);
|
2021-01-27 12:04:42 +01:00
|
|
|
{
|
2021-07-27 21:07:36 +02:00
|
|
|
if (ImGui::BulletHyperlink("hex.welcome.start.create_file"_lang))
|
|
|
|
EventManager::post<RequestOpenWindow>("Create File");
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BulletHyperlink("hex.welcome.start.open_file"_lang))
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<RequestOpenWindow>("Open File");
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BulletHyperlink("hex.welcome.start.open_project"_lang))
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<RequestOpenWindow>("Open Project");
|
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-02-18 12:09:19 +01:00
|
|
|
ImGui::TextUnformatted("hex.welcome.start.recent"_lang);
|
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) {
|
2021-02-01 19:03:45 +01:00
|
|
|
if (ImGui::BulletHyperlink(std::filesystem::path(path).filename().string().c_str())) {
|
2021-03-27 11:36:36 +01:00
|
|
|
EventManager::post<EventFileDropped>(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();
|
|
|
|
ImGui::TextUnformatted("hex.welcome.header.update"_lang);
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::TableNextColumn();
|
2021-02-18 12:09:19 +01:00
|
|
|
ImGui::TextUnformatted("hex.welcome.header.help"_lang);
|
2021-01-27 12:04:42 +01:00
|
|
|
{
|
2021-02-11 23:09:45 +01:00
|
|
|
if (ImGui::BulletHyperlink("hex.welcome.help.repo"_lang)) hex::openWebpage("hex.welcome.help.repo.link"_lang);
|
|
|
|
if (ImGui::BulletHyperlink("hex.welcome.help.gethelp"_lang)) hex::openWebpage("hex.welcome.help.gethelp.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();
|
|
|
|
ImGui::TextUnformatted("hex.welcome.header.plugins"_lang);
|
|
|
|
{
|
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()) {
|
2021-04-18 20:24:42 +02:00
|
|
|
if (ImGui::BeginTable("plugins", 3, 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);
|
|
|
|
ImGui::TableSetupColumn("hex.welcome.plugins.plugin"_lang);
|
|
|
|
ImGui::TableSetupColumn("hex.welcome.plugins.author"_lang);
|
|
|
|
ImGui::TableSetupColumn("hex.welcome.plugins.desc"_lang);
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
ImGuiListClipper clipper;
|
|
|
|
clipper.Begin(plugins.size());
|
|
|
|
|
|
|
|
while (clipper.Step()) {
|
|
|
|
for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted((plugins[i].getPluginName() + " ").c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted((plugins[i].getPluginAuthor() + " ").c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(plugins[i].getPluginDescription().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clipper.End();
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::BeginTable("Welcome Right", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, availableSpace.y))) {
|
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-02-18 12:09:19 +01:00
|
|
|
ImGui::TextUnformatted("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-02-18 12:09:19 +01:00
|
|
|
ImGui::TextUnformatted("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();
|
|
|
|
ImGui::TextUnformatted("hex.welcome.header.various"_lang);
|
|
|
|
{
|
|
|
|
for (const auto &callback : extraWelcomeScreenEntries)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-27 12:04:42 +01:00
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
2021-01-27 01:10:13 +01:00
|
|
|
}
|
|
|
|
|
2021-02-21 13:49:03 +01:00
|
|
|
void Window::resetLayout() {
|
|
|
|
auto dockId = ImGui::GetID("MainDock");
|
|
|
|
|
|
|
|
ImGui::DockBuilderRemoveNode(dockId);
|
|
|
|
ImGui::DockBuilderAddNode(dockId, ImGuiDockNodeFlags_DockSpace);
|
|
|
|
ImGui::DockBuilderSetNodeSize(dockId, ImGui::GetWindowSize());
|
|
|
|
|
|
|
|
ImGuiID mainWindowId, splitWindowId, hexEditorId, utilitiesId, inspectorId, patternDataId;
|
|
|
|
|
|
|
|
ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Left, 0.8, &mainWindowId, &utilitiesId);
|
|
|
|
ImGui::DockBuilderSplitNode(mainWindowId, ImGuiDir_Down, 0.3, &patternDataId, &splitWindowId);
|
|
|
|
ImGui::DockBuilderSplitNode(splitWindowId, ImGuiDir_Right, 0.3, &inspectorId, &hexEditorId);
|
|
|
|
|
|
|
|
for (auto &view : ContentRegistry::Views::getEntries())
|
2021-03-03 22:26:17 +01:00
|
|
|
ImGui::DockBuilderDockWindow(view->getUnlocalizedName().data(), utilitiesId);
|
2021-02-21 13:49:03 +01:00
|
|
|
|
2021-03-03 22:26:17 +01:00
|
|
|
ImGui::DockBuilderDockWindow("hex.view.hexeditor.name", hexEditorId);
|
|
|
|
ImGui::DockBuilderDockWindow("hex.view.data_inspector.name", inspectorId);
|
|
|
|
ImGui::DockBuilderDockWindow("hex.view.pattern_data.name", patternDataId);
|
2021-02-21 13:49:03 +01:00
|
|
|
|
|
|
|
ImGui::DockBuilderFinish(dockId);
|
|
|
|
}
|
|
|
|
|
2021-03-01 08:56:49 +01:00
|
|
|
void Window::initGLFW() {
|
2020-11-11 14:41:44 +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
|
|
|
});
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
if (!glfwInit())
|
|
|
|
throw std::runtime_error("Failed to initialize GLFW!");
|
|
|
|
|
2020-11-23 22:23:06 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
|
|
#endif
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2020-12-11 14:24:42 +01:00
|
|
|
if (auto *monitor = glfwGetPrimaryMonitor(); monitor) {
|
|
|
|
float xscale, yscale;
|
|
|
|
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
|
|
|
|
|
|
|
|
// In case the horizontal and vertical scale are different, fall back on the average
|
|
|
|
this->m_globalScale = this->m_fontScale = std::midpoint(xscale, yscale);
|
|
|
|
}
|
|
|
|
|
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);
|
2020-11-30 00:03:12 +01:00
|
|
|
|
2020-12-11 14:24:42 +01:00
|
|
|
this->m_window = glfwCreateWindow(1280 * this->m_globalScale, 720 * this->m_globalScale, "ImHex", nullptr, nullptr);
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-06-07 18:14:40 +02:00
|
|
|
glfwSetWindowUserPointer(this->m_window, this);
|
2020-11-23 23:57:19 +01:00
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
if (this->m_window == nullptr)
|
|
|
|
throw std::runtime_error("Failed to create window!");
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(this->m_window);
|
|
|
|
glfwSwapInterval(1);
|
|
|
|
|
2020-12-16 22:43:07 +01:00
|
|
|
{
|
|
|
|
int x = 0, y = 0;
|
|
|
|
glfwGetWindowPos(this->m_window, &x, &y);
|
2021-01-12 23:28:41 +01:00
|
|
|
SharedData::windowPos = ImVec2(x, y);
|
2020-12-16 22:43:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int width = 0, height = 0;
|
|
|
|
glfwGetWindowSize(this->m_window, &width, &height);
|
2021-01-12 23:28:41 +01:00
|
|
|
SharedData::windowSize = ImVec2(width, height);
|
2020-12-16 22:43:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
glfwSetWindowPosCallback(this->m_window, [](GLFWwindow *window, int x, int y) {
|
2021-01-12 23:28:41 +01:00
|
|
|
SharedData::windowPos = ImVec2(x, y);
|
2021-06-07 18:14:40 +02:00
|
|
|
|
|
|
|
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
|
|
|
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
|
|
|
|
|
|
|
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
|
|
|
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]);
|
|
|
|
|
2021-01-21 15:02:49 +01:00
|
|
|
if (action == GLFW_PRESS) {
|
|
|
|
auto &io = ImGui::GetIO();
|
|
|
|
io.KeysDown[key] = true;
|
|
|
|
io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0;
|
|
|
|
io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0;
|
|
|
|
io.KeyAlt = (mods & GLFW_MOD_ALT) != 0;
|
|
|
|
}
|
|
|
|
else if (action == GLFW_RELEASE) {
|
|
|
|
auto &io = ImGui::GetIO();
|
|
|
|
io.KeysDown[key] = false;
|
|
|
|
io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0;
|
|
|
|
io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0;
|
|
|
|
io.KeyAlt = (mods & GLFW_MOD_ALT) != 0;
|
|
|
|
}
|
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-03-27 11:36:36 +01:00
|
|
|
EventManager::post<EventFileDropped>(paths[0]);
|
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
|
|
|
});
|
|
|
|
|
|
|
|
glfwSetWindowSizeLimits(this->m_window, 720, 480, GLFW_DONT_CARE, GLFW_DONT_CARE);
|
2020-11-12 23:58:31 +01:00
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
if (gladLoadGL() == 0)
|
|
|
|
throw std::runtime_error("Failed to initialize OpenGL loader!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::initImGui() {
|
|
|
|
IMGUI_CHECKVERSION();
|
2021-02-03 00:56:33 +01:00
|
|
|
|
2021-02-18 17:10:56 +01:00
|
|
|
GImGui = ImGui::CreateContext();
|
2021-03-02 13:48:23 +01:00
|
|
|
GImPlot = ImPlot::CreateContext();
|
2021-02-03 00:56:33 +01:00
|
|
|
|
2020-11-15 15:49:21 +01:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2020-11-23 15:51:40 +01:00
|
|
|
ImGuiStyle& style = ImGui::GetStyle();
|
|
|
|
|
2021-02-18 17:10:56 +01:00
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
#if !defined(OS_LINUX)
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2021-03-21 14:51:21 +01:00
|
|
|
io.ConfigViewportsNoTaskBarIcon = true;
|
2021-01-21 15:02:49 +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;
|
|
|
|
io.KeyMap[ImGuiKey_KeyPadEnter] = GLFW_KEY_KP_ENTER;
|
|
|
|
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-02-25 00:17:41 +01:00
|
|
|
io.UserData = new ImGui::ImHexCustomData();
|
|
|
|
|
2020-12-11 14:24:42 +01:00
|
|
|
if (this->m_globalScale != 0.0f)
|
|
|
|
style.ScaleAllSizes(this->m_globalScale);
|
|
|
|
|
2021-03-01 08:56:49 +01:00
|
|
|
std::string fontFile;
|
|
|
|
for (const auto &dir : hex::getPath(ImHexPath::Resources)) {
|
|
|
|
fontFile = dir + "/font.ttf";
|
|
|
|
if (std::filesystem::exists(fontFile))
|
|
|
|
break;
|
|
|
|
}
|
2020-12-11 14:24:42 +01:00
|
|
|
|
2021-03-01 08:56:49 +01:00
|
|
|
if (this->setFont(fontFile)) {
|
2021-01-27 12:04:42 +01:00
|
|
|
|
|
|
|
}
|
2021-02-24 22:42:26 +01:00
|
|
|
else {
|
2020-12-11 14:24:42 +01:00
|
|
|
io.Fonts->Clear();
|
|
|
|
|
|
|
|
ImFontConfig cfg;
|
|
|
|
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
|
|
|
|
cfg.SizePixels = 13.0f * this->m_fontScale;
|
|
|
|
io.Fonts->AddFontDefault(&cfg);
|
2021-02-24 22:42:26 +01:00
|
|
|
|
|
|
|
cfg.MergeMode = true;
|
|
|
|
|
|
|
|
ImWchar fontAwesomeRange[] = {
|
|
|
|
ICON_MIN_FA, ICON_MAX_FA,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
std::uint8_t *px;
|
|
|
|
int w, h;
|
2021-04-21 19:27:05 +02:00
|
|
|
io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 11.0f * this->m_fontScale, &cfg, fontAwesomeRange);
|
2021-02-24 22:42:26 +01:00
|
|
|
io.Fonts->GetTexDataAsRGBA32(&px, &w, &h);
|
|
|
|
|
|
|
|
// 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, w, h, 0, GL_RGBA8, GL_UNSIGNED_INT, px);
|
|
|
|
io.Fonts->SetTexID(reinterpret_cast<ImTextureID>(tex));
|
2020-12-11 14:24:42 +01:00
|
|
|
}
|
|
|
|
|
2021-02-24 22:42:26 +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;
|
|
|
|
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)) {
|
|
|
|
iniFileName = dir + "/interface.ini";
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::deinitGLFW() {
|
|
|
|
glfwDestroyWindow(this->m_window);
|
|
|
|
glfwTerminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::deinitImGui() {
|
2021-02-25 00:17:41 +01:00
|
|
|
delete static_cast<ImGui::ImHexCustomData*>(ImGui::GetIO().UserData);
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
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
|
|
|
}
|