text viewer: display functions more changes.

- font functions move to tv_display.
- modify tv_init_display() and add tv_finalize_display().
- viewport functions are changed from global to static.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27154 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Yoshihisa Uchida 2010-06-27 11:36:37 +00:00
parent 96233f9cf7
commit b5a26851e0
4 changed files with 118 additions and 127 deletions

View file

@ -104,8 +104,8 @@ static struct tv_rect drawarea;
static int display_columns; static int display_columns;
static int display_rows; static int display_rows;
static int col_width; static int col_width = 1;
static int row_height; static int row_height = 1;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
@ -209,12 +209,6 @@ void tv_draw_text(int row, const unsigned char *text, int offset)
#endif #endif
} }
void tv_init_display(void)
{
display = rb->screens[SCREEN_MAIN];
display->clear_viewport();
}
void tv_start_display(void) void tv_start_display(void)
{ {
display->set_viewport(&vp_info); display->set_viewport(&vp_info);
@ -242,11 +236,7 @@ void tv_update_display(void)
display->update_viewport(); display->update_viewport();
} }
#ifdef HAVE_LCD_BITMAP void tv_set_layout(bool show_scrollbar)
void tv_set_layout(int col_w, bool show_scrollbar)
#else
void tv_set_layout(int col_w)
#endif
{ {
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH + 1 : 0; int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH + 1 : 0;
@ -279,6 +269,8 @@ void tv_set_layout(int col_w)
vertical_scrollbar.w = scrollbar_width; vertical_scrollbar.w = scrollbar_width;
vertical_scrollbar.h = drawarea.h; vertical_scrollbar.h = drawarea.h;
#else #else
(void) show_scrollbar;
row_height = 1; row_height = 1;
bookmark.x = 0; bookmark.x = 0;
@ -291,7 +283,6 @@ void tv_set_layout(int col_w)
drawarea.w = vp_info.width - 1; drawarea.w = vp_info.width - 1;
drawarea.h = vp_info.height; drawarea.h = vp_info.height;
#endif #endif
col_width = col_w;
display_columns = drawarea.w / col_width; display_columns = drawarea.w / col_width;
display_rows = drawarea.h / row_height; display_rows = drawarea.h / row_height;
@ -304,9 +295,15 @@ void tv_get_drawarea_info(int *width, int *cols, int *rows)
*rows = display_rows; *rows = display_rows;
} }
void tv_change_viewport(void)
{
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
static void tv_undo_viewport(void)
{
if (is_initialized_vp)
rb->viewportmanager_theme_undo(SCREEN_MAIN, false);
}
static void tv_change_viewport(void)
{
struct viewport vp; struct viewport vp;
if (is_initialized_vp) if (is_initialized_vp)
@ -317,8 +314,52 @@ void tv_change_viewport(void)
rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp); rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp);
vp_info = vp; vp_info = vp;
vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK; vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK;
}
static bool tv_set_font(const unsigned char *font)
{
unsigned char path[MAX_PATH];
if (font != NULL && *font != '\0')
{
rb->snprintf(path, MAX_PATH, "%s/%s.fnt", FONT_DIR, font);
if (rb->font_load(NULL, path) < 0)
{
rb->splash(HZ/2, "font load failed");
return false;
}
}
return true;
}
#endif
static void tv_change_preferences(const struct tv_preferences *oldp)
{
#ifdef HAVE_LCD_BITMAP
static bool font_changing = false;
const unsigned char *font_str;
struct tv_preferences new_prefs;
font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
/* change font */
if (font_changing || rb->strcmp(font_str, preferences->font_name))
{
if (!tv_set_font(preferences->font_name))
{
font_changing = true;
tv_copy_preferences(&new_prefs);
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
tv_set_preferences(&new_prefs);
font_changing = false;
}
col_width = 2 * rb->font_get_width(preferences->font, ' ');
}
tv_change_viewport();
#else #else
(void)oldp;
if (!is_initialized_vp) if (!is_initialized_vp)
{ {
rb->viewport_set_defaults(&vp_info, SCREEN_MAIN); rb->viewport_set_defaults(&vp_info, SCREEN_MAIN);
@ -327,10 +368,29 @@ void tv_change_viewport(void)
#endif #endif
} }
void tv_undo_viewport(void) bool tv_init_display(unsigned char **buf, size_t *size)
{
(void)buf;
(void)size;
display = rb->screens[SCREEN_MAIN];
display->clear_viewport();
tv_add_preferences_change_listner(tv_change_preferences);
return true;
}
void tv_finalize_display(void)
{ {
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
if (is_initialized_vp) /* restore font */
rb->viewportmanager_theme_undo(SCREEN_MAIN, false); if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
{
tv_set_font(rb->global_settings->font_file);
}
/* undo viewport */
tv_undo_viewport();
#endif #endif
} }

View file

@ -24,7 +24,29 @@
#include "plugin.h" #include "plugin.h"
#include "tv_screen_pos.h" #include "tv_screen_pos.h"
/* text viewer layout parts functions */ /* stuff for the screen access */
/*
* initialize the display module
*
* [In/Out] buf
* the start pointer of the buffer
*
* [In/Out] size
* buffer size
*
* return
* true initialize success
* false initialize failure
*/
bool tv_init_display(unsigned char **buf, size_t *size);
/* finalize the display module */
void tv_finalize_display(void);
/* layout parts accessing functions */
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* show headaer */ /* show headaer */
@ -66,7 +88,6 @@ void tv_init_scrollbar(off_t total, bool show_scrollbar);
* the size of text in displayed. * the size of text in displayed.
*/ */
void tv_show_scrollbar(int window, int col, off_t cur_pos, int size); void tv_show_scrollbar(int window, int col, off_t cur_pos, int size);
#endif
/* /*
* show bookmark * show bookmark
@ -79,10 +100,9 @@ void tv_show_scrollbar(int window, int col, off_t cur_pos, int size);
*/ */
void tv_show_bookmarks(const int *rows, int count); void tv_show_bookmarks(const int *rows, int count);
/* common display functons */ #endif
/* initialized display functions */ /* common display functons */
void tv_init_display(void);
/* start the display processing */ /* start the display processing */
void tv_start_display(void); void tv_start_display(void);
@ -107,32 +127,17 @@ void tv_update_display(void);
*/ */
void tv_draw_text(int row, const unsigned char *text, int offset); void tv_draw_text(int row, const unsigned char *text, int offset);
/* layout functions */ /* layout functions */
#ifdef HAVE_LCD_BITMAP
/* /*
* set the layout * set the layout
* *
* [In] col_w
* width per column
*
* [In] show_scrollbar * [In] show_scrollbar
* true: show the vertical scrollbar * true: show the vertical scrollbar
* false: does not show the vertical scrollbar * false: does not show the vertical scrollbar
*/ */
void tv_set_layout(int col_w, bool show_scrollbar); void tv_set_layout(bool show_scrollbar);
#else
/*
* set the layout
*
* [In] col_w
* width per column
*/
void tv_set_layout(int col_w);
#endif
/* /*
* get the draw area info * get the draw area info
@ -148,12 +153,4 @@ void tv_set_layout(int col_w);
*/ */
void tv_get_drawarea_info(int *width, int *cols, int *rows); void tv_get_drawarea_info(int *width, int *cols, int *rows);
/* viewport functions */
/* change the viewport */
void tv_change_viewport(void);
/* undo the viewport */
void tv_undo_viewport(void);
#endif #endif

View file

@ -30,7 +30,7 @@ const struct tv_preferences * const preferences = &prefs;
static int listner_count = 0; static int listner_count = 0;
#define TV_MAX_LISTNERS 4 #define TV_MAX_LISTNERS 5
static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp); static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
static void tv_notify_change_preferences(const struct tv_preferences *oldp) static void tv_notify_change_preferences(const struct tv_preferences *oldp)

