c83c6080bde1fd8c4077ad04254e618d0c0bc5b8
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");
57 static void tv_draw_bookmarks(const struct tv_screen_pos
*top_pos
)
59 struct tv_screen_pos bookmarks
[TV_MAX_BOOKMARKS
];
60 int disp_bookmarks
[TV_MAX_BOOKMARKS
];
61 int count
= tv_get_bookmark_positions(bookmarks
);
67 line
= (bookmarks
[count
].page
- top_pos
->page
) * display_lines
68 + (bookmarks
[count
].line
- top_pos
->line
);
69 if (line
>= 0 && line
< display_lines
)
70 disp_bookmarks
[disp_count
++] = line
;
73 tv_show_bookmarks(disp_bookmarks
, disp_count
);
76 void tv_draw_window(void)
78 struct tv_screen_pos pos
;
79 const unsigned char *text_buf
;
83 tv_copy_screen_pos(&pos
);
87 tv_read_start(cur_window
, (cur_column
> 0));
89 for (line
= 0; line
< display_lines
; line
++)
91 if (!tv_get_next_line(&text_buf
))
94 tv_draw_text(line
, text_buf
, cur_column
);
99 #ifdef HAVE_LCD_BITMAP
100 tv_show_scrollbar(cur_window
, cur_column
, pos
.file_pos
, size
);
102 tv_show_footer(&pos
);
104 tv_draw_bookmarks(&pos
);
110 bool tv_traverse_lines(void)
115 tv_read_start(0, false);
116 for (i
= 0; i
< display_lines
; i
++)
118 if (!tv_get_next_line(NULL
))
128 static void tv_change_preferences(const struct tv_preferences
*oldp
)
130 #ifndef HAVE_LCD_BITMAP
133 static bool font_changing
= false;
134 const unsigned char *font_str
;
135 bool need_vertical_scrollbar
;
136 struct tv_preferences new_prefs
;
137 tv_copy_preferences(&new_prefs
);
139 font_str
= (oldp
&& !font_changing
)? oldp
->font_name
: rb
->global_settings
->font_file
;
142 if (font_changing
|| rb
->strcmp(font_str
, preferences
->font_name
))
144 font_changing
= true;
145 if (!tv_set_font(preferences
->font_name
))
147 rb
->strlcpy(new_prefs
.font_name
, font_str
, MAX_PATH
);
148 tv_set_preferences(&new_prefs
);
153 font_changing
= false;
156 #ifdef HAVE_LCD_BITMAP
157 col_width
= 2 * rb
->font_get_width(preferences
->font
, ' ');
162 if (cur_window
>= preferences
->windows
)
165 /* change viewport */
166 tv_change_viewport();
168 #ifdef HAVE_LCD_BITMAP
169 need_vertical_scrollbar
= false;
170 tv_set_layout(col_width
, need_vertical_scrollbar
);
171 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
173 tv_set_read_conditions(preferences
->windows
, window_width
);
174 if (tv_traverse_lines() && preferences
->vertical_scrollbar
)
176 need_vertical_scrollbar
= true;
177 tv_set_layout(col_width
, need_vertical_scrollbar
);
178 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
182 tv_set_layout(col_width
);
183 tv_get_drawarea_info(&window_width
, &window_columns
, &display_lines
);
186 window_columns
= window_width
/ col_width
;
189 tv_set_read_conditions(preferences
->windows
, window_width
);
192 #ifdef HAVE_LCD_BITMAP
193 tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar
);
197 bool tv_init_window(unsigned char **buf
, size_t *size
)
199 tv_add_preferences_change_listner(tv_change_preferences
);
200 return tv_init_text_reader(buf
, size
);
203 void tv_finalize_window(void)
205 tv_finalize_text_reader();
207 #ifdef HAVE_LCD_BITMAP
209 if (rb
->strcmp(rb
->global_settings
->font_file
, preferences
->font_name
))
211 tv_set_font(rb
->global_settings
->font_file
);
219 void tv_move_window(int window_delta
, int column_delta
)
221 cur_window
+= window_delta
;
222 cur_column
+= column_delta
;
229 else if (cur_window
>= preferences
->windows
)
231 cur_window
= preferences
->windows
- 1;
242 cur_column
= window_columns
- 1;
247 if (cur_window
== preferences
->windows
- 1)
249 else if (cur_column
>= window_columns
)