File: ex_noframe.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 (96 lines) | stat: -rw-r--r-- 2,570 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
93
94
95
96
#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"

#include <stdio.h>

#include "common.c"

int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *bitmap;
   ALLEGRO_EVENT_QUEUE *events;
   ALLEGRO_EVENT event;
   bool down = false;
   int down_x = 0, down_y = 0;
   ALLEGRO_TIMER *timer;

   (void)argc;
   (void)argv;

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

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

   al_set_new_display_flags(ALLEGRO_FRAMELESS);
   display = al_create_display(300, 200);
   if (!display) {
      abort_example("Error creating display\n");
   }
   
   bitmap = al_load_bitmap("data/fakeamp.bmp");
   if (!bitmap) {
      abort_example("Error loading fakeamp.bmp\n");
   }

   timer = al_create_timer(1.0f/30.0f);

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

   al_start_timer(timer);

   for (;;) {
      al_wait_for_event(events, &event);
      if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
         if (event.mouse.button == 1 && event.mouse.x) {
            down = true;
            down_x = event.mouse.x;
            down_y = event.mouse.y;
         }
         if (event.mouse.button == 2) {
            al_set_display_flag(display, ALLEGRO_FRAMELESS,
               !(al_get_display_flags(display) & ALLEGRO_FRAMELESS));
         }
      }
      else if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
      else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
         if (event.mouse.button == 1) {
            down = false;
         }
      }
      else if (event.type == ALLEGRO_EVENT_MOUSE_AXES) {
         if (down) {
            int cx, cy;
            if (al_get_mouse_cursor_position(&cx, &cy)) {
               al_set_window_position(display, cx - down_x, cy - down_y);
            }
         }
      }
      else if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
	    event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
      else if (event.type == ALLEGRO_EVENT_TIMER) {
         al_draw_bitmap(bitmap, 0, 0, 0);
         al_flip_display();
      }
   }

   al_destroy_timer(timer);
   al_destroy_event_queue(events);
   al_destroy_display(display);

   return 0;
}