File: ex_expose.c

package info (click to toggle)
allegro5 2%3A5.2.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,820 kB
  • sloc: ansic: 109,795; cpp: 12,976; objc: 4,592; java: 2,845; python: 2,595; javascript: 1,238; sh: 1,008; makefile: 40; xml: 27; pascal: 24
file content (92 lines) | stat: -rw-r--r-- 2,807 bytes parent folder | download | duplicates (5)
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
91
92
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>

#include "common.c"

int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *bitmap;
   ALLEGRO_TIMER *timer;
   ALLEGRO_EVENT_QUEUE *queue;

   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_init_primitives_addon();
   al_init_image_addon();
   al_install_keyboard();
   al_install_mouse();
   init_platform_specific();

   al_set_new_display_flags(ALLEGRO_RESIZABLE |
      ALLEGRO_GENERATE_EXPOSE_EVENTS);
   al_set_new_display_option(ALLEGRO_SINGLE_BUFFER, true, ALLEGRO_REQUIRE);
   display = al_create_display(320, 200);
   if (!display) {
      abort_example("Error creating display\n");
   }

   bitmap = al_load_bitmap("data/mysha.pcx");
   if (!bitmap) {
      abort_example("mysha.pcx not found or failed to load\n");
   }
   al_draw_bitmap(bitmap, 0, 0, 0);
   al_flip_display();

   timer = al_create_timer(0.1);

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_mouse_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));
   al_register_event_source(queue, al_get_timer_event_source(timer));
   al_start_timer(timer);

   while (true) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);
      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
            break;
      if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
         event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
      if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
         al_acknowledge_resize(event.display.source);
      }
      if (event.type == ALLEGRO_EVENT_DISPLAY_EXPOSE) {
         int x = event.display.x,
            y = event.display.y, 
            w = event.display.width,
            h = event.display.height;
         /* Draw a red rectangle over the damaged area. */
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
         al_draw_filled_rectangle(x, y, x + w, y + h, al_map_rgba_f(1, 0, 0, 1));
         al_flip_display();
      }
      if (event.type == ALLEGRO_EVENT_TIMER) {
         /* Slowly restore the original bitmap. */
         int x, y;
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
         for (y = 0; y < al_get_display_height(display); y += 200) {
            for (x = 0; x < al_get_display_width(display); x += 320) {
               al_draw_tinted_bitmap(bitmap, al_map_rgba_f(1, 1, 1, 0.1), x, y, 0);
            }
         }
         al_flip_display();
      }
   }

   al_destroy_event_queue(queue);
   al_destroy_bitmap(bitmap);

   return 0;
}

/* vim: set sts=3 sw=3 et: */