summaryrefslogtreecommitdiff
path: root/apps/plugins/text_viewer/tv_window.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/text_viewer/tv_window.c')
-rw-r--r--apps/plugins/text_viewer/tv_window.c197
1 files changed, 43 insertions, 154 deletions
diff --git a/apps/plugins/text_viewer/tv_window.c b/apps/plugins/text_viewer/tv_window.c
index 1bb47b18f3..df3951aa28 100644
--- a/apps/plugins/text_viewer/tv_window.c
+++ b/apps/plugins/text_viewer/tv_window.c
@@ -22,29 +22,15 @@
22 ****************************************************************************/ 22 ****************************************************************************/
23#include "plugin.h" 23#include "plugin.h"
24#include "tv_bookmark.h" 24#include "tv_bookmark.h"
25#include "tv_display.h"
25#include "tv_preferences.h" 26#include "tv_preferences.h"
26#include "tv_screen_pos.h" 27#include "tv_screen_pos.h"
27#include "tv_text_reader.h" 28#include "tv_text_reader.h"
28#include "tv_window.h" 29#include "tv_window.h"
29 30
30#define TV_SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
31#define TV_SCROLLBAR_HEIGHT 4
32
33#ifndef HAVE_LCD_BITMAP
34#define TV_BOOKMARK_ICON 0xe101
35#endif
36
37#ifdef HAVE_LCD_BITMAP
38static int header_height;
39static int footer_height;
40static bool need_vertical_scrollbar = false;
41#endif
42
43static int start_width;
44static int display_lines;
45
46static int window_width; 31static int window_width;
47static int window_columns; 32static int window_columns;
33static int display_lines;
48static int col_width; 34static int col_width;
49 35
50static int cur_window; 36static int cur_window;
@@ -100,96 +86,6 @@ static bool tv_check_header_and_footer(struct tv_preferences *new_prefs)
100 86
101 return change_prefs; 87 return change_prefs;
102} 88}
103
104static void tv_show_header(void)
105{
106 unsigned header_mode = header_mode;
107 if (header_mode == HD_SBAR || header_mode == HD_BOTH)
108 rb->gui_syncstatusbar_draw(rb->statusbars, true);
109
110 if (header_mode == HD_PATH || header_mode == HD_BOTH)
111 rb->lcd_putsxy(0, header_height - preferences->font->height, preferences->file_name);
112}
113
114static void tv_show_footer(const struct tv_screen_pos *pos)
115{
116 unsigned char buf[12];
117 unsigned footer_mode = preferences->footer_mode;
118
119 if (footer_mode == FT_SBAR || footer_mode == FT_BOTH)
120 rb->gui_syncstatusbar_draw(rb->statusbars, true);
121
122 if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
123 {
124 if (pos->line == 0)
125 rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1);
126 else
127 rb->snprintf(buf, sizeof(buf), "%d - %d", pos->page + 1, pos->page + 2);
128
129 rb->lcd_putsxy(0, LCD_HEIGHT - footer_height, buf);
130 }
131}
132
133static void tv_show_scrollbar(off_t cur_pos, int size)
134{
135 int items;
136 int min_shown;
137 int max_shown;
138 int sb_width;
139 int sb_height;
140
141 sb_height = LCD_HEIGHT - header_height - footer_height;
142 if (preferences->horizontal_scrollbar)
143 {
144 items = preferences->windows * window_columns;
145 min_shown = cur_window * window_columns + cur_column;
146 max_shown = min_shown + window_columns;
147 sb_width = (need_vertical_scrollbar)? TV_SCROLLBAR_WIDTH : 0;
148 sb_height -= TV_SCROLLBAR_HEIGHT;
149
150 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
151 sb_width,
152 LCD_HEIGHT - footer_height - TV_SCROLLBAR_HEIGHT,
153 LCD_WIDTH - sb_width, TV_SCROLLBAR_HEIGHT,
154 items, min_shown, max_shown, HORIZONTAL);
155 }
156
157 if (need_vertical_scrollbar)
158 {
159 items = (int) tv_get_total_text_size();
160 min_shown = (int) cur_pos;
161 max_shown = min_shown + size;
162
163 rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], 0, header_height,
164 TV_SCROLLBAR_WIDTH-1, sb_height,
165 items, min_shown, max_shown, VERTICAL);
166 }
167}
168
169static int tv_calc_display_lines(void)
170{
171 int scrollbar_height = preferences->horizontal_scrollbar ? TV_SCROLLBAR_HEIGHT : 0;
172 unsigned header_mode = preferences->header_mode;
173 unsigned footer_mode = preferences->footer_mode;
174
175 header_height = (header_mode == HD_SBAR || header_mode == HD_BOTH)?
176 STATUSBAR_HEIGHT : 0;
177
178 footer_height = (footer_mode == FT_SBAR || footer_mode == FT_BOTH)?
179 STATUSBAR_HEIGHT : 0;
180
181 if (header_mode == HD_NONE || header_mode == HD_PATH ||
182 footer_mode == FT_NONE || footer_mode == FT_PAGE)
183 rb->gui_syncstatusbar_draw(rb->statusbars, false);
184
185 if (header_mode == HD_PATH || header_mode == HD_BOTH)
186 header_height += preferences->font->height;
187
188 if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
189 footer_height += preferences->font->height;
190
191 return (LCD_HEIGHT - header_height - footer_height - scrollbar_height) / preferences->font->height;
192}
193#endif 89#endif
194 90
195static void tv_show_bookmarks(const struct tv_screen_pos *top_pos) 91static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
@@ -199,8 +95,9 @@ static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
199 int line; 95 int line;
200 96
201#ifdef HAVE_LCD_BITMAP 97#ifdef HAVE_LCD_BITMAP
202 rb->lcd_set_drawmode(DRMODE_COMPLEMENT); 98 tv_set_drawmode(DRMODE_COMPLEMENT);
203#endif 99#endif
100
204 while (count--) 101 while (count--)
205 { 102 {
206 line = (bookmarks[count].page - top_pos->page) * display_lines 103 line = (bookmarks[count].page - top_pos->page) * display_lines
@@ -208,66 +105,51 @@ static void tv_show_bookmarks(const struct tv_screen_pos *top_pos)
208 if (line >= 0 && line < display_lines) 105 if (line >= 0 && line < display_lines)
209 { 106 {
210#ifdef HAVE_LCD_BITMAP 107#ifdef HAVE_LCD_BITMAP
211 rb->lcd_fillrect(start_width, header_height + line * preferences->font->height, 108 tv_fillrect(0, line, 1);
212 window_width, preferences->font->height);
213#else 109#else
214 rb->lcd_putc(start_width - 1, line, TV_BOOKMARK_ICON); 110 tv_put_bookmark_icon(line);
215#endif 111#endif
216 } 112 }
217 } 113 }
218#ifdef HAVE_LCD_BITMAP
219 rb->lcd_set_drawmode(DRMODE_SOLID);
220#endif
221} 114}
222 115
223void tv_draw_window(void) 116void tv_draw_window(void)
224{ 117{
225 struct tv_screen_pos pos; 118 struct tv_screen_pos pos;
226 const unsigned char *line_buf; 119 const unsigned char *text_buf;
227 int line; 120 int line;
228 int offset = cur_column * col_width;
229 int size = 0; 121 int size = 0;
230 int line_width;
231 int draw_width = (preferences->windows - cur_window) * LCD_WIDTH - offset;
232 int dx = start_width - offset;
233 122
234 tv_copy_screen_pos(&pos); 123 tv_copy_screen_pos(&pos);
235 rb->lcd_clear_display();
236 124
237 if (preferences->alignment == AL_LEFT) 125 tv_start_display();
238 tv_read_start(cur_window, (cur_column > 0)); 126
239 else 127#ifdef HAVE_LCD_BITMAP
240 tv_read_start(0, preferences->windows > 1); 128 tv_set_drawmode(DRMODE_SOLID);
129#endif
130 tv_clear_display();
131
132 tv_read_start(cur_window, (cur_column > 0));
241 133
242 for (line = 0; line < display_lines; line++) 134 for (line = 0; line < display_lines; line++)
243 { 135 {
244 if (!tv_get_next_line(&line_buf)) 136 if (!tv_get_next_line(&text_buf))
245 break; 137 break;
246 138
247 if (preferences->alignment == AL_RIGHT) 139 tv_draw_text(line, text_buf, cur_column);
248 {
249 rb->lcd_getstringsize(line_buf, &line_width, NULL);
250 dx = draw_width - line_width;
251 }
252
253#ifdef HAVE_LCD_BITMAP
254 rb->lcd_putsxy(dx, header_height + line * preferences->font->height, line_buf);
255#else
256 rb->lcd_puts(dx, line, line_buf);
257#endif
258 } 140 }
259 141
260 size = tv_read_end(); 142 size = tv_read_end();
261 143
262 tv_show_bookmarks(&pos);
263
264#ifdef HAVE_LCD_BITMAP 144#ifdef HAVE_LCD_BITMAP
265 tv_show_scrollbar(pos.file_pos, size); 145 tv_show_scrollbar(cur_window, cur_column, pos.file_pos, size);
266 tv_show_header(); 146 tv_show_header();
267 tv_show_footer(&pos); 147 tv_show_footer(&pos);
268#endif 148#endif
149 tv_show_bookmarks(&pos);
269 150
270 rb->lcd_update(); 151 tv_update_display();
152 tv_end_display();
271} 153}
272 154
273bool tv_traverse_lines(void) 155bool tv_traverse_lines(void)
@@ -290,10 +172,13 @@ bool tv_traverse_lines(void)
290 172
291static void tv_change_preferences(const struct tv_preferences *oldp) 173static void tv_change_preferences(const struct tv_preferences *oldp)
292{ 174{
293#ifdef HAVE_LCD_BITMAP 175#ifndef HAVE_LCD_BITMAP
176 (void)oldp;
177#else
294 static bool font_changing = false; 178 static bool font_changing = false;
295 const unsigned char *font_str; 179 const unsigned char *font_str;
296 bool change_prefs = false; 180 bool change_prefs = false;
181 bool need_vertical_scrollbar;
297 struct tv_preferences new_prefs; 182 struct tv_preferences new_prefs;
298 tv_copy_preferences(&new_prefs); 183 tv_copy_preferences(&new_prefs);
299 184
@@ -317,14 +202,6 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
317 } 202 }
318 203
319 font_changing = false; 204 font_changing = false;
320
321 /* calculates display lines */
322 display_lines = tv_calc_display_lines();
323#else
324 (void)oldp;
325
326 /* REAL fixed pitch :) all chars use up 1 cell */
327 display_lines = 2;
328#endif 205#endif
329 206
330#ifdef HAVE_LCD_BITMAP 207#ifdef HAVE_LCD_BITMAP
@@ -336,27 +213,36 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
336 if (cur_window >= preferences->windows) 213 if (cur_window >= preferences->windows)
337 cur_window = 0; 214 cur_window = 0;
338 215
339 window_width = LCD_WIDTH; 216 /* change viewport */
217 tv_change_viewport();
218
340#ifdef HAVE_LCD_BITMAP 219#ifdef HAVE_LCD_BITMAP
341 need_vertical_scrollbar = false; 220 need_vertical_scrollbar = false;
342 start_width = 0; 221 tv_set_layout(col_width, need_vertical_scrollbar);
222 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
343 tv_seek_top(); 223 tv_seek_top();
344 tv_set_read_conditions(preferences->windows, window_width); 224 tv_set_read_conditions(preferences->windows, window_width);
345 if (tv_traverse_lines() && preferences->vertical_scrollbar) 225 if (tv_traverse_lines() && preferences->vertical_scrollbar)
346 { 226 {
347 need_vertical_scrollbar = true; 227 need_vertical_scrollbar = true;
348 start_width = TV_SCROLLBAR_WIDTH; 228 tv_set_layout(col_width, need_vertical_scrollbar);
229 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
349 } 230 }
350 tv_seek_top(); 231 tv_seek_top();
351#else 232#else
352 start_width = 1; 233 tv_set_layout(col_width);
234 tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
353#endif 235#endif
354 window_width -= start_width;
355 window_columns = window_width / col_width;
356 236
237 window_columns = window_width / col_width;
357 cur_column = 0; 238 cur_column = 0;
358 239
359 tv_set_read_conditions(preferences->windows, window_width); 240 tv_set_read_conditions(preferences->windows, window_width);
241
242 tv_init_display();
243#ifdef HAVE_LCD_BITMAP
244 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar);
245#endif
360} 246}
361 247
362bool tv_init_window(unsigned char **buf, size_t *size) 248bool tv_init_window(unsigned char **buf, size_t *size)
@@ -375,6 +261,9 @@ void tv_finalize_window(void)
375 { 261 {
376 tv_set_font(rb->global_settings->font_file); 262 tv_set_font(rb->global_settings->font_file);
377 } 263 }
264
265 /* undo viewport */
266 tv_undo_viewport();
378#endif 267#endif
379} 268}
380 269