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"
33 #include "bitmaps/default_icons.h"
34 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
35 #include "bitmaps/remote_default_icons.h"
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 should probably be moved to config-<target>.h */
43 #define MAX_ICON_HEIGHT 24
44 #define MAX_ICON_WIDTH 24
47 /* We dont actually do anything with these pointers,
48 but they need to be grouped like this to save code
49 so storing them as void* is ok. (stops compile warning) */
50 static const void * inbuilt_icons
[NB_SCREENS
] = {
52 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
53 , (void*)remote_default_icons
57 static const int default_width
[NB_SCREENS
] = {
58 BMPWIDTH_default_icons
59 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
60 , BMPWIDTH_remote_default_icons
64 /* height of whole file */
65 static const int default_height
[NB_SCREENS
] = {
66 BMPHEIGHT_default_icons
67 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
68 , BMPHEIGHT_remote_default_icons
72 #define IMG_BUFSIZE (MAX_ICON_HEIGHT * MAX_ICON_WIDTH * \
73 Icon_Last_Themeable *LCD_DEPTH/8)
74 static unsigned char icon_buffer
[NB_SCREENS
][IMG_BUFSIZE
];
75 static bool custom_icons_loaded
[NB_SCREENS
] = {false};
76 static struct bitmap user_iconset
[NB_SCREENS
];
78 static unsigned char viewer_icon_buffer
[NB_SCREENS
][IMG_BUFSIZE
];
79 static bool viewer_icons_loaded
[NB_SCREENS
] = {false};
80 static struct bitmap viewer_iconset
[NB_SCREENS
];
83 #define ICON_HEIGHT(screen) (!custom_icons_loaded[screen]? \
84 default_height[screen] : \
85 user_iconset[screen].height) \
88 #define ICON_WIDTH(screen) (!custom_icons_loaded[screen]? \
89 default_width[screen] : \
90 user_iconset[screen].width)
92 /* x,y in letters, not pixles */
93 void screen_put_icon(struct screen
* display
,
94 int x
, int y
, enum themable_icons icon
)
96 screen_put_icon_with_offset(display
, x
, y
, 0, 0, icon
);
99 void screen_put_icon_with_offset(struct screen
* display
,
100 int x
, int y
, int off_x
, int off_y
,
101 enum themable_icons icon
)
105 int screen
= display
->screen_type
;
106 display
->getstringsize((unsigned char *)"M", &width
, &height
);
107 xpos
= x
*ICON_WIDTH(screen
) + off_x
;
108 ypos
= y
*height
+ off_y
;
110 if ( height
> ICON_HEIGHT(screen
) )/* center the cursor */
111 ypos
+= (height
- ICON_HEIGHT(screen
)) / 2;
112 screen_put_iconxy(display
, xpos
, ypos
, icon
);
116 void screen_put_iconxy(struct screen
* display
,
117 int xpos
, int ypos
, enum themable_icons icon
)
120 int screen
= display
->screen_type
;
121 int width
= ICON_WIDTH(screen
);
122 int height
= ICON_HEIGHT(screen
);
123 screen_bitmap_part_func
*draw_func
= NULL
;
125 if (icon
== Icon_NOICON
)
127 screen_clear_area(display
, xpos
, ypos
, width
, height
);
130 else if (icon
>= Icon_Last_Themeable
)
132 icon
-= Icon_Last_Themeable
;
133 if (!viewer_icons_loaded
[screen
] ||
134 (global_status
.viewer_icon_count
*height
135 > viewer_iconset
[screen
].height
) ||
136 (icon
* height
> viewer_iconset
[screen
].height
))
138 screen_put_iconxy(display
, xpos
, ypos
, Icon_Questionmark
);
141 data
= viewer_iconset
[screen
].data
;
143 else if (custom_icons_loaded
[screen
])
145 data
= user_iconset
[screen
].data
;
149 data
= inbuilt_icons
[screen
];
151 /* add some left padding to the icons if they are on the edge */
155 #if (LCD_DEPTH == 16) || defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH == 16)
156 if (display
->depth
== 16)
157 draw_func
= display
->transparent_bitmap_part
;
160 draw_func
= display
->bitmap_part
;
162 draw_func(data
, 0, height
* icon
, width
, xpos
, ypos
, width
, height
);
165 void screen_put_cursorxy(struct screen
* display
, int x
, int y
, bool on
)
167 #ifdef HAVE_LCD_BITMAP
168 screen_put_icon(display
, x
, y
, on
?Icon_Cursor
:0);
170 screen_put_icon(display
, x
, y
, on
?CURSOR_CHAR
:-1);
176 Iconset_Mainscreen_viewers
,
177 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
178 Iconset_Remotescreen
,
179 Iconset_Remotescreen_viewers
,
183 static void load_icons(const char* filename
, enum Iconset iconset
,
187 bool *loaded_ok
= NULL
;
188 struct bitmap
*bmp
= NULL
;
189 int bmpformat
= (FORMAT_NATIVE
|FORMAT_DITHER
);
193 case Iconset_Mainscreen
:
194 loaded_ok
= &custom_icons_loaded
[SCREEN_MAIN
];
195 bmp
= &user_iconset
[SCREEN_MAIN
];
196 bmp
->data
= icon_buffer
[SCREEN_MAIN
];
198 case Iconset_Mainscreen_viewers
:
199 loaded_ok
= &viewer_icons_loaded
[SCREEN_MAIN
];
200 bmp
= &viewer_iconset
[SCREEN_MAIN
];
201 bmp
->data
= viewer_icon_buffer
[SCREEN_MAIN
];
203 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
204 case Iconset_Remotescreen
:
205 loaded_ok
= &custom_icons_loaded
[SCREEN_REMOTE
];
206 bmp
= &user_iconset
[SCREEN_REMOTE
];
207 bmp
->data
= icon_buffer
[SCREEN_REMOTE
];
208 bmpformat
|= FORMAT_REMOTE
;
210 case Iconset_Remotescreen_viewers
:
211 loaded_ok
= &viewer_icons_loaded
[SCREEN_REMOTE
];
212 bmp
= &viewer_iconset
[SCREEN_REMOTE
];
213 bmp
->data
= viewer_icon_buffer
[SCREEN_REMOTE
];
214 bmpformat
|= FORMAT_REMOTE
;
220 if (!allow_disable
|| (filename
[0] && filename
[0] != '-'))
224 snprintf(path
, sizeof(path
), "%s/%s.bmp", ICON_DIR
, filename
);
225 size_read
= read_bmp_file(path
, bmp
, IMG_BUFSIZE
, bmpformat
, NULL
);
234 void icons_init(void)
236 load_icons(global_settings
.icon_file
, Iconset_Mainscreen
, true);
238 if (*global_settings
.viewers_icon_file
)
240 load_icons(global_settings
.viewers_icon_file
,
241 Iconset_Mainscreen_viewers
, true);
242 read_viewer_theme_file();
246 load_icons(DEFAULT_VIEWER_BMP
, Iconset_Mainscreen_viewers
, false);
249 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
250 load_icons(global_settings
.remote_icon_file
,
251 Iconset_Remotescreen
, true);
253 if (*global_settings
.remote_viewers_icon_file
)
255 load_icons(global_settings
.remote_viewers_icon_file
,
256 Iconset_Remotescreen_viewers
, true);
260 load_icons(DEFAULT_REMOTE_VIEWER_BMP
,
261 Iconset_Remotescreen_viewers
, false);
266 int get_icon_width(enum screen_type screen_type
)
268 return ICON_WIDTH(screen_type
);