summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2007-09-03 00:36:20 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2007-09-03 00:36:20 +0000
commitec5b48dfe3d8f877ad38435591f439d903079ffd (patch)
tree9e806e8af9a7a2cfb77189516a3e9220d4a9779c /apps
parente79128de66166c73490ad6c15c749a705a4b64eb (diff)
downloadrockbox-ec5b48dfe3d8f877ad38435591f439d903079ffd.tar.gz
rockbox-ec5b48dfe3d8f877ad38435591f439d903079ffd.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/credits.c417
1 files changed, 185 insertions, 232 deletions
diff --git a/apps/plugins/credits.c b/apps/plugins/credits.c
index 64475c8e4b..7970d2913b 100644
--- a/apps/plugins/credits.c
+++ b/apps/plugins/credits.c
@@ -21,124 +21,15 @@
PLUGIN_HEADER
-#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
-
-#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
-
+static struct plugin_api* rb;
-void roll_credits(void);
const char* const credits[] = {
#include "credits.raw" /* generated list of names from docs/CREDITS */
};
-static struct plugin_api* rb;
-
-enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
-{
- 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;
-}
+#define STOP_AUTOSCROLL(action) ((ACTION_KBD_ABORT == action) || \
+ (ACTION_KBD_UP == action) || \
+ (ACTION_KBD_DOWN == action))
#ifdef HAVE_LCD_CHARCELLS
@@ -165,7 +56,8 @@ void roll_credits(void)
int x2;
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
rb->lcd_puts(x, line, credits[name]);
@@ -185,7 +77,7 @@ void roll_credits(void)
rb->lcd_update();
/* abort on keypress */
- if (rb->button_get_w_tmo(HZ/8) & QUIT)
+ if(ACTION_KBD_ABORT == rb->get_action(CONTEXT_KEYBOARD,HZ/8))
return;
if (++curr_index >= curr_len)
@@ -202,8 +94,29 @@ void roll_credits(void)
#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)
{
+ /* to do: use target defines iso keypads to set animation timings */
#if (CONFIG_KEYPAD == RECORDER_PAD)
#define PAUSE_TIME 1.2
#define ANIM_SPEED 35
@@ -225,11 +138,15 @@ void roll_credits(void)
#define NUM_VISIBLE_LINES (LCD_HEIGHT/font_h - 1)
#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 credits_w, credits_pos;
int numnames = (sizeof(credits)/sizeof(char*));
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_clear_display();
@@ -264,151 +181,164 @@ void roll_credits(void)
i+1, numnames);
rb->lcd_getstringsize(elapsednames, &credits_w, NULL);
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;
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); /* 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_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 power key */
- btn = rb->button_get_w_tmo(HZ/ANIM_SPEED);
- if (btn != BUTTON_NONE && (btn & QUIT))
- return;
+ /* exit on abort, switch to manual on up/down */
+ action = rb->get_action(CONTEXT_KEYBOARD, HZ/ANIM_SPEED);
+ if(STOP_AUTOSCROLL(action))
+ break;
}
+ if(STOP_AUTOSCROLL(action))
+ break;
}
- j+=i;
-
- /* pause for a bit if needed */
- btn = rb->button_get_w_tmo(HZ*PAUSE_TIME); /* exit on keypress */
- if (btn != BUTTON_NONE && (btn & QUIT))
+
+ /* process user actions (if any) */
+ if(ACTION_KBD_ABORT == action)
return;
+ if(STOP_AUTOSCROLL(action))
+ manual_scroll = true; /* up/down - abort was catched above */
+
+ if(!manual_scroll)
+ {
+ 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;
+ }
- /* now begin looping the in-out animation */
- do {
- for(; j < numnames; j+=i)
+ if(!manual_scroll)
+ {
+ while(j < numnames)
{
- /* just a screen's worth at a time */
- for(i=0; i<NUM_VISIBLE_LINES; i++)
+ /* just a screen's worth at a time */
+ for(i=0; i<NUM_VISIBLE_LINES; i++)
{
- if(j+i >= numnames)
- break;
+ if(j+i >= numnames)
+ break;
+ offset_dummy=1;
- offset_dummy=1;
-
- rb->snprintf(name, sizeof(name), "%s",
- credits[(j>=NUM_VISIBLE_LINES)?
- j+i-NUM_VISIBLE_LINES:j+i]);
- 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);
- 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)
+ 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)
{
- 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));
+ /* clear trails */
+ rb->lcd_fillrect(0, font_h*(i+1), LCD_WIDTH, font_h);
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));
+ 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;
}
- 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. */
- }
+ if(STOP_AUTOSCROLL(action))
+ break;
+ namepos = name_targetpos;
+ } /* for(i=0; i<NUM_VISIBLE_LINES; i++) */
+ if(STOP_AUTOSCROLL(action))
+ break;
+
+ action = rb->get_action(CONTEXT_KEYBOARD, HZ*PAUSE_TIME);
+ if(STOP_AUTOSCROLL(action))
+ break;
- btn = rb->button_get_w_tmo(HZ*PAUSE_TIME); /* exit on keypress */
- if (btn != BUTTON_NONE && (btn & QUIT))
+ j+=i; /* no user intervention, draw the next screen-full */
+ } /* while(j < numnames) */
+
+ /* handle the keypress that we intercepted during autoscroll */
+ if(ACTION_KBD_ABORT == action)
return;
- }
+ if(STOP_AUTOSCROLL(action))
+ manual_scroll = true;
+ } /* if(!manual_scroll) */
- j = 0;
- if(k) {
- /* 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))
+ 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 */
+ }
+
+ action = rb->get_action(CONTEXT_KEYBOARD, HZ*3);
+ if(ACTION_KBD_ABORT == action)
return;
offset_dummy = 1;
/* 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++)
{
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
@@ -420,3 +350,26 @@ void roll_credits(void)
}
#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;
+}