2005-10-28 00:00:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-04-16 09:14:36 +00:00
|
|
|
* Copyright (C) 2007 Jonathan Gordon
|
2005-10-28 00:00:00 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2005-10-28 00:00:00 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-04-16 09:14:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "inttypes.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "icon.h"
|
|
|
|
#include "screen_access.h"
|
|
|
|
#include "icons.h"
|
2007-04-16 09:14:36 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "bmp.h"
|
|
|
|
#include "filetypes.h"
|
2009-10-05 11:43:38 +00:00
|
|
|
#include "language.h"
|
2007-04-16 09:14:36 +00:00
|
|
|
|
2008-11-03 14:37:50 +00:00
|
|
|
#include "bitmaps/default_icons.h"
|
2007-04-18 17:49:32 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
2008-11-03 14:37:50 +00:00
|
|
|
#include "bitmaps/remote_default_icons.h"
|
2007-04-16 09:14:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-17 08:37:01 +00:00
|
|
|
/* These are just the file names, the full path is snprint'ed when used */
|
2007-04-17 00:29:04 +00:00
|
|
|
#define DEFAULT_VIEWER_BMP "viewers"
|
|
|
|
#define DEFAULT_REMOTE_VIEWER_BMP "remote_viewers"
|
2007-04-16 09:14:36 +00:00
|
|
|
|
2009-08-18 00:53:27 +00:00
|
|
|
/* These can be defined in config-<target>.h, if it is not provide defaults */
|
|
|
|
#if !defined(MAX_ICON_HEIGHT)
|
2007-04-16 09:14:36 +00:00
|
|
|
#define MAX_ICON_HEIGHT 24
|
2009-08-18 00:53:27 +00:00
|
|
|
#endif
|
2007-04-16 09:14:36 +00:00
|
|
|
|
2009-08-18 00:53:27 +00:00
|
|
|
#if !defined(MAX_ICON_WIDTH)
|
|
|
|
#define MAX_ICON_WIDTH 24
|
|
|
|
#endif
|
2007-04-16 09:14:36 +00:00
|
|
|
|
|
|
|
/* We dont actually do anything with these pointers,
|
|
|
|
but they need to be grouped like this to save code
|
|
|
|
so storing them as void* is ok. (stops compile warning) */
|
2010-10-25 12:18:21 +00:00
|
|
|
static const struct bitmap inbuilt_iconset[NB_SCREENS] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.width = BMPWIDTH_default_icons,
|
|
|
|
.height = BMPHEIGHT_default_icons,
|
|
|
|
.data = (unsigned char*)default_icons,
|
|
|
|
},
|
2007-04-18 17:49:32 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
2010-10-25 12:18:21 +00:00
|
|
|
{
|
|
|
|
.width = BMPWIDTH_remote_default_icons,
|
|
|
|
.height = BMPHEIGHT_remote_default_icons,
|
|
|
|
.data = (unsigned char*)remote_default_icons,
|
|
|
|
},
|
2007-04-16 09:14:36 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#define IMG_BUFSIZE (MAX_ICON_HEIGHT * MAX_ICON_WIDTH * \
|
|
|
|
Icon_Last_Themeable *LCD_DEPTH/8)
|
2007-04-16 14:33:29 +00:00
|
|
|
static unsigned char icon_buffer[NB_SCREENS][IMG_BUFSIZE];
|
2007-04-16 09:14:36 +00:00
|
|
|
static bool custom_icons_loaded[NB_SCREENS] = {false};
|
|
|
|
static struct bitmap user_iconset[NB_SCREENS];
|
|
|
|
|
2007-04-16 14:33:29 +00:00
|
|
|
static unsigned char viewer_icon_buffer[NB_SCREENS][IMG_BUFSIZE];
|
2007-04-16 09:14:36 +00:00
|
|
|
static bool viewer_icons_loaded[NB_SCREENS] = {false};
|
|
|
|
static struct bitmap viewer_iconset[NB_SCREENS];
|
|
|
|
|
|
|
|
|
|
|
|
#define ICON_HEIGHT(screen) (!custom_icons_loaded[screen]? \
|
2010-10-25 12:18:21 +00:00
|
|
|
inbuilt_iconset : user_iconset)[screen].height \
|
2007-04-16 09:14:36 +00:00
|
|
|
/ Icon_Last_Themeable
|
2010-10-25 12:18:21 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
#define ICON_WIDTH(screen) (!custom_icons_loaded[screen]? \
|
2010-10-25 12:18:21 +00:00
|
|
|
inbuilt_iconset : user_iconset)[screen].width
|
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
/* x,y in letters, not pixles */
|
|
|
|
void screen_put_icon(struct screen * display,
|
|
|
|
int x, int y, enum themable_icons icon)
|
|
|
|
{
|
|
|
|
screen_put_icon_with_offset(display, x, y, 0, 0, icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void screen_put_icon_with_offset(struct screen * display,
|
|
|
|
int x, int y, int off_x, int off_y,
|
|
|
|
enum themable_icons icon)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
2010-10-25 12:18:21 +00:00
|
|
|
const int screen = display->screen_type;
|
|
|
|
const int icon_width = ICON_WIDTH(screen);
|
|
|
|
const int icon_height = ICON_HEIGHT(screen);
|
2005-10-28 00:00:00 +00:00
|
|
|
int xpos, ypos;
|
2007-04-16 09:14:36 +00:00
|
|
|
int width, height;
|
2006-03-25 13:35:31 +00:00
|
|
|
display->getstringsize((unsigned char *)"M", &width, &height);
|
2010-10-25 12:18:21 +00:00
|
|
|
xpos = x*icon_width + off_x;
|
2008-06-23 13:20:35 +00:00
|
|
|
ypos = y*height + off_y;
|
2007-04-16 09:14:36 +00:00
|
|
|
|
2010-10-25 12:18:21 +00:00
|
|
|
if ( height > icon_height )/* center the cursor */
|
|
|
|
ypos += (height - icon_height) / 2;
|
2007-04-16 09:14:36 +00:00
|
|
|
screen_put_iconxy(display, xpos, ypos, icon);
|
|
|
|
}
|
2005-11-16 02:12:25 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
/* x,y in pixels */
|
2007-04-16 23:55:19 +00:00
|
|
|
void screen_put_iconxy(struct screen * display,
|
2007-04-16 09:14:36 +00:00
|
|
|
int xpos, int ypos, enum themable_icons icon)
|
|
|
|
{
|
2007-04-16 23:55:19 +00:00
|
|
|
const void *data;
|
2009-10-05 23:13:01 +00:00
|
|
|
const int screen = display->screen_type;
|
|
|
|
const int width = ICON_WIDTH(screen);
|
|
|
|
const int height = ICON_HEIGHT(screen);
|
2009-10-05 23:41:59 +00:00
|
|
|
const int is_rtl = lang_is_rtl();
|
2009-08-29 19:31:29 +00:00
|
|
|
int stride;
|
2009-10-05 23:13:01 +00:00
|
|
|
const struct bitmap *iconset;
|
2007-04-16 23:55:19 +00:00
|
|
|
screen_bitmap_part_func *draw_func = NULL;
|
2007-04-16 09:14:36 +00:00
|
|
|
|
|
|
|
if (icon == Icon_NOICON)
|
|
|
|
{
|
2009-10-05 23:41:59 +00:00
|
|
|
if (is_rtl)
|
|
|
|
xpos = display->getwidth() - xpos - width;
|
2007-04-16 19:17:37 +00:00
|
|
|
screen_clear_area(display, xpos, ypos, width, height);
|
2007-04-16 09:14:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (icon >= Icon_Last_Themeable)
|
|
|
|
{
|
2009-10-05 23:13:01 +00:00
|
|
|
iconset = &viewer_iconset[screen];
|
2007-04-16 09:14:36 +00:00
|
|
|
icon -= Icon_Last_Themeable;
|
2007-04-16 12:50:01 +00:00
|
|
|
if (!viewer_icons_loaded[screen] ||
|
2009-10-05 23:13:01 +00:00
|
|
|
(global_status.viewer_icon_count * height > iconset->height) ||
|
2010-10-16 11:05:09 +00:00
|
|
|
(icon * height + height > iconset->height))
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2007-04-22 08:50:24 +00:00
|
|
|
screen_put_iconxy(display, xpos, ypos, Icon_Questionmark);
|
2007-04-16 09:14:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (custom_icons_loaded[screen])
|
|
|
|
{
|
2009-10-05 23:13:01 +00:00
|
|
|
iconset = &user_iconset[screen];
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
2005-11-16 02:12:25 +00:00
|
|
|
else
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2010-10-25 12:18:21 +00:00
|
|
|
iconset = &inbuilt_iconset[screen];
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
2010-10-25 12:18:21 +00:00
|
|
|
data = iconset->data;
|
|
|
|
stride = STRIDE(display->screen_type, iconset->width, iconset->height);
|
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
/* add some left padding to the icons if they are on the edge */
|
|
|
|
if (xpos == 0)
|
|
|
|
xpos++;
|
2009-10-05 23:13:01 +00:00
|
|
|
|
2009-10-05 23:41:59 +00:00
|
|
|
if (is_rtl)
|
2009-10-05 23:13:01 +00:00
|
|
|
xpos = display->getwidth() - xpos - width;
|
|
|
|
|
2007-04-17 00:08:58 +00:00
|
|
|
#if (LCD_DEPTH == 16) || defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH == 16)
|
2007-04-16 23:55:19 +00:00
|
|
|
if (display->depth == 16)
|
2009-08-29 19:31:29 +00:00
|
|
|
draw_func = display->transparent_bitmap_part;
|
2005-11-16 02:12:25 +00:00
|
|
|
else
|
2005-10-28 00:00:00 +00:00
|
|
|
#endif
|
2009-08-29 19:31:29 +00:00
|
|
|
draw_func = display->bitmap_part;
|
2007-04-16 23:55:19 +00:00
|
|
|
|
2009-08-29 19:31:29 +00:00
|
|
|
draw_func(data, 0, height * icon, stride, xpos, ypos, width, height);
|
2005-10-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
void screen_put_cursorxy(struct screen * display, int x, int y, bool on)
|
2005-10-28 00:00:00 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-04-16 09:14:36 +00:00
|
|
|
screen_put_icon(display, x, y, on?Icon_Cursor:0);
|
2005-10-28 00:00:00 +00:00
|
|
|
#else
|
2007-04-16 09:14:36 +00:00
|
|
|
screen_put_icon(display, x, y, on?CURSOR_CHAR:-1);
|
2005-10-28 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-10-25 12:18:21 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
enum Iconset {
|
|
|
|
Iconset_Mainscreen,
|
|
|
|
Iconset_Mainscreen_viewers,
|
2007-04-18 17:49:32 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
2007-04-16 09:14:36 +00:00
|
|
|
Iconset_Remotescreen,
|
|
|
|
Iconset_Remotescreen_viewers,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-10-16 12:50:44 +00:00
|
|
|
static void load_icons(const char* filename, enum Iconset iconset)
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
|
|
|
int size_read;
|
|
|
|
bool *loaded_ok = NULL;
|
|
|
|
struct bitmap *bmp = NULL;
|
2007-04-17 01:03:25 +00:00
|
|
|
int bmpformat = (FORMAT_NATIVE|FORMAT_DITHER);
|
2007-04-16 09:14:36 +00:00
|
|
|
|
|
|
|
switch (iconset)
|
|
|
|
{
|
|
|
|
case Iconset_Mainscreen:
|
|
|
|
loaded_ok = &custom_icons_loaded[SCREEN_MAIN];
|
|
|
|
bmp = &user_iconset[SCREEN_MAIN];
|
|
|
|
bmp->data = icon_buffer[SCREEN_MAIN];
|
|
|
|
break;
|
|
|
|
case Iconset_Mainscreen_viewers:
|
|
|
|
loaded_ok = &viewer_icons_loaded[SCREEN_MAIN];
|
|
|
|
bmp = &viewer_iconset[SCREEN_MAIN];
|
|
|
|
bmp->data = viewer_icon_buffer[SCREEN_MAIN];
|
|
|
|
break;
|
2007-04-18 17:49:32 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
2007-04-16 09:14:36 +00:00
|
|
|
case Iconset_Remotescreen:
|
2007-04-16 11:01:41 +00:00
|
|
|
loaded_ok = &custom_icons_loaded[SCREEN_REMOTE];
|
|
|
|
bmp = &user_iconset[SCREEN_REMOTE];
|
|
|
|
bmp->data = icon_buffer[SCREEN_REMOTE];
|
2007-04-17 01:03:25 +00:00
|
|
|
bmpformat |= FORMAT_REMOTE;
|
2007-04-16 09:14:36 +00:00
|
|
|
break;
|
|
|
|
case Iconset_Remotescreen_viewers:
|
|
|
|
loaded_ok = &viewer_icons_loaded[SCREEN_REMOTE];
|
|
|
|
bmp = &viewer_iconset[SCREEN_REMOTE];
|
|
|
|
bmp->data = viewer_icon_buffer[SCREEN_REMOTE];
|
2007-04-17 01:03:25 +00:00
|
|
|
bmpformat |= FORMAT_REMOTE;
|
2007-04-16 09:14:36 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
*loaded_ok = false;
|
2010-10-16 12:50:44 +00:00
|
|
|
if (filename[0] && filename[0] != '-')
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2007-04-16 19:17:37 +00:00
|
|
|
char path[MAX_PATH];
|
2010-11-04 23:15:52 +00:00
|
|
|
char temp[MAX_PATH];
|
|
|
|
const char * fname;
|
2007-04-16 19:17:37 +00:00
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "%s/%s.bmp", ICON_DIR, filename);
|
2010-11-04 23:15:52 +00:00
|
|
|
fname = get_user_file_path(path, IS_FILE, temp, sizeof(temp));
|
|
|
|
size_read = read_bmp_file(fname, bmp, IMG_BUFSIZE, bmpformat, NULL);
|
2007-04-16 09:14:36 +00:00
|
|
|
if (size_read > 0)
|
|
|
|
{
|
|
|
|
*loaded_ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void icons_init(void)
|
|
|
|
{
|
2010-10-16 12:50:44 +00:00
|
|
|
load_icons(global_settings.icon_file, Iconset_Mainscreen);
|
2007-04-16 19:17:37 +00:00
|
|
|
|
2010-10-16 12:50:44 +00:00
|
|
|
if (global_settings.viewers_icon_file[0] &&
|
|
|
|
global_settings.viewers_icon_file[0] != '-')
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2010-10-16 12:50:44 +00:00
|
|
|
load_icons(global_settings.viewers_icon_file,
|
|
|
|
Iconset_Mainscreen_viewers);
|
2007-04-16 09:14:36 +00:00
|
|
|
read_viewer_theme_file();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-16 12:50:44 +00:00
|
|
|
load_icons(DEFAULT_VIEWER_BMP, Iconset_Mainscreen_viewers);
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
2007-04-16 19:17:37 +00:00
|
|
|
|
2007-04-18 17:49:32 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
2007-04-16 19:17:37 +00:00
|
|
|
load_icons(global_settings.remote_icon_file,
|
2010-10-16 12:50:44 +00:00
|
|
|
Iconset_Remotescreen);
|
2007-04-16 19:17:37 +00:00
|
|
|
|
2010-10-16 12:50:44 +00:00
|
|
|
if (global_settings.remote_viewers_icon_file[0] &&
|
|
|
|
global_settings.remote_viewers_icon_file[0] != '-')
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2007-04-16 19:17:37 +00:00
|
|
|
load_icons(global_settings.remote_viewers_icon_file,
|
2010-10-16 12:50:44 +00:00
|
|
|
Iconset_Remotescreen_viewers);
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
|
|
|
else
|
2007-04-16 19:17:37 +00:00
|
|
|
{
|
|
|
|
load_icons(DEFAULT_REMOTE_VIEWER_BMP,
|
2010-10-16 12:50:44 +00:00
|
|
|
Iconset_Remotescreen_viewers);
|
2007-04-16 19:17:37 +00:00
|
|
|
}
|
2007-04-16 09:14:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_icon_width(enum screen_type screen_type)
|
|
|
|
{
|
|
|
|
return ICON_WIDTH(screen_type);
|
|
|
|
}
|