mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-13 07:02:31 -05:00
text viewer: can display the horizontal scroll bar.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26620 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
19ac3453e0
commit
240b198d65
6 changed files with 106 additions and 57 deletions
|
|
@ -48,8 +48,6 @@ TODO list
|
||||||
|
|
||||||
- for the horizontal scroll, allow the select scroll by screen/scroll by column for the settings menu.
|
- for the horizontal scroll, allow the select scroll by screen/scroll by column for the settings menu.
|
||||||
|
|
||||||
- can display the horizontal scroll bar.
|
|
||||||
|
|
||||||
- draw images that are linked to the text. (<img src="...">)
|
- draw images that are linked to the text. (<img src="...">)
|
||||||
|
|
||||||
- play audios that are linked to the text. (<audio src="...">)
|
- play audios that are linked to the text. (<audio src="...">)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,42 @@
|
||||||
|
|
||||||
static struct tv_preferences new_prefs;
|
static struct tv_preferences new_prefs;
|
||||||
|
|
||||||
|
/* scrollbar menu */
|
||||||
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
static bool tv_horizontal_scrollbar_setting(void)
|
||||||
|
{
|
||||||
|
static const struct opt_items names[] = {
|
||||||
|
{"No", -1},
|
||||||
|
{"Yes", -1},
|
||||||
|
};
|
||||||
|
|
||||||
|
return rb->set_option("Horizontal Scrollbar", &new_prefs.horizontal_scrollbar, INT,
|
||||||
|
names, 2, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool tv_vertical_scrollbar_setting(void)
|
||||||
|
{
|
||||||
|
static const struct opt_items names[] = {
|
||||||
|
{"No", -1},
|
||||||
|
{"Yes", -1},
|
||||||
|
};
|
||||||
|
|
||||||
|
return rb->set_option("Vertical Scrollbar", &new_prefs.vertical_scrollbar, INT,
|
||||||
|
names, 2, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
MENUITEM_FUNCTION(horizontal_scrollbar_item, 0, "Horizontal",
|
||||||
|
tv_horizontal_scrollbar_setting,
|
||||||
|
NULL, NULL, Icon_NOICON);
|
||||||
|
MENUITEM_FUNCTION(vertical_scrollbar_item, 0, "Vertical",
|
||||||
|
tv_vertical_scrollbar_setting,
|
||||||
|
NULL, NULL, Icon_NOICON);
|
||||||
|
MAKE_MENU(scrollbar_menu, "Scrollbar", NULL, Icon_NOICON,
|
||||||
|
&horizontal_scrollbar_item, &vertical_scrollbar_item);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* main menu */
|
||||||
|
|
||||||
static bool tv_encoding_setting(void)
|
static bool tv_encoding_setting(void)
|
||||||
{
|
{
|
||||||
static struct opt_items names[NUM_CODEPAGES];
|
static struct opt_items names[NUM_CODEPAGES];
|
||||||
|
|
@ -109,17 +145,6 @@ static bool tv_page_mode_setting(void)
|
||||||
names, 2, NULL);
|
names, 2, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool tv_scrollbar_setting(void)
|
|
||||||
{
|
|
||||||
static const struct opt_items names[] = {
|
|
||||||
{"Off", -1},
|
|
||||||
{"On", -1}
|
|
||||||
};
|
|
||||||
|
|
||||||
return rb->set_option("Show Scrollbar", &new_prefs.scrollbar_mode, INT,
|
|
||||||
names, 2, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool tv_header_setting(void)
|
static bool tv_header_setting(void)
|
||||||
{
|
{
|
||||||
int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
|
int len = (rb->global_settings->statusbar == STATUSBAR_TOP)? 4 : 2;
|
||||||
|
|
@ -272,8 +297,6 @@ MENUITEM_FUNCTION(windows_item, 0, "Screens Per Page", tv_windows_setting,
|
||||||
MENUITEM_FUNCTION(alignment_item, 0, "Alignment", tv_alignment_setting,
|
MENUITEM_FUNCTION(alignment_item, 0, "Alignment", tv_alignment_setting,
|
||||||
NULL, NULL, Icon_NOICON);
|
NULL, NULL, Icon_NOICON);
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
MENUITEM_FUNCTION(scrollbar_item, 0, "Show Scrollbar", tv_scrollbar_setting,
|
|
||||||
NULL, NULL, Icon_NOICON);
|
|
||||||
MENUITEM_FUNCTION(page_mode_item, 0, "Overlap Pages", tv_page_mode_setting,
|
MENUITEM_FUNCTION(page_mode_item, 0, "Overlap Pages", tv_page_mode_setting,
|
||||||
NULL, NULL, Icon_NOICON);
|
NULL, NULL, Icon_NOICON);
|
||||||
MENUITEM_FUNCTION(header_item, 0, "Show Header", tv_header_setting,
|
MENUITEM_FUNCTION(header_item, 0, "Show Header", tv_header_setting,
|
||||||
|
|
@ -291,7 +314,7 @@ MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON,
|
||||||
&encoding_item, &word_wrap_item, &line_mode_item, &windows_item,
|
&encoding_item, &word_wrap_item, &line_mode_item, &windows_item,
|
||||||
&alignment_item,
|
&alignment_item,
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
&scrollbar_item, &page_mode_item, &header_item, &footer_item, &font_item,
|
&scrollbar_menu, &page_mode_item, &header_item, &footer_item, &font_item,
|
||||||
#endif
|
#endif
|
||||||
&scroll_mode_item, &autoscroll_speed_item);
|
&scroll_mode_item, &autoscroll_speed_item);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,8 @@ static void tv_notify_change_preferences(const struct tv_preferences *oldp,
|
||||||
(oldp->word_mode != newp->word_mode) ||
|
(oldp->word_mode != newp->word_mode) ||
|
||||||
(oldp->line_mode != newp->line_mode) ||
|
(oldp->line_mode != newp->line_mode) ||
|
||||||
(oldp->windows != newp->windows) ||
|
(oldp->windows != newp->windows) ||
|
||||||
(oldp->scrollbar_mode != newp->scrollbar_mode) ||
|
(oldp->horizontal_scrollbar != newp->horizontal_scrollbar) ||
|
||||||
|
(oldp->vertical_scrollbar != newp->vertical_scrollbar) ||
|
||||||
(oldp->encoding != newp->encoding) ||
|
(oldp->encoding != newp->encoding) ||
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
(oldp->header_mode != newp->header_mode) ||
|
(oldp->header_mode != newp->header_mode) ||
|
||||||
|
|
@ -95,7 +96,8 @@ void tv_set_default_preferences(struct tv_preferences *p)
|
||||||
p->alignment = LEFT;
|
p->alignment = LEFT;
|
||||||
p->scroll_mode = PAGE;
|
p->scroll_mode = PAGE;
|
||||||
p->page_mode = NO_OVERLAP;
|
p->page_mode = NO_OVERLAP;
|
||||||
p->scrollbar_mode = SB_OFF;
|
p->horizontal_scrollbar = SB_OFF;
|
||||||
|
p->vertical_scrollbar = SB_OFF;
|
||||||
rb->memset(p->font_name, 0, MAX_PATH);
|
rb->memset(p->font_name, 0, MAX_PATH);
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
p->header_mode = HD_BOTH;
|
p->header_mode = HD_BOTH;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@
|
||||||
#ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H
|
#ifndef PLUGIN_TEXT_VIEWER_PREFERENCES_H
|
||||||
#define PLUGIN_TEXT_VIEWER_PREFERENCES_H
|
#define PLUGIN_TEXT_VIEWER_PREFERENCES_H
|
||||||
|
|
||||||
|
enum scrollbar_mode {
|
||||||
|
SB_OFF = 0,
|
||||||
|
SB_ON,
|
||||||
|
};
|
||||||
|
|
||||||
struct tv_preferences {
|
struct tv_preferences {
|
||||||
enum {
|
enum {
|
||||||
WRAP = 0,
|
WRAP = 0,
|
||||||
|
|
@ -43,10 +48,8 @@ struct tv_preferences {
|
||||||
|
|
||||||
enum codepages encoding;
|
enum codepages encoding;
|
||||||
|
|
||||||
enum {
|
enum scrollbar_mode horizontal_scrollbar;
|
||||||
SB_OFF = 0,
|
enum scrollbar_mode vertical_scrollbar;
|
||||||
SB_ON,
|
|
||||||
} scrollbar_mode;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NO_OVERLAP = 0,
|
NO_OVERLAP = 0,
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,15 @@
|
||||||
* windows 1 (when version <= 0x32, this value is view_mode)
|
* windows 1 (when version <= 0x32, this value is view_mode)
|
||||||
* alignment 1
|
* alignment 1
|
||||||
* encoding 1
|
* encoding 1
|
||||||
* scrollbar_mode 1
|
* vertical_scrollbar 1
|
||||||
* (unused) 1 (for compatibility)
|
* (unused) 1 (for compatibility)
|
||||||
* page_mode 1
|
* page_mode 1
|
||||||
* page_number_mode 1
|
* page_number_mode 1
|
||||||
* title_mode 1
|
* title_mode 1
|
||||||
* scroll_mode 1
|
* scroll_mode 1
|
||||||
* autoscroll_speed 1
|
* autoscroll_speed 1
|
||||||
* (reserved) 16
|
* horizontal_scrollbar 1
|
||||||
|
* (reserved) 15
|
||||||
* font name MAX_PATH
|
* font name MAX_PATH
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@
|
||||||
#define TV_GLOBAL_SETTINGS_FILE VIEWERS_DIR "/tv_global.dat"
|
#define TV_GLOBAL_SETTINGS_FILE VIEWERS_DIR "/tv_global.dat"
|
||||||
|
|
||||||
#define TV_GLOBAL_SETTINGS_HEADER "\x54\x56\x47\x53" /* "TVGS" */
|
#define TV_GLOBAL_SETTINGS_HEADER "\x54\x56\x47\x53" /* "TVGS" */
|
||||||
#define TV_GLOBAL_SETTINGS_VERSION 0x33
|
#define TV_GLOBAL_SETTINGS_VERSION 0x34
|
||||||
#define TV_GLOBAL_SETTINGS_HEADER_SIZE 5
|
#define TV_GLOBAL_SETTINGS_HEADER_SIZE 5
|
||||||
#define TV_GLOBAL_SETTINGS_FIRST_VERSION 0x31
|
#define TV_GLOBAL_SETTINGS_FIRST_VERSION 0x31
|
||||||
|
|
||||||
|
|
@ -77,14 +78,15 @@
|
||||||
* windows 1 (when version <= 0x33, this value is view_mode)
|
* windows 1 (when version <= 0x33, this value is view_mode)
|
||||||
* alignment 1
|
* alignment 1
|
||||||
* encoding 1
|
* encoding 1
|
||||||
* scrollbar_mode 1
|
* vertical_scrollbar 1
|
||||||
* (unused) 1 (for compatibility)
|
* (unused) 1 (for compatibility)
|
||||||
* page_mode 1
|
* page_mode 1
|
||||||
* header_mode 1
|
* header_mode 1
|
||||||
* footer_mode 1
|
* footer_mode 1
|
||||||
* scroll_mode 1
|
* scroll_mode 1
|
||||||
* autoscroll_speed 1
|
* autoscroll_speed 1
|
||||||
* (reserved) 16
|
* horizontal_scrollbar 1
|
||||||
|
* (reserved) 15
|
||||||
* font name MAX_PATH
|
* font name MAX_PATH
|
||||||
* bookmark count 1
|
* bookmark count 1
|
||||||
* [1st bookmark]
|
* [1st bookmark]
|
||||||
|
|
@ -106,7 +108,7 @@
|
||||||
#define TV_SETTINGS_TMP_FILE VIEWERS_DIR "/tv_file.tmp"
|
#define TV_SETTINGS_TMP_FILE VIEWERS_DIR "/tv_file.tmp"
|
||||||
|
|
||||||
#define TV_SETTINGS_HEADER "\x54\x56\x53" /* "TVS" */
|
#define TV_SETTINGS_HEADER "\x54\x56\x53" /* "TVS" */
|
||||||
#define TV_SETTINGS_VERSION 0x34
|
#define TV_SETTINGS_VERSION 0x35
|
||||||
#define TV_SETTINGS_HEADER_SIZE 4
|
#define TV_SETTINGS_HEADER_SIZE 4
|
||||||
#define TV_SETTINGS_FIRST_VERSION 0x32
|
#define TV_SETTINGS_FIRST_VERSION 0x32
|
||||||
|
|
||||||
|
|
@ -144,7 +146,7 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre
|
||||||
prefs->alignment = LEFT;
|
prefs->alignment = LEFT;
|
||||||
|
|
||||||
prefs->encoding = *p++;
|
prefs->encoding = *p++;
|
||||||
prefs->scrollbar_mode = *p++;
|
prefs->vertical_scrollbar = *p++;
|
||||||
/* skip need_scrollbar */
|
/* skip need_scrollbar */
|
||||||
p++;
|
p++;
|
||||||
prefs->page_mode = *p++;
|
prefs->page_mode = *p++;
|
||||||
|
|
@ -153,6 +155,11 @@ static bool tv_read_preferences(int pfd, int version, struct tv_preferences *pre
|
||||||
prefs->scroll_mode = *p++;
|
prefs->scroll_mode = *p++;
|
||||||
prefs->autoscroll_speed = *p++;
|
prefs->autoscroll_speed = *p++;
|
||||||
|
|
||||||
|
if (version > 2)
|
||||||
|
prefs->horizontal_scrollbar = *p;
|
||||||
|
else
|
||||||
|
prefs->horizontal_scrollbar = SB_OFF;
|
||||||
|
|
||||||
rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH);
|
rb->memcpy(prefs->font_name, buf + read_size - MAX_PATH, MAX_PATH);
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
|
@ -172,7 +179,7 @@ static bool tv_write_preferences(int pfd, const struct tv_preferences *prefs)
|
||||||
*p++ = prefs->windows;
|
*p++ = prefs->windows;
|
||||||
*p++ = prefs->alignment;
|
*p++ = prefs->alignment;
|
||||||
*p++ = prefs->encoding;
|
*p++ = prefs->encoding;
|
||||||
*p++ = prefs->scrollbar_mode;
|
*p++ = prefs->vertical_scrollbar;
|
||||||
/* skip need_scrollbar */
|
/* skip need_scrollbar */
|
||||||
p++;
|
p++;
|
||||||
*p++ = prefs->page_mode;
|
*p++ = prefs->page_mode;
|
||||||
|
|
@ -180,6 +187,7 @@ static bool tv_write_preferences(int pfd, const struct tv_preferences *prefs)
|
||||||
*p++ = prefs->footer_mode;
|
*p++ = prefs->footer_mode;
|
||||||
*p++ = prefs->scroll_mode;
|
*p++ = prefs->scroll_mode;
|
||||||
*p++ = prefs->autoscroll_speed;
|
*p++ = prefs->autoscroll_speed;
|
||||||
|
*p++ = prefs->horizontal_scrollbar;
|
||||||
|
|
||||||
rb->memcpy(buf + 28, prefs->font_name, MAX_PATH);
|
rb->memcpy(buf + 28, prefs->font_name, MAX_PATH);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include "tv_window.h"
|
#include "tv_window.h"
|
||||||
|
|
||||||
#define TV_SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
|
#define TV_SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
|
||||||
|
#define TV_SCROLLBAR_HEIGHT 4
|
||||||
|
|
||||||
#ifndef HAVE_LCD_BITMAP
|
#ifndef HAVE_LCD_BITMAP
|
||||||
#define TV_BOOKMARK_ICON 0xe101
|
#define TV_BOOKMARK_ICON 0xe101
|
||||||
|
|
@ -36,7 +37,7 @@
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
static int header_height;
|
static int header_height;
|
||||||
static int footer_height;
|
static int footer_height;
|
||||||
static bool need_scrollbar = false;
|
static bool need_vertical_scrollbar = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int start_width;
|
static int start_width;
|
||||||
|
|
@ -123,27 +124,41 @@ static void tv_show_scrollbar(off_t cur_pos, int size)
|
||||||
int items;
|
int items;
|
||||||
int min_shown;
|
int min_shown;
|
||||||
int max_shown;
|
int max_shown;
|
||||||
int sb_begin_y;
|
int sb_width;
|
||||||
int sb_height;
|
int sb_height;
|
||||||
|
|
||||||
if (!need_scrollbar)
|
sb_height = LCD_HEIGHT - header_height - footer_height;
|
||||||
return;
|
if (prefs->horizontal_scrollbar)
|
||||||
|
{
|
||||||
|
items = prefs->windows * window_columns;
|
||||||
|
min_shown = cur_window * window_columns + cur_column;
|
||||||
|
max_shown = min_shown + window_columns;
|
||||||
|
sb_width = (need_vertical_scrollbar)? TV_SCROLLBAR_WIDTH : 0;
|
||||||
|
sb_height -= TV_SCROLLBAR_HEIGHT;
|
||||||
|
|
||||||
|
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],
|
||||||
|
sb_width,
|
||||||
|
LCD_HEIGHT - footer_height - TV_SCROLLBAR_HEIGHT,
|
||||||
|
LCD_WIDTH - sb_width, TV_SCROLLBAR_HEIGHT,
|
||||||
|
items, min_shown, max_shown, HORIZONTAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (need_vertical_scrollbar)
|
||||||
|
{
|
||||||
items = (int) tv_get_total_text_size();
|
items = (int) tv_get_total_text_size();
|
||||||
min_shown = (int) cur_pos;
|
min_shown = (int) cur_pos;
|
||||||
|
|
||||||
max_shown = min_shown + size;
|
max_shown = min_shown + size;
|
||||||
|
|
||||||
sb_begin_y = header_height;
|
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN], 0, header_height,
|
||||||
sb_height = LCD_HEIGHT - header_height - footer_height;
|
|
||||||
|
|
||||||
rb->gui_scrollbar_draw(rb->screens[SCREEN_MAIN],0, sb_begin_y,
|
|
||||||
TV_SCROLLBAR_WIDTH-1, sb_height,
|
TV_SCROLLBAR_WIDTH-1, sb_height,
|
||||||
items, min_shown, max_shown, VERTICAL);
|
items, min_shown, max_shown, VERTICAL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int tv_calc_display_lines(void)
|
static int tv_calc_display_lines(void)
|
||||||
{
|
{
|
||||||
|
int scrollbar_height = (prefs->horizontal_scrollbar)? TV_SCROLLBAR_HEIGHT : 0;
|
||||||
|
|
||||||
header_height = (prefs->header_mode == HD_SBAR || prefs->header_mode == HD_BOTH)?
|
header_height = (prefs->header_mode == HD_SBAR || prefs->header_mode == HD_BOTH)?
|
||||||
STATUSBAR_HEIGHT : 0;
|
STATUSBAR_HEIGHT : 0;
|
||||||
|
|
||||||
|
|
@ -160,7 +175,7 @@ static int tv_calc_display_lines(void)
|
||||||
if (prefs->footer_mode == FT_PAGE || prefs->footer_mode == FT_BOTH)
|
if (prefs->footer_mode == FT_PAGE || prefs->footer_mode == FT_BOTH)
|
||||||
footer_height += prefs->font->height;
|
footer_height += prefs->font->height;
|
||||||
|
|
||||||
return (LCD_HEIGHT - header_height - footer_height) / prefs->font->height;
|
return (LCD_HEIGHT - header_height - footer_height - scrollbar_height) / prefs->font->height;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -314,13 +329,13 @@ static void tv_change_preferences(const struct tv_preferences *oldp)
|
||||||
|
|
||||||
window_width = LCD_WIDTH;
|
window_width = LCD_WIDTH;
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
need_scrollbar = false;
|
need_vertical_scrollbar = false;
|
||||||
start_width = 0;
|
start_width = 0;
|
||||||
tv_seek_top();
|
tv_seek_top();
|
||||||
tv_set_read_conditions(prefs->windows, window_width);
|
tv_set_read_conditions(prefs->windows, window_width);
|
||||||
if (tv_traverse_lines() && prefs->scrollbar_mode)
|
if (tv_traverse_lines() && prefs->vertical_scrollbar)
|
||||||
{
|
{
|
||||||
need_scrollbar = true;
|
need_vertical_scrollbar = true;
|
||||||
start_width = TV_SCROLLBAR_WIDTH;
|
start_width = TV_SCROLLBAR_WIDTH;
|
||||||
}
|
}
|
||||||
tv_seek_top();
|
tv_seek_top();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue