1
0
mirror of synced 2024-11-24 07:40:17 +01:00

fix: Key presses not always unlocking frame rate correctly

This commit is contained in:
WerWolv 2023-06-02 14:43:45 +02:00
parent 62ecfb0e0e
commit d10f033439
2 changed files with 13 additions and 6 deletions

View File

@ -61,7 +61,7 @@ namespace hex {
std::list<std::string> m_popupsToOpen;
std::vector<int> m_pressedKeys;
bool m_mouseButtonDown = false;
bool m_buttonDown = false;
bool m_hadEvent = false;
bool m_frameRateTemporarilyUnlocked = false;

View File

@ -170,7 +170,7 @@ namespace hex {
bool frameRateUnlocked =
ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) ||
TaskManager::getRunningTaskCount() > 0 ||
this->m_mouseButtonDown ||
this->m_buttonDown ||
this->m_hadEvent ||
!this->m_pressedKeys.empty();
@ -830,9 +830,9 @@ namespace hex {
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
if (action == GLFW_PRESS)
win->m_mouseButtonDown = true;
win->m_buttonDown = true;
else if (action == GLFW_RELEASE)
win->m_mouseButtonDown = false;
win->m_buttonDown = false;
win->processEvent();
});
@ -848,17 +848,24 @@ namespace hex {
glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) {
hex::unused(mods);
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
if (action == GLFW_RELEASE) {
win->m_buttonDown = false;
} else {
win->m_buttonDown = true;
}
if (key == GLFW_KEY_UNKNOWN) return;
auto keyName = glfwGetKeyName(key, scancode);
if (keyName != nullptr)
key = std::toupper(keyName[0]);
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
win->m_pressedKeys.push_back(key);
}
win->processEvent();
});