From 1b055723a36c410d1a33484ef5d1adc1e20a4437 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 16 Aug 2023 18:33:05 +0200 Subject: [PATCH] Fixed an issue where the key repeat in PDFViewer didn't work correctly if pages took a very long time to convert --- es-app/src/PDFViewer.cpp | 15 +++++++++------ es-app/src/PDFViewer.h | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/es-app/src/PDFViewer.cpp b/es-app/src/PDFViewer.cpp index 2822b7959..6f59e98f0 100644 --- a/es-app/src/PDFViewer.cpp +++ b/es-app/src/PDFViewer.cpp @@ -37,6 +37,7 @@ PDFViewer::PDFViewer() , mZoom {1.0f} , mPanAmount {0.0f} , mPanOffset {0.0f, 0.0f, 0.0f} + , mConversionTime {0} , mKeyRepeatLeftRight {0} , mKeyRepeatUpDown {0} , mKeyRepeatZoom {0} @@ -91,6 +92,7 @@ bool PDFViewer::startPDFViewer(FileData* game) mZoom = 1.0f; mPanAmount = 0.0f; mPanOffset = {0.0f, 0.0f, 0.0f}; + mConversionTime = 0; mKeyRepeatLeftRight = 0; mKeyRepeatUpDown = 0; mKeyRepeatZoom = 0; @@ -340,6 +342,8 @@ bool PDFViewer::getDocumentInfo() void PDFViewer::convertPage(int pageNum) { assert(pageNum <= static_cast(mPages.size())); + const auto conversionStartTime {std::chrono::system_clock::now()}; + mConversionTime = 0; if (mPages[pageNum].imageData.empty()) { #if defined(_WIN64) @@ -505,6 +509,9 @@ void PDFViewer::convertPage(int pageNum) mPanAmount = std::min(mRenderer->getScreenWidth(), mRenderer->getScreenHeight()) * 0.1f; + mConversionTime = static_cast(std::chrono::duration_cast( + std::chrono::system_clock::now() - conversionStartTime) + .count()); #if (DEBUG_PDF_CONVERSION) LOG(LogDebug) << "ABGR32 data stream size: " << mPages[pageNum].imageData.size(); #endif @@ -614,10 +621,8 @@ void PDFViewer::input(InputConfig* config, Input input) void PDFViewer::update(int deltaTime) { if (mKeyRepeatLeftRight != 0) { - mKeyRepeatTimer += deltaTime; - // Limit the accumulated backlog of keypresses if the computer can't keep up. - if (mKeyRepeatTimer > KEY_REPEAT_SPEED * 2) - mKeyRepeatTimer = KEY_REPEAT_SPEED * 2; + // Limit the accumulated time if the computer can't keep up. + mKeyRepeatTimer += (deltaTime < KEY_REPEAT_SPEED ? deltaTime : deltaTime - mConversionTime); while (mKeyRepeatTimer >= (mZoom > 1.0f ? KEY_REPEAT_SPEED_ZOOMED : KEY_REPEAT_SPEED)) { mKeyRepeatTimer -= (mZoom > 1.0f ? KEY_REPEAT_SPEED_ZOOMED : KEY_REPEAT_SPEED); if (mKeyRepeatLeftRight == 1) @@ -628,8 +633,6 @@ void PDFViewer::update(int deltaTime) } if (mKeyRepeatUpDown != 0) { mKeyRepeatTimer += deltaTime; - if (mKeyRepeatTimer > KEY_REPEAT_SPEED * 2) - mKeyRepeatTimer = KEY_REPEAT_SPEED * 2; while (mKeyRepeatTimer >= (mZoom > 1.0f ? KEY_REPEAT_SPEED_ZOOMED : KEY_REPEAT_SPEED)) { mKeyRepeatTimer -= (mZoom > 1.0f ? KEY_REPEAT_SPEED_ZOOMED : KEY_REPEAT_SPEED); if (mKeyRepeatUpDown == 1) diff --git a/es-app/src/PDFViewer.h b/es-app/src/PDFViewer.h index e94e0aa93..8a1d82eba 100644 --- a/es-app/src/PDFViewer.h +++ b/es-app/src/PDFViewer.h @@ -70,6 +70,7 @@ private: float mPanAmount; glm::vec3 mPanOffset; + int mConversionTime; int mKeyRepeatLeftRight; int mKeyRepeatUpDown; int mKeyRepeatZoom;