View file

@ -31,29 +31,10 @@
static int window_width; static int window_width;
static int window_columns; static int window_columns;
static int display_lines; static int display_lines;
static int col_width;
static int cur_window; static int cur_window;
static int cur_column; static int cur_column;
#ifdef HAVE_LCD_BITMAP
static bool tv_set_font(const unsigned char *font)
{
unsigned char path[MAX_PATH];
if (font != NULL && *font != '\0')
{
rb->snprintf(path, MAX_PATH, "%s/%s.fnt", FONT_DIR, font);
if (rb->font_load(NULL, path) < 0)
{
rb->splash(HZ/2, "font load failed");
return false;
}
}
return true;
}
#endif
static void tv_draw_bookmarks(const struct tv_screen_pos *top_pos) static void tv_draw_bookmarks(const struct tv_screen_pos *top_pos)
{ {
struct tv_screen_pos bookmarks[TV_MAX_BOOKMARKS]; struct tv_screen_pos bookmarks[TV_MAX_BOOKMARKS];
@ -127,68 +108,31 @@ bool tv_traverse_lines(void)
static void tv_change_preferences(const struct tv_preferences *oldp) static void tv_change_preferences(const struct tv_preferences *oldp)
{ {
#ifndef HAVE_LCD_BITMAP bool need_vertical_scrollbar = false;
(void)oldp; (void)oldp;
#else
static bool font_changing = false;
const unsigned char *font_str;
bool need_vertical_scrollbar;
struct tv_preferences new_prefs;
tv_copy_preferences(&new_prefs);
font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file; tv_set_layout(need_vertical_scrollbar);
/* change font */
if (font_changing || rb->strcmp(font_str, preferences->font_name))
{
font_changing = true;
if (!tv_set_font(preferences->font_name))
{
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
tv_set_preferences(&new_prefs);
return;
}
}
font_changing = false;
#endif
#ifdef HAVE_LCD_BITMAP
col_width = 2 * rb->font_get_width(preferences->font, ' ');
#else
col_width = 1;
#endif
if (cur_window >= preferences->windows)
cur_window = 0;
/* change viewport */
tv_change_viewport();
#ifdef HAVE_LCD_BITMAP
need_vertical_scrollbar = false;
tv_set_layout(col_width, need_vertical_scrollbar);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines); tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
#ifdef HAVE_LCD_BITMAP
tv_seek_top(); tv_seek_top();
tv_set_read_conditions(preferences->windows, window_width); tv_set_read_conditions(preferences->windows, window_width);
if (tv_traverse_lines() && preferences->vertical_scrollbar) if (tv_traverse_lines() && preferences->vertical_scrollbar)
{ {
need_vertical_scrollbar = true; need_vertical_scrollbar = true;
tv_set_layout(col_width, need_vertical_scrollbar); tv_set_layout(need_vertical_scrollbar);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines); tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
} }
tv_seek_top(); tv_seek_top();
#else
tv_set_layout(col_width);
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
#endif #endif
window_columns = window_width / col_width;
cur_column = 0; cur_column = 0;
tv_set_read_conditions(preferences->windows, window_width); if (cur_window >= preferences->windows)
cur_window = 0;
tv_init_display(); tv_set_read_conditions(preferences->windows, window_width);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar); tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar);
#endif #endif
@ -197,23 +141,13 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
bool tv_init_window(unsigned char **buf, size_t *size) bool tv_init_window(unsigned char **buf, size_t *size)
{ {
tv_add_preferences_change_listner(tv_change_preferences); tv_add_preferences_change_listner(tv_change_preferences);
return tv_init_text_reader(buf, size); return tv_init_display(buf, size) && tv_init_text_reader(buf, size);
} }
void tv_finalize_window(void) void tv_finalize_window(void)
{ {
tv_finalize_text_reader(); tv_finalize_text_reader();
tv_finalize_display();
#ifdef HAVE_LCD_BITMAP
/* restore font */
if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
{
tv_set_font(rb->global_settings->font_file);
}
/* undo viewport */
tv_undo_viewport();
#endif
} }
void tv_move_window(int window_delta, int column_delta) void tv_move_window(int window_delta, int column_delta)