1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Gilles Roux
* 2003 Garrett Derner
* 2010 Yoshihisa Uchida
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "plugin.h"
#include "tv_action.h"
#include "tv_bookmark.h"
#include "tv_pager.h"
#include "tv_screen_pos.h"
#include "tv_settings.h"
#include "tv_window.h"
bool tv_init(const unsigned char *file)
{
size_t size;
/* get the plugin buffer */
unsigned char *buf = rb->plugin_get_buffer(&size);
tv_init_bookmark();
/* initialize modules */
if (!tv_init_window(&buf, &size))
return false;
/* load the preferences and bookmark */
tv_load_settings(file);
/* select to read the page */
tv_select_bookmark();
return true;
}
void tv_exit(void *parameter)
{
(void)parameter;
/* save preference and bookmarks */
if (!tv_save_settings())
rb->splash(HZ, "Can't save preferences and bookmarks");
/* finalize modules */
tv_finalize_window();
}
void tv_draw(void)
{
struct tv_screen_pos pos;
tv_copy_screen_pos(&pos);
tv_draw_window();
if (pos.line == 0)
tv_new_page();
tv_move_screen(pos.page, pos.line, SEEK_SET);
}
void tv_scroll_up(unsigned mode)
{
int offset_page = 0;
int offset_line = -1;
if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
(mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == VS_PAGE))
{
offset_page--;
#ifdef HAVE_LCD_BITMAP
offset_line = (preferences->page_mode == PM_OVERLAP)? 1:0;
#endif
}
tv_move_screen(offset_page, offset_line, SEEK_CUR);
}
void tv_scroll_down(unsigned mode)
{
int offset_page = 0;
int offset_line = 1;
if ((mode == TV_VERTICAL_SCROLL_PAGE) ||
(mode == TV_VERTICAL_SCROLL_PREFS && preferences->vertical_scroll_mode == VS_PAGE))
{
offset_page++;
#ifdef HAVE_LCD_BITMAP
offset_line = (preferences->page_mode == PM_OVERLAP)? -1:0;
#endif
}
tv_move_screen(offset_page, offset_line, SEEK_CUR);
}
void tv_scroll_left(unsigned mode)
{
int offset_window = 0;
int offset_column = 0;
if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
(mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == HS_COLUMN))
{
/* Scroll left one column */
offset_column--;
}
else
{
/* Scroll left one window */
offset_window--;
}
tv_move_window(offset_window, offset_column);
}
void tv_scroll_right(unsigned mode)
{
int offset_window = 0;
int offset_column = 0;
if ((mode == TV_HORIZONTAL_SCROLL_COLUMN) ||
(mode == TV_HORIZONTAL_SCROLL_PREFS && preferences->horizontal_scroll_mode == HS_COLUMN))
{
/* Scroll right one column */
offset_column++;
}
else
{
/* Scroll right one window */
offset_window++;
}
tv_move_window(offset_window, offset_column);
}
void tv_top(void)
{
tv_move_screen(0, 0, SEEK_SET);
}
void tv_bottom(void)
{
tv_move_screen(0, 0, SEEK_END);
if (preferences->vertical_scroll_mode == VS_PAGE)
tv_move_screen(0, -tv_get_screen_pos()->line, SEEK_CUR);
}
unsigned tv_menu(void)
{
unsigned res;
struct tv_screen_pos cur_pos;
off_t cur_file_pos = tv_get_screen_pos()->file_pos;
res = tv_display_menu();
if (res == TV_MENU_RESULT_EXIT_MENU)
{
tv_convert_fpos(cur_file_pos, &cur_pos);
if (preferences->vertical_scroll_mode == VS_PAGE)
cur_pos.line = 0;
tv_move_screen(cur_pos.page, cur_pos.line, SEEK_SET);
}
else if (res == TV_MENU_RESULT_MOVE_PAGE)
res = TV_MENU_RESULT_EXIT_MENU;
return res;
}
void tv_add_or_remove_bookmark(void)
{
tv_toggle_bookmark();
}
|