summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-06-28 11:17:47 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-06-28 11:17:47 +0000
commitcf6554d8914bd9c15f800399ede8750d93f8c74c (patch)
tree9f14e8a8d15481f8354074c412b0366d80be85ba
parent31cf6d501338964538978f79be9a078deebdafdd (diff)
downloadrockbox-cf6554d8914bd9c15f800399ede8750d93f8c74c.tar.gz
rockbox-cf6554d8914bd9c15f800399ede8750d93f8c74c.zip
text viewer: tv_window doesn't depend on the layout of the text viewer.
And display functions change the following. - some functions change to static functions. - fix the problem that font_changing flag is invalid value. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27165 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/text_viewer/tv_display.c90
-rw-r--r--apps/plugins/text_viewer/tv_display.h92
-rw-r--r--apps/plugins/text_viewer/tv_window.c35
3 files changed, 108 insertions, 109 deletions
diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c
index 0bbaf42cfe..59b4bdf437 100644
--- a/apps/plugins/text_viewer/tv_display.c
+++ b/apps/plugins/text_viewer/tv_display.c
@@ -82,14 +82,12 @@ struct tv_rect {
82static struct viewport vp_info; 82static struct viewport vp_info;
83static bool is_initialized_vp = false; 83static bool is_initialized_vp = false;
84 84
85static struct screen* display;
86
85#ifdef HAVE_LCD_BITMAP 87#ifdef HAVE_LCD_BITMAP
86static int drawmode = DRMODE_SOLID; 88static int drawmode = DRMODE_SOLID;
87static int totalsize;
88static bool show_vertical_scrollbar;
89#endif 89#endif
90 90
91static struct screen* display;
92
93/* layout */ 91/* layout */
94#ifdef HAVE_LCD_BITMAP 92#ifdef HAVE_LCD_BITMAP
95static struct tv_rect header; 93static struct tv_rect header;
@@ -101,15 +99,19 @@ static struct tv_rect bookmark;
101#endif 99#endif
102static struct tv_rect drawarea; 100static struct tv_rect drawarea;
103 101
102static bool show_vertical_scrollbar;
103
104static int display_columns; 104static int display_columns;
105static int display_rows; 105static int display_rows;
106 106
107static int col_width = 1; 107static int col_width = 1;
108static int row_height = 1; 108static int row_height = 1;
109 109
110static int totalsize;
111
110#ifdef HAVE_LCD_BITMAP 112#ifdef HAVE_LCD_BITMAP
111 113
112void tv_show_header(void) 114static void tv_show_header(void)
113{ 115{
114 unsigned header_mode = header_mode; 116 unsigned header_mode = header_mode;
115 117
@@ -117,7 +119,7 @@ void tv_show_header(void)
117 display->putsxy(header.x, header.y, preferences->file_name); 119 display->putsxy(header.x, header.y, preferences->file_name);
118} 120}
119 121
120void tv_show_footer(const struct tv_screen_pos *pos) 122static void tv_show_footer(const struct tv_screen_pos *pos)
121{ 123{
122 unsigned char buf[12]; 124 unsigned char buf[12];
123 unsigned footer_mode = preferences->footer_mode; 125 unsigned footer_mode = preferences->footer_mode;
@@ -132,13 +134,7 @@ void tv_show_footer(const struct tv_screen_pos *pos)
132 } 134 }
133} 135}
134 136
135void tv_init_scrollbar(off_t total, bool show_scrollbar) 137static void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
136{
137 totalsize = total;
138 show_vertical_scrollbar = show_scrollbar;
139}
140
141void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
142{ 138{
143 int items; 139 int items;
144 int min_shown; 140 int min_shown;
@@ -171,6 +167,12 @@ void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
171 167
172#endif 168#endif
173 169
170void tv_init_scrollbar(off_t total, bool show_scrollbar)
171{
172 totalsize = total;
173 show_vertical_scrollbar = show_scrollbar;
174}
175
174void tv_show_bookmarks(const int *rows, int count) 176void tv_show_bookmarks(const int *rows, int count)
175{ 177{
176#ifdef HAVE_LCD_BITMAP 178#ifdef HAVE_LCD_BITMAP
@@ -188,6 +190,20 @@ void tv_show_bookmarks(const int *rows, int count)
188 } 190 }
189} 191}
190 192
193void tv_update_extra(int window, int col, const struct tv_screen_pos *pos, int size)
194{
195#ifdef HAVE_LCD_BITMAP
196 tv_show_scrollbar(window, col, pos->file_pos, size);
197 tv_show_header();
198 tv_show_footer(pos);
199#else
200 (void)window;
201 (void)col;
202 (void)pos;
203 (void)size;
204#endif
205}
206
191void tv_draw_text(int row, const unsigned char *text, int offset) 207void tv_draw_text(int row, const unsigned char *text, int offset)
192{ 208{
193 int xpos = -offset * col_width; 209 int xpos = -offset * col_width;
@@ -225,15 +241,13 @@ void tv_start_display(void)
225 241
226void tv_end_display(void) 242void tv_end_display(void)
227{ 243{
244 display->update_viewport();
245
228#ifdef HAVE_LCD_BITMAP 246#ifdef HAVE_LCD_BITMAP
229 rb->lcd_set_drawmode(drawmode); 247 rb->lcd_set_drawmode(drawmode);
230#endif 248#endif
231 display->set_viewport(NULL);
232}
233 249
234void tv_update_display(void) 250 display->set_viewport(NULL);
235{
236 display->update_viewport();
237} 251}
238 252
239void tv_set_layout(bool show_scrollbar) 253void tv_set_layout(bool show_scrollbar)
@@ -295,27 +309,29 @@ void tv_get_drawarea_info(int *width, int *cols, int *rows)
295 *rows = display_rows; 309 *rows = display_rows;
296} 310}
297 311
298#ifdef HAVE_LCD_BITMAP
299static void tv_undo_viewport(void)
300{
301 if (is_initialized_vp)
302 rb->viewportmanager_theme_undo(SCREEN_MAIN, false);
303}
304
305static void tv_change_viewport(void) 312static void tv_change_viewport(void)
306{ 313{
314#ifdef HAVE_LCD_BITMAP
307 struct viewport vp; 315 struct viewport vp;
308 316
309 if (is_initialized_vp) 317 if (is_initialized_vp)
310 tv_undo_viewport(); 318 rb->viewportmanager_theme_undo(SCREEN_MAIN, false);
311 else 319 else
312 is_initialized_vp = true; 320 is_initialized_vp = true;
313 321
314 rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp); 322 rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp);
315 vp_info = vp; 323 vp_info = vp;
316 vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK; 324 vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK;
325#else
326 if (!is_initialized_vp)
327 {
328 rb->viewport_set_defaults(&vp_info, SCREEN_MAIN);
329 is_initialized_vp = true;
330 }
331#endif
317} 332}
318 333
334#ifdef HAVE_LCD_BITMAP
319static bool tv_set_font(const unsigned char *font) 335static bool tv_set_font(const unsigned char *font)
320{ 336{
321 unsigned char path[MAX_PATH]; 337 unsigned char path[MAX_PATH];
@@ -351,21 +367,14 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
351 tv_copy_preferences(&new_prefs); 367 tv_copy_preferences(&new_prefs);
352 rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH); 368 rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
353 tv_set_preferences(&new_prefs); 369 tv_set_preferences(&new_prefs);
354 font_changing = false;
355 } 370 }
356 col_width = 2 * rb->font_get_width(preferences->font, ' '); 371 col_width = 2 * rb->font_get_width(preferences->font, ' ');
372 font_changing = false;
357 } 373 }
358
359 tv_change_viewport();
360#else 374#else
361 (void)oldp; 375 (void)oldp;
362
363 if (!is_initialized_vp)
364 {
365 rb->viewport_set_defaults(&vp_info, SCREEN_MAIN);
366 is_initialized_vp = true;
367 }
368#endif 376#endif
377 tv_change_viewport();
369} 378}
370 379
371bool tv_init_display(unsigned char **buf, size_t *size) 380bool tv_init_display(unsigned char **buf, size_t *size)
@@ -391,6 +400,15 @@ void tv_finalize_display(void)
391 } 400 }
392 401
393 /* undo viewport */ 402 /* undo viewport */
394 tv_undo_viewport(); 403 rb->viewportmanager_theme_undo(SCREEN_MAIN, false);
404#endif
405}
406
407bool tv_exist_scrollbar(void)
408{
409#ifdef HAVE_LCD_BITMAP
410 return true;
411#else
412 return false;
395#endif 413#endif
396} 414}
diff --git a/apps/plugins/text_viewer/tv_display.h b/apps/plugins/text_viewer/tv_display.h
index 383f121996..9726271e2f 100644
--- a/apps/plugins/text_viewer/tv_display.h
+++ b/apps/plugins/text_viewer/tv_display.h
@@ -44,65 +44,59 @@ bool tv_init_display(unsigned char **buf, size_t *size);
44/* finalize the display module */ 44/* finalize the display module */
45void tv_finalize_display(void); 45void tv_finalize_display(void);
46 46
47
48/* layout parts accessing functions */
49
50#ifdef HAVE_LCD_BITMAP
51
52/* show headaer */
53void tv_show_header(void);
54
55/* 47/*
56 * show footer 48 * draw the text
57 * 49 *
58 * [In] pos 50 * [In] row
59 * the current position 51 * the row that displays the text
52 *
53 * [In] text
54 * text
55 *
56 * [In] offset
57 * display the text that is since offset columns
60 */ 58 */
61void tv_show_footer(const struct tv_screen_pos *pos); 59void tv_draw_text(int row, const unsigned char *text, int offset);
62 60
63/* 61/*
64 * initialize the scrollbar 62 * show bookmark
65 * 63 *
66 * [In] total 64 * [In] rows
67 * total text size 65 * the array of row where the bookmark
68 * 66 *
69 * [In] show_scrollbar 67 * [In] count
70 * true: show the vertical scrollbar 68 * want to show bookmark count
71 * false: does not show the vertical scrollbar
72 */ 69 */
73void tv_init_scrollbar(off_t total, bool show_scrollbar); 70void tv_show_bookmarks(const int *rows, int count);
74 71
75/* 72/*
76 * show horizontal/vertical scrollbar 73 * update extra parts (header, footer, scrollbar, etc.)
77 * 74 *
78 * [In] window 75 * [In] window
79 * the current window 76 * current window
80 * 77 *
81 * [In] col 78 * [In] col
82 * the current column 79 * current column
83 * 80 *
84 * [In] cur_pos 81 * [In] pos
85 * the current text position 82 * current screen position (file position, page, line)
86 * 83 *
87 * [In] size 84 * [In] size
88 * the size of text in displayed. 85 * the size of text which is displayed.
89 */ 86 */
90void tv_show_scrollbar(int window, int col, off_t cur_pos, int size); 87void tv_update_extra(int window, int col, const struct tv_screen_pos *pos, int size);
91
92#endif
93 88
94/* 89/*
95 * show bookmark 90 * initialize the scrollbar
96 * 91 *
97 * [In] rows 92 * [In] total
98 * the array of row where the bookmark 93 * total text size
99 * 94 *
100 * [In] count 95 * [In] show_scrollbar
101 * want to show bookmark count 96 * true: show the vertical scrollbar
97 * false: does not show the vertical scrollbar
102 */ 98 */
103void tv_show_bookmarks(const int *rows, int count); 99void tv_init_scrollbar(off_t total, bool show_scrollbar);
104
105/* common display functons */
106 100
107/* start the display processing */ 101/* start the display processing */
108void tv_start_display(void); 102void tv_start_display(void);
@@ -110,23 +104,6 @@ void tv_start_display(void);
110/* end the display processing */ 104/* end the display processing */
111void tv_end_display(void); 105void tv_end_display(void);
112 106
113/*update the display */
114void tv_update_display(void);
115
116/*
117 * draw the text
118 *
119 * [In] row
120 * the row that displays the text
121 *
122 * [In] text
123 * text
124 *
125 * [In] offset
126 * display the text that is since offset columns
127 */
128void tv_draw_text(int row, const unsigned char *text, int offset);
129
130 107
131/* layout functions */ 108/* layout functions */
132 109
@@ -153,4 +130,13 @@ void tv_set_layout(bool show_scrollbar);
153 */ 130 */
154void tv_get_drawarea_info(int *width, int *cols, int *rows); 131void tv_get_drawarea_info(int *width, int *cols, int *rows);
155 132
133/*
134 * whether exist scrollbar
135 *
136 * return
137 * true exist scrollbar
138 * false does not exist scrollbar
139 */
140bool tv_exist_scrollbar(void);
141
156#endif 142#endif
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index 748b5b4cad..9e35b49c6d 100644
--- a/apps/plugins/text_viewer/tv_window.c
+++ b/apps/plugins/text_viewer/tv_window.c
@@ -77,14 +77,10 @@ void tv_draw_window(void)
77 77
78 size = tv_read_end(); 78 size = tv_read_end();
79 79
80#ifdef HAVE_LCD_BITMAP
81 tv_show_scrollbar(cur_window, cur_column, pos.file_pos, size);
82 tv_show_header();
83 tv_show_footer(&pos);
84#endif
85 tv_draw_bookmarks(&pos); 80 tv_draw_bookmarks(&pos);
86 81
87 tv_update_display(); 82 tv_update_extra(cur_window, cur_column, &pos, size);
83
88 tv_end_display(); 84 tv_end_display();
89} 85}
90 86
@@ -115,27 +111,26 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
115 tv_set_layout(need_vertical_scrollbar); 111 tv_set_layout(need_vertical_scrollbar);
116 tv_get_drawarea_info(&window_width, &window_columns, &display_lines); 112 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
117 113
118#ifdef HAVE_LCD_BITMAP 114 if (tv_exist_scrollbar())
119 tv_seek_top();
120 tv_set_read_conditions(preferences->windows, window_width);
121 if (tv_traverse_lines() && preferences->vertical_scrollbar)
122 { 115 {
123 need_vertical_scrollbar = true; 116 tv_seek_top();
124 tv_set_layout(need_vertical_scrollbar); 117 tv_set_read_conditions(preferences->windows, window_width);
125 tv_get_drawarea_info(&window_width, &window_columns, &display_lines); 118 if (tv_traverse_lines() && preferences->vertical_scrollbar)
119 {
120 need_vertical_scrollbar = true;
121 tv_set_layout(need_vertical_scrollbar);
122 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
123 }
124 tv_seek_top();
125 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar);
126 } 126 }
127 tv_seek_top();
128#endif
129
130 cur_column = 0;
131 127
132 if (cur_window >= preferences->windows) 128 if (cur_window >= preferences->windows)
133 cur_window = 0; 129 cur_window = 0;
134 130
131 cur_column = 0;
132
135 tv_set_read_conditions(preferences->windows, window_width); 133 tv_set_read_conditions(preferences->windows, window_width);
136#ifdef HAVE_LCD_BITMAP
137 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar);
138#endif
139} 134}
140 135
141bool tv_init_window(unsigned char **buf, size_t *size) 136bool tv_init_window(unsigned char **buf, size_t *size)