1
0
Fork 0
forked from len0rd/rockbox

text viewer:

-remove 1px gap at the top and bottom of the screen to maximize the draw erea, especially for small screens.
-fix trashes on the vertical scrollbar when scrolled the column left/right.
-fix bug that vertical scrllbar sometimes goes up while scrolling down.
-don't chage displayed line after closing menu.
-use simplelist to select bookmark to make it work better.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28213 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2010-10-06 12:35:37 +00:00
parent 90e8815673
commit 53a936ab83
6 changed files with 71 additions and 66 deletions

View file

@ -60,7 +60,7 @@ enum plugin_status plugin_start(const void* file)
atexit(tv_exit);
while (!done) {
#ifdef HAVE_LCD_BITMAP
if (rb->global_settings->statusbar != STATUSBAR_OFF && preferences->statusbar)
if (preferences->statusbar)
rb->send_event(GUI_EVENT_ACTIONUPDATE, NULL);
#endif

View file

@ -174,8 +174,6 @@ unsigned tv_menu(void)
if (res == TV_MENU_RESULT_EXIT_MENU)
{
tv_convert_fpos(cur_file_pos, &cur_pos);
if (preferences->vertical_scroll_mode == VS_PAGE)
cur_pos.line = 0;
tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);
}

View file

@ -166,6 +166,30 @@ void tv_create_system_bookmark(void)
}
}
static const char* get_bookmark_name(int selected, void * data,
char * buffer, size_t buffer_len)
{
(void)data;
struct tv_bookmark_info *bookmark = &bookmarks[selected];
rb->snprintf(buffer, buffer_len,
#ifdef HAVE_LCD_BITMAP
"%cPage: %d Line: %d",
#else
"%cP:%d L:%d",
#endif
(bookmark->flag & TV_BOOKMARK_SYSTEM)? '*' : ' ',
bookmark->pos.page + 1, bookmark->pos.line + 1);
return buffer;
}
static int list_action_callback(int action, struct gui_synclist *lists)
{
(void) lists;
if (action == ACTION_STD_OK)
return ACTION_STD_CANCEL;
return action;
}
void tv_select_bookmark(void)
{
int i;
@ -185,32 +209,18 @@ void tv_select_bookmark(void)
select_pos = bookmarks[0].pos;
else
{
int selected = -1;
struct opt_items items[bookmark_count];
unsigned char names[bookmark_count][24];
struct simplelist_info info;
rb->qsort(bookmarks, bookmark_count, sizeof(struct tv_bookmark_info), bm_comp);
for (i = 0; i < bookmark_count; i++)
{
rb->snprintf(names[i], sizeof(names[0]),
#if CONFIG_KEYPAD != PLAYER_PAD
"%cPage: %d Line: %d",
#else
"%cP:%d L:%d",
#endif
(bookmarks[i].flag & TV_BOOKMARK_SYSTEM)? '*' : ' ',
bookmarks[i].pos.page + 1,
bookmarks[i].pos.line + 1);
items[i].string = names[i];
items[i].voice_id = -1;
}
rb->simplelist_info_init(&info, "Select bookmark",
bookmark_count, bookmarks);
info.get_name = get_bookmark_name;
info.action_callback = list_action_callback;
rb->simplelist_show_list(&info);
rb->set_option("Select bookmark", &selected, INT, items,
bookmark_count, NULL);
if (selected >= 0 && selected < bookmark_count)
select_pos = bookmarks[selected].pos;
if (info.selection >= 0 && info.selection < bookmark_count)
select_pos = bookmarks[info.selection].pos;
else
{
/* when does not select any bookmarks, move to the current page */

View file

@ -81,14 +81,11 @@ struct tv_rect {
};
static struct viewport vp_info;
static struct viewport vp_text;
static bool is_initialized_vp = false;
static struct screen* display;
#ifdef HAVE_LCD_BITMAP
static int drawmode = DRMODE_SOLID;
#endif
/* layout */
#ifdef HAVE_LCD_BITMAP
static struct tv_rect header;
@ -98,7 +95,6 @@ static struct tv_rect vertical_scrollbar;
#else
static struct tv_rect bookmark;
#endif
static struct tv_rect drawarea;
static bool show_horizontal_scrollbar;
static bool show_vertical_scrollbar;
@ -176,18 +172,23 @@ void tv_init_scrollbar(off_t total, bool show_scrollbar)
void tv_show_bookmarks(const int *rows, int count)
{
#ifdef HAVE_LCD_BITMAP
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
display->set_viewport(&vp_text);
display->set_drawmode(DRMODE_COMPLEMENT);
#endif
while (count--)
{
#ifdef HAVE_LCD_BITMAP
display->fillrect(drawarea.x, drawarea.y + rows[count] * row_height,
drawarea.w, row_height);
display->fillrect(0, rows[count] * row_height,
vp_text.width, row_height);
#else
display->putchar(bookmark.x, drawarea.y + rows[count], TV_BOOKMARK_ICON);
display->putchar(bookmark.x, bookmark.y + rows[count], TV_BOOKMARK_ICON);
#endif
}
#ifdef HAVE_LCD_BITMAP
display->set_drawmode(DRMODE_SOLID);
display->set_viewport(&vp_info);
#endif
}
void tv_update_extra(int window, int col, const struct tv_screen_pos *pos, int size)
@ -215,22 +216,23 @@ void tv_draw_text(int row, const unsigned char *text, int offset)
if (preferences->alignment == AL_RIGHT)
{
display->getstringsize(text, &text_width, NULL);
xpos += ((offset > 0)? drawarea.w * 2 : drawarea.w) - text_width;
xpos += ((offset > 0)? vp_text.width * 2 : vp_text.width) - text_width;
}
display->set_viewport(&vp_text);
#ifdef HAVE_LCD_BITMAP
display->putsxy(drawarea.x + xpos, drawarea.y + row * row_height, text);
display->putsxy(xpos, row * row_height, text);
#else
display->puts(drawarea.x + xpos, drawarea.y + row, text);
display->puts(xpos, row, text);
#endif
display->set_viewport(&vp_info);
}
void tv_start_display(void)
{
display->set_viewport(&vp_info);
#ifdef HAVE_LCD_BITMAP
drawmode = rb->lcd_get_drawmode();
rb->lcd_set_drawmode(DRMODE_SOLID);
display->set_drawmode(DRMODE_SOLID);
#endif
#if LCD_DEPTH > 1
@ -242,11 +244,6 @@ void tv_start_display(void)
void tv_end_display(void)
{
display->update_viewport();
#ifdef HAVE_LCD_BITMAP
rb->lcd_set_drawmode(drawmode);
#endif
display->set_viewport(NULL);
}
@ -261,29 +258,30 @@ void tv_set_layout(bool show_scrollbar)
row_height = preferences->font->height;
header.x = 0;
header.y = 1;
header.y = 0;
header.w = vp_info.width;
header.h = (preferences->header_mode)? row_height + 1 : 0;
footer.x = 0;
footer.w = vp_info.width;
footer.h = (preferences->footer_mode)? row_height + 1 : 0;
footer.y = vp_info.height - 1 - footer.h;
footer.y = vp_info.height - footer.h;
drawarea.x = scrollbar_width;
drawarea.y = header.y + header.h;
drawarea.w = vp_info.width - scrollbar_width;
drawarea.h = footer.y - drawarea.y - scrollbar_height;
horizontal_scrollbar.x = drawarea.x;
horizontal_scrollbar.x = scrollbar_width;
horizontal_scrollbar.y = footer.y - scrollbar_height;
horizontal_scrollbar.w = drawarea.w;
horizontal_scrollbar.w = vp_info.width - scrollbar_width;
horizontal_scrollbar.h = scrollbar_height;
vertical_scrollbar.x = 0;
vertical_scrollbar.y = drawarea.y;
vertical_scrollbar.y = header.y + header.h;
vertical_scrollbar.w = scrollbar_width;
vertical_scrollbar.h = drawarea.h;
vertical_scrollbar.h = footer.y - vertical_scrollbar.y - scrollbar_height;
vp_text = vp_info;
vp_text.x += horizontal_scrollbar.x;
vp_text.y += vertical_scrollbar.y;
vp_text.width = horizontal_scrollbar.w;
vp_text.height = vertical_scrollbar.h;
#else
(void) show_scrollbar;
@ -294,19 +292,18 @@ void tv_set_layout(bool show_scrollbar)
bookmark.w = 1;
bookmark.h = vp_info.height;
drawarea.x = 1;
drawarea.y = 0;
drawarea.w = vp_info.width - 1;
drawarea.h = vp_info.height;
vp_text = vp_info;
vp_text.x += 1;
vp_text.width -= 1;
#endif
display_columns = drawarea.w / col_width;
display_rows = drawarea.h / row_height;
display_columns = vp_text.width / col_width;
display_rows = vp_text.height / row_height;
}
void tv_get_drawarea_info(int *width, int *cols, int *rows)
{
*width = drawarea.w;
*width = vp_text.width;
*cols = display_columns;
*rows = display_rows;
}
@ -314,8 +311,7 @@ void tv_get_drawarea_info(int *width, int *cols, int *rows)
static void tv_change_viewport(void)
{
#ifdef HAVE_LCD_BITMAP
bool show_statusbar = (rb->global_settings->statusbar != STATUSBAR_OFF &&
preferences->statusbar);
bool show_statusbar = preferences->statusbar;
if (is_initialized_vp)
rb->viewportmanager_theme_undo(SCREEN_MAIN, false);

View file

@ -220,7 +220,7 @@ void tv_convert_fpos(off_t fpos, struct tv_screen_pos *pos)
while (tv_create_line_positions() && cur_pos.file_pos < fpos)
rb->splashf(0, "converting %ld%%...", 100 * cur_pos.file_pos / fpos);
if (cur_pos.page < max_page)
if (i < max_page)
cur_pos.page--;
tv_seek_page(cur_pos.page, SEEK_SET);
for (i = 0; i < lines_per_page; i++)
@ -296,6 +296,8 @@ void tv_move_screen(int page_offset, int line_offset, int whence)
if (cur_pos.page < max_page && new_pos.line == lines_per_page)
{
tv_seek(line_pos[lines_per_page], SEEK_CUR);
cur_pos.file_pos += line_pos[lines_per_page];
for (i = 0; i < parse_lines; i++)
line_pos[i] = line_pos[i + lines_per_page] - line_pos[lines_per_page];

View file

@ -111,7 +111,6 @@ void tv_seek(off_t offset, int whence)
return;
}
file_pos += buf_pos;
whence = SEEK_SET;
break;
default: