forked from len0rd/rockbox
plugins: stopwatch: use UI viewport, fix vp not cleared
- lap times were not cleared after reset - fix stuck lap scroll position after reset - the running counter displayed stuck pixels depending on the font's character width Change-Id: I0427bb2257ae8646ae675ae92ae3a5601083c4d1
This commit is contained in:
parent
42e5fa3ea5
commit
9593dca0ef
1 changed files with 58 additions and 75 deletions
|
@ -352,15 +352,11 @@ static void ticks_to_string(int ticks,int lap,int buflen, char * buf)
|
|||
ticks -= (HZ * seconds);
|
||||
cs = ticks;
|
||||
if (!lap)
|
||||
{
|
||||
rb->snprintf(buf, buflen,
|
||||
"%2d:%02d:%02d.%02d",
|
||||
hours, minutes, seconds, cs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (lap > 1)
|
||||
"%2d:%02d:%02d.%02d ", /* add some blank space, in case */
|
||||
hours, minutes, seconds, cs); /* char width differs, since we */
|
||||
/* don't clear the viewport */
|
||||
else if (lap > 1)
|
||||
{
|
||||
int last_ticks, last_hours, last_minutes, last_seconds, last_cs;
|
||||
last_ticks = lap_times[(lap-1)%MAX_LAPS] - lap_times[(lap-2)%MAX_LAPS];
|
||||
|
@ -378,27 +374,19 @@ static void ticks_to_string(int ticks,int lap,int buflen, char * buf)
|
|||
last_minutes, last_seconds, last_cs);
|
||||
}
|
||||
else
|
||||
{
|
||||
rb->snprintf(buf, buflen,
|
||||
"%2d %2d:%02d:%02d.%02d",
|
||||
lap, hours, minutes, seconds, cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Load saved stopwatch state, if exists.
|
||||
*/
|
||||
static void load_stopwatch(void)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = rb->open(STOPWATCH_FILE, O_RDONLY);
|
||||
|
||||
int fd = rb->open(STOPWATCH_FILE, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* variable stopwatch isn't saved/loaded, because it is only used
|
||||
* temporarily in main loop
|
||||
|
@ -431,14 +419,9 @@ static void load_stopwatch(void)
|
|||
*/
|
||||
static void save_stopwatch(void)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC, 0666);
|
||||
|
||||
int fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC, 0666);
|
||||
if (fd < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* variable stopwatch isn't saved/loaded, because it is only used
|
||||
* temporarily in main loop
|
||||
|
@ -457,75 +440,72 @@ static void save_stopwatch(void)
|
|||
|
||||
enum plugin_status plugin_start(const void* parameter)
|
||||
{
|
||||
struct viewport vp, *last_vp;
|
||||
struct screen *display;
|
||||
char buf[32];
|
||||
int button;
|
||||
int lap;
|
||||
int done = false;
|
||||
bool update_lap = true;
|
||||
int lines;
|
||||
|
||||
int ret = PLUGIN_OK;
|
||||
(void)parameter;
|
||||
|
||||
int h;
|
||||
rb->lcd_setfont(FONT_UI);
|
||||
rb->lcd_getstringsize("M", NULL, &h);
|
||||
lines = (LCD_HEIGHT / h) - (LAP_Y);
|
||||
|
||||
FOR_NB_SCREENS(i)
|
||||
rb->viewportmanager_theme_enable(i, true, NULL);
|
||||
|
||||
rb->viewport_set_defaults(&vp, SCREEN_MAIN);
|
||||
display = rb->screens[SCREEN_MAIN];
|
||||
|
||||
display->setfont(FONT_UI);
|
||||
display->getstringsize("M", NULL, &h);
|
||||
lines = (vp.height / h) - (LAP_Y);
|
||||
|
||||
load_stopwatch();
|
||||
|
||||
rb->lcd_clear_display();
|
||||
|
||||
while (!done)
|
||||
{
|
||||
rb->send_event(GUI_EVENT_ACTIONUPDATE, NULL); /* update status bar */
|
||||
if (counting)
|
||||
{
|
||||
stopwatch = prev_total + *rb->current_tick - start_at;
|
||||
}
|
||||
else
|
||||
{
|
||||
stopwatch = prev_total;
|
||||
}
|
||||
|
||||
ticks_to_string(stopwatch,0,32,buf);
|
||||
rb->lcd_puts(0, TIMER_Y, buf);
|
||||
last_vp = display->set_viewport(&vp);
|
||||
|
||||
if(update_lap)
|
||||
{
|
||||
display->clear_viewport();
|
||||
display->puts(0, TIMER_Y, buf);
|
||||
lap_start = curr_lap - lap_scroll;
|
||||
for (lap = lap_start; lap > lap_start - lines; lap--)
|
||||
{
|
||||
if (lap > 0)
|
||||
{
|
||||
ticks_to_string(lap_times[(lap-1)%MAX_LAPS],lap,32,buf);
|
||||
rb->lcd_puts_scroll(0, LAP_Y + lap_start - lap, buf);
|
||||
display->puts_scroll(0, LAP_Y + lap_start - lap, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
rb->lcd_puts(0, LAP_Y + lap_start - lap,
|
||||
display->puts(0, LAP_Y + lap_start - lap,
|
||||
" ");
|
||||
}
|
||||
}
|
||||
update_lap = false;
|
||||
}
|
||||
|
||||
rb->lcd_update();
|
||||
|
||||
else
|
||||
display->puts(0, TIMER_Y, buf);
|
||||
display->update_viewport();
|
||||
display->set_viewport(last_vp);
|
||||
if (!counting)
|
||||
{
|
||||
button = rb->button_get(true);
|
||||
}
|
||||
button = rb->button_get_w_tmo(HZ/2);
|
||||
else
|
||||
{
|
||||
button = rb->button_get_w_tmo(10);
|
||||
|
||||
/* Make sure that the jukebox isn't powered off
|
||||
automatically */
|
||||
button = rb->button_get_w_tmo(HZ/10);
|
||||
rb->reset_poweroff_timer();
|
||||
}
|
||||
switch (button)
|
||||
{
|
||||
|
||||
/* exit */
|
||||
#ifdef STOPWATCH_RC_QUIT
|
||||
case STOPWATCH_RC_QUIT:
|
||||
#endif
|
||||
|
@ -555,6 +535,7 @@ enum plugin_status plugin_start(const void* parameter)
|
|||
{
|
||||
prev_total = 0;
|
||||
curr_lap = 0;
|
||||
lap_scroll = 0;
|
||||
update_lap = true;
|
||||
}
|
||||
break;
|
||||
|
@ -597,9 +578,11 @@ enum plugin_status plugin_start(const void* parameter)
|
|||
|
||||
default:
|
||||
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
||||
return PLUGIN_USB_CONNECTED;
|
||||
ret = PLUGIN_USB_CONNECTED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return PLUGIN_OK;
|
||||
FOR_NB_SCREENS(i)
|
||||
rb->viewportmanager_theme_undo(i, false);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue