Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal hold time for cancel of ShowProgress #820

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions arm9/source/common/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define FONT_MAX_WIDTH 8
#define FONT_MAX_HEIGHT 10
#define PROGRESS_REFRESH_RATE 30 // the progress bar is only allowed to draw to screen every X milliseconds
#define PROGRESS_CANCEL_MIN_HOLD_MS 1000

typedef struct {
char chunk_id[4]; // NOT null terminated
Expand Down Expand Up @@ -1391,6 +1392,16 @@ bool ShowRtcSetterPrompt(void* time, const char *format, ...) {
return ret;
}

static bool ShowProgressCancelCheck(u64 msec)
{
static u64 last_msec = 0;

if (msec != 0 && CheckButton(BUTTON_B)) return (msec > last_msec + PROGRESS_CANCEL_MIN_HOLD_MS);

last_msec = msec;
return false;
}

bool ShowProgress(u64 current, u64 total, const char* opstr)
{
static u32 last_prog_width = 0;
Expand All @@ -1410,7 +1421,8 @@ bool ShowProgress(u64 current, u64 total, const char* opstr)
if (!current) {
timer = timer_start();
last_sec_remain = 0;
} else if (timer_msec(timer) < last_msec_elapsed + PROGRESS_REFRESH_RATE) return !CheckButton(BUTTON_B);
ShowProgressCancelCheck(0); // reset counter
} else if (timer_msec(timer) < last_msec_elapsed + PROGRESS_REFRESH_RATE) return !ShowProgressCancelCheck(timer_msec(timer));
last_msec_elapsed = timer_msec(timer);
u64 sec_elapsed = (total > 0) ? timer_sec( timer ) : 0;
u64 sec_total = (current > 0) ? (sec_elapsed * total) / current : 0;
Expand Down Expand Up @@ -1440,7 +1452,7 @@ bool ShowProgress(u64 current, u64 total, const char* opstr)

last_prog_width = prog_width;

return !CheckButton(BUTTON_B);
return !ShowProgressCancelCheck(last_msec_elapsed);
}

int ShowBrightnessConfig(int set_brightness)
Expand Down