1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Yoshihisa Uchida
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "tv_display.h"
23 #include "tv_preferences.h"
28 * when is defined HAVE_LCD_BITMAP
29 * +-------------------------+
31 * +-------------------------+
33 * +---+---------------------+
44 * +---+---------------------+
46 * +---+---------------------+
48 * +-------------------------+
50 * +-------------------------+
52 * (1) displays when rb->global_settings->statusbar == STATUSBAR_TOP.
53 * (2) displays when preferences->header_mode is HD_PATH.
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.
57 * (6) displays when rb->global_settings->statusbar == STATUSBAR_BOTTOM.
60 * when isn't defined HAVE_LCD_BITMAP
61 * +---+---------------------+
65 * +---+---------------------+
69 #define TV_SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
70 #define TV_SCROLLBAR_HEIGHT 4
72 #ifndef HAVE_LCD_BITMAP
73 #define TV_BOOKMARK_ICON 0xe101
83 static struct viewport vp_info
;
84 static struct viewport vp_text
;
85 static bool is_initialized_vp
= false;
87 static struct screen
* display
;
90 #ifdef HAVE_LCD_BITMAP
91 static struct tv_rect header
;
92 static struct tv_rect footer
;
93 static struct tv_rect horizontal_scrollbar
;
94 static struct tv_rect vertical_scrollbar
;
96 static struct tv_rect bookmark
;
99 static bool show_horizontal_scrollbar
;
100 static bool show_vertical_scrollbar
;
102 static int display_columns
;
103 static int display_rows
;
105 static int col_width
= 1;
106 static int row_height
= 1;
108 static int totalsize
;
110 #ifdef HAVE_LCD_BITMAP
112 static void tv_show_header(void)
114 if (preferences
->header_mode
)
115 display
->putsxy(header
.x
, header
.y
, preferences
->file_name
);
118 static void tv_show_footer(const struct tv_screen_pos
*pos
)
120 unsigned char buf
[12];
122 if (preferences
->footer_mode
)
125 rb
->snprintf(buf
, sizeof(buf
), "%d", pos
->page
+ 1);
127 rb
->snprintf(buf
, sizeof(buf
), "%d - %d", pos
->page
+ 1, pos
->page
+ 2);
128 display
->putsxy(footer
.x
, footer
.y
+ 1, buf
);
132 static void tv_show_scrollbar(int window
, int col
, off_t cur_pos
, int size
)
138 if (show_horizontal_scrollbar
)
140 items
= preferences
->windows
* display_columns
;
141 min_shown
= window
* display_columns
+ col
;
142 max_shown
= min_shown
+ display_columns
;
144 rb
->gui_scrollbar_draw(display
,
145 horizontal_scrollbar
.x
, horizontal_scrollbar
.y
+ 1,
146 horizontal_scrollbar
.w
, TV_SCROLLBAR_HEIGHT
,
147 items
, min_shown
, max_shown
, HORIZONTAL
);
150 if (show_vertical_scrollbar
)
152 items
= (int) totalsize
;
153 min_shown
= (int) cur_pos
;
154 max_shown
= min_shown
+ size
;
156 rb
->gui_scrollbar_draw(display
,
157 vertical_scrollbar
.x
, vertical_scrollbar
.y
,
158 TV_SCROLLBAR_WIDTH
, vertical_scrollbar
.h
,
159 items
, min_shown
, max_shown
, VERTICAL
);
165 void tv_init_scrollbar(off_t total
, bool show_scrollbar
)
168 show_horizontal_scrollbar
= (show_scrollbar
&& preferences
->horizontal_scrollbar
);
169 show_vertical_scrollbar
= (show_scrollbar
&& preferences
->vertical_scrollbar
);
172 void tv_show_bookmarks(const int *rows
, int count
)
174 #ifdef HAVE_LCD_BITMAP
175 display
->set_viewport(&vp_text
);
176 display
->set_drawmode(DRMODE_COMPLEMENT
);
181 #ifdef HAVE_LCD_BITMAP
182 display
->fillrect(0, rows
[count
] * row_height
,
183 vp_text
.width
, row_height
);
185 display
->putchar(bookmark
.x
, bookmark
.y
+ rows
[count
], TV_BOOKMARK_ICON
);
188 #ifdef HAVE_LCD_BITMAP
189 display
->set_drawmode(DRMODE_SOLID
);
190 display
->set_viewport(&vp_info
);
194 void tv_update_extra(int window
, int col
, const struct tv_screen_pos
*pos
, int size
)
196 #ifdef HAVE_LCD_BITMAP
197 tv_show_scrollbar(window
, col
, pos
->file_pos
, size
);
208 void tv_draw_text(int row
, const unsigned char *text
, int offset
)
210 int xpos
= -offset
* col_width
;
213 if (row
< 0 || row
>= display_rows
)
216 if (preferences
->alignment
== AL_RIGHT
)
218 display
->getstringsize(text
, &text_width
, NULL
);
219 xpos
+= ((offset
> 0)? vp_text
.width
* 2 : vp_text
.width
) - text_width
;
222 display
->set_viewport(&vp_text
);
223 #ifdef HAVE_LCD_BITMAP
224 display
->putsxy(xpos
, row
* row_height
, text
);
226 display
->puts(xpos
, row
, text
);
228 display
->set_viewport(&vp_info
);
231 void tv_start_display(void)
233 display
->set_viewport(&vp_info
);
234 #ifdef HAVE_LCD_BITMAP
235 display
->set_drawmode(DRMODE_SOLID
);
239 rb
->lcd_set_backdrop(NULL
);
241 display
->clear_viewport();
244 void tv_end_display(void)
246 display
->update_viewport();
247 display
->set_viewport(NULL
);
250 void tv_set_layout(bool show_scrollbar
)
252 #ifdef HAVE_LCD_BITMAP
253 int scrollbar_width
= (show_scrollbar
&& preferences
->vertical_scrollbar
)?
254 TV_SCROLLBAR_WIDTH
+ 1 : 0;
255 int scrollbar_height
= (show_scrollbar
&& preferences
->horizontal_scrollbar
)?
256 TV_SCROLLBAR_HEIGHT
+ 1 : 0;
258 row_height
= preferences
->font
->height
;
262 header
.w
= vp_info
.width
;
263 header
.h
= (preferences
->header_mode
)? row_height
+ 1 : 0;
266 footer
.w
= vp_info
.width
;
267 footer
.h
= (preferences
->footer_mode
)? row_height
+ 1 : 0;
268 footer
.y
= vp_info
.height
- footer
.h
;
270 horizontal_scrollbar
.x
= scrollbar_width
;
271 horizontal_scrollbar
.y
= footer
.y
- scrollbar_height
;
272 horizontal_scrollbar
.w
= vp_info
.width
- scrollbar_width
;
273 horizontal_scrollbar
.h
= scrollbar_height
;
275 vertical_scrollbar
.x
= 0;
276 vertical_scrollbar
.y
= header
.y
+ header
.h
;
277 vertical_scrollbar
.w
= scrollbar_width
;
278 vertical_scrollbar
.h
= footer
.y
- vertical_scrollbar
.y
- scrollbar_height
;
281 vp_text
.x
+= horizontal_scrollbar
.x
;
282 vp_text
.y
+= vertical_scrollbar
.y
;
283 vp_text
.width
= horizontal_scrollbar
.w
;
284 vp_text
.height
= vertical_scrollbar
.h
;
286 (void) show_scrollbar
;
293 bookmark
.h
= vp_info
.height
;
300 display_columns
= vp_text
.width
/ col_width
;
301 display_rows
= vp_text
.height
/ row_height
;
304 void tv_get_drawarea_info(int *width
, int *cols
, int *rows
)
306 *width
= vp_text
.width
;
307 *cols
= display_columns
;
308 *rows
= display_rows
;
311 static void tv_change_viewport(void)
313 #ifdef HAVE_LCD_BITMAP
314 bool show_statusbar
= preferences
->statusbar
;
316 if (is_initialized_vp
)
317 rb
->viewportmanager_theme_undo(SCREEN_MAIN
, false);
319 is_initialized_vp
= true;
321 rb
->viewportmanager_theme_enable(SCREEN_MAIN
, show_statusbar
, &vp_info
);
322 vp_info
.flags
&= ~VP_FLAG_ALIGNMENT_MASK
;
323 display
->set_viewport(&vp_info
);
325 if (!is_initialized_vp
)
327 rb
->viewport_set_defaults(&vp_info
, SCREEN_MAIN
);
328 is_initialized_vp
= true;
333 #ifdef HAVE_LCD_BITMAP
334 static bool tv_set_font(const unsigned char *font
)
336 unsigned char path
[MAX_PATH
];
338 if (font
!= NULL
&& *font
!= '\0')
340 rb
->snprintf(path
, MAX_PATH
, "%s/%s.fnt", FONT_DIR
, font
);
341 if (rb
->font_load(NULL
, path
) < 0)
343 rb
->splash(HZ
/2, "font load failed");
351 static int tv_change_preferences(const struct tv_preferences
*oldp
)
353 #ifdef HAVE_LCD_BITMAP
354 static bool font_changing
= false;
355 const unsigned char *font_str
;
356 struct tv_preferences new_prefs
;
358 font_str
= (oldp
&& !font_changing
)? oldp
->font_name
: rb
->global_settings
->font_file
;
361 if (font_changing
|| rb
->strcmp(font_str
, preferences
->font_name
))
363 if (!tv_set_font(preferences
->font_name
))
366 * tv_set_font(rb->global_settings->font_file) doesn't fail usually.
367 * if it fails, a fatal problem occurs in Rockbox.
369 if (!rb
->strcmp(preferences
->font_name
, rb
->global_settings
->font_file
))
370 return TV_CALLBACK_ERROR
;
372 font_changing
= true;
373 tv_copy_preferences(&new_prefs
);
374 rb
->strlcpy(new_prefs
.font_name
, font_str
, MAX_PATH
);
376 return (tv_set_preferences(&new_prefs
))? TV_CALLBACK_STOP
: TV_CALLBACK_ERROR
;
378 col_width
= 2 * rb
->font_get_width(preferences
->font
, ' ');
379 font_changing
= false;
384 tv_change_viewport();
385 return TV_CALLBACK_OK
;
388 bool tv_init_display(unsigned char **buf
, size_t *size
)
393 display
= rb
->screens
[SCREEN_MAIN
];
394 display
->clear_viewport();
396 tv_add_preferences_change_listner(tv_change_preferences
);
401 void tv_finalize_display(void)
403 #ifdef HAVE_LCD_BITMAP
405 if (rb
->strcmp(rb
->global_settings
->font_file
, preferences
->font_name
))
407 tv_set_font(rb
->global_settings
->font_file
);
411 if (is_initialized_vp
)
412 rb
->viewportmanager_theme_undo(SCREEN_MAIN
, false);
416 bool tv_exist_scrollbar(void)
418 #ifdef HAVE_LCD_BITMAP