summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-06-26 09:14:53 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-06-26 09:14:53 +0000
commitac622c6d673c708d48527db8a189401422a5d03c (patch)
treefb6bbde022027ccf24b2cb1be49a3c7369cf45e0 /apps
parentbe70fd89be787e2b24604f9ba785b87c1f8f1d22 (diff)
downloadrockbox-ac622c6d673c708d48527db8a189401422a5d03c.tar.gz
rockbox-ac622c6d673c708d48527db8a189401422a5d03c.zip
text viewer: reworks screen access logics and some bugs fix.
- screen access logics separte from tv_window. (new tv_display.[ch]) - using multi screen api. - (bug fix) the head of the each line is not normally displayed when the alignment is RIGHT. - (bug fix) unnecessary blank line is not displayed. (a part of FS#11400). - (bug fix) the order by which callback functions were called was not correct. (FIFO->FILO) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27138 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/text_viewer/SOURCES1
-rw-r--r--apps/plugins/text_viewer/tv_display.c344
-rw-r--r--apps/plugins/text_viewer/tv_display.h175
-rw-r--r--apps/plugins/text_viewer/tv_preferences.c3
-rw-r--r--apps/plugins/text_viewer/tv_text_processor.c3
-rw-r--r--apps/plugins/text_viewer/tv_window.c197
6 files changed, 567 insertions, 156 deletions
diff --git a/apps/plugins/text_viewer/SOURCES b/apps/plugins/text_viewer/SOURCES
index 7e45d1fb68..80fec09c5f 100644
--- a/apps/plugins/text_viewer/SOURCES
+++ b/apps/plugins/text_viewer/SOURCES
@@ -1,6 +1,7 @@
1text_viewer.c 1text_viewer.c
2tv_action.c 2tv_action.c
3tv_bookmark.c 3tv_bookmark.c
4tv_display.c
4tv_menu.c 5tv_menu.c
5tv_pager.c 6tv_pager.c
6tv_preferences.c 7tv_preferences.c
diff --git a/apps/plugins/text_viewer/tv_display.c b/apps/plugins/text_viewer/tv_display.c
new file mode 100644
index 0000000000..78b5b4b074
--- /dev/null
+++ b/apps/plugins/text_viewer/tv_display.c
@@ -0,0 +1,344 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Yoshihisa Uchida
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "tv_display.h"
22#include "tv_preferences.h"
23
24/*
25 * display layout
26 *
27 * when is defined HAVE_LCD_BITMAP
28 * +-------------------------+
29 * |statusbar (1) |
30 * +-------------------------+
31 * |filename (2) |
32 * +---+---------------------+
33 * |s | |
34 * |c | |
35 * |r | draw area |
36 * |o | |
37 * |l | |
38 * |l | |
39 * |b | |
40 * |a | |
41 * |r | |
42 * |(3)| |
43 * +---+---------------------+
44 * | |scrollbar (4) |
45 * +---+---------------------+
46 * |page (5) |
47 * +-------------------------+
48 * |statusbar (6) |
49 * +-------------------------+
50 *
51 * (1) displays when rb->global_settings->statusbar == STATUSBAR_TOP
52 * and preferences->header_mode is HD_SBAR or HD_BOTH.
53 * (2) displays when preferences->header_mode is HD_PATH or HD_BOTH.
54 * (3) displays when preferences->vertical_scrollbar is SB_ON.
55 * (4) displays when preferences->horizontal_scrollbar is SB_ON.
56 * (5) displays when preferences->footer_mode is FT_PAGE or FT_BOTH.
57 * (6) displays when rb->global_settings->statusbar == STATUSBAR_BOTTOM
58 * and preferences->footer_mode is FT_SBAR or FT_BOTH.
59 *
60 *
61 * when isn't defined HAVE_LCD_BITMAP
62 * +---+---------------------+
63 * | | |
64 * |(7)| draw area |
65 * | | |
66 * +---+---------------------+
67 * (7) bookmark
68 */
69
70#define TV_SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
71#define TV_SCROLLBAR_HEIGHT 4
72
73#ifndef HAVE_LCD_BITMAP
74#define TV_BOOKMARK_ICON 0xe101
75#endif
76
77struct tv_rect {
78 int x;
79 int y;
80 int w;
81 int h;
82};
83
84static struct viewport vp_info;
85static bool is_initialized_vp = false;
86
87#ifdef HAVE_LCD_BITMAP
88static int drawmode = DRMODE_SOLID;
89static int totalsize;
90static bool show_vertical_scrollbar;
91#endif
92
93static struct screen* display;
94
95/* layout */
96#ifdef HAVE_LCD_BITMAP
97static struct tv_rect header;
98static struct tv_rect footer;
99static struct tv_rect horizontal_scrollbar;
100static struct tv_rect vertical_scrollbar;
101#else
102static struct tv_rect bookmark;
103#endif
104static struct tv_rect drawarea;
105
106static int display_columns;
107static int display_rows;
108
109static int col_width;
110static int row_height;
111
112#ifdef HAVE_LCD_BITMAP
113
114void tv_show_header(void)
115{
116 unsigned header_mode = header_mode;
117
118 if (preferences->header_mode == HD_PATH || preferences->header_mode == HD_BOTH)
119 display->putsxy(header.x, header.y, preferences->file_name);
120}
121
122void tv_show_footer(const struct tv_screen_pos *pos)
123{
124 unsigned char buf[12];
125 unsigned footer_mode = preferences->footer_mode;
126
127 if (footer_mode == FT_PAGE || footer_mode == FT_BOTH)
128 {
129 if (pos->line == 0)
130 rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1);
131 else
132 rb->snprintf(buf, sizeof(buf), "%d - %d", pos->page + 1, pos->page + 2);
133 display->putsxy(footer.x, footer.y, buf);
134 }
135}
136
137void tv_init_scrollbar(off_t total, bool show_scrollbar)
138{
139 totalsize = total;
140 show_vertical_scrollbar = show_scrollbar;
141}
142
143void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
144{
145 int items;
146 int min_shown;
147 int max_shown;
148
149 if (preferences->horizontal_scrollbar)
150 {
151 items = preferences->windows * display_columns;
152 min_shown = window * display_columns + col;
153 max_shown = min_shown + display_columns;
154
155 rb->gui_scrollbar_draw(display,
156 horizontal_scrollbar.x, horizontal_scrollbar.y,
157 horizontal_scrollbar.w, TV_SCROLLBAR_HEIGHT,
158 items, min_shown, max_shown, HORIZONTAL);
159 }
160
161 if (show_vertical_scrollbar)
162 {
163 items = (int) totalsize;
164 min_shown = (int) cur_pos;
165 max_shown = min_shown + size;
166
167 rb->gui_scrollbar_draw(display,
168 vertical_scrollbar.x, vertical_scrollbar.y,
169 TV_SCROLLBAR_WIDTH-1, vertical_scrollbar.h,
170 items, min_shown, max_shown, VERTICAL);
171 }
172}
173
174void tv_fillrect(int col, int row, int rows)
175{
176 display->fillrect(drawarea.x + col * col_width, drawarea.y + row * row_height,
177 drawarea.w - col * col_width, rows * row_height);
178}
179
180void tv_set_drawmode(int mode)
181{
182 rb->lcd_set_drawmode(mode);
183}
184
185#endif
186
187void tv_draw_text(int row, const unsigned char *text, int offset)
188{
189 int xpos = -offset * col_width;
190 int text_width;
191
192 if (row < 0 || row >= display_rows)
193 return;
194
195 if (preferences->alignment == AL_RIGHT)
196 {
197 display->getstringsize(text, &text_width, NULL);
198 xpos += ((offset > 0)? drawarea.w * 2 : drawarea.w) - text_width;
199 }
200
201#ifdef HAVE_LCD_BITMAP
202 display->putsxy(drawarea.x + xpos, drawarea.y + row * row_height, text);
203#else
204 display->puts(drawarea.x + xpos, drawarea.y + row, text);
205#endif
206}
207
208#ifndef HAVE_LCD_BITMAP
209void tv_put_bookmark_icon(int row)
210{
211 display->putchar(bookmark.x, drawarea.y + row, TV_BOOKMARK_ICON);
212}
213#endif
214
215void tv_init_display(void)
216{
217 display = rb->screens[SCREEN_MAIN];
218 display->clear_viewport();
219}
220
221void tv_start_display(void)
222{
223 display->set_viewport(&vp_info);
224#ifdef HAVE_LCD_BITMAP
225 drawmode = rb->lcd_get_drawmode();
226#endif
227}
228
229void tv_end_display(void)
230{
231#ifdef HAVE_LCD_BITMAP
232 rb->lcd_set_drawmode(drawmode);
233#endif
234 display->set_viewport(NULL);
235}
236
237void tv_clear_display(void)
238{
239 display->clear_viewport();
240}
241
242void tv_update_display(void)
243{
244 display->update_viewport();
245}
246
247#ifdef HAVE_LCD_BITMAP
248void tv_set_layout(int col_w, bool show_scrollbar)
249#else
250void tv_set_layout(int col_w)
251#endif
252{
253#ifdef HAVE_LCD_BITMAP
254 int scrollbar_width = (show_scrollbar)? TV_SCROLLBAR_WIDTH : 0;
255 int scrollbar_height = (preferences->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT : 0;
256 unsigned header_mode = preferences->header_mode;
257 unsigned footer_mode = preferences->footer_mode;
258
259 row_height = preferences->font->height;
260
261 header.x = 0;
262 header.y = 0;
263 header.w = vp_info.width;
264 header.h = (header_mode == HD_PATH || header_mode == HD_BOTH)? row_height : 0;
265
266 footer.x = 0;
267 footer.w = vp_info.width;
268 footer.h = (footer_mode == FT_PAGE || footer_mode == FT_BOTH)? row_height : 0;
269 footer.y = vp_info.height - footer.h;
270
271 drawarea.x = scrollbar_width;
272 drawarea.y = header.y + header.h;
273 drawarea.w = vp_info.width - scrollbar_width;
274 drawarea.h = footer.y - drawarea.y - scrollbar_height;
275
276 horizontal_scrollbar.x = drawarea.x;
277 horizontal_scrollbar.y = footer.y - scrollbar_height;
278 horizontal_scrollbar.w = drawarea.w;
279 horizontal_scrollbar.h = scrollbar_height;
280
281 vertical_scrollbar.x = 0;
282 vertical_scrollbar.y = drawarea.y;
283 vertical_scrollbar.w = scrollbar_width;
284 vertical_scrollbar.h = drawarea.h;
285#else
286 row_height = 1;
287
288 bookmark.x = 0;
289 bookmark.y = 0;
290 bookmark.w = 1;
291 bookmark.h = vp_info.height;
292
293 drawarea.x = 1;
294 drawarea.y = 0;
295 drawarea.w = vp_info.width - 1;
296 drawarea.h = vp_info.height;
297#endif
298 col_width = col_w;
299
300 display_columns = drawarea.w / col_width;
301 display_rows = drawarea.h / row_height;
302}
303
304void tv_get_drawarea_info(int *width, int *cols, int *rows)
305{
306 *width = drawarea.w;
307 *cols = display_columns;
308 *rows = display_rows;
309}
310
311void tv_change_viewport(void)
312{
313#ifdef HAVE_LCD_BITMAP
314 struct viewport vp;
315 bool show_statusbar = (preferences->header_mode == HD_SBAR ||
316 preferences->header_mode == HD_BOTH ||
317 preferences->footer_mode == FT_SBAR ||
318 preferences->footer_mode == FT_BOTH);
319
320 if (is_initialized_vp)
321 tv_undo_viewport();
322 else
323 is_initialized_vp = true;
324
325 rb->viewportmanager_theme_enable(SCREEN_MAIN, show_statusbar, &vp);
326 vp_info = vp;
327 vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK;
328
329#else
330 if (!is_initialized_vp)
331 {
332 rb->viewport_set_defaults(&vp_info, SCREEN_MAIN);
333 is_initialized_vp = true;
334 }
335#endif
336}
337
338void tv_undo_viewport(void)
339{
340#ifdef HAVE_LCD_BITMAP
341 if (is_initialized_vp)
342 rb->viewportmanager_theme_undo(SCREEN_MAIN, false);
343#endif
344}
diff --git a/apps/plugins/text_viewer/tv_display.h b/apps/plugins/text_viewer/tv_display.h
new file mode 100644
index 0000000000..005011c756
--- /dev/null
+++ b/apps/plugins/text_viewer/tv_display.h
@@ -0,0 +1,175 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Yoshihisa Uchida
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef PLUGIN_TEXT_VIEWER_DISPLAY_H
22#define PLUGIN_TEXT_VIEWER_DISPLAY_H
23
24#include "plugin.h"
25#include "tv_screen_pos.h"
26
27/* text viewer layout parts functions */
28#ifdef HAVE_LCD_BITMAP
29
30/* show headaer */
31void tv_show_header(void);
32
33/*
34 * show footer
35 *
36 * [In] pos
37 * the current position
38 */
39void tv_show_footer(const struct tv_screen_pos *pos);
40
41/*
42 * initialize the scrollbar
43 *
44 * [In] total
45 * total text size
46 *
47 * [In] show_scrollbar
48 * true: show the vertical scrollbar
49 * false: does not show the vertical scrollbar
50 */
51void tv_init_scrollbar(off_t total, bool show_scrollbar);
52
53/*
54 * show horizontal/vertical scrollbar
55 *
56 * [In] window
57 * the current window
58 *
59 * [In] col
60 * the current column
61 *
62 * [In] cur_pos
63 * the current text position
64 *
65 * [In] size
66 * the size of text in displayed.
67 */
68void tv_show_scrollbar(int window, int col, off_t cur_pos, int size);
69
70#else
71
72/*
73 * put the bookmark icon
74 *
75 * [In] row
76 * the row where the bookmark icon is put
77 */
78void tv_put_bookmark_icon(int row);
79
80#endif
81
82/* common display functons */
83
84/* initialized display functions */
85void tv_init_display(void);
86
87/* start the display processing */
88void tv_start_display(void);
89
90/* end the display processing */
91void tv_end_display(void);
92
93/* clear the display */
94void tv_clear_display(void);
95
96/*update the display */
97void tv_update_display(void);
98
99#ifdef HAVE_LCD_BITMAP
100
101/*
102 * set the drawmode
103 *
104 * [In] mode
105 * new drawmode
106 */
107void tv_set_drawmode(int mode);
108
109/*
110 * draw the rectangle that paints out inside
111 *
112 * [In] col
113 * the column of the upper left
114 *
115 * [In] row
116 * the row of the upper left
117 *
118 * [In] row
119 * draw rows
120 */
121void tv_fillrect(int col, int row, int rows);
122
123#endif
124
125/*
126 * draw the text
127 *
128 * [In] row
129 * the row that displays the text
130 *
131 * [In] text
132 * text
133 *
134 * [In] offset
135 * display the text that is since offset columns
136 */
137void tv_draw_text(int row, const unsigned char *text, int offset);
138
139/* layout functions */
140#ifdef HAVE_LCD_BITMAP
141
142/*
143 * set the layout
144 *
145 * [In] col_w
146 * width per column
147 *
148 * [In] show_scrollbar
149 * true: show the vertical scrollbar
150 * false: does not show the vertical scrollbar
151 */
152void tv_set_layout(int col_w, bool show_scrollbar);
153
154#else
155
156/*
157 * set the layout
158 *
159 * [In] col_w
160 * width per column
161 */
162void tv_set_layout(int col_w);
163
164#endif
165void tv_get_drawarea_info(int *width, int *cols, int *rows);
166
167/* viewport functions */
168
169/* change the viewport */
170void tv_change_viewport(void);
171
172/* undo the viewport */
173void tv_undo_viewport(void);
174
175#endif
diff --git a/apps/plugins/text_viewer/tv_preferences.c b/apps/plugins/text_viewer/tv_preferences.c
index 30b5f5ce51..72cda9d00f 100644
--- a/apps/plugins/text_viewer/tv_preferences.c
+++ b/apps/plugins/text_viewer/tv_preferences.c
@@ -62,7 +62,8 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp)
62#endif 62#endif
63 (rb->strcmp(oldp->file_name, preferences->file_name))) 63 (rb->strcmp(oldp->file_name, preferences->file_name)))
64 { 64 {
65 for (i = 0; i < listner_count; i++) 65 /* callback functions are called as FILO */
66 for (i = listner_count - 1; i >= 0; i--)
66 listners[i](oldp); 67 listners[i](oldp);
67 } 68 }
68} 69}
diff --git a/apps/plugins/text_viewer/tv_text_processor.c b/apps/plugins/text_viewer/tv_text_processor.c
index 1ddee62077..edb2ad0483 100644
--- a/apps/plugins/text_viewer/tv_text_processor.c
+++ b/apps/plugins/text_viewer/tv_text_processor.c
@@ -512,7 +512,8 @@ int tv_create_formed_text(const unsigned char *src, ssize_t bufsize,
512 tv_get_ucs(src, &ch); 512 tv_get_ucs(src, &ch);
513 is_indent = (tv_isspace(ch) && !is_break_line); 513 is_indent = (tv_isspace(ch) && !is_break_line);
514 514
515 if (is_indent && preferences->indent_spaces == 0 && (expand_extra_line = !expand_extra_line) == true) 515 if (is_indent && preferences->line_mode == LM_REFLOW && preferences->indent_spaces == 0
516 && (expand_extra_line = !expand_extra_line) == true)
516 return 0; 517 return 0;
517 518
518 for (i = 0; i < block_count; i++) 519 for (i = 0; i < block_count; i++)
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