diff options
Diffstat (limited to 'apps/plugins/text_viewer/tv_display.c')
-rw-r--r-- | apps/plugins/text_viewer/tv_display.c | 344 |
1 files changed, 344 insertions, 0 deletions
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 | |||
77 | struct tv_rect { | ||
78 | int x; | ||
79 | int y; | ||
80 | int w; | ||
81 | int h; | ||
82 | }; | ||
83 | |||
84 | static struct viewport vp_info; | ||
85 | static bool is_initialized_vp = false; | ||
86 | |||
87 | #ifdef HAVE_LCD_BITMAP | ||
88 | static int drawmode = DRMODE_SOLID; | ||
89 | static int totalsize; | ||
90 | static bool show_vertical_scrollbar; | ||
91 | #endif | ||
92 | |||
93 | static struct screen* display; | ||
94 | |||
95 | /* layout */ | ||
96 | #ifdef HAVE_LCD_BITMAP | ||
97 | static struct tv_rect header; | ||
98 | static struct tv_rect footer; | ||
99 | static struct tv_rect horizontal_scrollbar; | ||
100 | static struct tv_rect vertical_scrollbar; | ||
101 | #else | ||
102 | static struct tv_rect bookmark; | ||
103 | #endif | ||
104 | static struct tv_rect drawarea; | ||
105 | |||
106 | static int display_columns; | ||
107 | static int display_rows; | ||
108 | |||
109 | static int col_width; | ||
110 | static int row_height; | ||
111 | |||
112 | #ifdef HAVE_LCD_BITMAP | ||
113 | |||
114 | void 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 | |||
122 | void 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 | |||
137 | void tv_init_scrollbar(off_t total, bool show_scrollbar) | ||
138 | { | ||
139 | totalsize = total; | ||
140 | show_vertical_scrollbar = show_scrollbar; | ||
141 | } | ||
142 | |||
143 | void 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 | |||
174 | void 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 | |||
180 | void tv_set_drawmode(int mode) | ||
181 | { | ||
182 | rb->lcd_set_drawmode(mode); | ||
183 | } | ||
184 | |||
185 | #endif | ||
186 | |||
187 | void 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 | ||
209 | void tv_put_bookmark_icon(int row) | ||
210 | { | ||
211 | display->putchar(bookmark.x, drawarea.y + row, TV_BOOKMARK_ICON); | ||
212 | } | ||
213 | #endif | ||
214 | |||
215 | void tv_init_display(void) | ||
216 | { | ||
217 | display = rb->screens[SCREEN_MAIN]; | ||
218 | display->clear_viewport(); | ||
219 | } | ||
220 | |||
221 | void 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 | |||
229 | void 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 | |||
237 | void tv_clear_display(void) | ||
238 | { | ||
239 | display->clear_viewport(); | ||
240 | } | ||
241 | |||
242 | void tv_update_display(void) | ||
243 | { | ||
244 | display->update_viewport(); | ||
245 | } | ||
246 | |||
247 | #ifdef HAVE_LCD_BITMAP | ||
248 | void tv_set_layout(int col_w, bool show_scrollbar) | ||
249 | #else | ||
250 | void 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 | |||
304 | void 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 | |||
311 | void 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 | |||
338 | void 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 | } | ||