forked from len0rd/rockbox
Fixed scrolling for iPods (now scrolling the wheel forward will move down, and scrolling backward will move up).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8699 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
333a22e73c
commit
de23679fb2
1 changed files with 50 additions and 49 deletions
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
PLUGIN_HEADER
|
PLUGIN_HEADER
|
||||||
|
|
||||||
#define SETTINGS_FILE "/.rockbox/viewers/viewer.dat"
|
#define SETTINGS_FILE "/.rockbox/viewers/viewer.dat"
|
||||||
|
|
||||||
#define WRAP_TRIM 44 /* Max number of spaces to trim (arbitrary) */
|
#define WRAP_TRIM 44 /* Max number of spaces to trim (arbitrary) */
|
||||||
#define MAX_COLUMNS 64 /* Max displayable string len (over-estimate) */
|
#define MAX_COLUMNS 64 /* Max displayable string len (over-estimate) */
|
||||||
|
@ -117,10 +117,11 @@ PLUGIN_HEADER
|
||||||
#define VIEWER_COLUMN_LEFT (BUTTON_ON | BUTTON_LEFT)
|
#define VIEWER_COLUMN_LEFT (BUTTON_ON | BUTTON_LEFT)
|
||||||
#define VIEWER_COLUMN_RIGHT (BUTTON_ON | BUTTON_RIGHT)
|
#define VIEWER_COLUMN_RIGHT (BUTTON_ON | BUTTON_RIGHT)
|
||||||
|
|
||||||
|
/* iPods with the 4G pad */
|
||||||
#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
|
||||||
#define VIEWER_QUIT BUTTON_MENU
|
#define VIEWER_QUIT BUTTON_MENU
|
||||||
#define VIEWER_PAGE_UP BUTTON_SCROLL_FWD
|
#define VIEWER_PAGE_UP BUTTON_SCROLL_BACK
|
||||||
#define VIEWER_PAGE_DOWN BUTTON_SCROLL_BACK
|
#define VIEWER_PAGE_DOWN BUTTON_SCROLL_FWD
|
||||||
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
#define VIEWER_SCREEN_LEFT BUTTON_LEFT
|
||||||
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
#define VIEWER_SCREEN_RIGHT BUTTON_RIGHT
|
||||||
#define VIEWER_MODE_WRAP (BUTTON_SELECT | BUTTON_LEFT)
|
#define VIEWER_MODE_WRAP (BUTTON_SELECT | BUTTON_LEFT)
|
||||||
|
@ -287,9 +288,9 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
|
||||||
bool first_chars;
|
bool first_chars;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
|
||||||
if (is_short != NULL)
|
if (is_short != NULL)
|
||||||
*is_short = true;
|
*is_short = true;
|
||||||
|
|
||||||
if BUFFER_OOB(cur_line)
|
if BUFFER_OOB(cur_line)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -297,7 +298,7 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
|
||||||
search_len = MAX_WIDTH;
|
search_len = MAX_WIDTH;
|
||||||
}
|
}
|
||||||
else { /* view_mode == NARROW */
|
else { /* view_mode == NARROW */
|
||||||
search_len = crop_at_width(cur_line) - cur_line;
|
search_len = crop_at_width(cur_line) - cur_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = BUFFER_OOB(cur_line+search_len) ? buffer_end-cur_line : search_len;
|
size = BUFFER_OOB(cur_line+search_len) ? buffer_end-cur_line : search_len;
|
||||||
|
@ -326,7 +327,7 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
|
||||||
}
|
}
|
||||||
if (j==0) /* i=1 is intentional */
|
if (j==0) /* i=1 is intentional */
|
||||||
for (i=0; i<par_indent_spaces; i++)
|
for (i=0; i<par_indent_spaces; i++)
|
||||||
ADVANCE_COUNTERS(' ');
|
ADVANCE_COUNTERS(' ');
|
||||||
}
|
}
|
||||||
if (!first_chars) spaces++;
|
if (!first_chars) spaces++;
|
||||||
break;
|
break;
|
||||||
|
@ -339,7 +340,7 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
|
||||||
return (unsigned char*) next_line;
|
return (unsigned char*) next_line;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
newlines++;
|
newlines++;
|
||||||
size += spaces -1;
|
size += spaces -1;
|
||||||
if (BUFFER_OOB(cur_line+size) || size > 2*search_len)
|
if (BUFFER_OOB(cur_line+size) || size > 2*search_len)
|
||||||
|
@ -360,9 +361,9 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
|
||||||
}
|
}
|
||||||
newlines=0;
|
newlines=0;
|
||||||
} else if (spaces) {
|
} else if (spaces) {
|
||||||
/* REFLOW, multiple spaces between words: count only
|
/* REFLOW, multiple spaces between words: count only
|
||||||
* one. If more are needed, they will be added
|
* one. If more are needed, they will be added
|
||||||
* while drawing. */
|
* while drawing. */
|
||||||
search_len = size;
|
search_len = size;
|
||||||
spaces=0;
|
spaces=0;
|
||||||
ADVANCE_COUNTERS(' ');
|
ADVANCE_COUNTERS(' ');
|
||||||
|
@ -370,7 +371,7 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
|
||||||
size = search_len = j;
|
size = search_len = j;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first_chars = false;
|
first_chars = false;
|
||||||
ADVANCE_COUNTERS(c);
|
ADVANCE_COUNTERS(c);
|
||||||
break;
|
break;
|
||||||
|
@ -418,7 +419,7 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
|
||||||
|
|
||||||
if (is_short)
|
if (is_short)
|
||||||
*is_short = false;
|
*is_short = false;
|
||||||
|
|
||||||
return (unsigned char*) next_line;
|
return (unsigned char*) next_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +515,7 @@ static int read_and_synch(int direction)
|
||||||
/* direction: 1 for down (i.e., further into file), -1 for up */
|
/* direction: 1 for down (i.e., further into file), -1 for up */
|
||||||
int move_size, move_vector, offset;
|
int move_size, move_vector, offset;
|
||||||
unsigned char *fill_buf;
|
unsigned char *fill_buf;
|
||||||
|
|
||||||
if (direction == -1) /* up */ {
|
if (direction == -1) /* up */ {
|
||||||
move_size = SMALL_BLOCK_SIZE;
|
move_size = SMALL_BLOCK_SIZE;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
@ -668,7 +669,7 @@ static void viewer_draw(int col)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col != -1)
|
if (col != -1)
|
||||||
if (k > col) {
|
if (k > col) {
|
||||||
scratch_buffer[k] = 0;
|
scratch_buffer[k] = 0;
|
||||||
|
@ -693,10 +694,10 @@ static void viewer_draw(int col)
|
||||||
case ' ':
|
case ' ':
|
||||||
case 0:
|
case 0:
|
||||||
if ((j==0) && (word_mode==WRAP))
|
if ((j==0) && (word_mode==WRAP))
|
||||||
/* special case: indent the paragraph,
|
/* special case: indent the paragraph,
|
||||||
* don't count spaces */
|
* don't count spaces */
|
||||||
indent_spaces = par_indent_spaces;
|
indent_spaces = par_indent_spaces;
|
||||||
else if (!multiple_spacing)
|
else if (!multiple_spacing)
|
||||||
spaces++;
|
spaces++;
|
||||||
multiple_spacing = true;
|
multiple_spacing = true;
|
||||||
break;
|
break;
|
||||||
|
@ -708,10 +709,10 @@ static void viewer_draw(int col)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (multiple_spacing) spaces--;
|
if (multiple_spacing) spaces--;
|
||||||
|
|
||||||
if (spaces) {
|
if (spaces) {
|
||||||
/* total number of spaces to insert between words */
|
/* total number of spaces to insert between words */
|
||||||
extra_spaces = (draw_columns-width) / glyph_width[' ']
|
extra_spaces = (draw_columns-width) / glyph_width[' ']
|
||||||
- indent_spaces;
|
- indent_spaces;
|
||||||
/* number of spaces between each word*/
|
/* number of spaces between each word*/
|
||||||
spaces_per_word = extra_spaces / spaces;
|
spaces_per_word = extra_spaces / spaces;
|
||||||
|
@ -720,7 +721,7 @@ static void viewer_draw(int col)
|
||||||
if (spaces_per_word > 2) { /* too much spacing is awful */
|
if (spaces_per_word > 2) { /* too much spacing is awful */
|
||||||
spaces_per_word = 3;
|
spaces_per_word = 3;
|
||||||
extra_spaces = 0;
|
extra_spaces = 0;
|
||||||
}
|
}
|
||||||
} else { /* this doesn't matter much... no spaces anyway */
|
} else { /* this doesn't matter much... no spaces anyway */
|
||||||
spaces_per_word = extra_spaces = 0;
|
spaces_per_word = extra_spaces = 0;
|
||||||
}
|
}
|
||||||
|
@ -728,7 +729,7 @@ static void viewer_draw(int col)
|
||||||
spaces_per_word = 1;
|
spaces_per_word = 1;
|
||||||
extra_spaces = 0;
|
extra_spaces = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
multiple_spacing = false;
|
multiple_spacing = false;
|
||||||
for (j=k=spaces=0; j < line_len; j++) {
|
for (j=k=spaces=0; j < line_len; j++) {
|
||||||
if (k == MAX_COLUMNS)
|
if (k == MAX_COLUMNS)
|
||||||
|
@ -742,7 +743,7 @@ static void viewer_draw(int col)
|
||||||
for (j=0; j<par_indent_spaces; j++)
|
for (j=0; j<par_indent_spaces; j++)
|
||||||
scratch_buffer[k++] = ' ';
|
scratch_buffer[k++] = ' ';
|
||||||
j=0;
|
j=0;
|
||||||
}
|
}
|
||||||
else if (!multiple_spacing) {
|
else if (!multiple_spacing) {
|
||||||
for (width = spaces<extra_spaces ? -1:0; width < spaces_per_word; width++)
|
for (width = spaces<extra_spaces ? -1:0; width < spaces_per_word; width++)
|
||||||
scratch_buffer[k++] = ' ';
|
scratch_buffer[k++] = ' ';
|
||||||
|
@ -756,13 +757,13 @@ static void viewer_draw(int col)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col != -1)
|
if (col != -1)
|
||||||
if (k > col) {
|
if (k > col) {
|
||||||
scratch_buffer[k] = 0;
|
scratch_buffer[k] = 0;
|
||||||
rb->lcd_puts(left_col, i, scratch_buffer + col);
|
rb->lcd_puts(left_col, i, scratch_buffer + col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { /* line_mode != JOIN && line_mode != REFLOW */
|
else { /* line_mode != JOIN && line_mode != REFLOW */
|
||||||
if (col != -1)
|
if (col != -1)
|
||||||
if (line_len > col) {
|
if (line_len > col) {
|
||||||
|
@ -848,16 +849,16 @@ static bool viewer_init(void)
|
||||||
pf = rb->font_get(FONT_UI);
|
pf = rb->font_get(FONT_UI);
|
||||||
if (pf->width != NULL)
|
if (pf->width != NULL)
|
||||||
{ /* variable pitch font -- fill structure from font width data */
|
{ /* variable pitch font -- fill structure from font width data */
|
||||||
ch = pf->defaultchar - pf->firstchar;
|
ch = pf->defaultchar - pf->firstchar;
|
||||||
rb->memset(glyph_width, pf->width[ch], 256);
|
rb->memset(glyph_width, pf->width[ch], 256);
|
||||||
idx = pf->firstchar;
|
idx = pf->firstchar;
|
||||||
rb->memcpy(&glyph_width[idx], pf->width, pf->size);
|
rb->memcpy(&glyph_width[idx], pf->width, pf->size);
|
||||||
idx += pf->size;
|
idx += pf->size;
|
||||||
rb->memset(&glyph_width[idx], pf->width[ch], 256-idx);
|
rb->memset(&glyph_width[idx], pf->width[ch], 256-idx);
|
||||||
}
|
}
|
||||||
else /* fixed pitch font -- same width for all glyphs */
|
else /* fixed pitch font -- same width for all glyphs */
|
||||||
rb->memset(glyph_width, pf->maxwidth, 256);
|
rb->memset(glyph_width, pf->maxwidth, 256);
|
||||||
|
|
||||||
display_lines = LCD_HEIGHT / pf->height;
|
display_lines = LCD_HEIGHT / pf->height;
|
||||||
display_columns = LCD_WIDTH;
|
display_columns = LCD_WIDTH;
|
||||||
#else
|
#else
|
||||||
|
@ -916,16 +917,16 @@ typedef struct {
|
||||||
|
|
||||||
static void viewer_load_settings(void)
|
static void viewer_load_settings(void)
|
||||||
{
|
{
|
||||||
int settings_fd, file_name_len, req_line_len, line_len;
|
int settings_fd, file_name_len, req_line_len, line_len;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
|
|
||||||
settings_fd=rb->open(SETTINGS_FILE, O_RDONLY);
|
settings_fd=rb->open(SETTINGS_FILE, O_RDONLY);
|
||||||
if (settings_fd < 0) return;
|
if (settings_fd < 0) return;
|
||||||
|
|
||||||
file_name_len = rb->strlen(file_name);
|
file_name_len = rb->strlen(file_name);
|
||||||
req_line_len = file_name_len + sizeof(viewer_settings_string);
|
req_line_len = file_name_len + sizeof(viewer_settings_string);
|
||||||
while ((line_len = rb->read_line(settings_fd, line, sizeof(line))) > 0) {
|
while ((line_len = rb->read_line(settings_fd, line, sizeof(line))) > 0) {
|
||||||
if ((line_len == req_line_len) &&
|
if ((line_len == req_line_len) &&
|
||||||
(rb->strncasecmp(line, file_name, file_name_len) == 0)) {
|
(rb->strncasecmp(line, file_name, file_name_len) == 0)) {
|
||||||
/* found a match, load stored values */
|
/* found a match, load stored values */
|
||||||
viewer_settings_string *prefs = (void*) &line[file_name_len];
|
viewer_settings_string *prefs = (void*) &line[file_name_len];
|
||||||
|
@ -933,27 +934,27 @@ static void viewer_load_settings(void)
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
/* view mode will be initialized later anyways */
|
/* view mode will be initialized later anyways */
|
||||||
for (view_mode=0; view_mode<VIEW_MODES; ++view_mode)
|
for (view_mode=0; view_mode<VIEW_MODES; ++view_mode)
|
||||||
scrollbar_mode[view_mode] =
|
scrollbar_mode[view_mode] =
|
||||||
rb->atoi(prefs->scrollbar_mode[view_mode]);
|
rb->atoi(prefs->scrollbar_mode[view_mode]);
|
||||||
|
|
||||||
page_mode = rb->atoi(prefs->page_mode);
|
page_mode = rb->atoi(prefs->page_mode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
word_mode = rb->atoi(prefs->word_mode);
|
word_mode = rb->atoi(prefs->word_mode);
|
||||||
line_mode = rb->atoi(prefs->line_mode);
|
line_mode = rb->atoi(prefs->line_mode);
|
||||||
view_mode = rb->atoi(prefs->view_mode);
|
view_mode = rb->atoi(prefs->view_mode);
|
||||||
|
|
||||||
init_need_scrollbar();
|
init_need_scrollbar();
|
||||||
/* the following settings are safety checked
|
/* the following settings are safety checked
|
||||||
* (file may have changed on disk)
|
* (file may have changed on disk)
|
||||||
*/
|
*/
|
||||||
file_pos = rb->atoi(prefs->file_pos); /* should be atol() */
|
file_pos = rb->atoi(prefs->file_pos); /* should be atol() */
|
||||||
if (file_pos > file_size) {
|
if (file_pos > file_size) {
|
||||||
file_pos = 0;
|
file_pos = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
buffer_end = BUFFER_END(); /* Update whenever file_pos changes */
|
||||||
|
|
||||||
screen_top_ptr = buffer + rb->atoi(prefs->screen_top_ptr);
|
screen_top_ptr = buffer + rb->atoi(prefs->screen_top_ptr);
|
||||||
if (BUFFER_OOB(screen_top_ptr)) {
|
if (BUFFER_OOB(screen_top_ptr)) {
|
||||||
screen_top_ptr = buffer;
|
screen_top_ptr = buffer;
|
||||||
|
@ -962,16 +963,16 @@ static void viewer_load_settings(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb->close(settings_fd);
|
rb->close(settings_fd);
|
||||||
|
|
||||||
fill_buffer(file_pos, buffer, BUFFER_SIZE);
|
fill_buffer(file_pos, buffer, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void viewer_save_settings(void)
|
static void viewer_save_settings(void)
|
||||||
{
|
{
|
||||||
int settings_fd, file_name_len, req_line_len, line_len;
|
int settings_fd, file_name_len, req_line_len, line_len;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
viewer_settings_string prefs;
|
viewer_settings_string prefs;
|
||||||
|
|
||||||
settings_fd=rb->open(SETTINGS_FILE, O_RDWR | O_CREAT);
|
settings_fd=rb->open(SETTINGS_FILE, O_RDWR | O_CREAT);
|
||||||
DEBUGF("SETTINGS_FILE: %d\n", settings_fd);
|
DEBUGF("SETTINGS_FILE: %d\n", settings_fd);
|
||||||
if (settings_fd < 0) return;
|
if (settings_fd < 0) return;
|
||||||
|
@ -979,16 +980,16 @@ static void viewer_save_settings(void)
|
||||||
file_name_len = rb->strlen(file_name);
|
file_name_len = rb->strlen(file_name);
|
||||||
req_line_len = file_name_len + sizeof(viewer_settings_string);
|
req_line_len = file_name_len + sizeof(viewer_settings_string);
|
||||||
while ((line_len = rb->read_line(settings_fd, line, sizeof(line))) > 0) {
|
while ((line_len = rb->read_line(settings_fd, line, sizeof(line))) > 0) {
|
||||||
if ((line_len == req_line_len) &&
|
if ((line_len == req_line_len) &&
|
||||||
(rb->strncasecmp(line, file_name, file_name_len) == 0)) {
|
(rb->strncasecmp(line, file_name, file_name_len) == 0)) {
|
||||||
/* found a match, reposition file pointer to overwrite this line */
|
/* found a match, reposition file pointer to overwrite this line */
|
||||||
rb->lseek(settings_fd, -line_len, SEEK_CUR);
|
rb->lseek(settings_fd, -line_len, SEEK_CUR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill structure in order to prevent overwriting with 0s (snprintf
|
/* fill structure in order to prevent overwriting with 0s (snprintf
|
||||||
* intentionally overflows so that no terminating NULLs are written
|
* intentionally overflows so that no terminating NULLs are written
|
||||||
* to disk). */
|
* to disk). */
|
||||||
rb->snprintf(prefs.word_mode, 3, "%2d", word_mode);
|
rb->snprintf(prefs.word_mode, 3, "%2d", word_mode);
|
||||||
rb->snprintf(prefs.line_mode, 3, "%2d", line_mode);
|
rb->snprintf(prefs.line_mode, 3, "%2d", line_mode);
|
||||||
|
@ -997,18 +998,18 @@ static void viewer_save_settings(void)
|
||||||
rb->snprintf(prefs.screen_top_ptr, 12, "%11d", screen_top_ptr-buffer);
|
rb->snprintf(prefs.screen_top_ptr, 12, "%11d", screen_top_ptr-buffer);
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
/* view_mode is not needed anymore */
|
/* view_mode is not needed anymore */
|
||||||
for (view_mode=0; view_mode<VIEW_MODES; ++view_mode)
|
for (view_mode=0; view_mode<VIEW_MODES; ++view_mode)
|
||||||
rb->snprintf(prefs.scrollbar_mode[view_mode], 3,
|
rb->snprintf(prefs.scrollbar_mode[view_mode], 3,
|
||||||
"%2d", scrollbar_mode[view_mode]);
|
"%2d", scrollbar_mode[view_mode]);
|
||||||
|
|
||||||
rb->snprintf(prefs.page_mode, 3, "%2d", page_mode);
|
rb->snprintf(prefs.page_mode, 3, "%2d", page_mode);
|
||||||
#endif
|
#endif
|
||||||
prefs.EOL = '\n';
|
prefs.EOL = '\n';
|
||||||
|
|
||||||
rb->write(settings_fd, file_name, file_name_len);
|
rb->write(settings_fd, file_name, file_name_len);
|
||||||
rb->write(settings_fd, &prefs, sizeof(prefs));
|
rb->write(settings_fd, &prefs, sizeof(prefs));
|
||||||
rb->close(settings_fd);
|
rb->close(settings_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void viewer_exit(void *parameter)
|
static void viewer_exit(void *parameter)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue