1
0
Fork 0
forked from len0rd/rockbox

text viewer: reworks screen access logics and some bugs fix.

- screen access logics separte from tv_window. (new tv_display.[ch])
- using multi screen api.
- (bug fix) the head of the each line is not normally displayed when the alignment is RIGHT.
- (bug fix) unnecessary blank line is not displayed. (a part of FS#11400).
- (bug fix) the order by which callback functions were called was not correct. (FIFO->FILO)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27138 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Yoshihisa Uchida 2010-06-26 09:14:53 +00:00
parent be70fd89be
commit ac622c6d67
6 changed files with 567 additions and 156 deletions

View file

@ -22,29 +22,15 @@
****************************************************************************/
#include "plugin.h"
#include "tv_bookmark.h"
#include "tv_display.h"
#include "tv_preferences.h"
#include "tv_screen_pos.h"
#include "tv_text_reader.h"
#include "tv_window.h"
#define TV_SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
#define TV_SCROLLBAR_HEIGHT 4
#ifndef HAVE_LCD_BITMAP
#define TV_BOOKMARK_ICON 0xe101
#endif
#ifdef HAVE_LCD_BITMAP
static int header_height;
static int footer_height;
static bool need_vertical_scrollbar = false;
#endif
static int start_width;
static int display_lines;
static int window_width;
static int window_columns;
static int display_lines;
static int col_width;
static int cur_window;
@ -100,96 +86,6 @@ static bool tv_check_header_and_footer(struct tv_preferences *new_prefs)
return change_prefs;
}
static void tv_show_header(void)
{
unsigned header_mode = header_mode;
if (header_mode == HD_SBAR || header_mode == HD_BOTH)
rb->gui_syncstatusbar_draw(rb->statusbars, true);
if (header_mode == HD_PATH || header_mode == HD_BOTH)
rb->lcd_putsxy(0, header_height - preferences->font->height, preferences->file_name);
}
static void tv_show_footer(const struct tv_screen_pos *pos)
{
unsigned char buf[12];
unsigned footer_mode = preferences->footer_mode;
if (footer_mode == FT_SBAR || footer_mode == FT_BOTH)
rb->gui_syncstatusbar_draw(rb->statusbars, true);
if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
{
if (pos->line == 0)
rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1);
else
rb->snprintf(buf, sizeof(buf), "%d - %d", pos->page + 1, pos->page + 2);
rb->lcd_putsxy(0, LCD_HEIGHT - footer_height, buf);
}
}
static void tv_show_scrollbar(off_t cur_pos, int size)
{
int items;
int min_shown;
int max_shown;
int sb_width;
int sb_height;
sb_height = LCD_HEIGHT - header_height - footer_height;
if (preferences->horizontal_scrollbar)
{
items = preferences->windows * window_columns;
min_shown = cur_window * window_columns + cur_column;
max_shown = min_shown + window_columns;
sb_width = (need_vertical_scrollbar)? TV_SCROLLBAR_WIDTH : 0;
sb_height -= TV_SCROLLBAR_HEIGHT;
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
sb_width,
LCD_HEIGHT - footer_height - TV_SCROLLBAR_HEIGHT,
LCD_WIDTH - sb_width, TV_SCROLLBAR_HEIGHT,
items, min_shown, max_shown, HORIZONTAL);
}
if (need_vertical_scrollbar)
{
items = (int) tv_get_total_text_size();
min_shown = (int) cur_pos;
max_shown = min_shown + size;
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], 0, header_height,
TV_SCROLLBAR_WIDTH-1, sb_height,
items, min_shown, max_shown, VERTICAL);
}
}
static int tv_calc_display_lines(void)
{
int scrollbar_height = preferences->horizontal_scrollbar ? TV_SCROLLBAR_HEIGHT : 0;
unsigned header_mode = preferences->header_mode;
unsigned footer_mode = preferences->footer_mode;
header_height = (header_mode == HD_SBAR || header_mode == HD_BOTH)?
STATUSBAR_HEIGHT : 0;
footer_height = (footer_mode == FT_SBAR || footer_mode == FT_BOTH)?
STATUSBAR_HEIGHT : 0;
if (header_mode == HD_NONE || header_mode == HD_PATH ||
footer_mode == FT_NONE || footer_mode == FT_PAGE)
rb->gui_syncstatusbar_draw(rb->statusbars, false);
if (header_mode == HD_PATH || header_mode == HD_BOTH)
header_height += preferences->font->height;
if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
footer_height += preferences->font->height;
return (LCD_HEIGHT - header_height - footer_height - scrollbar_height) / preferences->font->height;
}
#endif
static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
@ -199,8 +95,9 @@ static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
int line;
#ifdef HAVE_LCD_BITMAP
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
tv_set_drawmode(DRMODE_COMPLEMENT);
#endif
while (count--)
{
line = (bookmarks[count].page - top_pos->page) * display_lines
@ -208,66 +105,51 @@ static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
if (line >= 0 && line < display_lines)
{
#ifdef HAVE_LCD_BITMAP
rb->lcd_fillrect(start_width, header_height + line * preferences->font->height,
window_width, preferences->font->height);
tv_fillrect(0, line, 1);
#else
rb->lcd_putc(start_width - 1, line, TV_BOOKMARK_ICON);
tv_put_bookmark_icon(line);
#endif
}
}
#ifdef HAVE_LCD_BITMAP
rb->lcd_set_drawmode(DRMODE_SOLID);
#endif
}
void tv_draw_window(void)
{
struct tv_screen_pos pos;
const unsigned char *line_buf;
const unsigned char *text_buf;
int line;
int offset = cur_column * col_width;
int size = 0;
int line_width;
int draw_width = (preferences->windows - cur_window) * LCD_WIDTH - offset;
int dx = start_width - offset;
tv_copy_screen_pos(&pos);
rb->lcd_clear_display();
if (preferences->alignment == AL_LEFT)
tv_read_start(cur_window, (cur_column > 0));
else
tv_read_start(0, preferences->windows > 1);
tv_start_display();
#ifdef HAVE_LCD_BITMAP
tv_set_drawmode(DRMODE_SOLID);
#endif
tv_clear_display();
tv_read_start(cur_window, (cur_column > 0));
for (line = 0; line < display_lines; line++)
{
if (!tv_get_next_line(&line_buf))
if (!tv_get_next_line(&text_buf))
break;
if (preferences->alignment == AL_RIGHT)
{
rb->lcd_getstringsize(line_buf, &line_width, NULL);
dx = draw_width - line_width;
}
#ifdef HAVE_LCD_BITMAP
rb->lcd_putsxy(dx, header_height + line * preferences->font->height, line_buf);
#else
rb->lcd_puts(dx, line, line_buf);
#endif
tv_draw_text(line, text_buf, cur_column);
}
size = tv_read_end();
tv_show_bookmarks(&pos);
#ifdef HAVE_LCD_BITMAP
tv_show_scrollbar(pos.file_pos, size);
tv_show_scrollbar(cur_window, cur_column, pos.file_pos, size);
tv_show_header();
tv_show_footer(&pos);
#endif
tv_show_bookmarks(&pos);
rb->lcd_update();
tv_update_display();
tv_end_display();
}
bool tv_traverse_lines(void)
@ -290,10 +172,13 @@ bool tv_traverse_lines(void)
static void tv_change_preferences(const struct tv_preferences *oldp)
{
#ifdef HAVE_LCD_BITMAP
#ifndef HAVE_LCD_BITMAP
(void)oldp;
#else
static bool font_changing = false;
const unsigned char *font_str;
bool change_prefs = false;
bool need_vertical_scrollbar;
struct tv_preferences new_prefs;
tv_copy_preferences(&new_prefs);
@ -317,14 +202,6 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
}
font_changing = false;
/* calculates display lines */
display_lines = tv_calc_display_lines();
#else
(void)oldp;
/* REAL fixed pitch :) all chars use up 1 cell */
display_lines = 2;
#endif
#ifdef HAVE_LCD_BITMAP
@ -336,27 +213,36 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
if (cur_window >= preferences->windows)
cur_window = 0;
window_width = LCD_WIDTH;
/* change viewport */
tv_change_viewport();
#ifdef HAVE_LCD_BITMAP
need_vertical_scrollbar = false;
start_width = 0;
tv_set_layout(col_width, need_vertical_scrollbar);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
tv_seek_top();
tv_set_read_conditions(preferences->windows, window_width);
if (tv_traverse_lines() && preferences->vertical_scrollbar)
{
need_vertical_scrollbar = true;
start_width = TV_SCROLLBAR_WIDTH;
tv_set_layout(col_width, need_vertical_scrollbar);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
}
tv_seek_top();
#else
start_width = 1;
tv_set_layout(col_width);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
#endif
window_width -= start_width;
window_columns = window_width / col_width;
window_columns = window_width / col_width;
cur_column = 0;
tv_set_read_conditions(preferences->windows, window_width);
tv_init_display();
#ifdef HAVE_LCD_BITMAP
tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar);
#endif
}
bool tv_init_window(unsigned char **buf, size_t *size)
@ -375,6 +261,9 @@ void tv_finalize_window(void)
{
tv_set_font(rb->global_settings->font_file);
}
/* undo viewport */
tv_undo_viewport();
#endif
}