Do some #ifdef'ing to make the Player happy.
[kugel-rb.git] / apps / gui / icon.c
blob6a5ff708d162d2eb8dfb7f81154b8eaaf7b2db08
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "inttypes.h"
25 #include "config.h"
26 #include "icon.h"
27 #include "screen_access.h"
28 #include "icons.h"
29 #include "settings.h"
30 #include "bmp.h"
31 #include "filetypes.h"
33 #include "bitmaps/default_icons.h"
34 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
35 #include "bitmaps/remote_default_icons.h"
36 #endif
38 /* These are just the file names, the full path is snprint'ed when used */
39 #define DEFAULT_VIEWER_BMP "viewers"
40 #define DEFAULT_REMOTE_VIEWER_BMP "remote_viewers"
42 /* These can be defined in config-<target>.h, if it is not provide defaults */
43 #if !defined(MAX_ICON_HEIGHT)
44 #define MAX_ICON_HEIGHT 24
45 #endif
47 #if !defined(MAX_ICON_WIDTH)
48 #define MAX_ICON_WIDTH 24
49 #endif
51 /* We dont actually do anything with these pointers,
52 but they need to be grouped like this to save code
53 so storing them as void* is ok. (stops compile warning) */
54 static const void * inbuilt_icons[NB_SCREENS] = {
55 (void*)default_icons
56 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
57 , (void*)remote_default_icons
58 #endif
61 static const int default_width[NB_SCREENS] = {
62 BMPWIDTH_default_icons
63 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
64 , BMPWIDTH_remote_default_icons
65 #endif
68 /* height of whole file */
69 static const int default_height[NB_SCREENS] = {
70 BMPHEIGHT_default_icons
71 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
72 , BMPHEIGHT_remote_default_icons
73 #endif
76 #define IMG_BUFSIZE (MAX_ICON_HEIGHT * MAX_ICON_WIDTH * \
77 Icon_Last_Themeable *LCD_DEPTH/8)
78 static unsigned char icon_buffer[NB_SCREENS][IMG_BUFSIZE];
79 static bool custom_icons_loaded[NB_SCREENS] = {false};
80 static struct bitmap user_iconset[NB_SCREENS];
82 static unsigned char viewer_icon_buffer[NB_SCREENS][IMG_BUFSIZE];
83 static bool viewer_icons_loaded[NB_SCREENS] = {false};
84 static struct bitmap viewer_iconset[NB_SCREENS];
87 #define ICON_HEIGHT(screen) (!custom_icons_loaded[screen]? \
88 default_height[screen] : \
89 user_iconset[screen].height) \
90 / Icon_Last_Themeable
92 #define ICON_WIDTH(screen) (!custom_icons_loaded[screen]? \
93 default_width[screen] : \
94 user_iconset[screen].width)
96 /* x,y in letters, not pixles */
97 void screen_put_icon(struct screen * display,
98 int x, int y, enum themable_icons icon)
100 screen_put_icon_with_offset(display, x, y, 0, 0, icon);
103 void screen_put_icon_with_offset(struct screen * display,
104 int x, int y, int off_x, int off_y,
105 enum themable_icons icon)
107 int xpos, ypos;
108 int width, height;
109 int screen = display->screen_type;
110 display->getstringsize((unsigned char *)"M", &width, &height);
111 xpos = x*ICON_WIDTH(screen) + off_x;
112 ypos = y*height + off_y;
114 if ( height > ICON_HEIGHT(screen) )/* center the cursor */
115 ypos += (height - ICON_HEIGHT(screen)) / 2;
116 screen_put_iconxy(display, xpos, ypos, icon);
119 /* x,y in pixels */
120 void screen_put_iconxy(struct screen * display,
121 int xpos, int ypos, enum themable_icons icon)
123 const void *data;
124 int screen = display->screen_type;
125 int width = ICON_WIDTH(screen);
126 int height = ICON_HEIGHT(screen);
127 screen_bitmap_part_func *draw_func = NULL;
129 if (icon == Icon_NOICON)
131 screen_clear_area(display, xpos, ypos, width, height);
132 return;
134 else if (icon >= Icon_Last_Themeable)
136 icon -= Icon_Last_Themeable;
137 if (!viewer_icons_loaded[screen] ||
138 (global_status.viewer_icon_count*height
139 > viewer_iconset[screen].height) ||
140 (icon * height > viewer_iconset[screen].height))
142 screen_put_iconxy(display, xpos, ypos, Icon_Questionmark);
143 return;
145 data = viewer_iconset[screen].data;
147 else if (custom_icons_loaded[screen])
149 data = user_iconset[screen].data;
151 else
153 data = inbuilt_icons[screen];
155 /* add some left padding to the icons if they are on the edge */
156 if (xpos == 0)
157 xpos++;
159 #if (LCD_DEPTH == 16) || defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH == 16)
160 if (display->depth == 16)
161 draw_func = display->transparent_bitmap_part;
162 else
163 #endif
164 draw_func = display->bitmap_part;
166 draw_func(data, 0, height * icon, width, xpos, ypos, width, height);
169 void screen_put_cursorxy(struct screen * display, int x, int y, bool on)
171 #ifdef HAVE_LCD_BITMAP
172 screen_put_icon(display, x, y, on?Icon_Cursor:0);
173 #else
174 screen_put_icon(display, x, y, on?CURSOR_CHAR:-1);
175 #endif
178 enum Iconset {
179 Iconset_Mainscreen,
180 Iconset_Mainscreen_viewers,
181 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
182 Iconset_Remotescreen,
183 Iconset_Remotescreen_viewers,
184 #endif
187 static void load_icons(const char* filename, enum Iconset iconset,
188 bool allow_disable)
190 int size_read;
191 bool *loaded_ok = NULL;
192 struct bitmap *bmp = NULL;
193 int bmpformat = (FORMAT_NATIVE|FORMAT_DITHER);
195 switch (iconset)
197 case Iconset_Mainscreen:
198 loaded_ok = &custom_icons_loaded[SCREEN_MAIN];
199 bmp = &user_iconset[SCREEN_MAIN];
200 bmp->data = icon_buffer[SCREEN_MAIN];
201 break;
202 case Iconset_Mainscreen_viewers:
203 loaded_ok = &viewer_icons_loaded[SCREEN_MAIN];
204 bmp = &viewer_iconset[SCREEN_MAIN];
205 bmp->data = viewer_icon_buffer[SCREEN_MAIN];
206 break;
207 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
208 case Iconset_Remotescreen:
209 loaded_ok = &custom_icons_loaded[SCREEN_REMOTE];
210 bmp = &user_iconset[SCREEN_REMOTE];
211 bmp->data = icon_buffer[SCREEN_REMOTE];
212 bmpformat |= FORMAT_REMOTE;
213 break;
214 case Iconset_Remotescreen_viewers:
215 loaded_ok = &viewer_icons_loaded[SCREEN_REMOTE];
216 bmp = &viewer_iconset[SCREEN_REMOTE];
217 bmp->data = viewer_icon_buffer[SCREEN_REMOTE];
218 bmpformat |= FORMAT_REMOTE;
219 break;
220 #endif
223 *loaded_ok = false;
224 if (!allow_disable || (filename[0] && filename[0] != '-'))
226 char path[MAX_PATH];
228 snprintf(path, sizeof(path), "%s/%s.bmp", ICON_DIR, filename);
229 size_read = read_bmp_file(path, bmp, IMG_BUFSIZE, bmpformat, NULL);
230 if (size_read > 0)
232 *loaded_ok = true;
238 void icons_init(void)
240 load_icons(global_settings.icon_file, Iconset_Mainscreen, true);
242 if (*global_settings.viewers_icon_file)
244 load_icons(global_settings.viewers_icon_file,
245 Iconset_Mainscreen_viewers, true);
246 read_viewer_theme_file();
248 else
250 load_icons(DEFAULT_VIEWER_BMP, Iconset_Mainscreen_viewers, false);
253 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
254 load_icons(global_settings.remote_icon_file,
255 Iconset_Remotescreen, true);
257 if (*global_settings.remote_viewers_icon_file)
259 load_icons(global_settings.remote_viewers_icon_file,
260 Iconset_Remotescreen_viewers, true);
262 else
264 load_icons(DEFAULT_REMOTE_VIEWER_BMP,
265 Iconset_Remotescreen_viewers, false);
267 #endif
270 int get_icon_width(enum screen_type screen_type)
272 return ICON_WIDTH(screen_type);