1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
27 #include "screen_access.h"
31 #include "filetypes.h"
34 #include "bitmaps/default_icons.h"
35 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
36 #include "bitmaps/remote_default_icons.h"
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
48 #if !defined(MAX_ICON_WIDTH)
49 #define MAX_ICON_WIDTH 24
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 void * inbuilt_icons
[NB_SCREENS
] = {
57 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
58 , (void*)remote_default_icons
62 static const int default_width
[NB_SCREENS
] = {
63 BMPWIDTH_default_icons
64 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
65 , BMPWIDTH_remote_default_icons
69 /* height of whole file */
70 static const int default_height
[NB_SCREENS
] = {
71 BMPHEIGHT_default_icons
72 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
73 , BMPHEIGHT_remote_default_icons
77 #define IMG_BUFSIZE (MAX_ICON_HEIGHT * MAX_ICON_WIDTH * \
78 Icon_Last_Themeable *LCD_DEPTH/8)
79 static unsigned char icon_buffer
[NB_SCREENS
][IMG_BUFSIZE
];
80 static bool custom_icons_loaded
[NB_SCREENS
] = {false};
81 static struct bitmap user_iconset
[NB_SCREENS
];
83 static unsigned char viewer_icon_buffer
[NB_SCREENS
][IMG_BUFSIZE
];
84 static bool viewer_icons_loaded
[NB_SCREENS
] = {false};
85 static struct bitmap viewer_iconset
[NB_SCREENS
];
88 #define ICON_HEIGHT(screen) (!custom_icons_loaded[screen]? \
89 default_height[screen] : \
90 user_iconset[screen].height) \
93 #define ICON_WIDTH(screen) (!custom_icons_loaded[screen]? \
94 default_width[screen] : \
95 user_iconset[screen].width)
97 /* x,y in letters, not pixles */
98 void screen_put_icon(struct screen
* display
,
99 int x
, int y
, enum themable_icons icon
)
101 screen_put_icon_with_offset(display
, x
, y
, 0, 0, icon
);
104 void screen_put_icon_with_offset(struct screen
* display
,
105 int x
, int y
, int off_x
, int off_y
,
106 enum themable_icons icon
)
110 int screen
= display
->screen_type
;
111 display
->getstringsize((unsigned char *)"M", &width
, &height
);
112 xpos
= x
*ICON_WIDTH(screen
) + off_x
;
113 ypos
= y
*height
+ off_y
;
115 if ( height
> ICON_HEIGHT(screen
) )/* center the cursor */
116 ypos
+= (height
- ICON_HEIGHT(screen
)) / 2;
117 screen_put_iconxy(display
, xpos
, ypos
, icon
);
121 void screen_put_iconxy(struct screen
* display
,
122 int xpos
, int ypos
, enum themable_icons icon
)
125 const int screen
= display
->screen_type
;
126 const int width
= ICON_WIDTH(screen
);
127 const int height
= ICON_HEIGHT(screen
);
128 const int is_rtl
= lang_is_rtl();
130 const struct bitmap
*iconset
;
131 screen_bitmap_part_func
*draw_func
= NULL
;
133 if (icon
== Icon_NOICON
)
136 xpos
= display
->getwidth() - xpos
- width
;
137 screen_clear_area(display
, xpos
, ypos
, width
, height
);
140 else if (icon
>= Icon_Last_Themeable
)
142 iconset
= &viewer_iconset
[screen
];
143 icon
-= Icon_Last_Themeable
;
144 if (!viewer_icons_loaded
[screen
] ||
145 (global_status
.viewer_icon_count
* height
> iconset
->height
) ||
146 (icon
* height
> iconset
->height
))
148 screen_put_iconxy(display
, xpos
, ypos
, Icon_Questionmark
);
151 data
= iconset
->data
;
152 stride
= STRIDE(display
->screen_type
, iconset
->width
, iconset
->height
);
154 else if (custom_icons_loaded
[screen
])
156 iconset
= &user_iconset
[screen
];
157 data
= iconset
->data
;
158 stride
= STRIDE(display
->screen_type
, iconset
->width
, iconset
->height
);
162 data
= inbuilt_icons
[screen
];
163 stride
= STRIDE( display
->screen_type
, BMPWIDTH_default_icons
,
164 BMPHEIGHT_default_icons
);
166 /* add some left padding to the icons if they are on the edge */
171 xpos
= display
->getwidth() - xpos
- width
;
173 #if (LCD_DEPTH == 16) || defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH == 16)
174 if (display
->depth
== 16)
175 draw_func
= display
->transparent_bitmap_part
;
178 draw_func
= display
->bitmap_part
;
180 draw_func(data
, 0, height
* icon
, stride
, xpos
, ypos
, width
, height
);
183 void screen_put_cursorxy(struct screen
* display
, int x
, int y
, bool on
)
185 #ifdef HAVE_LCD_BITMAP
186 screen_put_icon(display
, x
, y
, on
?Icon_Cursor
:0);
188 screen_put_icon(display
, x
, y
, on
?CURSOR_CHAR
:-1);
194 Iconset_Mainscreen_viewers
,
195 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
196 Iconset_Remotescreen
,
197 Iconset_Remotescreen_viewers
,
201 static void load_icons(const char* filename
, enum Iconset iconset
,
205 bool *loaded_ok
= NULL
;
206 struct bitmap
*bmp
= NULL
;
207 int bmpformat
= (FORMAT_NATIVE
|FORMAT_DITHER
);
211 case Iconset_Mainscreen
:
212 loaded_ok
= &custom_icons_loaded
[SCREEN_MAIN
];
213 bmp
= &user_iconset
[SCREEN_MAIN
];
214 bmp
->data
= icon_buffer
[SCREEN_MAIN
];
216 case Iconset_Mainscreen_viewers
:
217 loaded_ok
= &viewer_icons_loaded
[SCREEN_MAIN
];
218 bmp
= &viewer_iconset
[SCREEN_MAIN
];
219 bmp
->data
= viewer_icon_buffer
[SCREEN_MAIN
];
221 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
222 case Iconset_Remotescreen
:
223 loaded_ok
= &custom_icons_loaded
[SCREEN_REMOTE
];
224 bmp
= &user_iconset
[SCREEN_REMOTE
];
225 bmp
->data
= icon_buffer
[SCREEN_REMOTE
];
226 bmpformat
|= FORMAT_REMOTE
;
228 case Iconset_Remotescreen_viewers
:
229 loaded_ok
= &viewer_icons_loaded
[SCREEN_REMOTE
];
230 bmp
= &viewer_iconset
[SCREEN_REMOTE
];
231 bmp
->data
= viewer_icon_buffer
[SCREEN_REMOTE
];
232 bmpformat
|= FORMAT_REMOTE
;
238 if (!allow_disable
|| (filename
[0] && filename
[0] != '-'))
242 snprintf(path
, sizeof(path
), "%s/%s.bmp", ICON_DIR
, filename
);
243 size_read
= read_bmp_file(path
, bmp
, IMG_BUFSIZE
, bmpformat
, NULL
);
252 void icons_init(void)
254 load_icons(global_settings
.icon_file
, Iconset_Mainscreen
, true);
256 if (*global_settings
.viewers_icon_file
)
258 load_icons(global_settings
.viewers_icon_file
,
259 Iconset_Mainscreen_viewers
, true);
260 read_viewer_theme_file();
264 load_icons(DEFAULT_VIEWER_BMP
, Iconset_Mainscreen_viewers
, false);
267 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
268 load_icons(global_settings
.remote_icon_file
,
269 Iconset_Remotescreen
, true);
271 if (*global_settings
.remote_viewers_icon_file
)
273 load_icons(global_settings
.remote_viewers_icon_file
,
274 Iconset_Remotescreen_viewers
, true);
278 load_icons(DEFAULT_REMOTE_VIEWER_BMP
,
279 Iconset_Remotescreen_viewers
, false);
284 int get_icon_width(enum screen_type screen_type
)
286 return ICON_WIDTH(screen_type
);