mirror of https://github.com/WerWolv/ImHex.git
fix: unify the line terminators
This commit is contained in:
parent
167084355f
commit
af10d1e8d9
|
@ -1,46 +1,46 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
# Change this to the name of your plugin #
|
||||
project(builtin)
|
||||
|
||||
# Add your source files here #
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
source/plugin_builtin.cpp
|
||||
|
||||
source/content/command_palette_commands.cpp
|
||||
source/content/data_inspector.cpp
|
||||
source/content/pl_builtin_functions.cpp
|
||||
source/content/settings_entries.cpp
|
||||
source/content/tools_entries.cpp
|
||||
source/content/data_processor_nodes.cpp
|
||||
source/content/ui_items.cpp
|
||||
|
||||
source/math_evaluator.cpp
|
||||
|
||||
source/lang/en_US.cpp
|
||||
source/lang/de_DE.cpp
|
||||
source/lang/it_IT.cpp
|
||||
source/lang/zh_CN.cpp
|
||||
)
|
||||
|
||||
# Add additional include directories here #
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||
# Add additional libraries here #
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE libimhex LLVMDemangle)
|
||||
|
||||
|
||||
|
||||
# ---- No need to change anything from here downwards unless you know what you're doing ---- #
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".hexplug")
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition -fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(IMHEX_PLUGIN_NAME=${PROJECT_NAME})
|
||||
|
||||
if (NOT TARGET libimhex)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
# Change this to the name of your plugin #
|
||||
project(builtin)
|
||||
|
||||
# Add your source files here #
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
source/plugin_builtin.cpp
|
||||
|
||||
source/content/command_palette_commands.cpp
|
||||
source/content/data_inspector.cpp
|
||||
source/content/pl_builtin_functions.cpp
|
||||
source/content/settings_entries.cpp
|
||||
source/content/tools_entries.cpp
|
||||
source/content/data_processor_nodes.cpp
|
||||
source/content/ui_items.cpp
|
||||
|
||||
source/math_evaluator.cpp
|
||||
|
||||
source/lang/en_US.cpp
|
||||
source/lang/de_DE.cpp
|
||||
source/lang/it_IT.cpp
|
||||
source/lang/zh_CN.cpp
|
||||
)
|
||||
|
||||
# Add additional include directories here #
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||
# Add additional libraries here #
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE libimhex LLVMDemangle)
|
||||
|
||||
|
||||
|
||||
# ---- No need to change anything from here downwards unless you know what you're doing ---- #
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".hexplug")
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition -fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(IMHEX_PLUGIN_NAME=${PROJECT_NAME})
|
||||
|
||||
if (NOT TARGET libimhex)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
|
||||
endif()
|
File diff suppressed because it is too large
Load Diff
|
@ -1,42 +1,42 @@
|
|||
#include <hex/plugin.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
void registerDataInspectorEntries();
|
||||
void registerToolEntries();
|
||||
void registerPatternLanguageFunctions();
|
||||
void registerCommandPaletteCommands();
|
||||
void registerSettings();
|
||||
void registerDataProcessorNodes();
|
||||
|
||||
void addFooterItems();
|
||||
void addToolbarItems();
|
||||
|
||||
void registerLanguageEnUS();
|
||||
void registerLanguageDeDE();
|
||||
void registerLanguageItIT();
|
||||
void registerLanguageZhCN();
|
||||
|
||||
}
|
||||
|
||||
IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
|
||||
|
||||
using namespace hex::plugin::builtin;
|
||||
|
||||
registerDataInspectorEntries();
|
||||
registerToolEntries();
|
||||
registerPatternLanguageFunctions();
|
||||
registerCommandPaletteCommands();
|
||||
registerSettings();
|
||||
registerDataProcessorNodes();
|
||||
|
||||
addFooterItems();
|
||||
addToolbarItems();
|
||||
|
||||
registerLanguageEnUS();
|
||||
registerLanguageDeDE();
|
||||
registerLanguageItIT();
|
||||
registerLanguageZhCN();
|
||||
}
|
||||
|
||||
|
||||
#include <hex/plugin.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
void registerDataInspectorEntries();
|
||||
void registerToolEntries();
|
||||
void registerPatternLanguageFunctions();
|
||||
void registerCommandPaletteCommands();
|
||||
void registerSettings();
|
||||
void registerDataProcessorNodes();
|
||||
|
||||
void addFooterItems();
|
||||
void addToolbarItems();
|
||||
|
||||
void registerLanguageEnUS();
|
||||
void registerLanguageDeDE();
|
||||
void registerLanguageItIT();
|
||||
void registerLanguageZhCN();
|
||||
|
||||
}
|
||||
|
||||
IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
|
||||
|
||||
using namespace hex::plugin::builtin;
|
||||
|
||||
registerDataInspectorEntries();
|
||||
registerToolEntries();
|
||||
registerPatternLanguageFunctions();
|
||||
registerCommandPaletteCommands();
|
||||
registerSettings();
|
||||
registerDataProcessorNodes();
|
||||
|
||||
addFooterItems();
|
||||
addToolbarItems();
|
||||
|
||||
registerLanguageEnUS();
|
||||
registerLanguageDeDE();
|
||||
registerLanguageItIT();
|
||||
registerLanguageZhCN();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# Change this to the name of your plugin #
|
||||
project(windows)
|
||||
|
||||
# Add your source files here #
|
||||
if (WIN32)
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
source/plugin_windows.cpp
|
||||
|
||||
source/views/view_tty_console.cpp
|
||||
|
||||
source/lang/en_US.cpp
|
||||
source/lang/zh_CN.cpp
|
||||
|
||||
source/content/footer_items.cpp
|
||||
)
|
||||
|
||||
# Add additional include directories here #
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||
# Add additional libraries here #
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE libimhex)
|
||||
endif ()
|
||||
|
||||
|
||||
|
||||
# ---- No need to change anything from here downwards unless you know what you're doing ---- #
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".hexplug")
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition -fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(IMHEX_PLUGIN_NAME=${PROJECT_NAME})
|
||||
|
||||
if (NOT TARGET libimhex)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# Change this to the name of your plugin #
|
||||
project(windows)
|
||||
|
||||
# Add your source files here #
|
||||
if (WIN32)
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
source/plugin_windows.cpp
|
||||
|
||||
source/views/view_tty_console.cpp
|
||||
|
||||
source/lang/en_US.cpp
|
||||
source/lang/zh_CN.cpp
|
||||
|
||||
source/content/footer_items.cpp
|
||||
)
|
||||
|
||||
# Add additional include directories here #
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE include)
|
||||
# Add additional libraries here #
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE libimhex)
|
||||
endif ()
|
||||
|
||||
|
||||
|
||||
# ---- No need to change anything from here downwards unless you know what you're doing ---- #
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".hexplug")
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition -fvisibility=hidden")
|
||||
endif()
|
||||
|
||||
add_compile_definitions(IMHEX_PLUGIN_NAME=${PROJECT_NAME})
|
||||
|
||||
if (NOT TARGET libimhex)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
|
||||
endif()
|
|
@ -1,30 +1,30 @@
|
|||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/helpers/lang.hpp>
|
||||
|
||||
namespace hex::plugin::windows {
|
||||
|
||||
void registerLanguageZhCN() {
|
||||
ContentRegistry::Language::addLocalizations("zh-CN", {
|
||||
{ "hex.windows.view.tty_console.name", "TTY控制台" },
|
||||
{ "hex.windows.view.tty_console.config", "配置"},
|
||||
{ "hex.windows.view.tty_console.port", "端口" },
|
||||
{ "hex.windows.view.tty_console.reload", "重载" },
|
||||
{ "hex.windows.view.tty_console.baud", "波特率" },
|
||||
{ "hex.windows.view.tty_console.num_bits", "数据位" },
|
||||
{ "hex.windows.view.tty_console.stop_bits", "终止位" },
|
||||
{ "hex.windows.view.tty_console.parity_bits", "奇偶校验位" },
|
||||
{ "hex.windows.view.tty_console.cts", "使用CTS流控制" },
|
||||
{ "hex.windows.view.tty_console.connect", "连接" },
|
||||
{ "hex.windows.view.tty_console.disconnect", "断开" },
|
||||
{ "hex.windows.view.tty_console.connect_error", "无法连接到COM端口!" },
|
||||
{ "hex.windows.view.tty_console.clear", "清除" },
|
||||
{ "hex.windows.view.tty_console.auto_scroll", "自动滚动" },
|
||||
{ "hex.windows.view.tty_console.console", "控制台" },
|
||||
{ "hex.windows.view.tty_console.send_etx", "发送ETX" },
|
||||
{ "hex.windows.view.tty_console.send_eot", "发送EOT" },
|
||||
{ "hex.windows.view.tty_console.send_sub", "发送SUB" }
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/helpers/lang.hpp>
|
||||
|
||||
namespace hex::plugin::windows {
|
||||
|
||||
void registerLanguageZhCN() {
|
||||
ContentRegistry::Language::addLocalizations("zh-CN", {
|
||||
{ "hex.windows.view.tty_console.name", "TTY控制台" },
|
||||
{ "hex.windows.view.tty_console.config", "配置"},
|
||||
{ "hex.windows.view.tty_console.port", "端口" },
|
||||
{ "hex.windows.view.tty_console.reload", "重载" },
|
||||
{ "hex.windows.view.tty_console.baud", "波特率" },
|
||||
{ "hex.windows.view.tty_console.num_bits", "数据位" },
|
||||
{ "hex.windows.view.tty_console.stop_bits", "终止位" },
|
||||
{ "hex.windows.view.tty_console.parity_bits", "奇偶校验位" },
|
||||
{ "hex.windows.view.tty_console.cts", "使用CTS流控制" },
|
||||
{ "hex.windows.view.tty_console.connect", "连接" },
|
||||
{ "hex.windows.view.tty_console.disconnect", "断开" },
|
||||
{ "hex.windows.view.tty_console.connect_error", "无法连接到COM端口!" },
|
||||
{ "hex.windows.view.tty_console.clear", "清除" },
|
||||
{ "hex.windows.view.tty_console.auto_scroll", "自动滚动" },
|
||||
{ "hex.windows.view.tty_console.console", "控制台" },
|
||||
{ "hex.windows.view.tty_console.send_etx", "发送ETX" },
|
||||
{ "hex.windows.view.tty_console.send_eot", "发送EOT" },
|
||||
{ "hex.windows.view.tty_console.send_sub", "发送SUB" }
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
#include <hex/plugin.hpp>
|
||||
|
||||
#include "views/view_tty_console.hpp"
|
||||
|
||||
namespace hex::plugin::windows {
|
||||
|
||||
void registerLanguageEnUS();
|
||||
void registerLanguageZhCN();
|
||||
|
||||
void addFooterItems();
|
||||
}
|
||||
|
||||
|
||||
IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") {
|
||||
using namespace hex::plugin::windows;
|
||||
|
||||
ContentRegistry::Views::add<ViewTTYConsole>();
|
||||
|
||||
registerLanguageEnUS();
|
||||
registerLanguageZhCN();
|
||||
|
||||
addFooterItems();
|
||||
}
|
||||
|
||||
|
||||
#include <hex/plugin.hpp>
|
||||
|
||||
#include "views/view_tty_console.hpp"
|
||||
|
||||
namespace hex::plugin::windows {
|
||||
|
||||
void registerLanguageEnUS();
|
||||
void registerLanguageZhCN();
|
||||
|
||||
void addFooterItems();
|
||||
}
|
||||
|
||||
|
||||
IMHEX_PLUGIN_SETUP("Windows", "WerWolv", "Windows-only features") {
|
||||
using namespace hex::plugin::windows;
|
||||
|
||||
ContentRegistry::Views::add<ViewTTYConsole>();
|
||||
|
||||
registerLanguageEnUS();
|
||||
registerLanguageZhCN();
|
||||
|
||||
addFooterItems();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,263 +1,263 @@
|
|||
#include "window.hpp"
|
||||
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <codicons_font.h>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3native.h>
|
||||
#undef GLFW_EXPOSE_NATIVE_WIN32
|
||||
|
||||
#include <winuser.h>
|
||||
#include <dwmapi.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
static LONG_PTR oldWndProc;
|
||||
static float titleBarHeight;
|
||||
static ImGuiMouseCursor mouseCursorIcon;
|
||||
|
||||
static bool isTaskbarAutoHideEnabled(UINT edge, RECT monitor) {
|
||||
APPBARDATA data = { .cbSize = sizeof(APPBARDATA), .uEdge = edge, .rc = monitor };
|
||||
return ::SHAppBarMessage(ABM_GETAUTOHIDEBAR, &data);
|
||||
}
|
||||
|
||||
static LRESULT windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
switch (uMsg) {
|
||||
case WM_NCCALCSIZE: {
|
||||
RECT &rect = *reinterpret_cast<RECT*>(lParam);
|
||||
RECT client = rect;
|
||||
|
||||
DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
|
||||
|
||||
if (IsMaximized(hwnd)) {
|
||||
WINDOWINFO windowInfo = { .cbSize = sizeof(WINDOWINFO) };
|
||||
GetWindowInfo(hwnd, &windowInfo);
|
||||
rect = RECT {
|
||||
.left = static_cast<LONG>(client.left + windowInfo.cyWindowBorders),
|
||||
.top = static_cast<LONG>(client.top + windowInfo.cyWindowBorders),
|
||||
.right = static_cast<LONG>(client.right - windowInfo.cyWindowBorders),
|
||||
.bottom = static_cast<LONG>(client.bottom - windowInfo.cyWindowBorders)
|
||||
};
|
||||
|
||||
HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO monitorInfo = { .cbSize = sizeof(MONITORINFO) };
|
||||
GetMonitorInfoW(hMonitor, &monitorInfo);
|
||||
|
||||
if (EqualRect(&rect, &monitorInfo.rcMonitor)) {
|
||||
if (isTaskbarAutoHideEnabled(ABE_BOTTOM, monitorInfo.rcMonitor))
|
||||
rect.bottom--;
|
||||
else if (isTaskbarAutoHideEnabled(ABE_LEFT, monitorInfo.rcMonitor))
|
||||
rect.left++;
|
||||
else if (isTaskbarAutoHideEnabled(ABE_TOP, monitorInfo.rcMonitor))
|
||||
rect.top++;
|
||||
else if (isTaskbarAutoHideEnabled(ABE_RIGHT, monitorInfo.rcMonitor))
|
||||
rect.right--;
|
||||
}
|
||||
} else {
|
||||
rect = client;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
case WM_SETCURSOR: {
|
||||
auto cursorPos = LOWORD(lParam);
|
||||
|
||||
switch (cursorPos) {
|
||||
case HTRIGHT:
|
||||
case HTLEFT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeEW;
|
||||
return TRUE;
|
||||
case HTTOP:
|
||||
case HTBOTTOM:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNS;
|
||||
return TRUE;
|
||||
case HTTOPLEFT:
|
||||
case HTBOTTOMRIGHT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNWSE;
|
||||
return TRUE;
|
||||
case HTTOPRIGHT:
|
||||
case HTBOTTOMLEFT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNESW;
|
||||
return TRUE;
|
||||
default:
|
||||
mouseCursorIcon = ImGuiMouseCursor_None;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
case WM_NCHITTEST: {
|
||||
POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
||||
|
||||
const POINT border{
|
||||
static_cast<LONG>((::GetSystemMetrics(SM_CXFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * SharedData::globalScale / 2.0F),
|
||||
static_cast<LONG>((::GetSystemMetrics(SM_CYFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * SharedData::globalScale / 2.0F)
|
||||
};
|
||||
|
||||
RECT window;
|
||||
if (!::GetWindowRect(hwnd, &window)) {
|
||||
return HTNOWHERE;
|
||||
}
|
||||
|
||||
constexpr auto RegionClient = 0b0000;
|
||||
constexpr auto RegionLeft = 0b0001;
|
||||
constexpr auto RegionRight = 0b0010;
|
||||
constexpr auto RegionTop = 0b0100;
|
||||
constexpr auto RegionBottom = 0b1000;
|
||||
|
||||
const auto result =
|
||||
RegionLeft * (cursor.x < (window.left + border.x)) |
|
||||
RegionRight * (cursor.x >= (window.right - border.x)) |
|
||||
RegionTop * (cursor.y < (window.top + border.y)) |
|
||||
RegionBottom * (cursor.y >= (window.bottom - border.y));
|
||||
|
||||
switch (result) {
|
||||
case RegionLeft:
|
||||
return HTLEFT;
|
||||
case RegionRight:
|
||||
return HTRIGHT;
|
||||
case RegionTop:
|
||||
return HTTOP;
|
||||
case RegionBottom:
|
||||
return HTBOTTOM;
|
||||
case RegionTop | RegionLeft:
|
||||
return HTTOPLEFT;
|
||||
case RegionTop | RegionRight:
|
||||
return HTTOPRIGHT;
|
||||
case RegionBottom | RegionLeft:
|
||||
return HTBOTTOMLEFT;
|
||||
case RegionBottom | RegionRight:
|
||||
return HTBOTTOMRIGHT;
|
||||
case RegionClient:
|
||||
default:
|
||||
if ((cursor.y < (window.top + titleBarHeight * 2)) && !ImGui::IsAnyItemHovered())
|
||||
return HTCAPTION;
|
||||
else break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_SETTINGCHANGE:
|
||||
{
|
||||
if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) {
|
||||
EventManager::post<EventOSThemeChanged>();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
return CallWindowProc((WNDPROC)oldWndProc, hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
void Window::initNative() {
|
||||
auto hConsoleWindow = ::GetConsoleWindow();
|
||||
#if !defined(DEBUG)
|
||||
::ShowWindow(hConsoleWindow, FALSE);
|
||||
#endif
|
||||
|
||||
auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hConsole != INVALID_HANDLE_VALUE) {
|
||||
DWORD mode = 0;
|
||||
if (::GetConsoleMode(hConsole, &mode)) {
|
||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
::SetConsoleMode(hConsole, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setupNativeWindow() {
|
||||
auto hwnd = glfwGetWin32Window(this->m_window);
|
||||
|
||||
oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)windowProc);
|
||||
|
||||
MARGINS borderless = {1,1,1,1};
|
||||
::DwmExtendFrameIntoClientArea(hwnd, &borderless);
|
||||
|
||||
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS | SWP_NOSIZE | SWP_NOMOVE);
|
||||
::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_POPUP | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU);
|
||||
|
||||
bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color") == 0;
|
||||
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem]{
|
||||
if (!themeFollowSystem) return;
|
||||
|
||||
HKEY hkey;
|
||||
if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", &hkey) == ERROR_SUCCESS) {
|
||||
DWORD value = 0;
|
||||
DWORD size = sizeof(DWORD);
|
||||
|
||||
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
|
||||
if (error == ERROR_SUCCESS) {
|
||||
EventManager::post<RequestChangeTheme>(value == 0 ? 1 : 2);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (themeFollowSystem)
|
||||
EventManager::post<EventOSThemeChanged>();
|
||||
}
|
||||
|
||||
void Window::updateNativeWindow() {
|
||||
titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
|
||||
|
||||
if (mouseCursorIcon != ImGuiMouseCursor_None)
|
||||
ImGui::SetMouseCursor(mouseCursorIcon);
|
||||
}
|
||||
|
||||
void Window::drawTitleBar() {
|
||||
auto buttonSize = ImVec2(titleBarHeight * 1.5F, titleBarHeight - 1);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
||||
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::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * 6);
|
||||
#if defined(DEBUG)
|
||||
if (ImGui::TitleBarButton(ICON_VS_DEBUG, buttonSize))
|
||||
hex::openWebpage("https://imhex.werwolv.net/debug");
|
||||
ImGui::InfoTooltip("hex.menu.debug_build"_lang);
|
||||
#endif
|
||||
if (ImGui::TitleBarButton(ICON_VS_SMILEY, buttonSize))
|
||||
hex::openWebpage("mailto://hey@werwolv.net");
|
||||
ImGui::InfoTooltip("hex.menu.feedback"_lang);
|
||||
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * 3);
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_MINIMIZE, buttonSize))
|
||||
glfwIconifyWindow(this->m_window);
|
||||
if (glfwGetWindowAttrib(this->m_window, GLFW_MAXIMIZED)) {
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_RESTORE, buttonSize))
|
||||
glfwRestoreWindow(this->m_window);
|
||||
} else {
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_MAXIMIZE, buttonSize))
|
||||
glfwMaximizeWindow(this->m_window);
|
||||
}
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, 0xFF7A70F1);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, 0xFF2311E8);
|
||||
|
||||
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_CLOSE, buttonSize)) {
|
||||
ImHexApi::Common::closeImHex();
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(5);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowWidth() - ImGui::CalcTextSize(this->m_windowTitle.c_str()).x) / 2);
|
||||
ImGui::TextUnformatted(this->m_windowTitle.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "window.hpp"
|
||||
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <codicons_font.h>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3native.h>
|
||||
#undef GLFW_EXPOSE_NATIVE_WIN32
|
||||
|
||||
#include <winuser.h>
|
||||
#include <dwmapi.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
static LONG_PTR oldWndProc;
|
||||
static float titleBarHeight;
|
||||
static ImGuiMouseCursor mouseCursorIcon;
|
||||
|
||||
static bool isTaskbarAutoHideEnabled(UINT edge, RECT monitor) {
|
||||
APPBARDATA data = { .cbSize = sizeof(APPBARDATA), .uEdge = edge, .rc = monitor };
|
||||
return ::SHAppBarMessage(ABM_GETAUTOHIDEBAR, &data);
|
||||
}
|
||||
|
||||
static LRESULT windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
switch (uMsg) {
|
||||
case WM_NCCALCSIZE: {
|
||||
RECT &rect = *reinterpret_cast<RECT*>(lParam);
|
||||
RECT client = rect;
|
||||
|
||||
DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
|
||||
|
||||
if (IsMaximized(hwnd)) {
|
||||
WINDOWINFO windowInfo = { .cbSize = sizeof(WINDOWINFO) };
|
||||
GetWindowInfo(hwnd, &windowInfo);
|
||||
rect = RECT {
|
||||
.left = static_cast<LONG>(client.left + windowInfo.cyWindowBorders),
|
||||
.top = static_cast<LONG>(client.top + windowInfo.cyWindowBorders),
|
||||
.right = static_cast<LONG>(client.right - windowInfo.cyWindowBorders),
|
||||
.bottom = static_cast<LONG>(client.bottom - windowInfo.cyWindowBorders)
|
||||
};
|
||||
|
||||
HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
|
||||
MONITORINFO monitorInfo = { .cbSize = sizeof(MONITORINFO) };
|
||||
GetMonitorInfoW(hMonitor, &monitorInfo);
|
||||
|
||||
if (EqualRect(&rect, &monitorInfo.rcMonitor)) {
|
||||
if (isTaskbarAutoHideEnabled(ABE_BOTTOM, monitorInfo.rcMonitor))
|
||||
rect.bottom--;
|
||||
else if (isTaskbarAutoHideEnabled(ABE_LEFT, monitorInfo.rcMonitor))
|
||||
rect.left++;
|
||||
else if (isTaskbarAutoHideEnabled(ABE_TOP, monitorInfo.rcMonitor))
|
||||
rect.top++;
|
||||
else if (isTaskbarAutoHideEnabled(ABE_RIGHT, monitorInfo.rcMonitor))
|
||||
rect.right--;
|
||||
}
|
||||
} else {
|
||||
rect = client;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
case WM_SETCURSOR: {
|
||||
auto cursorPos = LOWORD(lParam);
|
||||
|
||||
switch (cursorPos) {
|
||||
case HTRIGHT:
|
||||
case HTLEFT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeEW;
|
||||
return TRUE;
|
||||
case HTTOP:
|
||||
case HTBOTTOM:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNS;
|
||||
return TRUE;
|
||||
case HTTOPLEFT:
|
||||
case HTBOTTOMRIGHT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNWSE;
|
||||
return TRUE;
|
||||
case HTTOPRIGHT:
|
||||
case HTBOTTOMLEFT:
|
||||
mouseCursorIcon = ImGuiMouseCursor_ResizeNESW;
|
||||
return TRUE;
|
||||
default:
|
||||
mouseCursorIcon = ImGuiMouseCursor_None;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
case WM_NCHITTEST: {
|
||||
POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
||||
|
||||
const POINT border{
|
||||
static_cast<LONG>((::GetSystemMetrics(SM_CXFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * SharedData::globalScale / 2.0F),
|
||||
static_cast<LONG>((::GetSystemMetrics(SM_CYFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * SharedData::globalScale / 2.0F)
|
||||
};
|
||||
|
||||
RECT window;
|
||||
if (!::GetWindowRect(hwnd, &window)) {
|
||||
return HTNOWHERE;
|
||||
}
|
||||
|
||||
constexpr auto RegionClient = 0b0000;
|
||||
constexpr auto RegionLeft = 0b0001;
|
||||
constexpr auto RegionRight = 0b0010;
|
||||
constexpr auto RegionTop = 0b0100;
|
||||
constexpr auto RegionBottom = 0b1000;
|
||||
|
||||
const auto result =
|
||||
RegionLeft * (cursor.x < (window.left + border.x)) |
|
||||
RegionRight * (cursor.x >= (window.right - border.x)) |
|
||||
RegionTop * (cursor.y < (window.top + border.y)) |
|
||||
RegionBottom * (cursor.y >= (window.bottom - border.y));
|
||||
|
||||
switch (result) {
|
||||
case RegionLeft:
|
||||
return HTLEFT;
|
||||
case RegionRight:
|
||||
return HTRIGHT;
|
||||
case RegionTop:
|
||||
return HTTOP;
|
||||
case RegionBottom:
|
||||
return HTBOTTOM;
|
||||
case RegionTop | RegionLeft:
|
||||
return HTTOPLEFT;
|
||||
case RegionTop | RegionRight:
|
||||
return HTTOPRIGHT;
|
||||
case RegionBottom | RegionLeft:
|
||||
return HTBOTTOMLEFT;
|
||||
case RegionBottom | RegionRight:
|
||||
return HTBOTTOMRIGHT;
|
||||
case RegionClient:
|
||||
default:
|
||||
if ((cursor.y < (window.top + titleBarHeight * 2)) && !ImGui::IsAnyItemHovered())
|
||||
return HTCAPTION;
|
||||
else break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_SETTINGCHANGE:
|
||||
{
|
||||
if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) {
|
||||
EventManager::post<EventOSThemeChanged>();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
return CallWindowProc((WNDPROC)oldWndProc, hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
void Window::initNative() {
|
||||
auto hConsoleWindow = ::GetConsoleWindow();
|
||||
#if !defined(DEBUG)
|
||||
::ShowWindow(hConsoleWindow, FALSE);
|
||||
#endif
|
||||
|
||||
auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hConsole != INVALID_HANDLE_VALUE) {
|
||||
DWORD mode = 0;
|
||||
if (::GetConsoleMode(hConsole, &mode)) {
|
||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
::SetConsoleMode(hConsole, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setupNativeWindow() {
|
||||
auto hwnd = glfwGetWin32Window(this->m_window);
|
||||
|
||||
oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)windowProc);
|
||||
|
||||
MARGINS borderless = {1,1,1,1};
|
||||
::DwmExtendFrameIntoClientArea(hwnd, &borderless);
|
||||
|
||||
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS | SWP_NOSIZE | SWP_NOMOVE);
|
||||
::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_POPUP | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU);
|
||||
|
||||
bool themeFollowSystem = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color") == 0;
|
||||
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem]{
|
||||
if (!themeFollowSystem) return;
|
||||
|
||||
HKEY hkey;
|
||||
if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", &hkey) == ERROR_SUCCESS) {
|
||||
DWORD value = 0;
|
||||
DWORD size = sizeof(DWORD);
|
||||
|
||||
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
|
||||
if (error == ERROR_SUCCESS) {
|
||||
EventManager::post<RequestChangeTheme>(value == 0 ? 1 : 2);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (themeFollowSystem)
|
||||
EventManager::post<EventOSThemeChanged>();
|
||||
}
|
||||
|
||||
void Window::updateNativeWindow() {
|
||||
titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
|
||||
|
||||
if (mouseCursorIcon != ImGuiMouseCursor_None)
|
||||
ImGui::SetMouseCursor(mouseCursorIcon);
|
||||
}
|
||||
|
||||
void Window::drawTitleBar() {
|
||||
auto buttonSize = ImVec2(titleBarHeight * 1.5F, titleBarHeight - 1);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
||||
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::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * 6);
|
||||
#if defined(DEBUG)
|
||||
if (ImGui::TitleBarButton(ICON_VS_DEBUG, buttonSize))
|
||||
hex::openWebpage("https://imhex.werwolv.net/debug");
|
||||
ImGui::InfoTooltip("hex.menu.debug_build"_lang);
|
||||
#endif
|
||||
if (ImGui::TitleBarButton(ICON_VS_SMILEY, buttonSize))
|
||||
hex::openWebpage("mailto://hey@werwolv.net");
|
||||
ImGui::InfoTooltip("hex.menu.feedback"_lang);
|
||||
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * 3);
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_MINIMIZE, buttonSize))
|
||||
glfwIconifyWindow(this->m_window);
|
||||
if (glfwGetWindowAttrib(this->m_window, GLFW_MAXIMIZED)) {
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_RESTORE, buttonSize))
|
||||
glfwRestoreWindow(this->m_window);
|
||||
} else {
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_MAXIMIZE, buttonSize))
|
||||
glfwMaximizeWindow(this->m_window);
|
||||
}
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, 0xFF7A70F1);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, 0xFF2311E8);
|
||||
|
||||
|
||||
if (ImGui::TitleBarButton(ICON_VS_CHROME_CLOSE, buttonSize)) {
|
||||
ImHexApi::Common::closeImHex();
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor(5);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowWidth() - ImGui::CalcTextSize(this->m_windowTitle.c_str()).x) / 2);
|
||||
ImGui::TextUnformatted(this->m_windowTitle.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue