1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Gilles Roux
12 * 2010 Yoshihisa Uchida
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "tv_bookmark.h"
25 #include "tv_display.h"
26 #include "tv_preferences.h"
27 #include "tv_screen_pos.h"
28 #include "tv_text_reader.h"
29 #include "tv_window.h"
31 static int window_width
;
32 static int window_columns
;
33 static int display_lines
;
36 static int cur_window
;
37 static int cur_column
;
39 #ifdef HAVE_LCD_BITMAP
40 static bool tv_set_font(const unsigned char *font
)
42 unsigned char path
[MAX_PATH
];
44 if (font
!= NULL
&& *font
!= '\0')
46 rb
->snprintf(path
, MAX_PATH
, "%s/%s.fnt", FONT_DIR
, font
);
47 if (rb
->font_load(NULL
, path
) < 0)
49 rb
->splash(HZ
/2, "font load failed");
56 static bool tv_check_header_and_footer(struct tv_preferences
*new_prefs
)
58 bool change_prefs
= false;
60 if (rb
->global_settings
->statusbar
!= STATUSBAR_TOP
)
62 if (new_prefs
->header_mode
== HD_SBAR
)
64 new_prefs
->header_mode
= HD_NONE
;
67 else if (new_prefs
->header_mode
== HD_BOTH
)
69 new_prefs
->header_mode
= HD_PATH
;
73 if (rb
->global_settings
->statusbar
!= STATUSBAR_BOTTOM
)
75 if (new_prefs
->footer_mode
== FT_SBAR
)
77 new_prefs
->footer_mode
= FT_NONE
;
80 else if (new_prefs
->footer_mode
== FT_BOTH
)
82 new_prefs
->footer_mode
= FT_PAGE
;
91 static void tv_show_bookmarks(const struct tv_screen_pos
*top_pos
)
93 struct tv_screen_pos bookmarks
[TV_MAX_BOOKMARKS
];
94 int count
= tv_get_bookmark_positions(bookmarks
);
97 #ifdef HAVE_LCD_BITMAP
98 tv_set_drawmode(DRMODE_COMPLEMENT
);
103 line
= (bookmarks
[count
].page
- top_pos
->page
) * display_lines
104 + (bookmarks
[count
].line
- top_pos
->line
);
105 if (line
>= 0 && line
< display_lines
)
107 #ifdef HAVE_LCD_BITMAP
108 tv_fillrect(0, line
, 1);
110 tv_put_bookmark_icon(line
);
116 void tv_draw_window(void)
118 struct tv_screen_pos pos
;
119 const unsigned char *text_buf
;
123 tv_copy_screen_pos(&pos
);
127 #ifdef HAVE_LCD_BITMAP
128 tv_set_drawmode(DRMODE_SOLID
);
132 tv_read_start(cur_window
, (cur_column
> 0));
134 for (line
= 0; line
< display_lines
; line
++)
136 if (!tv_get_next_line(&text_buf
))
139 tv_draw_text(line
, text_buf
, cur_column
);
142 size
= tv_read_end();
144 #ifdef HAVE_LCD_BITMAP
145 tv_show_scrollbar(cur_window
, cur_column
, pos
.file_pos
, size
);
147 tv_show_footer(&pos
);
149 tv_show_bookmarks(&pos
);
155 bool tv_traverse_lines(void)
160 tv_read_start(0, false);
161 for (i
= 0; i
< display_lines
; i
++)
163 if (!tv_get_next_line(NULL
))
173 static void tv_change_preferences(const struct tv_preferences
*oldp
)
175 #ifndef HAVE_LCD_BITMAP
178 static bool font_changing
= false;
179 const unsigned char *font_str
;
180 bool change_prefs
= false;
181 bool need_vertical_scrollbar
;
182 struct tv_preferences new_prefs
;
183 tv_copy_preferences(&new_prefs
);
185 font_str
= (oldp
&& !font_changing
)? oldp
->font_name
: rb
->global_settings
->font_file
;
188 if (font_changing
|| rb
->strcmp(font_str
, preferences
->font_name
))
190 font_changing
= true;
191 if (!tv_set_font(preferences
->font_name
))
193 rb
->strlcpy(new_prefs
.font_name
, font_str
, MAX_PATH
);
198 if (tv_check_header_and_footer(&new_prefs
) || change_prefs
)
200 tv_set_preferences(&new_prefs
);
204 font_changing
= false;
207 #ifdef HAVE_LCD_BITMAP
208 col_width
= 2 * rb
->font_get_width(preferences
->font
, ' ');
213 if (cur_window
>= preferences
->windows
)
216 /* change viewport */
217 tv_change_viewport();
219 #ifdef HAVE_LCD_BITMAP
220 need_vertical_scrollbar
= false;
221 tv_set_layout(col_width
, need_vertical_scrollbar
);
222 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
224 tv_set_read_conditions(preferences
->windows
, window_width
);
225 if (tv_traverse_lines() && preferences
->vertical_scrollbar
)
227 need_vertical_scrollbar
= true;
228 tv_set_layout(col_width
, need_vertical_scrollbar
);
229 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
233 tv_set_layout(col_width
);
234 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
237 window_columns
= window_width
/ col_width
;
240 tv_set_read_conditions(preferences
->windows
, window_width
);
243 #ifdef HAVE_LCD_BITMAP
244 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar
);
248 bool tv_init_window(unsigned char **buf
, size_t *size
)
250 tv_add_preferences_change_listner(tv_change_preferences
);
251 return tv_init_text_reader(buf
, size
);
254 void tv_finalize_window(void)
256 tv_finalize_text_reader();
258 #ifdef HAVE_LCD_BITMAP
260 if (rb
->strcmp(rb
->global_settings
->font_file
, preferences
->font_name
))
262 tv_set_font(rb
->global_settings
->font_file
);
270 void tv_move_window(int window_delta
, int column_delta
)
272 cur_window
+= window_delta
;
273 cur_column
+= column_delta
;
280 else if (cur_window
>= preferences
->windows
)
282 cur_window
= preferences
->windows
- 1;
293 cur_column
= window_columns
- 1;
298 if (cur_window
== preferences
->windows
- 1)
300 else if (cur_column
>= window_columns
)