static void test_relative_timeout(ALLEGRO_EVENT_QUEUE *queue)
{
   ALLEGRO_EVENT event;
   float shade = 0.1;

   while (true) {
      if (al_wait_for_event_timed(queue, &event, 0.1)) {
         if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
               return;
            }
            else {
               shade = 0.1;
            }
         }
      }
      else {
         /* timed out */
         shade += 0.1;
         if (shade > 1.0)
            shade = 1.0;
      }

      al_clear_to_color(al_map_rgba_f(0.5 * shade, 0.25 * shade, shade, 0));
      al_flip_display();
   }
}
static void main_loop(void)
{
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;
   bool redraw = true;

   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));

   theta = 0.0;

   for (;;) {
      if (redraw && al_is_event_queue_empty(queue)) {
         draw();
         redraw = false;
      }

      if (!al_wait_for_event_timed(queue, &event, 1.0/FPS)) {
         redraw = true;
         continue;
      }

      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
      if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
            event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
         break;
      }
   }

   al_destroy_event_queue(queue);
}
Esempio n. 3
0
static void *sound_update_proc(ALLEGRO_THREAD *thread, void *arg)
{
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;
   (void)arg;

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_timer_event_source(ping_timer));
   if (music_timer)
      al_register_event_source(queue, al_get_timer_event_source(music_timer));

   while (!al_get_thread_should_stop(thread)) {
      if (!al_wait_for_event_timed(queue, &event, 0.25))
	 continue;

      if (event.any.source == (void *)music_timer)
	 music_player();

      if (event.any.source == (void *)ping_timer) {
	 if (!ping_proc())
	    al_stop_timer(ping_timer);
      }
   }

   al_destroy_event_queue(queue);

   return NULL;
}
Esempio n. 4
0
static int allua_Event_queue_wait_for_event_timed(lua_State * L)
{
   ALLUA_event_queue event_queue = allua_check_event_queue(L, 1);
   float secs = luaL_checknumber(L, 2);
   ALLEGRO_EVENT event;
   bool got_event = al_wait_for_event_timed(event_queue, &event, secs);
   return allua_Event_queue_get_event_common(L, got_event, &event);
}
Esempio n. 5
0
int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *displays[2];
   ALLEGRO_MONITOR_INFO *info;
   int adapter_count;
   int x, y;
   ALLEGRO_FONT *myfont;
   ALLEGRO_EVENT_QUEUE *events;
   ALLEGRO_EVENT event;
   int i;

   (void)argc;
   (void)argv;

   srand(time(NULL));

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

   al_install_mouse();
   al_init_font_addon();
   al_init_image_addon();

   adapter_count = al_get_num_video_adapters();

   info = malloc(adapter_count * sizeof(ALLEGRO_MONITOR_INFO));

   for (i = 0; i < adapter_count; i++) {
      al_get_monitor_info(i, &info[i]);
   }

   x = ((info[0].x2 - info[0].x1) / 3) - (W / 2);
   y = ((info[0].y2 - info[0].y1) / 2) - (H / 2);

   al_set_new_window_position(x, y);

   displays[0] = al_create_display(W, H);

   x *= 2;
   al_set_new_window_position(x, y);

   displays[1] = al_create_display(W, H);

   if (!displays[0] || !displays[1]) {
      abort_example("Could not create displays.\n");
   }

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   myfont = al_load_font("data/fixed_font.tga", 0, 0);
   if (!myfont) {
      abort_example("Could not load font.\n");
   }

   events = al_create_event_queue();
   al_register_event_source(events, al_get_mouse_event_source());
   al_register_event_source(events, al_get_display_event_source(displays[0]));
   al_register_event_source(events, al_get_display_event_source(displays[1]));

   for (;;) {
      for (i = 0; i < 2; i++) {
        al_set_target_backbuffer(displays[i]);
        al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
        if (i == 0)
           al_clear_to_color(al_map_rgb(255, 0, 255));
        else
           al_clear_to_color(al_map_rgb(155, 255, 0));
        al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
        al_draw_textf(myfont, al_map_rgb(0, 0, 0), 50, 50, ALLEGRO_ALIGN_CENTRE, "Click me..");
        al_flip_display();
      }

      if (al_wait_for_event_timed(events, &event, 1)) {
         if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
            break;
         }
         else if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
            int a = rand() % adapter_count;
            int w = info[a].x2 - info[a].x1;
            int h = info[a].y2 - info[a].y1;
            int margin = 20;
            x = margin + info[a].x1 + (rand() % (w - W - margin));
            y = margin + info[a].y1 + (rand() % (h - H - margin));
            al_set_window_position(event.mouse.display, x, y);
         }
      }
   }

   al_destroy_event_queue(events);

   al_destroy_display(displays[0]);
   al_destroy_display(displays[1]);

   free(info);

   return 0;
}
Esempio n. 6
0
int WPJInputUtil::PeekEvent(ALLEGRO_EVENT &e)
{
	return al_wait_for_event_timed(m_pEventQueue, &e, 0.001f);
}