2010-06-26 09:14:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2010-06-29 11:37:58 +00:00
|
|
|
#include "plugin.h"
|
2010-06-26 09:14:53 +00:00
|
|
|
#include "tv_display.h"
|
|
|
|
#include "tv_preferences.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* display layout
|
|
|
|
*
|
|
|
|
* when is defined HAVE_LCD_BITMAP
|
|
|
|
* +-------------------------+
|
|
|
|
* |statusbar (1) |
|
|
|
|
* +-------------------------+
|
|
|
|
* |filename (2) |
|
|
|
|
* +---+---------------------+
|
|
|
|
* |s | |
|
|
|
|
* |c | |
|
|
|
|
* |r | draw area |
|
|
|
|
* |o | |
|
|
|
|
* |l | |
|
|
|
|
* |l | |
|
|
|
|
* |b | |
|
|
|
|
* |a | |
|
|
|
|
* |r | |
|
|
|
|
* |(3)| |
|
|
|
|
* +---+---------------------+
|
|
|
|
* | |scrollbar (4) |
|
|
|
|
* +---+---------------------+
|
|
|
|
* |page (5) |
|
|
|
|
* +-------------------------+
|
|
|
|
* |statusbar (6) |
|
|
|
|
* +-------------------------+
|
|
|
|
*
|
2010-06-26 12:17:01 +00:00
|
|
|
* (1) displays when rb->global_settings->statusbar == STATUSBAR_TOP.
|
|
|
|
* (2) displays when preferences->header_mode is HD_PATH.
|
2010-06-26 09:14:53 +00:00
|
|
|
* (3) displays when preferences->vertical_scrollbar is SB_ON.
|
|
|
|
* (4) displays when preferences->horizontal_scrollbar is SB_ON.
|
2010-06-26 12:17:01 +00:00
|
|
|
* (5) displays when preferences->footer_mode is FT_PAGE.
|
|
|
|
* (6) displays when rb->global_settings->statusbar == STATUSBAR_BOTTOM.
|
2010-06-26 09:14:53 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* when isn't defined HAVE_LCD_BITMAP
|
|
|
|
* +---+---------------------+
|
|
|
|
* | | |
|
|
|
|
* |(7)| draw area |
|
|
|
|
* | | |
|
|
|
|
* +---+---------------------+
|
|
|
|
* (7) bookmark
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TV_SCROLLBAR_WIDTH rb->global_settings->scrollbar_width
|
|
|
|
#define TV_SCROLLBAR_HEIGHT 4
|
|
|
|
|
|
|
|
#ifndef HAVE_LCD_BITMAP
|
|
|
|
#define TV_BOOKMARK_ICON 0xe101
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct tv_rect {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct viewport vp_info;
|
|
|
|
static bool is_initialized_vp = false;
|
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
static struct screen* display;
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static int drawmode = DRMODE_SOLID;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* layout */
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static struct tv_rect header;
|
|
|
|
static struct tv_rect footer;
|
|
|
|
static struct tv_rect horizontal_scrollbar;
|
|
|
|
static struct tv_rect vertical_scrollbar;
|
|
|
|
#else
|
|
|
|
static struct tv_rect bookmark;
|
|
|
|
#endif
|
|
|
|
static struct tv_rect drawarea;
|
|
|
|
|
2010-07-01 11:31:28 +00:00
|
|
|
static bool show_horizontal_scrollbar;
|
2010-06-28 11:17:47 +00:00
|
|
|
static bool show_vertical_scrollbar;
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
static int display_columns;
|
|
|
|
static int display_rows;
|
|
|
|
|
2010-06-27 11:36:37 +00:00
|
|
|
static int col_width = 1;
|
|
|
|
static int row_height = 1;
|
2010-06-26 09:14:53 +00:00
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
static int totalsize;
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
static void tv_show_header(void)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
2010-06-29 12:23:41 +00:00
|
|
|
if (preferences->header_mode)
|
2010-06-26 09:14:53 +00:00
|
|
|
display->putsxy(header.x, header.y, preferences->file_name);
|
|
|
|
}
|
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
static void tv_show_footer(const struct tv_screen_pos *pos)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
|
|
|
unsigned char buf[12];
|
|
|
|
|
2010-06-29 12:23:41 +00:00
|
|
|
if (preferences->footer_mode)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
|
|
|
if (pos->line == 0)
|
|
|
|
rb->snprintf(buf, sizeof(buf), "%d", pos->page + 1);
|
|
|
|
else
|
|
|
|
rb->snprintf(buf, sizeof(buf), "%d - %d", pos->page + 1, pos->page + 2);
|
2010-06-26 12:17:01 +00:00
|
|
|
display->putsxy(footer.x, footer.y + 1, buf);
|
2010-06-26 09:14:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
static void tv_show_scrollbar(int window, int col, off_t cur_pos, int size)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
|
|
|
int items;
|
|
|
|
int min_shown;
|
|
|
|
int max_shown;
|
|
|
|
|
2010-07-01 11:31:28 +00:00
|
|
|
if (show_horizontal_scrollbar)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
|
|
|
items = preferences->windows * display_columns;
|
|
|
|
min_shown = window * display_columns + col;
|
|
|
|
max_shown = min_shown + display_columns;
|
|
|
|
|
|
|
|
rb->gui_scrollbar_draw(display,
|
2010-06-26 12:17:01 +00:00
|
|
|
horizontal_scrollbar.x, horizontal_scrollbar.y + 1,
|
2010-06-26 09:14:53 +00:00
|
|
|
horizontal_scrollbar.w, TV_SCROLLBAR_HEIGHT,
|
|
|
|
items, min_shown, max_shown, HORIZONTAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_vertical_scrollbar)
|
|
|
|
{
|
|
|
|
items = (int) totalsize;
|
|
|
|
min_shown = (int) cur_pos;
|
|
|
|
max_shown = min_shown + size;
|
|
|
|
|
|
|
|
rb->gui_scrollbar_draw(display,
|
|
|
|
vertical_scrollbar.x, vertical_scrollbar.y,
|
2010-06-26 12:17:01 +00:00
|
|
|
TV_SCROLLBAR_WIDTH, vertical_scrollbar.h,
|
2010-06-26 09:14:53 +00:00
|
|
|
items, min_shown, max_shown, VERTICAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-27 08:08:33 +00:00
|
|
|
#endif
|
2010-06-26 09:14:53 +00:00
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
void tv_init_scrollbar(off_t total, bool show_scrollbar)
|
|
|
|
{
|
|
|
|
totalsize = total;
|
2010-07-01 11:31:28 +00:00
|
|
|
show_horizontal_scrollbar = (show_scrollbar && preferences->horizontal_scrollbar);
|
|
|
|
show_vertical_scrollbar = (show_scrollbar && preferences->vertical_scrollbar);
|
2010-06-28 11:17:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-27 08:08:33 +00:00
|
|
|
void tv_show_bookmarks(const int *rows, int count)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
2010-06-27 08:08:33 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
#endif
|
2010-06-26 09:14:53 +00:00
|
|
|
|
2010-06-27 08:08:33 +00:00
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
display->fillrect(drawarea.x, drawarea.y + rows[count] * row_height,
|
|
|
|
drawarea.w, row_height);
|
|
|
|
#else
|
|
|
|
display->putchar(bookmark.x, drawarea.y + rows[count], TV_BOOKMARK_ICON);
|
2010-06-26 09:14:53 +00:00
|
|
|
#endif
|
2010-06-27 08:08:33 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-26 09:14:53 +00:00
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
void tv_update_extra(int window, int col, const struct tv_screen_pos *pos, int size)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
tv_show_scrollbar(window, col, pos->file_pos, size);
|
|
|
|
tv_show_header();
|
|
|
|
tv_show_footer(pos);
|
|
|
|
#else
|
|
|
|
(void)window;
|
|
|
|
(void)col;
|
|
|
|
(void)pos;
|
|
|
|
(void)size;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
void tv_draw_text(int row, const unsigned char *text, int offset)
|
|
|
|
{
|
|
|
|
int xpos = -offset * col_width;
|
|
|
|
int text_width;
|
|
|
|
|
|
|
|
if (row < 0 || row >= display_rows)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (preferences->alignment == AL_RIGHT)
|
|
|
|
{
|
|
|
|
display->getstringsize(text, &text_width, NULL);
|
|
|
|
xpos += ((offset > 0)? drawarea.w * 2 : drawarea.w) - text_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
display->putsxy(drawarea.x + xpos, drawarea.y + row * row_height, text);
|
|
|
|
#else
|
|
|
|
display->puts(drawarea.x + xpos, drawarea.y + row, text);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void tv_start_display(void)
|
|
|
|
{
|
|
|
|
display->set_viewport(&vp_info);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
drawmode = rb->lcd_get_drawmode();
|
2010-06-27 08:08:33 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2010-06-26 09:14:53 +00:00
|
|
|
#endif
|
2010-06-27 08:08:33 +00:00
|
|
|
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
#endif
|
|
|
|
display->clear_viewport();
|
2010-06-26 09:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tv_end_display(void)
|
|
|
|
{
|
2010-06-28 11:17:47 +00:00
|
|
|
display->update_viewport();
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_set_drawmode(drawmode);
|
|
|
|
#endif
|
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
display->set_viewport(NULL);
|
2010-06-26 09:14:53 +00:00
|
|
|
}
|
|
|
|
|
2010-06-27 11:36:37 +00:00
|
|
|
void tv_set_layout(bool show_scrollbar)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-07-01 11:31:28 +00:00
|
|
|
int scrollbar_width = (show_scrollbar && preferences->vertical_scrollbar)?
|
|
|
|
TV_SCROLLBAR_WIDTH + 1 : 0;
|
|
|
|
int scrollbar_height = (show_scrollbar && preferences->horizontal_scrollbar)?
|
|
|
|
TV_SCROLLBAR_HEIGHT + 1 : 0;
|
2010-06-26 09:14:53 +00:00
|
|
|
|
|
|
|
row_height = preferences->font->height;
|
|
|
|
|
|
|
|
header.x = 0;
|
2010-06-26 12:17:01 +00:00
|
|
|
header.y = 1;
|
2010-06-26 09:14:53 +00:00
|
|
|
header.w = vp_info.width;
|
2010-06-29 12:23:41 +00:00
|
|
|
header.h = (preferences->header_mode)? row_height + 1 : 0;
|
2010-06-26 09:14:53 +00:00
|
|
|
|
|
|
|
footer.x = 0;
|
|
|
|
footer.w = vp_info.width;
|
2010-06-29 12:23:41 +00:00
|
|
|
footer.h = (preferences->footer_mode)? row_height + 1 : 0;
|
2010-06-26 12:17:01 +00:00
|
|
|
footer.y = vp_info.height - 1 - footer.h;
|
2010-06-26 09:14:53 +00:00
|
|
|
|
|
|
|
drawarea.x = scrollbar_width;
|
|
|
|
drawarea.y = header.y + header.h;
|
|
|
|
drawarea.w = vp_info.width - scrollbar_width;
|
|
|
|
drawarea.h = footer.y - drawarea.y - scrollbar_height;
|
|
|
|
|
|
|
|
horizontal_scrollbar.x = drawarea.x;
|
|
|
|
horizontal_scrollbar.y = footer.y - scrollbar_height;
|
|
|
|
horizontal_scrollbar.w = drawarea.w;
|
|
|
|
horizontal_scrollbar.h = scrollbar_height;
|
|
|
|
|
|
|
|
vertical_scrollbar.x = 0;
|
|
|
|
vertical_scrollbar.y = drawarea.y;
|
|
|
|
vertical_scrollbar.w = scrollbar_width;
|
|
|
|
vertical_scrollbar.h = drawarea.h;
|
|
|
|
#else
|
2010-06-27 11:36:37 +00:00
|
|
|
(void) show_scrollbar;
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
row_height = 1;
|
|
|
|
|
|
|
|
bookmark.x = 0;
|
|
|
|
bookmark.y = 0;
|
|
|
|
bookmark.w = 1;
|
|
|
|
bookmark.h = vp_info.height;
|
|
|
|
|
|
|
|
drawarea.x = 1;
|
|
|
|
drawarea.y = 0;
|
|
|
|
drawarea.w = vp_info.width - 1;
|
|
|
|
drawarea.h = vp_info.height;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
display_columns = drawarea.w / col_width;
|
|
|
|
display_rows = drawarea.h / row_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tv_get_drawarea_info(int *width, int *cols, int *rows)
|
|
|
|
{
|
|
|
|
*width = drawarea.w;
|
|
|
|
*cols = display_columns;
|
|
|
|
*rows = display_rows;
|
|
|
|
}
|
|
|
|
|
2010-06-27 11:36:37 +00:00
|
|
|
static void tv_change_viewport(void)
|
|
|
|
{
|
2010-06-28 11:17:47 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-07-08 14:17:04 +00:00
|
|
|
bool show_statusbar = (rb->global_settings->statusbar != STATUSBAR_OFF &&
|
|
|
|
preferences->statusbar);
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
if (is_initialized_vp)
|
2010-06-28 11:17:47 +00:00
|
|
|
rb->viewportmanager_theme_undo(SCREEN_MAIN, false);
|
2010-06-26 09:14:53 +00:00
|
|
|
else
|
|
|
|
is_initialized_vp = true;
|
|
|
|
|
2010-07-08 14:17:04 +00:00
|
|
|
rb->viewportmanager_theme_enable(SCREEN_MAIN, show_statusbar, &vp_info);
|
2010-06-26 09:14:53 +00:00
|
|
|
vp_info.flags &= ~VP_FLAG_ALIGNMENT_MASK;
|
2010-07-07 12:07:23 +00:00
|
|
|
display->set_viewport(&vp_info);
|
2010-06-28 11:17:47 +00:00
|
|
|
#else
|
|
|
|
if (!is_initialized_vp)
|
|
|
|
{
|
|
|
|
rb->viewport_set_defaults(&vp_info, SCREEN_MAIN);
|
|
|
|
is_initialized_vp = true;
|
|
|
|
}
|
|
|
|
#endif
|
2010-06-27 11:36:37 +00:00
|
|
|
}
|
2010-06-26 09:14:53 +00:00
|
|
|
|
2010-06-28 11:17:47 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-27 11:36:37 +00:00
|
|
|
static bool tv_set_font(const unsigned char *font)
|
|
|
|
{
|
|
|
|
unsigned char path[MAX_PATH];
|
|
|
|
|
|
|
|
if (font != NULL && *font != '\0')
|
|
|
|
{
|
|
|
|
rb->snprintf(path, MAX_PATH, "%s/%s.fnt", FONT_DIR, font);
|
|
|
|
if (rb->font_load(NULL, path) < 0)
|
|
|
|
{
|
|
|
|
rb->splash(HZ/2, "font load failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-29 11:05:36 +00:00
|
|
|
static int tv_change_preferences(const struct tv_preferences *oldp)
|
2010-06-27 11:36:37 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
static bool font_changing = false;
|
|
|
|
const unsigned char *font_str;
|
|
|
|
struct tv_preferences new_prefs;
|
|
|
|
|
|
|
|
font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
|
|
|
|
|
|
|
|
/* change font */
|
|
|
|
if (font_changing || rb->strcmp(font_str, preferences->font_name))
|
|
|
|
{
|
|
|
|
if (!tv_set_font(preferences->font_name))
|
|
|
|
{
|
2010-06-29 11:05:36 +00:00
|
|
|
/*
|
|
|
|
* tv_set_font(rb->global_settings->font_file) doesn't fail usually.
|
|
|
|
* if it fails, a fatal problem occurs in Rockbox.
|
|
|
|
*/
|
|
|
|
if (!rb->strcmp(preferences->font_name, rb->global_settings->font_file))
|
|
|
|
return TV_CALLBACK_ERROR;
|
|
|
|
|
2010-06-27 11:36:37 +00:00
|
|
|
font_changing = true;
|
|
|
|
tv_copy_preferences(&new_prefs);
|
|
|
|
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
|
2010-06-29 11:05:36 +00:00
|
|
|
|
|
|
|
return (tv_set_preferences(&new_prefs))? TV_CALLBACK_STOP : TV_CALLBACK_ERROR;
|
2010-06-27 11:36:37 +00:00
|
|
|
}
|
|
|
|
col_width = 2 * rb->font_get_width(preferences->font, ' ');
|
2010-06-28 11:17:47 +00:00
|
|
|
font_changing = false;
|
2010-06-27 11:36:37 +00:00
|
|
|
}
|
2010-06-26 09:14:53 +00:00
|
|
|
#else
|
2010-06-27 11:36:37 +00:00
|
|
|
(void)oldp;
|
2010-06-26 09:14:53 +00:00
|
|
|
#endif
|
2010-06-28 11:17:47 +00:00
|
|
|
tv_change_viewport();
|
2010-06-29 11:05:36 +00:00
|
|
|
return TV_CALLBACK_OK;
|
2010-06-26 09:14:53 +00:00
|
|
|
}
|
|
|
|
|
2010-06-27 11:36:37 +00:00
|
|
|
bool tv_init_display(unsigned char **buf, size_t *size)
|
|
|
|
{
|
|
|
|
(void)buf;
|
|
|
|
(void)size;
|
|
|
|
|
|
|
|
display = rb->screens[SCREEN_MAIN];
|
|
|
|
display->clear_viewport();
|
|
|
|
|
|
|
|
tv_add_preferences_change_listner(tv_change_preferences);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tv_finalize_display(void)
|
2010-06-26 09:14:53 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-27 11:36:37 +00:00
|
|
|
/* restore font */
|
|
|
|
if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
|
|
|
|
{
|
|
|
|
tv_set_font(rb->global_settings->font_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* undo viewport */
|
2010-07-07 12:07:23 +00:00
|
|
|
if (is_initialized_vp)
|
|
|
|
rb->viewportmanager_theme_undo(SCREEN_MAIN, false);
|
2010-06-28 11:17:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tv_exist_scrollbar(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
2010-06-26 09:14:53 +00:00
|
|
|
#endif
|
|
|
|
}
|