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 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
,
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 \
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
);
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
);
115 void screen_put_iconxy(struct screen
* display
,
116 int xpos
, int ypos
, enum themable_icons icon
)
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();
124 const struct bitmap
*iconset
;
125 screen_bitmap_part_func
*draw_func
= NULL
;
127 if (icon
== Icon_NOICON
)
130 xpos
= display
->getwidth() - xpos
- width
;
131 screen_clear_area(display
, xpos
, ypos
, width
, height
);
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
);
146 else if (custom_icons_loaded
[screen
])
148 iconset
= &user_iconset
[screen
];
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 */
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
;
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);
179 screen_put_icon(display
, x
, y
, on
?CURSOR_CHAR
:-1);
185 Iconset_Mainscreen_viewers
,
186 #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1)
187 Iconset_Remotescreen
,
188 Iconset_Remotescreen_viewers
,
192 static void load_icons(const char* filename
, enum Iconset iconset
)
195 bool *loaded_ok
= NULL
;
196 struct bitmap
*bmp
= NULL
;
197 int bmpformat
= (FORMAT_NATIVE
|FORMAT_DITHER
);
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
];
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
];
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
;
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
;
228 if (filename
[0] && filename
[0] != '-')
232 snprintf(path
, sizeof(path
), ICON_DIR
"/%s.bmp", filename
);
233 size_read
= read_bmp_file(path
, bmp
, IMG_BUFSIZE
, bmpformat
, NULL
);
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();
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
);
270 load_icons(DEFAULT_REMOTE_VIEWER_BMP
,
271 Iconset_Remotescreen_viewers
);
276 int get_icon_width(enum screen_type screen_type
)
278 return ICON_WIDTH(screen_type
);