2010-06-05 10:30:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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_bookmark.h"
|
2010-06-26 09:14:53 +00:00
|
|
|
#include "tv_display.h"
|
2010-06-05 10:30:08 +00:00
|
|
|
#include "tv_preferences.h"
|
|
|
|
#include "tv_screen_pos.h"
|
|
|
|
#include "tv_text_reader.h"
|
|
|
|
#include "tv_window.h"
|
|
|
|
|
|
|
|
static int window_width;
|
|
|
|
static int window_columns;
|
2010-06-26 09:14:53 +00:00
|
|
|
static int display_lines;
|
2010-06-05 10:30:08 +00:00
|
|
|
static int col_width;
|
|
|
|
|
|
|
|
static int cur_window;
|
|
|
|
static int cur_column;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
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-27 08:08:33 +00:00
|
|
|
static void tv_draw_bookmarks(const struct tv_screen_pos *top_pos)
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
|
|
|
struct tv_screen_pos bookmarks[TV_MAX_BOOKMARKS];
|
2010-06-27 08:08:33 +00:00
|
|
|
int disp_bookmarks[TV_MAX_BOOKMARKS];
|
2010-06-05 10:30:08 +00:00
|
|
|
int count = tv_get_bookmark_positions(bookmarks);
|
2010-06-27 08:08:33 +00:00
|
|
|
int disp_count = 0;
|
2010-06-05 10:30:08 +00:00
|
|
|
int line;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
line = (bookmarks[count].page - top_pos->page) * display_lines
|
|
|
|
+ (bookmarks[count].line - top_pos->line);
|
|
|
|
if (line >= 0 && line < display_lines)
|
2010-06-27 08:08:33 +00:00
|
|
|
disp_bookmarks[disp_count++] = line;
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
2010-06-27 08:08:33 +00:00
|
|
|
|
|
|
|
tv_show_bookmarks(disp_bookmarks, disp_count);
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tv_draw_window(void)
|
|
|
|
{
|
|
|
|
struct tv_screen_pos pos;
|
2010-06-26 09:14:53 +00:00
|
|
|
const unsigned char *text_buf;
|
2010-06-05 10:30:08 +00:00
|
|
|
int line;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
tv_copy_screen_pos(&pos);
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
tv_start_display();
|
|
|
|
|
|
|
|
tv_read_start(cur_window, (cur_column > 0));
|
2010-06-05 10:30:08 +00:00
|
|
|
|
|
|
|
for (line = 0; line < display_lines; line++)
|
|
|
|
{
|
2010-06-26 09:14:53 +00:00
|
|
|
if (!tv_get_next_line(&text_buf))
|
2010-06-05 10:30:08 +00:00
|
|
|
break;
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
tv_draw_text(line, text_buf, cur_column);
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size = tv_read_end();
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-26 09:14:53 +00:00
|
|
|
tv_show_scrollbar(cur_window, cur_column, pos.file_pos, size);
|
2010-06-05 10:30:08 +00:00
|
|
|
tv_show_header();
|
|
|
|
tv_show_footer(&pos);
|
|
|
|
#endif
|
2010-06-27 08:08:33 +00:00
|
|
|
tv_draw_bookmarks(&pos);
|
2010-06-05 10:30:08 +00:00
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
tv_update_display();
|
|
|
|
tv_end_display();
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool tv_traverse_lines(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
bool res = true;
|
|
|
|
|
|
|
|
tv_read_start(0, false);
|
|
|
|
for (i = 0; i < display_lines; i++)
|
|
|
|
{
|
|
|
|
if (!tv_get_next_line(NULL))
|
|
|
|
{
|
|
|
|
res = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tv_read_end();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tv_change_preferences(const struct tv_preferences *oldp)
|
|
|
|
{
|
2010-06-26 09:14:53 +00:00
|
|
|
#ifndef HAVE_LCD_BITMAP
|
|
|
|
(void)oldp;
|
|
|
|
#else
|
2010-06-08 10:34:13 +00:00
|
|
|
static bool font_changing = false;
|
2010-06-07 12:03:30 +00:00
|
|
|
const unsigned char *font_str;
|
2010-06-26 09:14:53 +00:00
|
|
|
bool need_vertical_scrollbar;
|
2010-06-23 13:56:08 +00:00
|
|
|
struct tv_preferences new_prefs;
|
|
|
|
tv_copy_preferences(&new_prefs);
|
2010-06-05 10:30:08 +00:00
|
|
|
|
2010-06-08 10:34:13 +00:00
|
|
|
font_str = (oldp && !font_changing)? oldp->font_name : rb->global_settings->font_file;
|
2010-06-05 10:30:08 +00:00
|
|
|
|
|
|
|
/* change font */
|
2010-06-20 21:53:47 +00:00
|
|
|
if (font_changing || rb->strcmp(font_str, preferences->font_name))
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
2010-06-09 14:41:24 +00:00
|
|
|
font_changing = true;
|
2010-06-20 21:53:47 +00:00
|
|
|
if (!tv_set_font(preferences->font_name))
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
|
|
|
rb->strlcpy(new_prefs.font_name, font_str, MAX_PATH);
|
2010-06-26 12:17:01 +00:00
|
|
|
tv_set_preferences(&new_prefs);
|
|
|
|
return;
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-23 13:56:08 +00:00
|
|
|
|
2010-06-09 14:41:24 +00:00
|
|
|
font_changing = false;
|
2010-06-05 10:30:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-20 21:53:47 +00:00
|
|
|
col_width = 2 * rb->font_get_width(preferences->font, ' ');
|
2010-06-05 10:30:08 +00:00
|
|
|
#else
|
|
|
|
col_width = 1;
|
|
|
|
#endif
|
|
|
|
|
2010-06-20 21:53:47 +00:00
|
|
|
if (cur_window >= preferences->windows)
|
2010-06-05 10:30:08 +00:00
|
|
|
cur_window = 0;
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
/* change viewport */
|
|
|
|
tv_change_viewport();
|
|
|
|
|
2010-06-05 10:30:08 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-06 10:52:19 +00:00
|
|
|
need_vertical_scrollbar = false;
|
2010-06-26 09:14:53 +00:00
|
|
|
tv_set_layout(col_width, need_vertical_scrollbar);
|
|
|
|
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
|
2010-06-05 10:30:08 +00:00
|
|
|
tv_seek_top();
|
2010-06-20 21:53:47 +00:00
|
|
|
tv_set_read_conditions(preferences->windows, window_width);
|
|
|
|
if (tv_traverse_lines() && preferences->vertical_scrollbar)
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
2010-06-06 10:52:19 +00:00
|
|
|
need_vertical_scrollbar = true;
|
2010-06-26 09:14:53 +00:00
|
|
|
tv_set_layout(col_width, need_vertical_scrollbar);
|
|
|
|
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
tv_seek_top();
|
|
|
|
#else
|
2010-06-26 09:14:53 +00:00
|
|
|
tv_set_layout(col_width);
|
|
|
|
tv_get_drawarea_info(&window_width, &window_columns, &display_lines);
|
2010-06-05 10:30:08 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-26 09:14:53 +00:00
|
|
|
window_columns = window_width / col_width;
|
2010-06-05 10:30:08 +00:00
|
|
|
cur_column = 0;
|
|
|
|
|
2010-06-20 21:53:47 +00:00
|
|
|
tv_set_read_conditions(preferences->windows, window_width);
|
2010-06-26 09:14:53 +00:00
|
|
|
|
|
|
|
tv_init_display();
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
tv_init_scrollbar(tv_get_total_text_size(), need_vertical_scrollbar);
|
|
|
|
#endif
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
2010-06-23 13:56:08 +00:00
|
|
|
bool tv_init_window(unsigned char **buf, size_t *size)
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
|
|
|
tv_add_preferences_change_listner(tv_change_preferences);
|
2010-06-23 13:56:08 +00:00
|
|
|
return tv_init_text_reader(buf, size);
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tv_finalize_window(void)
|
|
|
|
{
|
|
|
|
tv_finalize_text_reader();
|
2010-06-07 12:03:30 +00:00
|
|
|
|
2010-06-07 13:10:38 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2010-06-07 12:03:30 +00:00
|
|
|
/* restore font */
|
2010-06-20 21:53:47 +00:00
|
|
|
if (rb->strcmp(rb->global_settings->font_file, preferences->font_name))
|
2010-06-07 12:03:30 +00:00
|
|
|
{
|
|
|
|
tv_set_font(rb->global_settings->font_file);
|
|
|
|
}
|
2010-06-26 09:14:53 +00:00
|
|
|
|
|
|
|
/* undo viewport */
|
|
|
|
tv_undo_viewport();
|
2010-06-07 13:10:38 +00:00
|
|
|
#endif
|
2010-06-05 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tv_move_window(int window_delta, int column_delta)
|
|
|
|
{
|
|
|
|
cur_window += window_delta;
|
|
|
|
cur_column += column_delta;
|
|
|
|
|
|
|
|
if (cur_window < 0)
|
|
|
|
{
|
|
|
|
cur_window = 0;
|
|
|
|
cur_column = 0;
|
|
|
|
}
|
2010-06-20 21:53:47 +00:00
|
|
|
else if (cur_window >= preferences->windows)
|
2010-06-05 10:30:08 +00:00
|
|
|
{
|
2010-06-20 21:53:47 +00:00
|
|
|
cur_window = preferences->windows - 1;
|
2010-06-05 10:30:08 +00:00
|
|
|
cur_column = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_column < 0)
|
|
|
|
{
|
|
|
|
if (cur_window == 0)
|
|
|
|
cur_column = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cur_window--;
|
|
|
|
cur_column = window_columns - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-20 21:53:47 +00:00
|
|
|
if (cur_window == preferences->windows - 1)
|
2010-06-05 10:30:08 +00:00
|
|
|
cur_column = 0;
|
|
|
|
else if (cur_column >= window_columns)
|
|
|
|
{
|
|
|
|
cur_window++;
|
|
|
|
cur_column = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|