From b5a26851e002d090e9c6ae93e29857ca3cd63fe5 Mon Sep 17 00:00:00 2001 From: Yoshihisa Uchida Date: Sun, 27 Jun 2010 11:36:37 +0000 Subject: [PATCH] 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 --- apps/plugins/text_viewer/tv_display.c | 98 ++++++++++++++++++----- apps/plugins/text_viewer/tv_display.h | 57 +++++++------ apps/plugins/text_viewer/tv_preferences.c | 2 +- apps/plugins/text_viewer/tv_window.c | 88 +++----------------- 4 files changed, 118 insertions(+), 127 deletions(-) diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c index 05f968dc91..0bbaf42cfe 100644 --- a/apps/plugins/text_viewer/tv_display.c +++ b/apps/plugins/text_viewer/tv_display.c @@ -104,8 +104,8 @@ static struct tv_rect drawarea; static int display_columns; static int display_rows; -static int col_width; -static int row_height; +static int col_width = 1; +static int row_height = 1; #ifdef HAVE_LCD_BITMAP @@ -209,12 +209,6 @@ void tv_draw_text(int row, const unsigned char *text, int offset) #endif } -void tv_init_display(void) -{ - display = rb->screens[SCREEN_MAIN]; - display->clear_viewport(); -} - void tv_start_display(void) { display->set_viewport(&vp_info); @@ -242,11 +236,7 @@ void tv_update_display(void) display->update_viewport(); } -#ifdef HAVE_LCD_BITMAP -void tv_set_layout(int col_w, bool show_scrollbar) -#else -void tv_set_layout(int col_w) -#endif +void tv_set_layout(bool show_scrollbar) { #ifdef HAVE_LCD_BITMAP 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.h = drawarea.h; #else + (void) show_scrollbar; + row_height = 1; bookmark.x = 0; @@ -291,7 +283,6 @@ void tv_set_layout(int col_w) drawarea.w = vp_info.width - 1; drawarea.h = vp_info.height; #endif - col_width = col_w; display_columns = drawarea.w / col_width; display_rows = drawarea.h / row_height; @@ -304,9 +295,15 @@ void tv_get_drawarea_info(int *width, int *cols, int *rows) *rows = display_rows; } -void tv_change_viewport(void) -{ #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; if (is_initialized_vp) @@ -317,8 +314,52 @@ void tv_change_viewport(void) rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp); vp_info = vp; 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 + (void)oldp; + if (!is_initialized_vp) { rb->viewport_set_defaults(&vp_info, SCREEN_MAIN); @@ -327,10 +368,29 @@ void tv_change_viewport(void) #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 - if (is_initialized_vp) - rb->viewportmanager_theme_undo(SCREEN_MAIN, false); + /* 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 } diff --git a/apps/plugins/text_viewer/tv_display.h b/apps/plugins/text_viewer/tv_display.h index aa30436c4c..67709f825d 100644 --- a/apps/plugins/text_viewer/tv_display.h +++ b/apps/plugins/text_viewer/tv_display.h @@ -24,7 +24,29 @@ #include "plugin.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 /* show headaer */ @@ -66,7 +88,6 @@ void tv_init_scrollbar(off_t total, bool show_scrollbar); * the size of text in displayed. */ void tv_show_scrollbar(int window, int col, off_t cur_pos, int size); -#endif /* * 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); -/* common display functons */ +#endif -/* initialized display functions */ -void tv_init_display(void); +/* common display functons */ /* start the display processing */ 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); + /* layout functions */ -#ifdef HAVE_LCD_BITMAP /* * set the layout * - * [In] col_w - * width per column - * * [In] show_scrollbar * true: show the vertical scrollbar * false: does not show the vertical scrollbar */ -void tv_set_layout(int col_w, bool show_scrollbar); - -#else - -/* - * set the layout - * - * [In] col_w - * width per column - */ -void tv_set_layout(int col_w); - -#endif +void tv_set_layout(bool show_scrollbar); /* * 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); -/* viewport functions */ - -/* change the viewport */ -void tv_change_viewport(void); - -/* undo the viewport */ -void tv_undo_viewport(void); - #endif diff --git a/apps/plugins/text_viewer/tv_preferences.c b/apps/plugins/text_viewer/tv_preferences.c index a90c72d8e9..924cedb0d0 100644 --- a/apps/plugins/text_viewer/tv_preferences.c +++ b/apps/plugins/text_viewer/tv_preferences.c @@ -30,7 +30,7 @@ const struct tv_preferences * const preferences = &prefs; 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 tv_notify_change_preferences(const struct tv_preferences *oldp) diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c index c83c6080bd..748b5b4cad 100644 --- a/apps/plugins/text_viewer/tv_window.c +++ b/apps/plugins/text_viewer/tv_window.c @@ -31,29 +31,10 @@ static int window_width; static int window_columns; static int display_lines; -static int col_width; static int cur_window; 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) { 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) { -#ifndef HAVE_LCD_BITMAP + bool need_vertical_scrollbar = false; + (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; - - /* 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_set_layout(need_vertical_scrollbar); tv_get_drawarea_info(&window_width, &window_columns, &display_lines); + +#ifdef HAVE_LCD_BITMAP tv_seek_top(); tv_set_read_conditions(preferences->windows, window_width); if (tv_traverse_lines() && preferences->vertical_scrollbar) { 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_seek_top(); -#else - tv_set_layout(col_width); - tv_get_drawarea_info(&window_width, &window_columns, &display_lines); #endif - window_columns = window_width / col_width; 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 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar); #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) { 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) { tv_finalize_text_reader(); - -#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 + tv_finalize_display(); } void tv_move_window(int window_delta, int column_delta)