sys: Improve shortcut api

This commit is contained in:
WerWolv
2021-04-16 19:43:54 +02:00
parent 59dd372ec8
commit 771bb22962
8 changed files with 54 additions and 44 deletions

View File

@@ -181,10 +181,17 @@ namespace hex {
}
void Window::loop() {
bool pressedKeys[512] = { 0 };
this->m_lastFrameTime = glfwGetTime();
while (!glfwWindowShouldClose(this->m_window)) {
std::copy_n(ImGui::GetIO().KeysDown, 512, this->m_prevKeysDown);
this->frameBegin();
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();
@@ -201,6 +208,7 @@ namespace hex {
ImGui::SetNextWindowSizeConstraints(minSize, view->getMaxSize());
view->drawContent();
view->handleShortcut(pressedKeys, ImGui::GetIO().KeyCtrl, ImGui::GetIO().KeyShift, ImGui::GetIO().KeyAlt);
}
View::drawCommonInterfaces();
@@ -352,17 +360,6 @@ namespace hex {
ImGui::EndMenuBar();
}
if (auto &[key, mods] = Window::s_currShortcut; key != -1) {
for (auto &view : ContentRegistry::Views::getEntries()) {
if (view->shouldProcess()) {
if (view->handleShortcut(key, mods))
break;
}
}
Window::s_currShortcut = { -1, -1 };
}
if (SharedData::currentProvider == nullptr) {
char title[256];
ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock"));