Add "elfzip" target to make which creates a zip of all elf files, as mapzip does...
[maemo-rb.git] / apps / gui / icon.c
blob628196a98f2659167e1080ffe33cedf010ef76e0
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"
32 #include "language.h"
34 #include "bitmaps/default_icons.h"
35 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
36 #include "bitmaps/remote_default_icons.h"
37 #endif
39 /* These are just the file names, the full path is snprint'ed when used */
40 #define DEFAULT_VIEWER_BMP "viewers"
41 #define DEFAULT_REMOTE_VIEWER_BMP "remote_viewers"
43 /* These can be defined in config-<target>.h, if it is not provide defaults */
44 #if !defined(MAX_ICON_HEIGHT)
45 #define MAX_ICON_HEIGHT 24
46 #endif
48 #if !defined(MAX_ICON_WIDTH)
49 #define MAX_ICON_WIDTH 24
50 #endif
52 /* We dont actually do anything with these pointers,
53 but they need to be grouped like this to save code
54 so storing them as void* is ok. (stops compile warning) */
55 static const struct bitmap inbuilt_iconset[NB_SCREENS] =
58 .width = BMPWIDTH_default_icons,
59 .height = BMPHEIGHT_default_icons,
60 .data = (unsigned char*)default_icons,
62 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
64 .width = BMPWIDTH_remote_default_icons,
65 .height = BMPHEIGHT_remote_default_icons,
66 .data = (unsigned char*)remote_default_icons,
68 #endif
71 #define IMG_BUFSIZE (MAX_ICON_HEIGHT * MAX_ICON_WIDTH * \
72 Icon_Last_Themeable *LCD_DEPTH/8)
73 static unsigned char icon_buffer[NB_SCREENS][IMG_BUFSIZE];
74 static bool custom_icons_loaded[NB_SCREENS] = {false};
75 static struct bitmap user_iconset[NB_SCREENS];
77 static unsigned char viewer_icon_buffer[NB_SCREENS][IMG_BUFSIZE];
78 static bool viewer_icons_loaded[NB_SCREENS] = {false};
79 static struct bitmap viewer_iconset[NB_SCREENS];
82 #define ICON_HEIGHT(screen) (!custom_icons_loaded[screen]? \
83 inbuilt_iconset : user_iconset)[screen].height \
84 / Icon_Last_Themeable
86 #define ICON_WIDTH(screen) (!custom_icons_loaded[screen]? \
87 inbuilt_iconset : user_iconset)[screen].width
89 /* x,y in letters, not pixles */
90 void screen_put_icon(struct screen * display,
91 int x, int y, enum themable_icons icon)
93 screen_put_icon_with_offset(display, x, y, 0, 0, icon);
96 void screen_put_icon_with_offset(struct screen * display,
97 int x, int y, int off_x, int off_y,
98 enum themable_icons icon)
100 const int screen = display->screen_type;
101 const int icon_width = ICON_WIDTH(screen);
102 const int icon_height = ICON_HEIGHT(screen);
103 int xpos, ypos;
104 int width, height;
105 display->getstringsize((unsigned char *)"M", &width, &height);
106 xpos = x*icon_width + off_x;
107 ypos = y*height + off_y;
109 if ( height > icon_height )/* center the cursor */
110 ypos += (height - icon_height) / 2;
111 screen_put_iconxy(display, xpos, ypos, icon);
114 /* x,y in pixels */
115 void screen_put_iconxy(struct screen * display,
116 int xpos, int ypos, enum themable_icons icon)
118 const void *data;
119 const int screen = display->screen_type;
120 const int width = ICON_WIDTH(screen);
121 const int height = ICON_HEIGHT(screen);
122 const int is_rtl = lang_is_rtl();
123 int stride;
124 const struct bitmap *iconset;
125 screen_bitmap_part_func *draw_func = NULL;
127 if (icon == Icon_NOICON)
129 if (is_rtl)
130 xpos = display->getwidth() - xpos - width;
131 screen_clear_area(display, xpos, ypos, width, height);
132 return;
134 else if (icon >= Icon_Last_Themeable)
136 iconset = &viewer_iconset[screen];
137 icon -= Icon_Last_Themeable;
138 if (!viewer_icons_loaded[screen] ||
139 (global_status.viewer_icon_count * height > iconset->height) ||
140 (icon * height + height > iconset->height))
142 screen_put_iconxy(display, xpos, ypos, Icon_Questionmark);
143 return;
146 else if (custom_icons_loaded[screen])
148 iconset = &user_iconset[screen];
150 else
152 iconset = &inbuilt_iconset[screen];
154 data = iconset->data;
155 stride = STRIDE(display->screen_type, iconset->width, iconset->height);
157 /* add some left padding to the icons if they are on the edge */
158 if (xpos == 0)
159 xpos++;
161 if (is_rtl)
162 xpos = display->getwidth() - xpos - width;
164 #if (LCD_DEPTH == 16) || defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH == 16)
165 if (display->depth == 16)
166 draw_func = display->transparent_bitmap_part;
167 else
168 #endif
169 draw_func = display->bitmap_part;
171 draw_func(data, 0, height * icon, stride, xpos, ypos, width, height);
174 void screen_put_cursorxy(struct screen * display, int x, int y, bool on)
176 #ifdef HAVE_LCD_BITMAP
177 screen_put_icon(display, x, y, on?Icon_Cursor:0);
178 #else
179 screen_put_icon(display, x, y, on?CURSOR_CHAR:-1);
180 #endif
183 enum Iconset {
184 Iconset_Mainscreen,
185 Iconset_Mainscreen_viewers,
186 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
187 Iconset_Remotescreen,
188 Iconset_Remotescreen_viewers,
189 #endif
192 static void load_icons(const char* filename, enum Iconset iconset)
194 int size_read;
195 bool *loaded_ok = NULL;
196 struct bitmap *bmp = NULL;
197 int bmpformat = (FORMAT_NATIVE|FORMAT_DITHER);
199 switch (iconset)
201 case Iconset_Mainscreen:
202 loaded_ok = &custom_icons_loaded[SCREEN_MAIN];
203 bmp = &user_iconset[SCREEN_MAIN];
204 bmp->data = icon_buffer[SCREEN_MAIN];
205 break;
206 case Iconset_Mainscreen_viewers:
207 loaded_ok = &viewer_icons_loaded[SCREEN_MAIN];
208 bmp = &viewer_iconset[SCREEN_MAIN];
209 bmp->data = viewer_icon_buffer[SCREEN_MAIN];
210 break;
211 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
212 case Iconset_Remotescreen:
213 loaded_ok = &custom_icons_loaded[SCREEN_REMOTE];
214 bmp = &user_iconset[SCREEN_REMOTE];
215 bmp->data = icon_buffer[SCREEN_REMOTE];
216 bmpformat |= FORMAT_REMOTE;
217 break;
218 case Iconset_Remotescreen_viewers:
219 loaded_ok = &viewer_icons_loaded[SCREEN_REMOTE];
220 bmp = &viewer_iconset[SCREEN_REMOTE];
221 bmp->data = viewer_icon_buffer[SCREEN_REMOTE];
222 bmpformat |= FORMAT_REMOTE;
223 break;
224 #endif
227 *loaded_ok = false;
228 if (filename[0] && filename[0] != '-')
230 char path[MAX_PATH];
232 snprintf(path, sizeof(path), ICON_DIR "/%s.bmp", filename);
233 size_read = read_bmp_file(path, bmp, IMG_BUFSIZE, bmpformat, NULL);
234 if (size_read > 0)
236 *loaded_ok = true;
242 void icons_init(void)
244 load_icons(global_settings.icon_file, Iconset_Mainscreen);
246 if (global_settings.viewers_icon_file[0] &&
247 global_settings.viewers_icon_file[0] != '-')
249 load_icons(global_settings.viewers_icon_file,
250 Iconset_Mainscreen_viewers);
251 read_viewer_theme_file();
253 else
255 load_icons(DEFAULT_VIEWER_BMP, Iconset_Mainscreen_viewers);
258 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
259 load_icons(global_settings.remote_icon_file,
260 Iconset_Remotescreen);
262 if (global_settings.remote_viewers_icon_file[0] &&
263 global_settings.remote_viewers_icon_file[0] != '-')
265 load_icons(global_settings.remote_viewers_icon_file,
266 Iconset_Remotescreen_viewers);
268 else
270 load_icons(DEFAULT_REMOTE_VIEWER_BMP,
271 Iconset_Remotescreen_viewers);
273 #endif
276 int get_icon_width(enum screen_type screen_type)
278 return ICON_WIDTH(screen_type);