-
Notifications
You must be signed in to change notification settings - Fork 279
/
ex_icon2.c
90 lines (72 loc) · 2.12 KB
/
ex_icon2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Example program for the Allegro library.
*
* Set multiple window icons, a big one and a small one.
* The small would would be used for the task bar,
* and the big one for the alt-tab popup, for example.
*/
#define ALLEGRO_UNSTABLE
#include <allegro5/allegro.h>
#include "allegro5/allegro_image.h"
#ifdef ALLEGRO_UNIX
#include <allegro5/allegro_x.h>
#endif
#include "common.c"
#define NUM_ICONS 2
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display;
ALLEGRO_BITMAP *icons[NUM_ICONS];
ALLEGRO_EVENT_QUEUE *queue;
int u, v;
(void)argc;
(void)argv;
if (!al_init()) {
abort_example("Could not init Allegro.\n");
}
al_install_keyboard();
al_init_image_addon();
init_platform_specific();
/* First icon 16x16: Read from file. */
icons[0] = al_load_bitmap("data/cursor.tga");
if (!icons[0]) {
abort_example("icons.tga not found\n");
}
#if defined(ALLEGRO_UNIX) && !defined(ALLEGRO_RASPBERRYPI)
al_x_set_initial_icon(icons[0]);
#endif
display = al_create_display(320, 200);
if (!display) {
abort_example("Error creating display\n");
}
al_clear_to_color(al_map_rgb_f(0, 0, 0));
al_flip_display();
/* Second icon 32x32: Create it. */
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
icons[1] = al_create_bitmap(32, 32);
al_set_target_bitmap(icons[1]);
for (v = 0; v < 32; v++) {
for (u = 0; u < 32; u++) {
al_put_pixel(u, v, al_map_rgb_f(u / 31.0, v / 31.0, 1));
}
}
al_set_target_backbuffer(display);
al_set_display_icons(display, NUM_ICONS, icons);
queue = al_create_event_queue();
al_register_event_source(queue, al_get_keyboard_event_source());
al_register_event_source(queue, al_get_display_event_source(display));
for (;;) {
ALLEGRO_EVENT event;
al_wait_for_event(queue, &event);
if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
break;
}
if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;
}
}
al_uninstall_system();
return 0;
}
/* vim: set sts=3 sw=3 et: */