ui/ux: Allow ImHex to redraw the screen while moving and resizing

This commit is contained in:
WerWolv 2021-06-07 18:14:40 +02:00
parent e0112472d6
commit fff91d555b
2 changed files with 53 additions and 41 deletions

View File

@ -28,6 +28,7 @@ namespace hex {
bool setFont(const std::filesystem::path &font_path); bool setFont(const std::filesystem::path &font_path);
private: private:
void frameBegin(); void frameBegin();
void frame();
void frameEnd(); void frameEnd();
void drawWelcomeScreen(); void drawWelcomeScreen();
@ -41,7 +42,6 @@ namespace hex {
GLFWwindow* m_window = nullptr; GLFWwindow* m_window = nullptr;
float m_globalScale = 1.0f, m_fontScale = 1.0f; float m_globalScale = 1.0f, m_fontScale = 1.0f;
bool m_fpsVisible = false;
double m_targetFps = 60.0; double m_targetFps = 60.0;
bool m_demoWindowOpen = false; bool m_demoWindowOpen = false;
bool m_layoutConfigured = false; bool m_layoutConfigured = false;

View File

@ -179,45 +179,15 @@ namespace hex {
} }
void Window::loop() { void Window::loop() {
bool pressedKeys[512] = { false };
this->m_lastFrameTime = glfwGetTime(); this->m_lastFrameTime = glfwGetTime();
while (!glfwWindowShouldClose(this->m_window)) { while (!glfwWindowShouldClose(this->m_window)) {
std::copy_n(ImGui::GetIO().KeysDown, 512, this->m_prevKeysDown); if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED))
glfwWaitEvents();
glfwPollEvents();
this->frameBegin(); this->frameBegin();
this->frame();
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
this->frameEnd(); this->frameEnd();
} }
} }
@ -278,11 +248,6 @@ namespace hex {
void Window::frameBegin() { void Window::frameBegin() {
if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED))
glfwWaitEvents();
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
@ -385,6 +350,42 @@ namespace hex {
} }
} }
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
}
void Window::frameEnd() { void Window::frameEnd() {
ImGui::Render(); ImGui::Render();
@ -583,6 +584,7 @@ namespace hex {
this->m_window = glfwCreateWindow(1280 * this->m_globalScale, 720 * this->m_globalScale, "ImHex", nullptr, nullptr); this->m_window = glfwCreateWindow(1280 * this->m_globalScale, 720 * this->m_globalScale, "ImHex", nullptr, nullptr);
glfwSetWindowUserPointer(this->m_window, this);
if (this->m_window == nullptr) if (this->m_window == nullptr)
throw std::runtime_error("Failed to create window!"); throw std::runtime_error("Failed to create window!");
@ -604,10 +606,20 @@ namespace hex {
glfwSetWindowPosCallback(this->m_window, [](GLFWwindow *window, int x, int y) { glfwSetWindowPosCallback(this->m_window, [](GLFWwindow *window, int x, int y) {
SharedData::windowPos = ImVec2(x, y); SharedData::windowPos = ImVec2(x, y);
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
win->frameBegin();
win->frame();
win->frameEnd();
}); });
glfwSetWindowSizeCallback(this->m_window, [](GLFWwindow *window, int width, int height) { glfwSetWindowSizeCallback(this->m_window, [](GLFWwindow *window, int width, int height) {
SharedData::windowSize = ImVec2(width, height); SharedData::windowSize = ImVec2(width, height);
auto win = static_cast<Window*>(glfwGetWindowUserPointer(window));
win->frameBegin();
win->frame();
win->frameEnd();
}); });
glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) { glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) {