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"
|
2011-11-08 09:36:35 +00:00
|
|
|
#include "core_alloc.h"
|
2005-10-28 00:00:00 +00:00
|
|
|
#include "icon.h"
|
|
|
|
#include "screen_access.h"
|
|
|
|
#include "icons.h"
|
2007-04-16 09:14:36 +00:00
|
|
|
#include "settings.h"
|
2021-04-10 14:42:38 +00:00
|
|
|
#include "rbpaths.h"
|
2007-04-16 09:14:36 +00:00
|
|
|
#include "bmp.h"
|
|
|
|
#include "filetypes.h"
|
2009-10-05 11:43:38 +00:00
|
|
|
#include "language.h"
|
2022-11-20 03:39:14 +00:00
|
|
|
#include "misc.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
|
|
|
|
|
|
|
/* 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) */
|
2011-11-13 15:37:16 +00:00
|
|
|
static const struct bitmap *inbuilt_iconset[NB_SCREENS] =
|
2010-10-25 12:18:21 +00:00
|
|
|
{
|
2011-11-13 15:37:16 +00:00
|
|
|
&bm_default_icons,
|
2007-04-18 17:49:32 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
2011-11-13 15:37:16 +00:00
|
|
|
&bm_remote_default_icons,
|
2007-04-16 09:14:36 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2011-11-08 09:36:35 +00:00
|
|
|
enum Iconset {
|
|
|
|
Iconset_user,
|
|
|
|
Iconset_viewers,
|
|
|
|
Iconset_Count
|
|
|
|
};
|
2007-04-16 09:14:36 +00:00
|
|
|
|
2011-12-20 21:05:56 +00:00
|
|
|
static struct iconset {
|
2011-11-08 09:36:35 +00:00
|
|
|
struct bitmap bmp;
|
|
|
|
bool loaded;
|
|
|
|
int handle;
|
|
|
|
} iconsets[Iconset_Count][NB_SCREENS];
|
2007-04-16 09:14:36 +00:00
|
|
|
|
2011-11-08 09:36:35 +00:00
|
|
|
#define ICON_HEIGHT(screen) (!iconsets[Iconset_user][screen].loaded ? \
|
2011-11-13 15:37:16 +00:00
|
|
|
(*(inbuilt_iconset[screen])) : iconsets[Iconset_user][screen].bmp).height \
|
2007-04-16 09:14:36 +00:00
|
|
|
/ Icon_Last_Themeable
|
2010-10-25 12:18:21 +00:00
|
|
|
|
2011-11-08 09:36:35 +00:00
|
|
|
#define ICON_WIDTH(screen) (!iconsets[Iconset_user][screen].loaded ? \
|
2011-11-13 15:37:16 +00:00
|
|
|
(*(inbuilt_iconset[screen])) : iconsets[Iconset_user][screen].bmp).width
|
2010-10-25 12:18:21 +00:00
|
|
|
|
2007-04-16 09:14:36 +00:00
|
|
|
/* x,y in letters, not pixles */
|
2021-08-15 00:35:02 +00:00
|
|
|
void screen_put_icon(struct screen * display,
|
2007-04-16 09:14:36 +00:00
|
|
|
int x, int y, enum themable_icons icon)
|
|
|
|
{
|
|
|
|
screen_put_icon_with_offset(display, x, y, 0, 0, icon);
|
|
|
|
}
|
|
|
|
|
2021-08-15 00:35:02 +00:00
|
|
|
void screen_put_icon_with_offset(struct screen * display,
|
2007-04-16 09:14:36 +00:00
|
|
|
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)
|
|
|
|
{
|
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-10-05 23:13:01 +00:00
|
|
|
const struct bitmap *iconset;
|
2021-08-15 00:35:02 +00:00
|
|
|
|
2019-09-25 04:40:38 +00:00
|
|
|
if (icon <= Icon_NOICON)
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
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)
|
|
|
|
{
|
2011-11-08 09:36:35 +00:00
|
|
|
iconset = &iconsets[Iconset_viewers][screen].bmp;
|
2007-04-16 09:14:36 +00:00
|
|
|
icon -= Icon_Last_Themeable;
|
2021-08-15 00:35:02 +00:00
|
|
|
if (!iconsets[Iconset_viewers][screen].loaded ||
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-11-08 09:36:35 +00:00
|
|
|
else if (iconsets[Iconset_user][screen].loaded)
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2011-11-08 09:36:35 +00:00
|
|
|
iconset = &iconsets[Iconset_user][screen].bmp;
|
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
|
|
|
{
|
2011-11-13 15:37:16 +00:00
|
|
|
iconset = inbuilt_iconset[screen];
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
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-16 23:55:19 +00:00
|
|
|
|
2011-11-08 21:34:46 +00:00
|
|
|
display->bmp_part(iconset, 0, height * icon, 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
|
|
|
{
|
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
|
|
|
}
|
2010-10-25 12:18:21 +00:00
|
|
|
|
2011-11-08 09:36:35 +00:00
|
|
|
static int buflib_move_callback(int handle, void* current, void* new)
|
|
|
|
{
|
2011-11-08 21:23:02 +00:00
|
|
|
(void)handle;
|
2011-11-08 09:36:35 +00:00
|
|
|
(void)new;
|
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(j)
|
|
|
|
{
|
|
|
|
for (i=0; i<Iconset_Count; i++)
|
|
|
|
{
|
2011-11-08 21:23:02 +00:00
|
|
|
struct iconset *set = &iconsets[i][j];
|
|
|
|
if (set->bmp.data == current)
|
2011-11-08 09:36:35 +00:00
|
|
|
{
|
2011-11-08 21:23:02 +00:00
|
|
|
set->bmp.data = new;
|
2011-11-08 09:36:35 +00:00
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
2007-04-16 09:14:36 +00:00
|
|
|
|
2011-11-08 09:36:35 +00:00
|
|
|
static void load_icons(const char* filename, enum Iconset iconset,
|
|
|
|
enum screen_type screen)
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2022-12-20 02:12:07 +00:00
|
|
|
static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL, NULL};
|
|
|
|
const int bmpformat = (FORMAT_ANY|FORMAT_DITHER|FORMAT_TRANSPARENT);
|
2011-11-08 09:36:35 +00:00
|
|
|
struct iconset *ic = &iconsets[iconset][screen];
|
2022-12-20 02:12:07 +00:00
|
|
|
ssize_t buf_reqd;
|
2021-08-15 00:35:02 +00:00
|
|
|
|
2011-11-08 09:36:35 +00:00
|
|
|
ic->loaded = false;
|
2022-12-20 02:12:07 +00:00
|
|
|
ic->handle = CLB_ALOC_ERR;
|
2010-10-16 12:50:44 +00:00
|
|
|
if (filename[0] && filename[0] != '-')
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2022-11-24 02:46:13 +00:00
|
|
|
char fname[MAX_PATH];
|
2022-12-20 02:12:07 +00:00
|
|
|
snprintf(fname, sizeof(fname), ICON_DIR "/%s.bmp", filename);
|
|
|
|
ic->handle = core_load_bmp(fname, &ic->bmp, bmpformat, &buf_reqd, &buflib_ops);
|
|
|
|
if (ic->handle != CLB_ALOC_ERR)
|
2021-08-15 00:35:02 +00:00
|
|
|
{
|
2022-12-20 02:12:07 +00:00
|
|
|
ic->bmp.data = core_get_data(ic->handle);
|
2011-11-08 21:23:02 +00:00
|
|
|
ic->loaded = true;
|
2022-12-20 02:12:07 +00:00
|
|
|
}
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void icons_init(void)
|
|
|
|
{
|
2011-11-08 09:36:35 +00:00
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(j)
|
|
|
|
{
|
|
|
|
for (i=0; i<Iconset_Count; i++)
|
|
|
|
{
|
2011-11-08 21:23:02 +00:00
|
|
|
struct iconset* set = &iconsets[i][j];
|
|
|
|
if (set->loaded && set->handle > 0)
|
2011-11-08 09:36:35 +00:00
|
|
|
{
|
2011-11-08 21:23:02 +00:00
|
|
|
set->handle = core_free(set->handle);
|
|
|
|
set->loaded = false;
|
2011-11-08 09:36:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-08 21:23:02 +00:00
|
|
|
|
2011-11-27 10:10:26 +00:00
|
|
|
if (global_settings.show_icons)
|
2007-04-16 09:14:36 +00:00
|
|
|
{
|
2011-11-27 10:10:26 +00:00
|
|
|
load_icons(global_settings.icon_file, Iconset_user, SCREEN_MAIN);
|
|
|
|
|
2021-08-15 00:35:02 +00:00
|
|
|
if (global_settings.viewers_icon_file[0] == '-' ||
|
|
|
|
global_settings.viewers_icon_file[0] == '\0')
|
2011-11-27 10:10:26 +00:00
|
|
|
{
|
2021-08-15 00:35:02 +00:00
|
|
|
load_icons(DEFAULT_VIEWER_BMP, Iconset_viewers, SCREEN_MAIN);
|
2011-11-27 10:10:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 00:35:02 +00:00
|
|
|
load_icons(global_settings.viewers_icon_file,
|
|
|
|
Iconset_viewers, SCREEN_MAIN);
|
|
|
|
read_viewer_theme_file();
|
2011-11-27 10:10:26 +00:00
|
|
|
}
|
2007-04-18 17:49:32 +00:00
|
|
|
#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
|
2021-08-15 00:35:02 +00:00
|
|
|
load_icons(global_settings.remote_icon_file,
|
2011-11-27 10:10:26 +00:00
|
|
|
Iconset_user, SCREEN_REMOTE);
|
2021-08-15 00:35:02 +00:00
|
|
|
|
|
|
|
if (global_settings.remote_viewers_icon_file[0] == '-' ||
|
|
|
|
global_settings.remote_viewers_icon_file[0] == '\0')
|
2011-11-27 10:10:26 +00:00
|
|
|
{
|
2021-08-15 00:35:02 +00:00
|
|
|
load_icons(DEFAULT_REMOTE_VIEWER_BMP,
|
2011-11-27 10:10:26 +00:00
|
|
|
Iconset_viewers, SCREEN_REMOTE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 00:35:02 +00:00
|
|
|
load_icons(global_settings.remote_viewers_icon_file,
|
2011-11-27 10:10:26 +00:00
|
|
|
Iconset_viewers, SCREEN_REMOTE);
|
|
|
|
}
|
2007-04-16 09:14:36 +00:00
|
|
|
#endif
|
2011-11-27 10:10:26 +00:00
|
|
|
}
|
2007-04-16 09:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_icon_width(enum screen_type screen_type)
|
|
|
|
{
|
|
|
|
return ICON_WIDTH(screen_type);
|
|
|
|
}
|
2011-10-17 17:38:10 +00:00
|
|
|
|
|
|
|
int get_icon_height(enum screen_type screen_type)
|
|
|
|
{
|
|
|
|
return ICON_HEIGHT(screen_type);
|
|
|
|
}
|
2013-12-28 14:10:46 +00:00
|
|
|
|
|
|
|
#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
|
|
|
|
int get_icon_format(enum screen_type screen)
|
|
|
|
{
|
|
|
|
const struct bitmap *iconset;
|
|
|
|
|
|
|
|
if (iconsets[Iconset_user][screen].loaded)
|
|
|
|
iconset = &iconsets[Iconset_user][screen].bmp;
|
|
|
|
else
|
|
|
|
iconset = inbuilt_iconset[screen];
|
|
|
|
|
|
|
|
return iconset->format;
|
|
|
|
}
|
|
|
|
#endif
|