2021-08-18 22:36:46 +02:00
|
|
|
#include "window.hpp"
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
#if defined(OS_WINDOWS)
|
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2021-09-16 22:23:51 +02:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
#include <imgui.h>
|
2021-08-25 19:32:47 +02:00
|
|
|
#include <imgui_internal.h>
|
2022-07-26 14:59:08 +02:00
|
|
|
#include <fonts/codicons_font.h>
|
2021-08-18 22:36:46 +02:00
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
|
|
|
#include <GLFW/glfw3native.h>
|
2021-08-25 19:32:47 +02:00
|
|
|
#undef GLFW_EXPOSE_NATIVE_WIN32
|
|
|
|
|
2023-01-07 10:32:01 +01:00
|
|
|
#include <winbase.h>
|
2021-08-18 22:36:46 +02:00
|
|
|
#include <winuser.h>
|
|
|
|
#include <dwmapi.h>
|
|
|
|
#include <windowsx.h>
|
2023-01-14 14:21:16 +01:00
|
|
|
#include <shobjidl.h>
|
|
|
|
#include <wrl/client.h>
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-08-12 15:11:27 +02:00
|
|
|
#include <csignal>
|
2023-03-18 11:35:01 +01:00
|
|
|
#include <cstdio>
|
2022-08-12 15:11:27 +02:00
|
|
|
|
2022-08-04 09:46:17 +02:00
|
|
|
#include <imgui_impl_glfw.h>
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
static LONG_PTR g_oldWndProc;
|
|
|
|
static float g_titleBarHeight;
|
|
|
|
static ImGuiMouseCursor g_mouseCursorIcon;
|
2023-01-14 14:21:16 +01:00
|
|
|
static Microsoft::WRL::ComPtr<ITaskbarList4> g_taskbarList;
|
2022-01-24 20:53:17 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Custom Window procedure for receiving OS events
|
2022-09-15 09:47:47 +02:00
|
|
|
static LRESULT commonWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
switch (uMsg) {
|
2023-02-17 12:03:53 +01:00
|
|
|
case WM_COPYDATA: {
|
|
|
|
// Handle opening files in existing instance
|
|
|
|
|
2022-09-15 09:47:47 +02:00
|
|
|
auto message = reinterpret_cast<COPYDATASTRUCT *>(lParam);
|
|
|
|
if (message == nullptr) break;
|
|
|
|
|
|
|
|
auto data = reinterpret_cast<const char8_t *>(message->lpData);
|
|
|
|
if (data == nullptr) break;
|
|
|
|
|
|
|
|
std::fs::path path = data;
|
2023-03-12 18:43:05 +01:00
|
|
|
log::info("Opening file in existing instance: {}", wolv::util::toUTF8String(path));
|
2022-09-15 09:47:47 +02:00
|
|
|
EventManager::post<RequestOpenFile>(path);
|
|
|
|
break;
|
|
|
|
}
|
2023-02-17 12:03:53 +01:00
|
|
|
case WM_SETTINGCHANGE: {
|
|
|
|
// Handle Windows theme changes
|
2022-09-15 09:47:47 +02:00
|
|
|
if (lParam == 0) break;
|
|
|
|
|
|
|
|
if (LPCTSTR(lParam) == std::string_view("ImmersiveColorSet")) {
|
|
|
|
EventManager::post<EventOSThemeChanged>();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallWindowProc((WNDPROC)g_oldWndProc, hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Custom window procedure for borderless window
|
2022-09-15 09:47:47 +02:00
|
|
|
static LRESULT borderlessWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2022-01-24 20:53:17 +01:00
|
|
|
switch (uMsg) {
|
2022-02-01 22:09:44 +01:00
|
|
|
case WM_NCACTIVATE:
|
|
|
|
case WM_NCPAINT:
|
2023-02-17 12:03:53 +01:00
|
|
|
// Handle Windows Aero Snap
|
2022-02-01 22:09:44 +01:00
|
|
|
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
2023-02-17 12:03:53 +01:00
|
|
|
case WM_NCCALCSIZE: {
|
|
|
|
// Handle window resizing
|
|
|
|
|
|
|
|
RECT &rect = *reinterpret_cast<RECT *>(lParam);
|
|
|
|
RECT client = rect;
|
|
|
|
|
|
|
|
CallWindowProc((WNDPROC)g_oldWndProc, hwnd, uMsg, wParam, lParam);
|
|
|
|
|
|
|
|
if (IsMaximized(hwnd)) {
|
|
|
|
WINDOWINFO windowInfo = { };
|
|
|
|
windowInfo.cbSize = sizeof(WINDOWINFO);
|
2022-01-24 20:53:17 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
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) + 1
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
rect = client;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
2021-12-10 16:09:55 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_SETCURSOR: {
|
|
|
|
// Handle mouse cursor icon
|
|
|
|
auto cursorPos = LOWORD(lParam);
|
|
|
|
|
|
|
|
switch (cursorPos) {
|
|
|
|
case HTRIGHT:
|
|
|
|
case HTLEFT:
|
|
|
|
g_mouseCursorIcon = ImGuiMouseCursor_ResizeEW;
|
|
|
|
break;
|
|
|
|
case HTTOP:
|
|
|
|
case HTBOTTOM:
|
|
|
|
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNS;
|
|
|
|
break;
|
|
|
|
case HTTOPLEFT:
|
|
|
|
case HTBOTTOMRIGHT:
|
|
|
|
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNWSE;
|
|
|
|
break;
|
|
|
|
case HTTOPRIGHT:
|
|
|
|
case HTBOTTOMLEFT:
|
|
|
|
g_mouseCursorIcon = ImGuiMouseCursor_ResizeNESW;
|
|
|
|
break;
|
|
|
|
case HTCAPTION:
|
|
|
|
case HTCLIENT:
|
|
|
|
g_mouseCursorIcon = ImGuiMouseCursor_None;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WM_NCHITTEST: {
|
|
|
|
// Handle window resizing and moving
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
const POINT border {
|
|
|
|
static_cast<LONG>((::GetSystemMetrics(SM_CXFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * ImHexApi::System::getGlobalScale() / 1.5F),
|
|
|
|
static_cast<LONG>((::GetSystemMetrics(SM_CYFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)) * ImHexApi::System::getGlobalScale() / 1.5F)
|
|
|
|
};
|
2022-02-01 22:09:44 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
RECT window;
|
|
|
|
if (!::GetWindowRect(hwnd, &window)) {
|
|
|
|
return HTNOWHERE;
|
|
|
|
}
|
2022-02-01 22:09:44 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
constexpr static auto RegionClient = 0b0000;
|
|
|
|
constexpr static auto RegionLeft = 0b0001;
|
|
|
|
constexpr static auto RegionRight = 0b0010;
|
|
|
|
constexpr static auto RegionTop = 0b0100;
|
|
|
|
constexpr static auto RegionBottom = 0b1000;
|
2022-02-01 22:09:44 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
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));
|
|
|
|
|
|
|
|
if (result != 0 && (ImGui::IsItemHovered() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId)))
|
2021-09-16 22:23:51 +02:00
|
|
|
break;
|
2023-02-17 12:03:53 +01:00
|
|
|
|
2023-04-06 14:58:05 +02:00
|
|
|
if (GImGui->HoveredWindow != nullptr &&
|
|
|
|
GImGui->HoveredWindow->Name != std::string("##MainMenuBar") &&
|
|
|
|
GImGui->HoveredWindow->Name != std::string("ImHexDockSpace"))
|
|
|
|
break;
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
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 + g_titleBarHeight * 2)) && !(ImGui::IsAnyItemHovered() || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId)))
|
|
|
|
return HTCAPTION;
|
|
|
|
else break;
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2023-02-17 12:03:53 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-02-01 22:09:44 +01:00
|
|
|
default:
|
2022-01-24 20:53:17 +01:00
|
|
|
break;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2022-09-15 09:47:47 +02:00
|
|
|
return commonWindowProc(hwnd, uMsg, wParam, lParam);
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-22 20:24:42 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
|
|
|
|
void Window::initNative() {
|
2023-01-14 14:21:16 +01:00
|
|
|
ImHexApi::System::impl::setBorderlessWindowMode(true);
|
2023-01-07 10:32:01 +01:00
|
|
|
|
|
|
|
// Add plugin library folders to dll search path
|
|
|
|
for (const auto &path : hex::fs::getDefaultPaths(fs::ImHexPath::Libraries)) {
|
|
|
|
if (std::fs::exists(path))
|
|
|
|
AddDllDirectory(path.c_str());
|
|
|
|
}
|
|
|
|
|
2023-03-18 11:35:01 +01:00
|
|
|
// Various libraries sadly directly print to stderr with no way to disable it
|
|
|
|
// We redirect stderr to NUL to prevent this
|
|
|
|
freopen("NUL:", "w", stderr);
|
|
|
|
setvbuf(stderr, nullptr, _IONBF, 0);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
// Attach to parent console if one exists
|
|
|
|
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
|
2023-03-18 11:35:01 +01:00
|
|
|
// Redirect stdin and stdout to that new console
|
2022-01-24 20:53:17 +01:00
|
|
|
freopen("CONIN$", "r", stdin);
|
|
|
|
freopen("CONOUT$", "w", stdout);
|
|
|
|
setvbuf(stdin, nullptr, _IONBF, 0);
|
|
|
|
setvbuf(stdout, nullptr, _IONBF, 0);
|
|
|
|
|
|
|
|
fmt::print("\n");
|
|
|
|
|
|
|
|
// Enable color format specifiers in console
|
|
|
|
{
|
|
|
|
auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
if (hConsole != INVALID_HANDLE_VALUE) {
|
|
|
|
DWORD mode = 0;
|
|
|
|
if (::GetConsoleMode(hConsole, &mode)) {
|
|
|
|
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
|
|
|
::SetConsoleMode(hConsole, mode);
|
2021-11-28 13:43:44 +01:00
|
|
|
}
|
2021-08-22 20:24:42 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
} else {
|
|
|
|
log::redirectToFile();
|
|
|
|
}
|
2021-12-30 23:21:32 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
// Open new files in already existing ImHex instance
|
|
|
|
constexpr static auto UniqueMutexId = "ImHex/a477ea68-e334-4d07-a439-4f159c683763";
|
|
|
|
|
|
|
|
HANDLE globalMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, UniqueMutexId);
|
|
|
|
if (!globalMutex) {
|
2023-02-17 12:03:53 +01:00
|
|
|
// If no ImHex instance is running, create a new global mutex
|
2022-01-24 20:53:17 +01:00
|
|
|
globalMutex = CreateMutex(nullptr, FALSE, UniqueMutexId);
|
|
|
|
} else {
|
2023-02-17 12:03:53 +01:00
|
|
|
// If an ImHex instance is already running, send the file path to it and exit
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
if (ImHexApi::System::getProgramArguments().argc > 1) {
|
2023-02-17 12:03:53 +01:00
|
|
|
// Find the ImHex Window and send the file path as a message to it
|
2022-03-27 00:01:28 +01:00
|
|
|
::EnumWindows([](HWND hWnd, LPARAM) -> BOOL {
|
2022-02-01 18:09:40 +01:00
|
|
|
auto &programArgs = ImHexApi::System::getProgramArguments();
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Get the window name
|
2022-01-24 20:53:17 +01:00
|
|
|
auto length = ::GetWindowTextLength(hWnd);
|
|
|
|
std::string windowName(length + 1, '\x00');
|
|
|
|
::GetWindowText(hWnd, windowName.data(), windowName.size());
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Check if the window is visible and if it's an ImHex window
|
2022-01-24 20:53:17 +01:00
|
|
|
if (::IsWindowVisible(hWnd) && length != 0) {
|
|
|
|
if (windowName.starts_with("ImHex")) {
|
2023-02-17 12:03:53 +01:00
|
|
|
// Create the message
|
2022-01-24 20:53:17 +01:00
|
|
|
COPYDATASTRUCT message = {
|
|
|
|
.dwData = 0,
|
2022-02-01 18:09:40 +01:00
|
|
|
.cbData = static_cast<DWORD>(std::strlen(programArgs.argv[1])) + 1,
|
|
|
|
.lpData = programArgs.argv[1]
|
2022-01-24 20:53:17 +01:00
|
|
|
};
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Send the message
|
2022-01-24 20:53:17 +01:00
|
|
|
SendMessage(hWnd, WM_COPYDATA, reinterpret_cast<WPARAM>(hWnd), reinterpret_cast<LPARAM>(&message));
|
|
|
|
|
|
|
|
return FALSE;
|
2021-12-30 23:21:32 +01:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-12-30 23:21:32 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
return TRUE;
|
2023-02-17 12:03:53 +01:00
|
|
|
}, 0);
|
2021-12-30 23:21:32 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::exit(0);
|
2021-12-30 23:21:32 +01:00
|
|
|
}
|
2021-08-22 20:24:42 +02:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-22 20:24:42 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::setupNativeWindow() {
|
|
|
|
// Setup borderless window
|
|
|
|
auto hwnd = glfwGetWin32Window(this->m_window);
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2022-08-04 09:46:17 +02:00
|
|
|
bool borderlessWindowMode = ImHexApi::System::isBorderlessWindowModeEnabled();
|
|
|
|
|
|
|
|
ImGui_ImplGlfw_SetBorderlessWindowMode(borderlessWindowMode);
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Set up the correct window procedure based on the borderless window mode state
|
2022-08-04 09:46:17 +02:00
|
|
|
if (borderlessWindowMode) {
|
2022-09-15 09:47:47 +02:00
|
|
|
g_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)borderlessWindowProc);
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2022-02-15 22:36:36 +01:00
|
|
|
MARGINS borderless = { 1, 1, 1, 1 };
|
|
|
|
::DwmExtendFrameIntoClientArea(hwnd, &borderless);
|
2021-08-21 13:55:21 +02:00
|
|
|
|
2022-02-15 22:36:36 +01:00
|
|
|
DWORD attribute = DWMNCRP_ENABLED;
|
|
|
|
::DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &attribute, sizeof(attribute));
|
2021-11-28 11:57:52 +01:00
|
|
|
|
2022-02-15 22:36:36 +01:00
|
|
|
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE);
|
|
|
|
::SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
|
2022-09-15 09:47:47 +02:00
|
|
|
} else {
|
|
|
|
g_oldWndProc = ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)commonWindowProc);
|
2022-02-15 22:36:36 +01:00
|
|
|
}
|
2022-08-12 15:11:27 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Add a custom exception handler to detect heap corruptions
|
2022-08-12 15:11:27 +02:00
|
|
|
{
|
|
|
|
::AddVectoredExceptionHandler(TRUE, [](PEXCEPTION_POINTERS exception) -> LONG {
|
|
|
|
if ((exception->ExceptionRecord->ExceptionCode & 0xF000'0000) == 0xC000'0000) {
|
|
|
|
log::fatal("Exception raised: 0x{:08X}", exception->ExceptionRecord->ExceptionCode);
|
|
|
|
if (exception->ExceptionRecord->ExceptionCode == STATUS_HEAP_CORRUPTION) {
|
|
|
|
log::fatal("Heap corruption detected!");
|
|
|
|
std::raise(SIGABRT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
});
|
|
|
|
}
|
2023-01-14 14:21:16 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Set up a taskbar progress handler
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) {
|
|
|
|
CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, &g_taskbarList);
|
2023-01-14 14:21:16 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
EventManager::subscribe<EventSetTaskBarIconState>([hwnd](u32 state, u32 type, u32 progress){
|
|
|
|
using enum ImHexApi::System::TaskProgressState;
|
|
|
|
switch (ImHexApi::System::TaskProgressState(state)) {
|
|
|
|
case Reset:
|
|
|
|
g_taskbarList->SetProgressState(hwnd, TBPF_NOPROGRESS);
|
|
|
|
g_taskbarList->SetProgressValue(hwnd, 0, 0);
|
|
|
|
break;
|
|
|
|
case Flash:
|
|
|
|
FlashWindow(hwnd, true);
|
|
|
|
break;
|
|
|
|
case Progress:
|
|
|
|
g_taskbarList->SetProgressState(hwnd, TBPF_INDETERMINATE);
|
|
|
|
g_taskbarList->SetProgressValue(hwnd, progress, 100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
using enum ImHexApi::System::TaskProgressType;
|
|
|
|
switch (ImHexApi::System::TaskProgressType(type)) {
|
|
|
|
case Normal:
|
|
|
|
g_taskbarList->SetProgressState(hwnd, TBPF_NORMAL);
|
|
|
|
break;
|
|
|
|
case Warning:
|
|
|
|
g_taskbarList->SetProgressState(hwnd, TBPF_PAUSED);
|
|
|
|
break;
|
|
|
|
case Error:
|
|
|
|
g_taskbarList->SetProgressState(hwnd, TBPF_ERROR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::beginNativeWindowFrame() {
|
|
|
|
g_titleBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
|
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::endNativeWindowFrame() {
|
2022-08-04 09:46:17 +02:00
|
|
|
if (!ImHexApi::System::isBorderlessWindowModeEnabled())
|
|
|
|
return;
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
if (g_mouseCursorIcon != ImGuiMouseCursor_None) {
|
|
|
|
ImGui::SetMouseCursor(g_mouseCursorIcon);
|
|
|
|
}
|
2021-12-10 16:09:55 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Translate ImGui mouse cursors to Win32 mouse cursors
|
2022-01-24 20:53:17 +01:00
|
|
|
switch (ImGui::GetMouseCursor()) {
|
2022-02-01 22:09:44 +01:00
|
|
|
case ImGuiMouseCursor_Arrow:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_ARROW));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_Hand:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_HAND));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeEW:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZEWE));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeNS:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZENS));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeNWSE:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZENWSE));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeNESW:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZENESW));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_ResizeAll:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_SIZEALL));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_NotAllowed:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_NO));
|
|
|
|
break;
|
|
|
|
case ImGuiMouseCursor_TextInput:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_IBEAM));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case ImGuiMouseCursor_None:
|
|
|
|
SetCursor(LoadCursor(nullptr, IDC_ARROW));
|
|
|
|
break;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void Window::drawTitleBar() {
|
2023-02-17 12:03:53 +01:00
|
|
|
// In borderless window mode, we draw our own title bar
|
|
|
|
|
2022-02-15 23:07:48 +01:00
|
|
|
if (!ImHexApi::System::isBorderlessWindowModeEnabled()) return;
|
2022-02-15 22:36:36 +01:00
|
|
|
|
2022-11-04 15:19:24 +01:00
|
|
|
auto startX = ImGui::GetCursorPosX();
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
auto buttonSize = ImVec2(g_titleBarHeight * 1.5F, g_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));
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
auto &titleBarButtons = ContentRegistry::Interface::impl::getTitleBarButtons();
|
2022-02-02 00:36:09 +01:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Draw custom title bar buttons
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * (4 + titleBarButtons.size()));
|
|
|
|
for (const auto &[icon, tooltip, callback] : titleBarButtons) {
|
|
|
|
if (ImGui::TitleBarButton(icon.c_str(), buttonSize)) {
|
|
|
|
callback();
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::InfoTooltip(LangEntry(tooltip));
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Draw minimize, restore and maximize buttons
|
2022-01-24 20:53:17 +01:00
|
|
|
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);
|
|
|
|
}
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, 0xFF7A70F1);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, 0xFF2311E8);
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Draw close button
|
2022-01-24 20:53:17 +01:00
|
|
|
if (ImGui::TitleBarButton(ICON_VS_CHROME_CLOSE, buttonSize)) {
|
2023-03-21 15:33:43 +01:00
|
|
|
ImHexApi::System::closeImHex();
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGui::PopStyleColor(5);
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
2022-11-04 15:19:24 +01:00
|
|
|
ImGui::SetCursorPosX(std::max(startX, (ImGui::GetWindowWidth() - ImGui::CalcTextSize(this->m_windowTitle.c_str()).x) / 2));
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGui::TextUnformatted(this->m_windowTitle.c_str());
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
}
|
|
|
|
|
2021-08-18 22:36:46 +02:00
|
|
|
#endif
|