Chameleon

Chameleon Commit Details

Date:2010-07-24 23:41:51 (9 years 11 months ago)
Author:Tamás Kosárszky
Commit:225
Parents: 224
Message:Updated gui.c with rollover image and optional device image support.
Changes:
M/branches/zef/i386/boot2/gui.c

File differences

branches/zef/i386/boot2/gui.c
1212
1313
1414
15
1516
1617
1718
1819
1920
20
21
22
21
22
23
2324
2425
25
26
2627
2728
2829
......
3233
3334
3435
35
36
37
3638
3739
3840
......
4143
4244
4345
44
45
46
47
4648
47
48
49
50
51
52
53
54
55
56
49
50
51
52
53
54
55
56
57
58
59
60
61
62
5763
58
59
60
61
62
63
64
65
66
67
68
64
65
66
6967
70
71
68
69
70
71
72
73
74
75
76
77
78
7279
73
74
80
81
7582
76
77
83
84
85
86
87
7888
7989
8090
81
82
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
83108
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
115133
116134
117135
......
149167
150168
151169
170
171
172
173
174
175
176
177
178
179
180
152181
153
182
154183
155184
156185
157186
158187
159188
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
178215
179216
180217
181
218
182219
183220
184
221
185222
186223
187224
......
189226
190227
191228
192
193
194
195
196
197
198
199
200
201
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
202258
203
204
259
260
205261
206
207
208
209
210
211
212
213
214
262
263
264
215265
216266
217267
218
219268
220269
221
222
270
271
223272
224
225
226
227
228
229
230
231
232
233
273
274
275
276
277
278
279
280
281
282
283
284
285
286
234287
235
236
237
238
239
240
241
242
243
244
245
288
289
290
246291
247
248
292
293
294
295
296
297
298
299
300
301
302
249303
250
251
304
305
252306
253
254
307
308
255309
310
311
312
256313
257314
258315
......
601658
602659
603660
661
662
663
604664
605665
606666
......
624684
625685
626686
627
687
628688
629689
630690
......
663723
664724
665725
726
727
728
666729
667730
668731
......
712775
713776
714777
715
778
716779
717
780
718781
719
782
783
720784
721
722
723
724
725
726
727
728
785
786
787
788
789
790
791
792
793
794
729795
730796
731797
......
733799
734800
735801
736
737
738
739
740
741
742
743
744
745
746
747
748
749
802
803
804
805
806
807
808
809
810
811
812
813
814
815
750816
751817
752818
753
819
754820
755821
756822
#include "appleboot.h"
#include "vers.h"
#define IMG_REQUIRED -1
#define THEME_NAME_DEFAULT"Default"
static const char *theme_name = THEME_NAME_DEFAULT;
#ifdef EMBED_THEME
#include "art.h"
#define LOADPNG(img) \
if (loadThemeImage(#img) != 0) \
if (loadEmbeddedThemeImage(#img, __## img ##_png, __## img ##_png_len) != 0) \
#define LOADPNG(img, alt_img) \
if (loadThemeImage(#img, alt_img) != 0) \
if (loadEmbeddedThemeImage(#img, __## img ##_png, __## img ##_png_len, alt_img) != 0) \
return 1;
#else
#define LOADPNG(img)if (loadThemeImage(#img) != 0) { return 1; }
#define LOADPNG(img, alt_img) if (loadThemeImage(#img, alt_img) != 0) { return 1; }
#endif
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define vram VIDEO(baseAddr)
int lasttime=0; // we need this for animating maybe
int lasttime = 0; // we need this for animating maybe
bool useRollOver = false;
extern int gDeviceCount;
* ATTENTION: the enum and the following array images[] MUST match !!!
*/
enum {
iBackground = 0,
iLogo,
iBackground = 0,
iLogo,
iDeviceGeneric,
iDeviceHFS,
iDeviceEXT3,
iDeviceFAT16,
iDeviceFAT32,
iDeviceNTFS,
iDeviceCDROM,
iSelection,
iDeviceScrollPrev,
iDeviceScrollNext,
iDeviceGeneric,
iDeviceGeneric_o,
iDeviceHFS,
iDeviceHFS_o,
iDeviceEXT3,
iDeviceEXT3_o,
iDeviceFAT16,
iDeviceFAT16_o,
iDeviceFAT32,
iDeviceFAT32_o,
iDeviceNTFS,
iDeviceNTFS_o,
iDeviceCDROM,
iDeviceCDROM_o,
iMenuBoot,
iMenuVerbose,
iMenuIgnoreCaches,
iMenuSingleUser,
iMenuMemoryInfo,
iMenuVideoInfo,
iMenuHelp,
iMenuVerboseDisabled,
iMenuIgnoreCachesDisabled,
iMenuSingleUserDisabled,
iMenuSelection,
iSelection,
iDeviceScrollPrev,
iDeviceScrollNext,
iProgressBar,
iProgressBarBackground,
iMenuBoot,
iMenuVerbose,
iMenuIgnoreCaches,
iMenuSingleUser,
iMenuMemoryInfo,
iMenuVideoInfo,
iMenuHelp,
iMenuVerboseDisabled,
iMenuIgnoreCachesDisabled,
iMenuSingleUserDisabled,
iMenuSelection,
iTextScrollPrev,
iTextScrollNext,
iProgressBar,
iProgressBarBackground,
iFontConsole,
iFontSmall,
iTextScrollPrev,
iTextScrollNext,
iFontConsole,
iFontSmall,
};
image_t images[] = {
{.name = "background",.image = NULL},
{.name = "logo",.image = NULL},
{.name = "background", .image = NULL},
{.name = "logo", .image = NULL},
{.name = "device_generic", .image = NULL},
{.name = "device_generic_o", .image = NULL},
{.name = "device_hfsplus", .image = NULL},
{.name = "device_hfsplus_o", .image = NULL},
{.name = "device_ext3", .image = NULL},
{.name = "device_ext3_o", .image = NULL},
{.name = "device_fat16", .image = NULL},
{.name = "device_fat16_o", .image = NULL},
{.name = "device_fat32", .image = NULL},
{.name = "device_fat32_o", .image = NULL},
{.name = "device_ntfs", .image = NULL},
{.name = "device_ntfs_o", .image = NULL},
{.name = "device_cdrom", .image = NULL},
{.name = "device_cdrom_o", .image = NULL},
{.name = "device_generic",.image = NULL},
{.name = "device_hfsplus",.image = NULL},
{.name = "device_ext3",.image = NULL},
{.name = "device_fat16",.image = NULL},
{.name = "device_fat32",.image = NULL},
{.name = "device_ntfs",.image = NULL},
{.name = "device_cdrom",.image = NULL},
{.name = "device_selection",.image = NULL},
{.name = "device_scroll_prev",.image = NULL},
{.name = "device_scroll_next",.image = NULL},
{.name = "menu_boot",.image = NULL},
{.name = "menu_verbose",.image = NULL},
{.name = "menu_ignore_caches",.image = NULL},
{.name = "menu_single_user",.image = NULL},
{.name = "menu_memory_info",.image = NULL},
{.name = "menu_video_info",.image = NULL},
{.name = "menu_help",.image = NULL},
{.name = "menu_verbose_disabled",.image = NULL},
{.name = "menu_ignore_caches_disabled",.image = NULL},
{.name = "menu_single_user_disabled",.image = NULL},
{.name = "menu_selection",.image = NULL},
{.name = "progress_bar",.image = NULL},
{.name = "progress_bar_background",.image = NULL},
{.name = "text_scroll_prev",.image = NULL},
{.name = "text_scroll_next",.image = NULL},
{.name = "font_console",.image = NULL},
{.name = "font_small",.image = NULL},
{.name = "device_selection", .image = NULL},
{.name = "device_scroll_prev", .image = NULL},
{.name = "device_scroll_next", .image = NULL},
{.name = "menu_boot", .image = NULL},
{.name = "menu_verbose", .image = NULL},
{.name = "menu_ignore_caches", .image = NULL},
{.name = "menu_single_user", .image = NULL},
{.name = "menu_memory_info", .image = NULL},
{.name = "menu_video_info", .image = NULL},
{.name = "menu_help", .image = NULL},
{.name = "menu_verbose_disabled", .image = NULL},
{.name = "menu_ignore_caches_disabled", .image = NULL},
{.name = "menu_single_user_disabled", .image = NULL},
{.name = "menu_selection", .image = NULL},
{.name = "progress_bar", .image = NULL},
{.name = "progress_bar_background", .image = NULL},
{.name = "text_scroll_prev", .image = NULL},
{.name = "text_scroll_next", .image = NULL},
{.name = "font_console", .image = NULL},
{.name = "font_small", .image = NULL},
};
int imageCnt = 0;
static unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};// here we store the used screen resolution
static int getImageIndexByName(const char *name)
{
int i;
for (i = 0; i < sizeof(images) / sizeof(images[0]); i++)
{
if (strcmp(name, images[i].name) == 0)
return i; // found the name
}
return -1;
}
#ifdef EMBED_THEME
static int loadEmbeddedThemeImage(const char *image, unsigned char *image_data, unsigned int image_size)
static int loadEmbeddedThemeImage(const char *image, unsigned char *image_data, unsigned int image_size, int alt_image)
{
inti;
uint16_twidth;
uint16_theight;
uint8_t*imagedata;
for (i=0; i < sizeof(images) / sizeof(images[0]); i++) {
if (strcmp(image, images[i].name) == 0) {
if (images[i].image == NULL) {
images[i].image = malloc(sizeof(pixmap_t));
}
width = 0;
height = 0;
imagedata = NULL;
if ((loadEmbeddedPngImage(image_data, image_size, &width, &height, &imagedata)) != 0) {
return 1;
}
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
}
if ((i = getImageIndexByName(image)) >= 0)
{
if (images[i].image == NULL) {
images[i].image = malloc(sizeof(pixmap_t));
}
width = 0;
height = 0;
imagedata = NULL;
if (image_size > 0 && (loadEmbeddedPngImage(image_data, image_size, &width, &height, &imagedata)) == 0)
{
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
else if (alt_image != IMG_REQUIRED && images[alt_image].image->pixels != NULL)
{
// Using the passed alternate image for non-mandatory images.
// We don't clone the already existing pixmap, but using its properties instead!
images[i].image->width = images[alt_image].image->width;
images[i].image->height = images[alt_image].image->height;
images[i].image->pixels = images[alt_image].image->pixels;
return 0;
}
}
return 1;
}
#endif
static int loadThemeImage(const char *image)
static int loadThemeImage(const char *image, int alt_image)
{
chardirspec[256];
inti;
int i;
uint16_twidth;
uint16_theight;
uint8_t*imagedata;
if ((strlen(image) + strlen(theme_name) + 20 ) > sizeof(dirspec)) {
return 1;
}
for (i=0; i < sizeof(images) / sizeof(images[0]); i++) {
if (strcmp(image, images[i].name) == 0) {
if (images[i].image == NULL) {
images[i].image = malloc(sizeof(pixmap_t));
}
sprintf(dirspec,"/Extra/Themes/%s/%s.png", theme_name, image);
width = 0;
height = 0;
imagedata = NULL;
if ((loadPngImage(dirspec, &width, &height, &imagedata)) != 0) {
if ((i = getImageIndexByName(image)) >= 0)
{
if (images[i].image == NULL) {
images[i].image = malloc(sizeof(pixmap_t));
}
sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image);
width = 0;
height = 0;
imagedata = NULL;
if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0)
{
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
else if (alt_image != IMG_REQUIRED && images[alt_image].image->pixels != NULL)
{
// Using the passed alternate image for non-mandatory images.
// We don't clone the already existing pixmap, but using its properties instead!
images[i].image->width = images[alt_image].image->width;
images[i].image->height = images[alt_image].image->height;
images[i].image->pixels = images[alt_image].image->pixels;
return 0;
}
else
{
#ifndef EMBED_THEME
printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);
sleep(2);
printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image);
sleep(2);
#endif
return 1;
}
images[i].image->width = width;
images[i].image->height = height;
images[i].image->pixels = (pixel_t *)imagedata;
flipRB(images[i].image);
return 0;
}
}
return 1;
}
}
return 1;
}
static int loadGraphics(void)
{
LOADPNG(background);
LOADPNG(logo);
LOADPNG(background, IMG_REQUIRED);
LOADPNG(logo, IMG_REQUIRED);
LOADPNG(device_generic);
LOADPNG(device_hfsplus);
LOADPNG(device_ext3);
LOADPNG(device_fat16);
LOADPNG(device_fat32);
LOADPNG(device_ntfs);
LOADPNG(device_cdrom);
LOADPNG(device_selection);
LOADPNG(device_scroll_prev);
LOADPNG(device_scroll_next);
LOADPNG(device_generic, IMG_REQUIRED);
LOADPNG(device_generic_o, iDeviceGeneric);
LOADPNG(device_hfsplus, iDeviceGeneric);
LOADPNG(device_hfsplus_o, iDeviceGeneric_o);
LOADPNG(device_ext3, iDeviceGeneric);
LOADPNG(device_ext3_o, iDeviceGeneric_o);
LOADPNG(device_fat16, iDeviceGeneric);
LOADPNG(device_fat16_o, iDeviceGeneric_o);
LOADPNG(device_fat32, iDeviceGeneric);
LOADPNG(device_fat32_o, iDeviceGeneric_o);
LOADPNG(device_ntfs, iDeviceGeneric);
LOADPNG(device_ntfs_o, iDeviceGeneric_o);
LOADPNG(device_cdrom, iDeviceGeneric);
LOADPNG(device_cdrom_o, iDeviceGeneric_o);
LOADPNG(menu_boot);
LOADPNG(menu_verbose);
LOADPNG(menu_ignore_caches);
LOADPNG(menu_single_user);
LOADPNG(menu_memory_info);
LOADPNG(menu_video_info);
LOADPNG(menu_help);
LOADPNG(menu_verbose_disabled);
LOADPNG(menu_ignore_caches_disabled);
LOADPNG(menu_single_user_disabled);
LOADPNG(menu_selection);
LOADPNG(device_selection, IMG_REQUIRED);
LOADPNG(device_scroll_prev, IMG_REQUIRED);
LOADPNG(device_scroll_next, IMG_REQUIRED);
LOADPNG(progress_bar);
LOADPNG(progress_bar_background);
LOADPNG(menu_boot, IMG_REQUIRED);
LOADPNG(menu_verbose, IMG_REQUIRED);
LOADPNG(menu_ignore_caches, IMG_REQUIRED);
LOADPNG(menu_single_user, IMG_REQUIRED);
LOADPNG(menu_memory_info, IMG_REQUIRED);
LOADPNG(menu_video_info, IMG_REQUIRED);
LOADPNG(menu_help, IMG_REQUIRED);
LOADPNG(menu_verbose_disabled, IMG_REQUIRED);
LOADPNG(menu_ignore_caches_disabled, IMG_REQUIRED);
LOADPNG(menu_single_user_disabled, IMG_REQUIRED);
LOADPNG(menu_selection, IMG_REQUIRED);
LOADPNG(text_scroll_prev);
LOADPNG(text_scroll_next);
LOADPNG(progress_bar, IMG_REQUIRED);
LOADPNG(progress_bar_background, IMG_REQUIRED);
LOADPNG(font_console);
LOADPNG(font_small);
LOADPNG(text_scroll_prev, IMG_REQUIRED);
LOADPNG(text_scroll_next, IMG_REQUIRED);
LOADPNG(font_console, IMG_REQUIRED);
LOADPNG(font_small, IMG_REQUIRED);
initFont( &font_console, &images[iFontConsole]);
initFont( &font_small, &images[iFontSmall]);
colorFont(&font_small, gui.screen.font_small_color);
colorFont(&font_console, gui.screen.font_console_color);
// use the alternate images for the selected item if available.
useRollOver = (images[iDeviceGeneric].image->pixels != images[iDeviceGeneric_o].image->pixels) ? true : false;
// create the screen & window buffers
if (createBackBuffer(&gui.screen) == 0) {
if (createWindowBuffer(&gui.screen) == 0) {
return 1;
}
void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p)
void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p, bool isSelected)
{
int devicetype;
}
}
// Use the next (device_*_o) image for the selected item if available.
if (isSelected && useRollOver) devicetype++;
// draw icon
blend( images[devicetype].image, buffer, centeredAt( images[devicetype].image, p ));
}
// draw visible device icons
for ( i=0; i < gui.maxdevices; i++ )
for (i = 0; i < gui.maxdevices; i++)
{
BVRef param = menuItems[start+i].param;
BVRef param = menuItems[start + i].param;
if((start+i) == selection)
bool isSelected = ((start + i) == selection) ? true : false;
if (isSelected)
{
if(param->flags & kBVFlagNativeBoot)
infoMenuNativeBoot = true;
else
{
infoMenuNativeBoot = false;
if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
infoMenuSelection = 0;
}
if (param->flags & kBVFlagNativeBoot)
{
infoMenuNativeBoot = true;
}
else
{
infoMenuNativeBoot = false;
if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END)
infoMenuSelection = 0;
}
if(gui.menu.draw)
drawInfoMenuItems();
blend( images[iSelection].image, gui.devicelist.pixmap, centeredAt( images[iSelection].image, p ) );
#if DEBUG
gui.debug.cursor = pos( 10, 100);
dprintf( &gui.screen, "label %s\n", param->label );
dprintf( &gui.screen, "biosdev 0x%x\n", param->biosdev );
dprintf(&gui.screen, "width %d\n", gui.screen.width);
dprintf(&gui.screen, "height %d\n", gui.screen.height);
dprintf( &gui.screen, "type 0x%x\n", param->type );
dprintf( &gui.screen, "flags 0x%x\n", param->flags );
dprintf( &gui.screen, "part_no %d\n", param->part_no );
dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );
dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );
dprintf( &gui.screen, "bps 0x%x\n", param->bps );
dprintf( &gui.screen, "name %s\n", param->name );
dprintf( &gui.screen, "type_name %s\n", param->type_name );
dprintf( &gui.screen, "modtime %d\n", param->modTime );
gui.debug.cursor = pos( 10, 100);
dprintf( &gui.screen, "label %s\n", param->label );
dprintf( &gui.screen, "biosdev 0x%x\n", param->biosdev );
dprintf(&gui.screen, "width %d\n", gui.screen.width);
dprintf(&gui.screen, "height %d\n", gui.screen.height);
dprintf( &gui.screen, "type 0x%x\n", param->type );
dprintf( &gui.screen, "flags 0x%x\n", param->flags );
dprintf( &gui.screen, "part_no %d\n", param->part_no );
dprintf( &gui.screen, "part_boff 0x%x\n", param->part_boff );
dprintf( &gui.screen, "part_type 0x%x\n", param->part_type );
dprintf( &gui.screen, "bps 0x%x\n", param->bps );
dprintf( &gui.screen, "name %s\n", param->name );
dprintf( &gui.screen, "type_name %s\n", param->type_name );
dprintf( &gui.screen, "modtime %d\n", param->modTime );
#endif
}
drawDeviceIcon( param, gui.devicelist.pixmap, p );
drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
if (gui.layout == HorizontalLayout)
{

Archive Download the corresponding diff file

Revision: 225