Added press and hold logic to Qt TAS editor playback push buttons.

This commit is contained in:
mjbudd77 2021-12-20 21:55:45 -05:00
parent f1eb0a94fe
commit d0bdab8c63
2 changed files with 41 additions and 18 deletions

View File

@ -92,54 +92,58 @@ void PLAYBACK::update()
// controls: // controls:
// update < and > buttons // update < and > buttons
rewindButtonOldState = rewindButtonState; rewindButtonOldState = rewindButtonState;
//rewindButtonState = ((Button_GetState(hwndRewind) & BST_PUSHED) != 0 || mustRewindNow); rewindButtonState = tasWin->rewindFrmBtn->isDown();
if (rewindButtonState) if (rewindButtonState)
{ {
if (!rewindButtonOldState) if (!rewindButtonOldState)
{ {
buttonHoldTimer = clock(); buttonHoldTimer = clock();
handleRewindFrame(); //handleRewindFrame();
} else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock()) }
else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock())
{ {
handleRewindFrame(); handleRewindFrame();
} }
} }
forwardButtonOldState = forwardButtonState; forwardButtonOldState = forwardButtonState;
//forwardButtonState = (Button_GetState(hwndForward) & BST_PUSHED) != 0; forwardButtonState = tasWin->advFrmBtn->isDown();
if (forwardButtonState && !rewindButtonState) if (forwardButtonState && !rewindButtonState)
{ {
if (!forwardButtonOldState) if (!forwardButtonOldState)
{ {
buttonHoldTimer = clock(); buttonHoldTimer = clock();
handleForwardFrame(); //handleForwardFrame();
} else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock()) }
else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock())
{ {
handleForwardFrame(); handleForwardFrame();
} }
} }
// update << and >> buttons // update << and >> buttons
rewindFullButtonOldState = rewindFullButtonState; rewindFullButtonOldState = rewindFullButtonState;
//rewindFullButtonState = ((Button_GetState(hwndRewindFull) & BST_PUSHED) != 0); rewindFullButtonState = tasWin->rewindMkrBtn->isDown();
if (rewindFullButtonState && !rewindButtonState && !forwardButtonState) if (rewindFullButtonState && !rewindButtonState && !forwardButtonState)
{ {
if (!rewindFullButtonOldState) if (!rewindFullButtonOldState)
{ {
buttonHoldTimer = clock(); buttonHoldTimer = clock();
handleRewindFull(); //handleRewindFull();
} else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock()) }
else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock())
{ {
handleRewindFull(); handleRewindFull();
} }
} }
forwardFullButtonOldState = forwardFullButtonState; forwardFullButtonOldState = forwardFullButtonState;
//forwardFullButtonState = (Button_GetState(hwndForwardFull) & BST_PUSHED) != 0; forwardFullButtonState = tasWin->advMkrBtn->isDown();
if (forwardFullButtonState && !rewindButtonState && !forwardButtonState && !rewindFullButtonState) if (forwardFullButtonState && !rewindButtonState && !forwardButtonState && !rewindFullButtonState)
{ {
if (!forwardFullButtonOldState) if (!forwardFullButtonOldState)
{ {
buttonHoldTimer = clock(); buttonHoldTimer = clock();
handleForwardFull(); //handleForwardFull();
} else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock()) }
else if (buttonHoldTimer + BUTTON_HOLD_REPEAT_DELAY < clock())
{ {
handleForwardFull(); handleForwardFull();
} }
@ -179,10 +183,14 @@ void PLAYBACK::update()
// pause when seeking hits pause_frame // pause when seeking hits pause_frame
if (pauseFrame && currFrameCounter + 1 >= pauseFrame) if (pauseFrame && currFrameCounter + 1 >= pauseFrame)
{
stopSeeking(); stopSeeking();
}
else if (currFrameCounter >= getLastPosition() && currFrameCounter >= currMovieData.getNumRecords() - 1 && mustAutopauseAtTheEnd && taseditorConfig->autopauseAtTheEndOfMovie && !isTaseditorRecording()) else if (currFrameCounter >= getLastPosition() && currFrameCounter >= currMovieData.getNumRecords() - 1 && mustAutopauseAtTheEnd && taseditorConfig->autopauseAtTheEndOfMovie && !isTaseditorRecording())
{
// pause at the end of the movie // pause at the end of the movie
pauseEmulation(); pauseEmulation();
}
// update flashing pauseframe // update flashing pauseframe
if (oldPauseFrame != pauseFrame && oldPauseFrame) if (oldPauseFrame != pauseFrame && oldPauseFrame)
@ -199,7 +207,11 @@ void PLAYBACK::update()
showPauseFrame = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD_WHEN_PAUSED) & 1; showPauseFrame = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD_WHEN_PAUSED) & 1;
else else
showPauseFrame = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD_WHEN_SEEKING) & 1; showPauseFrame = (int)(clock() / PAUSEFRAME_BLINKING_PERIOD_WHEN_SEEKING) & 1;
} else showPauseFrame = false; }
else
{
showPauseFrame = false;
}
if (oldStateOfShowPauseFrame != showPauseFrame) if (oldStateOfShowPauseFrame != showPauseFrame)
{ {
// update pauseframe gfx // update pauseframe gfx
@ -213,16 +225,20 @@ void PLAYBACK::update()
if (pauseFrame) if (pauseFrame)
{ {
if (oldStateOfShowPauseFrame != showPauseFrame) // update progressbar from time to time if (oldStateOfShowPauseFrame != showPauseFrame) // update progressbar from time to time
{
// display seeking progress // display seeking progress
setProgressbar(currFrameCounter - seekingBeginningFrame, pauseFrame - seekingBeginningFrame); setProgressbar(currFrameCounter - seekingBeginningFrame, pauseFrame - seekingBeginningFrame);
} else if (emuPausedOldState != emuPausedState) }
}
else if (emuPausedOldState != emuPausedState)
{ {
// emulator got paused/unpaused externally // emulator got paused/unpaused externally
if (emuPausedOldState && !emuPausedState) if (emuPausedOldState && !emuPausedState)
{ {
// externally unpaused - show empty progressbar // externally unpaused - show empty progressbar
setProgressbar(0, 1); setProgressbar(0, 1);
} else }
else
{ {
// externally paused - progressbar should be full // externally paused - progressbar should be full
setProgressbar(1, 1); setProgressbar(1, 1);
@ -233,15 +249,21 @@ void PLAYBACK::update()
if (emuPausedState) if (emuPausedState)
{ {
if (currFrameCounter < currMovieData.getNumRecords() - 1) if (currFrameCounter < currMovieData.getNumRecords() - 1)
{
mustAutopauseAtTheEnd = true; mustAutopauseAtTheEnd = true;
}
else else
{
mustAutopauseAtTheEnd = false; mustAutopauseAtTheEnd = false;
}
} }
// this little statement is very important for adequate work of the "green arrow" and "Restore last position" // this little statement is very important for adequate work of the "green arrow" and "Restore last position"
if (!emuPausedState) if (!emuPausedState)
{
// when emulating, lost_position_frame becomes unstable (which means that it's probably not equal to the end of current segment anymore) // when emulating, lost_position_frame becomes unstable (which means that it's probably not equal to the end of current segment anymore)
lastPositionIsStable = false; lastPositionIsStable = false;
}
} }
// called after saving the project, because saving uses the progressbar for itself // called after saving the project, because saving uses the progressbar for itself

View File

@ -1,14 +1,15 @@
// Specification file for Playback class // Specification file for Playback class
#pragma once #pragma once
#include <time.h>
#include <QLineEdit> #include <QLineEdit>
#define PROGRESSBAR_WIDTH 200 #define PROGRESSBAR_WIDTH 200
#define PAUSEFRAME_BLINKING_PERIOD_WHEN_SEEKING 100 #define PAUSEFRAME_BLINKING_PERIOD_WHEN_SEEKING (100 * (CLOCKS_PER_SEC / 1000))
#define PAUSEFRAME_BLINKING_PERIOD_WHEN_PAUSED 250 #define PAUSEFRAME_BLINKING_PERIOD_WHEN_PAUSED (250 * (CLOCKS_PER_SEC / 1000))
#define BUTTON_HOLD_REPEAT_DELAY 250 // in milliseconds #define BUTTON_HOLD_REPEAT_DELAY (250 * (CLOCKS_PER_SEC / 1000)) // in milliseconds
class UpperMarkerNoteEdit : public QLineEdit class UpperMarkerNoteEdit : public QLineEdit
{ {