summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/text_viewer/tv_display.c98
-rw-r--r--apps/plugins/text_viewer/tv_display.h57
-rw-r--r--apps/plugins/text_viewer/tv_preferences.c2
-rw-r--r--apps/plugins/text_viewer/tv_window.c86
4 files changed, 117 insertions, 126 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;
104static int display_columns; 104static int display_columns;
105static int display_rows; 105static int display_rows;
106 106
107static int col_width; 107static int col_width = 1;
108static int row_height; 108static int row_height = 1;
109 109
110#ifdef HAVE_LCD_BITMAP 110#ifdef HAVE_LCD_BITMAP
111 111
@@ -209,12 +209,6 @@ void tv_draw_text(int row, const unsigned char *text, int offset)
209#endif 209#endif
210} 210}
211 211
212void tv_init_display(void)
213{
214 display = rb->screens[SCREEN_MAIN];
215 display->clear_viewport();
216}
217
218void tv_start_display(void) 212void tv_start_display(void)
219{ 213{
220 display->set_viewport(&vp_info); 214 display->set_viewport(&vp_info);
@@ -242,11 +236,7 @@ void tv_update_display(void)
242 display->update_viewport(); 236 display->update_viewport();
243} 237}
244 238
245#ifdef HAVE_LCD_BITMAP 239void tv_set_layout(bool show_scrollbar)
246void tv_set_layout(int col_w, bool show_scrollbar)
247#else
248void tv_set_layout(int col_w)
249#endif
250{ 240{
251#ifdef HAVE_LCD_BITMAP 241#ifdef HAVE_LCD_BITMAP
252 int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH + 1 : 0; 242 int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH + 1 : 0;
@@ -279,6 +269,8 @@ void tv_set_layout(int col_w)
279 vertical_scrollbar.w = scrollbar_width; 269 vertical_scrollbar.w = scrollbar_width;
280 vertical_scrollbar.h = drawarea.h; 270 vertical_scrollbar.h = drawarea.h;
281#else 271#else
272 (void) show_scrollbar;
273
282 row_height = 1; 274 row_height = 1;
283 275
284 bookmark.x = 0; 276 bookmark.x = 0;
@@ -291,7 +283,6 @@ void tv_set_layout(int col_w)
291 drawarea.w = vp_info.width - 1; 283 drawarea.w = vp_info.width - 1;
292 drawarea.h = vp_info.height; 284 drawarea.h = vp_info.height;
293#endif 285#endif
294 col_width = col_w;
295 286
296 display_columns = drawarea.w / col_width; 287 display_columns = drawarea.w / col_width;
297 display_rows = drawarea.h / row_height; 288 display_rows = drawarea.h / row_height;
@@ -304,9 +295,15 @@ void tv_get_drawarea_info(int *width, int *cols, int *rows)
304 *rows = display_rows; 295 *rows = display_rows;
305} 296}
306 297
307void tv_change_viewport(void)
308{
309#ifdef HAVE_LCD_BITMAP 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)
306{
310 struct viewport vp; 307 struct viewport vp;
311 308
312 if (is_initialized_vp) 309 if (is_initialized_vp)
@@ -317,8 +314,52 @@ void tv_change_viewport(void)
317 rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp); 314 rb->viewportmanager_theme_enable(SCREEN_MAIN, preferences->statusbar, &vp);
318 vp_info = vp; 315 vp_info = vp;
319 vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK; 316 vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK;
317}
320 318
319static bool tv_set_font(const unsigned char *font)
320{
321 unsigned char path[MAX_PATH];
322
323 if (font != NULL && *font != '\0')
324 {
325 rb->snprintf(path, MAX_PATH, "%s/%s.fnt", FONT_DIR, font);
326 if (rb->font_load(NULL, path) < 0)
327 {
328 rb->splash(HZ/2, "font load failed");
329 return false;
330 }
331 }
332 return true;
333}
334#endif
335
336static void tv_change_preferences(const struct tv_preferences *oldp)
337{
338#ifdef HAVE_LCD_BITMAP
339 static bool font_changing = false;
340 const unsigned char *font_str;
341 struct tv_preferences new_prefs;
342
343 font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
344
345 /* change font */
346 if (font_changing || rb->strcmp(font_str, preferences->font_name))
347 {
348 if (!tv_set_font(preferences->font_name))
349 {
350 font_changing = true;
351 tv_copy_preferences(&new_prefs);
352 rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
353 tv_set_preferences(&new_prefs);
354 font_changing = false;
355 }
356 col_width = 2 * rb->font_get_width(preferences->font, ' ');
357 }
358
359 tv_change_viewport();
321#else 360#else
361 (void)oldp;
362
322 if (!is_initialized_vp) 363 if (!is_initialized_vp)
323 { 364 {
324 rb->viewport_set_defaults(&vp_info, SCREEN_MAIN); 365 rb->viewport_set_defaults(&vp_info, SCREEN_MAIN);
@@ -327,10 +368,29 @@ void tv_change_viewport(void)
327#endif 368#endif
328} 369}
329 370
330void tv_undo_viewport(void) 371bool tv_init_display(unsigned char **buf, size_t *size)
372{
373 (void)buf;
374 (void)size;
375
376 display = rb->screens[SCREEN_MAIN];
377 display->clear_viewport();
378
379 tv_add_preferences_change_listner(tv_change_preferences);
380
381 return true;
382}
383
384void tv_finalize_display(void)
331{ 385{
332#ifdef HAVE_LCD_BITMAP 386#ifdef HAVE_LCD_BITMAP
333 if (is_initialized_vp) 387 /* restore font */
334 rb->viewportmanager_theme_undo(SCREEN_MAIN, false); 388 if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
389 {
390 tv_set_font(rb->global_settings->font_file);
391 }
392
393 /* undo viewport */
394 tv_undo_viewport();
335#endif 395#endif
336} 396}
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 @@
24#include "plugin.h" 24#include "plugin.h"
25#include "tv_screen_pos.h" 25#include "tv_screen_pos.h"
26 26
27/* text viewer layout parts functions */ 27/* stuff for the screen access */
28
29/*
30 * initialize the display module
31 *
32 * [In/Out] buf
33 * the start pointer of the buffer
34 *
35 * [In/Out] size
36 * buffer size
37 *
38 * return
39 * true initialize success
40 * false initialize failure
41 */
42bool tv_init_display(unsigned char **buf, size_t *size);
43
44/* finalize the display module */
45void tv_finalize_display(void);
46
47
48/* layout parts accessing functions */
49
28#ifdef HAVE_LCD_BITMAP 50#ifdef HAVE_LCD_BITMAP
29 51
30/* show headaer */ 52/* show headaer */
@@ -66,7 +88,6 @@ void tv_init_scrollbar(off_t total, bool show_scrollbar);
66 * the size of text in displayed. 88 * the size of text in displayed.
67 */ 89 */
68void tv_show_scrollbar(int window, int col, off_t cur_pos, int size); 90void tv_show_scrollbar(int window, int col, off_t cur_pos, int size);
69#endif
70 91
71/* 92/*
72 * show bookmark 93 * show bookmark
@@ -79,10 +100,9 @@ void tv_show_scrollbar(int window, int col, off_t cur_pos, int size);
79 */ 100 */
80void tv_show_bookmarks(const int *rows, int count); 101void tv_show_bookmarks(const int *rows, int count);
81 102
82/* common display functons */ 103#endif
83 104
84/* initialized display functions */ 105/* common display functons */
85void tv_init_display(void);
86 106
87/* start the display processing */ 107/* start the display processing */
88void tv_start_display(void); 108void tv_start_display(void);
@@ -107,32 +127,17 @@ void tv_update_display(void);
107 */ 127 */
108void tv_draw_text(int row, const unsigned char *text, int offset); 128void tv_draw_text(int row, const unsigned char *text, int offset);
109 129
130
110/* layout functions */ 131/* layout functions */
111#ifdef HAVE_LCD_BITMAP
112 132
113/* 133/*
114 * set the layout 134 * set the layout
115 * 135 *
116 * [In] col_w
117 * width per column
118 *
119 * [In] show_scrollbar 136 * [In] show_scrollbar
120 * true: show the vertical scrollbar 137 * true: show the vertical scrollbar
121 * false: does not show the vertical scrollbar 138 * false: does not show the vertical scrollbar
122 */ 139 */
123void tv_set_layout(int col_w, bool show_scrollbar); 140void tv_set_layout(bool show_scrollbar);
124
125#else
126
127/*
128 * set the layout
129 *
130 * [In] col_w
131 * width per column
132 */
133void tv_set_layout(int col_w);
134
135#endif
136 141
137/* 142/*
138 * get the draw area info 143 * get the draw area info
@@ -148,12 +153,4 @@ void tv_set_layout(int col_w);
148 */ 153 */
149void tv_get_drawarea_info(int *width, int *cols, int *rows); 154void tv_get_drawarea_info(int *width, int *cols, int *rows);
150 155
151/* viewport functions */
152
153/* change the viewport */
154void tv_change_viewport(void);
155
156/* undo the viewport */
157void tv_undo_viewport(void);
158
159#endif 156#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;
30 30
31static int listner_count = 0; 31static int listner_count = 0;
32 32
33#define TV_MAX_LISTNERS 4 33#define TV_MAX_LISTNERS 5
34static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp); 34static void (*listners[TV_MAX_LISTNERS])(const struct tv_preferences *oldp);
35 35
36static void tv_notify_change_preferences(const struct tv_preferences *oldp) 36static 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 @@
31static int window_width; 31static int window_width;
32static int window_columns; 32static int window_columns;
33static int display_lines; 33static int display_lines;
34static int col_width;
35 34
36static int cur_window; 35static int cur_window;
37static int cur_column; 36static int cur_column;
38 37
39#ifdef HAVE_LCD_BITMAP
40static bool tv_set_font(const unsigned char *font)
41{
42 unsigned char path[MAX_PATH];
43
44 if (font != NULL && *font != '\0')
45 {
46 rb->snprintf(path, MAX_PATH, "%s/%s.fnt", FONT_DIR, font);
47 if (rb->font_load(NULL, path) < 0)
48 {
49 rb->splash(HZ/2, "font load failed");
50 return false;
51 }
52 }
53 return true;
54}
55#endif
56
57static void tv_draw_bookmarks(const struct tv_screen_pos *top_pos) 38static void tv_draw_bookmarks(const struct tv_screen_pos *top_pos)
58{ 39{
59 struct tv_screen_pos bookmarks[TV_MAX_BOOKMARKS]; 40 struct tv_screen_pos bookmarks[TV_MAX_BOOKMARKS];
@@ -127,68 +108,31 @@ bool tv_traverse_lines(void)
127 108
128static void tv_change_preferences(const struct tv_preferences *oldp) 109static void tv_change_preferences(const struct tv_preferences *oldp)
129{ 110{
130#ifndef HAVE_LCD_BITMAP 111 bool need_vertical_scrollbar = false;
131 (void)oldp;
132#else
133 static bool font_changing = false;
134 const unsigned char *font_str;
135 bool need_vertical_scrollbar;
136 struct tv_preferences new_prefs;
137 tv_copy_preferences(&new_prefs);
138
139 font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
140
141 /* change font */
142 if (font_changing || rb->strcmp(font_str, preferences->font_name))
143 {
144 font_changing = true;
145 if (!tv_set_font(preferences->font_name))
146 {
147 rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
148 tv_set_preferences(&new_prefs);
149 return;
150 }
151 }
152
153 font_changing = false;
154#endif
155 112
156#ifdef HAVE_LCD_BITMAP 113 (void)oldp;
157 col_width = 2 * rb->font_get_width(preferences->font, ' ');
158#else
159 col_width = 1;
160#endif
161
162 if (cur_window >= preferences->windows)
163 cur_window = 0;
164 114
165 /* change viewport */ 115 tv_set_layout(need_vertical_scrollbar);
166 tv_change_viewport(); 116 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
167 117
168#ifdef HAVE_LCD_BITMAP 118#ifdef HAVE_LCD_BITMAP
169 need_vertical_scrollbar = false;
170 tv_set_layout(col_width, need_vertical_scrollbar);
171 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
172 tv_seek_top(); 119 tv_seek_top();
173 tv_set_read_conditions(preferences->windows, window_width); 120 tv_set_read_conditions(preferences->windows, window_width);
174 if (tv_traverse_lines() && preferences->vertical_scrollbar) 121 if (tv_traverse_lines() && preferences->vertical_scrollbar)
175 { 122 {
176 need_vertical_scrollbar = true; 123 need_vertical_scrollbar = true;
177 tv_set_layout(col_width, need_vertical_scrollbar); 124 tv_set_layout(need_vertical_scrollbar);
178 tv_get_drawarea_info(&window_width, &window_columns, &display_lines); 125 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
179 } 126 }
180 tv_seek_top(); 127 tv_seek_top();
181#else
182 tv_set_layout(col_width);
183 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
184#endif 128#endif
185 129
186 window_columns = window_width / col_width;
187 cur_column = 0; 130 cur_column = 0;
188 131
189 tv_set_read_conditions(preferences->windows, window_width); 132 if (cur_window >= preferences->windows)
133 cur_window = 0;
190 134
191 tv_init_display(); 135 tv_set_read_conditions(preferences->windows, window_width);
192#ifdef HAVE_LCD_BITMAP 136#ifdef HAVE_LCD_BITMAP
193 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar); 137 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar);
194#endif 138#endif
@@ -197,23 +141,13 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
197bool tv_init_window(unsigned char **buf, size_t *size) 141bool tv_init_window(unsigned char **buf, size_t *size)
198{ 142{
199 tv_add_preferences_change_listner(tv_change_preferences); 143 tv_add_preferences_change_listner(tv_change_preferences);
200 return tv_init_text_reader(buf, size); 144 return tv_init_display(buf, size) && tv_init_text_reader(buf, size);
201} 145}
202 146
203void tv_finalize_window(void) 147void tv_finalize_window(void)
204{ 148{
205 tv_finalize_text_reader(); 149 tv_finalize_text_reader();
206 150 tv_finalize_display();
207#ifdef HAVE_LCD_BITMAP
208 /* restore font */
209 if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
210 {
211 tv_set_font(rb->global_settings->font_file);
212 }
213
214 /* undo viewport */
215 tv_undo_viewport();
216#endif
217} 151}
218 152
219void tv_move_window(int window_delta, int column_delta) 153void tv_move_window(int window_delta, int column_delta)