1 /* An example showing how to set the title of a window, by Beoran. */
2 
3 #include <allegro5/allegro.h>
4 #include <allegro5/allegro_image.h>
5 #include <allegro5/allegro_font.h>
6 
7 #include "common.c"
8 
9 #define INTERVAL 1.0
10 
11 
12 float bmp_x = 200;
13 float bmp_y = 200;
14 float bmp_dx = 96;
15 float bmp_dy = 96;
16 int bmp_flag = 0;
17 
18 #define NEW_WINDOW_TITLE "A Custom Window Title. Press space to start changing it."
19 #define TITLE_SIZE 256
20 
main(int argc,char ** argv)21 int main(int argc, char **argv)
22 {
23    ALLEGRO_DISPLAY *display;
24    ALLEGRO_TIMER *timer;
25    ALLEGRO_EVENT_QUEUE *queue;
26    ALLEGRO_FONT *font;
27    int step = 0;
28    const char *text;
29    char   title[TITLE_SIZE] = "";
30    bool done = false;
31    bool redraw = true;
32 
33    (void)argc;
34    (void)argv;
35 
36    if (!al_init()) {
37       abort_example("Failed to init Allegro.\n");
38    }
39 
40    if (!al_init_image_addon()) {
41       abort_example("Failed to init IIO addon.\n");
42    }
43 
44    al_init_font_addon();
45    init_platform_specific();
46 
47    text = NEW_WINDOW_TITLE;
48 
49    al_set_new_window_title(NEW_WINDOW_TITLE);
50 
51    display = al_create_display(640, 480);
52    if (!display) {
53       abort_example("Error creating display.\n");
54    }
55 
56    if (!al_install_keyboard()) {
57       abort_example("Error installing keyboard.\n");
58    }
59 
60    font = al_load_font("data/fixed_font.tga", 0, 0);
61    if (!font) {
62       abort_example("Error loading data/fixed_font.tga\n");
63    }
64 
65    text = al_get_new_window_title();
66 
67    timer = al_create_timer(INTERVAL);
68 
69    queue = al_create_event_queue();
70    al_register_event_source(queue, al_get_keyboard_event_source());
71    al_register_event_source(queue, al_get_timer_event_source(timer));
72    al_register_event_source(queue, al_get_display_event_source(display));
73 
74 
75 
76    while (!done) {
77       ALLEGRO_EVENT event;
78 
79       if (redraw && al_is_event_queue_empty(queue)) {
80          al_clear_to_color(al_map_rgb_f(0, 0, 0));
81          al_draw_text(font, al_map_rgba_f(1, 1, 1, 0.5), 0, 0, 0, text);
82          al_flip_display();
83          redraw = false;
84       }
85 
86       al_wait_for_event(queue, &event);
87       switch (event.type) {
88          case ALLEGRO_EVENT_KEY_DOWN:
89             if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
90                done = true;
91             else if (event.keyboard.keycode == ALLEGRO_KEY_SPACE)
92                al_start_timer(timer);
93             break;
94 
95          case ALLEGRO_EVENT_DISPLAY_CLOSE:
96             done = true;
97             break;
98 
99          case ALLEGRO_EVENT_TIMER:
100             redraw = true;
101             step++;
102             sprintf(title, "Title: %d", step);
103             text = title;
104             al_set_window_title(display, title);
105             break;
106       }
107    }
108 
109    return 0;
110 }
111 
112 /* vim: set sts=3 sw=3 et: */
113