summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_display.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_viewer/tv_display.c')
-rw-r--r--apps/plugins/text_viewer/tv_display.c98
1 files changed, 79 insertions, 19 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}