1
0
Fork 0
forked from len0rd/rockbox

Make the credits scrolling changes a bit more user friendly, use actions and some code cleanup

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14590 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Peter D'Hoye 2007-09-03 00:36:20 +00:00
parent e79128de66
commit ec5b48dfe3

View file

@ -21,124 +21,15 @@
PLUGIN_HEADER PLUGIN_HEADER
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) static struct plugin_api* rb;
#define QUIT BUTTON_OFF
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == ONDIO_PAD
#define QUIT BUTTON_OFF
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == RECORDER_PAD
#define QUIT BUTTON_OFF
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
#define QUIT BUTTON_OFF
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || \
(CONFIG_KEYPAD == IPOD_4G_PAD)
#define QUIT BUTTON_MENU
#define UP BUTTON_SCROLL_BACK
#define DOWN BUTTON_SCROLL_FWD
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
#define QUIT BUTTON_A
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD /* grayscale at the moment */
#define QUIT BUTTON_POWER
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == SANSA_E200_PAD
#define QUIT BUTTON_POWER
#define UP BUTTON_SCROLL_UP
#define DOWN BUTTON_SCROLL_DOWN
#elif CONFIG_KEYPAD == IRIVER_H10_PAD /* grayscale at the moment */
#define QUIT BUTTON_POWER
#define UP BUTTON_SCROLL_UP
#define DOWN BUTTON_SCROLL_DOWN
#elif CONFIG_KEYPAD == PLAYER_PAD
#define QUIT BUTTON_STOP
#define UP BUTTON_LEFT
#define DOWN BUTTON_RIGHT
#elif CONFIG_KEYPAD == IPOD_1G2G_PAD
#define QUIT (BUTTON_PLAY|BUTTON_REPEAT)
#define UP BUTTON_SCROLL_BACK
#define DOWN BUTTON_SCROLL_FWD
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
#define QUIT BUTTON_PLAY
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#else
#error Unsupported keypad
#endif
void roll_credits(void);
const char* const credits[] = { const char* const credits[] = {
#include "credits.raw" /* generated list of names from docs/CREDITS */ #include "credits.raw" /* generated list of names from docs/CREDITS */
}; };
static struct plugin_api* rb; #define STOP_AUTOSCROLL(action) ((ACTION_KBD_ABORT == action) || \
(ACTION_KBD_UP == action) || \
enum plugin_status plugin_start(struct plugin_api* api, void* parameter) (ACTION_KBD_DOWN == action))
{
int j = 0;
int btn;
(void)parameter;
rb = api;
/* Turn off backlight timeout */
backlight_force_on(rb); /* backlight control in lib/helper.c */
rb->show_logo();
#ifdef HAVE_LCD_CHARCELLS
rb->lcd_double_height(false);
#endif
/* Show the logo for about 3 secs allowing the user to stop */
for (j = 0; j < 15; j++) {
rb->sleep((HZ*2)/10);
btn = rb->button_get(false);
if (btn != BUTTON_NONE && (btn & QUIT))
goto end_of_proc;
}
roll_credits();
end_of_proc:
/* Turn on backlight timeout (revert to settings) */
backlight_use_settings(rb); /* backlight control in lib/helper.c */
return PLUGIN_OK;
}
#ifdef HAVE_LCD_CHARCELLS #ifdef HAVE_LCD_CHARCELLS
@ -165,7 +56,8 @@ void roll_credits(void)
int x2; int x2;
if (x < 0) if (x < 0)
rb->lcd_puts(0, line, credits[name] + rb->utf8seek(credits[name], -x)); rb->lcd_puts(0, line,
credits[name] + rb->utf8seek(credits[name], -x));
else else
rb->lcd_puts(x, line, credits[name]); rb->lcd_puts(x, line, credits[name]);
@ -185,7 +77,7 @@ void roll_credits(void)
rb->lcd_update(); rb->lcd_update();
/* abort on keypress */ /* abort on keypress */
if (rb->button_get_w_tmo(HZ/8) & QUIT) if(ACTION_KBD_ABORT == rb->get_action(CONTEXT_KEYBOARD,HZ/8))
return; return;
if (++curr_index >= curr_len) if (++curr_index >= curr_len)
@ -202,8 +94,29 @@ void roll_credits(void)
#else #else
int update_rowpos(int action, int cur_pos, int rows_per_screen, int tot_rows)
{
switch(action)
{
case ACTION_KBD_UP:
cur_pos--;
break;
case ACTION_KBD_DOWN:
cur_pos++;
break;
}
if(cur_pos > tot_rows - rows_per_screen)
cur_pos = 0;
if(cur_pos < 0)
cur_pos = tot_rows - rows_per_screen;
return cur_pos;
}
void roll_credits(void) void roll_credits(void)
{ {
/* to do: use target defines iso keypads to set animation timings */
#if (CONFIG_KEYPAD == RECORDER_PAD) #if (CONFIG_KEYPAD == RECORDER_PAD)
#define PAUSE_TIME 1.2 #define PAUSE_TIME 1.2
#define ANIM_SPEED 35 #define ANIM_SPEED 35
@ -225,11 +138,15 @@ void roll_credits(void)
#define NUM_VISIBLE_LINES (LCD_HEIGHT/font_h - 1) #define NUM_VISIBLE_LINES (LCD_HEIGHT/font_h - 1)
#define CREDITS_TARGETPOS ((LCD_WIDTH/2)-(credits_w/2)) #define CREDITS_TARGETPOS ((LCD_WIDTH/2)-(credits_w/2))
int i=0, j=0, k=0, namepos=0, offset_dummy, btn; int i=0, j=0, namepos=0, offset_dummy;
int name_w, name_h, name_targetpos=1, font_h; int name_w, name_h, name_targetpos=1, font_h;
int credits_w, credits_pos; int credits_w, credits_pos;
int numnames = (sizeof(credits)/sizeof(char*)); int numnames = (sizeof(credits)/sizeof(char*));
char name[40], elapsednames[20]; char name[40], elapsednames[20];
int action = ACTION_NONE;
/* control if scrolling is automatic (with animation) or manual */
bool manual_scroll = false;
rb->lcd_setfont(FONT_UI); rb->lcd_setfont(FONT_UI);
rb->lcd_clear_display(); rb->lcd_clear_display();
@ -264,151 +181,164 @@ void roll_credits(void)
i+1, numnames); i+1, numnames);
rb->lcd_getstringsize(elapsednames, &credits_w, NULL); rb->lcd_getstringsize(elapsednames, &credits_w, NULL);
rb->lcd_putsxy(CREDITS_TARGETPOS, 0, elapsednames); rb->lcd_putsxy(CREDITS_TARGETPOS, 0, elapsednames);
rb->lcd_update_rect(CREDITS_TARGETPOS, 0, credits_w, font_h);
for(namepos = 0-name_w; namepos <= name_targetpos; for(namepos = 0-name_w; namepos <= name_targetpos;
namepos += (name_targetpos - namepos + 14) / 7) namepos += (name_targetpos - namepos + 14) / 7)
{ {
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(0, font_h*(i+1), LCD_WIDTH, font_h); /* clear any trails left behind */ /* clear any trails left behind */
rb->lcd_fillrect(0, font_h*(i+1), LCD_WIDTH, font_h);
rb->lcd_set_drawmode(DRMODE_SOLID); rb->lcd_set_drawmode(DRMODE_SOLID);
rb->lcd_putsxy(namepos, font_h*(i+1), name); rb->lcd_putsxy(namepos, font_h*(i+1), name);
rb->lcd_update_rect(0, font_h*(i+1), LCD_WIDTH, font_h); rb->lcd_update_rect(0, font_h*(i+1), LCD_WIDTH, font_h);
rb->lcd_update_rect(CREDITS_TARGETPOS, 0, credits_w, font_h);
/* exit on power key */ /* exit on abort, switch to manual on up/down */
btn = rb->button_get_w_tmo(HZ/ANIM_SPEED); action = rb->get_action(CONTEXT_KEYBOARD, HZ/ANIM_SPEED);
if (btn != BUTTON_NONE && (btn & QUIT)) if(STOP_AUTOSCROLL(action))
return; break;
} }
if(STOP_AUTOSCROLL(action))
break;
} }
j+=i;
/* pause for a bit if needed */ /* process user actions (if any) */
btn = rb->button_get_w_tmo(HZ*PAUSE_TIME); /* exit on keypress */ if(ACTION_KBD_ABORT == action)
if (btn != BUTTON_NONE && (btn & QUIT))
return; return;
if(STOP_AUTOSCROLL(action))
manual_scroll = true; /* up/down - abort was catched above */
/* now begin looping the in-out animation */ if(!manual_scroll)
do { {
for(; j < numnames; j+=i) j+= i;
/* pause for a bit if needed */
action = rb->get_action(CONTEXT_KEYBOARD, HZ*PAUSE_TIME);
if(ACTION_KBD_ABORT == action)
return;
if(STOP_AUTOSCROLL(action))
manual_scroll = true;
}
if(!manual_scroll)
{
while(j < numnames)
{ {
/* just a screen's worth at a time */ /* just a screen's worth at a time */
for(i=0; i<NUM_VISIBLE_LINES; i++) for(i=0; i<NUM_VISIBLE_LINES; i++)
{ {
if(j+i >= numnames) if(j+i >= numnames)
break;
offset_dummy=1;
rb->snprintf(name, sizeof(name), "%s",
credits[j+i-NUM_VISIBLE_LINES]);
rb->lcd_getstringsize(name, &name_w, &name_h);
/* fly out an existing line.. */
while(namepos<LCD_WIDTH+offset_dummy)
{
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
/* clear trails */
rb->lcd_fillrect(0, font_h*(i+1), LCD_WIDTH, font_h);
rb->lcd_set_drawmode(DRMODE_SOLID);
rb->lcd_putsxy(namepos, font_h*(i+1), name);
rb->lcd_update_rect(0, font_h*(i+1), LCD_WIDTH, font_h);
/* exit on keypress, react to scrolling */
action = rb->get_action(CONTEXT_KEYBOARD, HZ/ANIM_SPEED);
if(STOP_AUTOSCROLL(action))
break;
namepos += offset_dummy;
offset_dummy++;
} /* while(namepos<LCD_WIDTH+offset_dummy) */
if(STOP_AUTOSCROLL(action))
break;
rb->snprintf(name, sizeof(name), "%s", credits[j+i]);
rb->lcd_getstringsize(name, &name_w, &name_h);
rb->snprintf(elapsednames, sizeof(elapsednames),
"[Credits] %d/%d", j+i+1, numnames);
rb->lcd_getstringsize(elapsednames, &credits_w, NULL);
rb->lcd_putsxy(CREDITS_TARGETPOS, 0, elapsednames);
if (j+i < NUM_VISIBLE_LINES) /* takes care of trail on loop */
rb->lcd_update_rect(0, 0, LCD_WIDTH, font_h);
for(namepos = 0-name_w; namepos <= name_targetpos;
namepos += (name_targetpos - namepos + 14) / 7)
{
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(0, font_h*(i+1), LCD_WIDTH, font_h);
rb->lcd_set_drawmode(DRMODE_SOLID);
rb->lcd_putsxy(namepos, font_h*(i+1), name);
rb->lcd_update_rect(0, font_h*(i+1), LCD_WIDTH, font_h);
rb->lcd_update_rect(CREDITS_TARGETPOS, 0, credits_w,font_h);
/* stop on keypress */
action = rb->get_action(CONTEXT_KEYBOARD, HZ/ANIM_SPEED);
if(STOP_AUTOSCROLL(action))
break;
}
if(STOP_AUTOSCROLL(action))
break;
namepos = name_targetpos;
} /* for(i=0; i<NUM_VISIBLE_LINES; i++) */
if(STOP_AUTOSCROLL(action))
break; break;
offset_dummy=1; action = rb->get_action(CONTEXT_KEYBOARD, HZ*PAUSE_TIME);
if(STOP_AUTOSCROLL(action))
break;
rb->snprintf(name, sizeof(name), "%s", j+=i; /* no user intervention, draw the next screen-full */
credits[(j>=NUM_VISIBLE_LINES)? } /* while(j < numnames) */
j+i-NUM_VISIBLE_LINES:j+i]);
rb->lcd_getstringsize(name, &name_w, &name_h);
/* fly out an existing line.. */ /* handle the keypress that we intercepted during autoscroll */
while(namepos<LCD_WIDTH+offset_dummy) if(ACTION_KBD_ABORT == action)
{
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(0, font_h*(i+1), LCD_WIDTH, font_h); /* clear trails */
rb->lcd_set_drawmode(DRMODE_SOLID);
rb->lcd_putsxy(namepos, font_h*(i+1), name);
rb->lcd_update_rect(0, font_h*(i+1), LCD_WIDTH, font_h);
/* exit on keypress, react to scrolling */
btn = rb->button_get_w_tmo(HZ/ANIM_SPEED);
if (btn != BUTTON_NONE)
{
if (btn & QUIT)
return;
else if ((btn & UP) ^ (btn & DOWN))
{
/* compute the new position */
j+=((btn & UP)?-1:1)*(NUM_VISIBLE_LINES/2);
if (j+i >= numnames) j=numnames-i-1;
if (j < 0) j = 0;
/* and refresh the whole screen */
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(0, 0, LCD_WIDTH,
font_h * (NUM_VISIBLE_LINES+1));
rb->lcd_set_drawmode(DRMODE_SOLID);
rb->snprintf(elapsednames, sizeof(elapsednames),
"[Credits] %d/%d", j+i+1, numnames);
rb->lcd_getstringsize(elapsednames, &credits_w, NULL);
rb->lcd_putsxy(CREDITS_TARGETPOS, 0, elapsednames);
for (k=0; k<NUM_VISIBLE_LINES; k++)
if (k!=i)
{
rb->snprintf(name, sizeof(name), "%s",
credits[(j>=NUM_VISIBLE_LINES)?
((k<i)?
(j+k):(j+k-NUM_VISIBLE_LINES)):
j+k]);
rb->lcd_putsxy(0, font_h*(k+1), name);
}
rb->lcd_update_rect(0, font_h, LCD_WIDTH,
font_h * (NUM_VISIBLE_LINES+1));
break;
}
}
namepos += offset_dummy;
offset_dummy++;
}
rb->snprintf(name, sizeof(name), "%s", credits[j+i]);
rb->lcd_getstringsize(name, &name_w, &name_h);
rb->snprintf(elapsednames, sizeof(elapsednames), "[Credits] %d/%d",
j+i+1, numnames);
rb->lcd_getstringsize(elapsednames, &credits_w, NULL);
rb->lcd_putsxy(CREDITS_TARGETPOS, 0, elapsednames);
if (j+i < NUM_VISIBLE_LINES) /* takes care of trail on loop */
rb->lcd_update_rect(0, 0, LCD_WIDTH, font_h);
for(namepos = 0-name_w; namepos <= name_targetpos;
namepos += (name_targetpos - namepos + 14) / 7)
{
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(0, font_h*(i+1), LCD_WIDTH, font_h);
rb->lcd_set_drawmode(DRMODE_SOLID);
rb->lcd_putsxy(namepos, font_h*(i+1), name);
rb->lcd_update_rect(0, font_h*(i+1), LCD_WIDTH, font_h);
rb->lcd_update_rect(CREDITS_TARGETPOS, 0, credits_w, font_h);
/* exit on keypress */
btn = rb->button_get_w_tmo(HZ/ANIM_SPEED);
if (btn != BUTTON_NONE && (btn & QUIT))
return;
}
namepos = name_targetpos;
/* ..and repeat. */
}
btn = rb->button_get_w_tmo(HZ*PAUSE_TIME); /* exit on keypress */
if (btn != BUTTON_NONE && (btn & QUIT))
return; return;
if(STOP_AUTOSCROLL(action))
manual_scroll = true;
} /* if(!manual_scroll) */
if(manual_scroll)
{
/* user went into manual scrolling, handle it here */
rb->lcd_set_drawmode(DRMODE_SOLID);
while(ACTION_KBD_ABORT != action)
{
rb->lcd_clear_display();
rb->snprintf(elapsednames, sizeof(elapsednames),
"[Credits] %d/%d", j+NUM_VISIBLE_LINES, numnames);
rb->lcd_getstringsize(elapsednames, &credits_w, NULL);
rb->lcd_putsxy(CREDITS_TARGETPOS, 0, elapsednames);
for(i=0; i<NUM_VISIBLE_LINES; i++)
{
rb->snprintf(name, sizeof(name), "%s", credits[j+i]);
rb->lcd_putsxy(0, font_h*(i+1), name);
}
rb->lcd_update();
/* wait for user action */
action = rb->get_action(CONTEXT_KEYBOARD, TIMEOUT_BLOCK);
if(ACTION_KBD_ABORT == action)
return;
j = update_rowpos(action, j, NUM_VISIBLE_LINES, numnames);
} }
return; /* exit without animation */
}
j = 0; action = rb->get_action(CONTEXT_KEYBOARD, HZ*3);
if(k) { if(ACTION_KBD_ABORT == action)
/* on loop, the new credit line might shorten */
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(0, 0, LCD_WIDTH, font_h);
}
} while(k); /* repeat in-out animation forever if scrolling occured */
btn = rb->button_get_w_tmo(HZ*2.5); /* exit on keypress */
if (btn != BUTTON_NONE && (btn & QUIT))
return; return;
offset_dummy = 1; offset_dummy = 1;
/* now make the text exit to the right */ /* now make the text exit to the right */
for(credits_pos = (LCD_WIDTH/2)-(credits_w/2); credits_pos <= LCD_WIDTH+offset_dummy; for(credits_pos = (LCD_WIDTH/2)-(credits_w/2);
credits_pos <= LCD_WIDTH+offset_dummy;
credits_pos += offset_dummy, offset_dummy++) credits_pos += offset_dummy, offset_dummy++)
{ {
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
@ -420,3 +350,26 @@ void roll_credits(void)
} }
#endif #endif
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
(void)parameter;
rb = api;
/* Turn off backlight timeout */
backlight_force_on(rb); /* backlight control in lib/helper.c */
rb->show_logo();
#ifdef HAVE_LCD_CHARCELLS
rb->lcd_double_height(false);
#endif
/* Show the logo for about 3 secs allowing the user to stop */
if(ACTION_KBD_ABORT != rb->get_action(CONTEXT_KEYBOARD,3*HZ))
roll_credits();
/* Turn on backlight timeout (revert to settings) */
backlight_use_settings(rb); /* backlight control in lib/helper.c */
return PLUGIN_OK;
}