Пример #1
0
/* Function: al_shutdown_native_dialog_addon
 */
void al_shutdown_native_dialog_addon(void)
{
   if (inited_addon) {
      al_destroy_user_event_source(al_get_default_menu_event_source());
      _al_shutdown_native_dialog_addon();
      inited_addon = false;
   }
}
Пример #2
0
int main(int argc, char **argv)
{
   ALLEGRO_EVENT_SOURCE fake_src;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT fake_keydown_event, fake_joystick_event;
   ALLEGRO_EVENT event;

   (void)argc;
   (void)argv;

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

   open_log();

   /* register our 'fake' event source with the queue */
   al_init_user_event_source(&fake_src);
   queue = al_create_event_queue();
   al_register_event_source(queue, &fake_src);

   /* fake a joystick event */
   fake_joystick_event.any.type = ALLEGRO_EVENT_JOYSTICK_AXIS;
   fake_joystick_event.joystick.stick = 1;
   fake_joystick_event.joystick.axis = 0;
   fake_joystick_event.joystick.pos = 0.5;
   al_emit_user_event(&fake_src, &fake_joystick_event, NULL);

   /* fake a keyboard event */
   fake_keydown_event.any.type = ALLEGRO_EVENT_KEY_DOWN;
   fake_keydown_event.keyboard.keycode = ALLEGRO_KEY_ENTER;
   al_emit_user_event(&fake_src, &fake_keydown_event, NULL);

   /* poll for the events we injected */
   while (!al_is_event_queue_empty(queue)) {
      al_wait_for_event(queue, &event);

      switch (event.type) {
         case ALLEGRO_EVENT_KEY_DOWN:
            ALLEGRO_ASSERT(event.user.source == &fake_src);
            log_printf("Got keydown: %d\n", event.keyboard.keycode);
            break;
         case ALLEGRO_EVENT_JOYSTICK_AXIS:
            ALLEGRO_ASSERT(event.user.source == &fake_src);
            log_printf("Got joystick axis: stick=%d axis=%d pos=%f\n",
               event.joystick.stick, event.joystick.axis, event.joystick.pos);
            break;
      }
   }

   al_destroy_user_event_source(&fake_src);
   al_destroy_event_queue(queue);

   log_printf("Done.\n");
   close_log(true);

   return 0;
}
Пример #3
0
/* Function: al_disable_menu_event_source
 */
void al_disable_menu_event_source(ALLEGRO_MENU *menu)
{
   ASSERT(menu);

   if (menu->is_event_source) {
      al_destroy_user_event_source(&menu->es);
      menu->is_event_source = false;
   }
}
Пример #4
0
/* Function: al_close_video
 */
void al_close_video(ALLEGRO_VIDEO *video)
{
   if (video) {
      video->vtable->close_video(video);
      if (video->es_inited) {
         al_destroy_user_event_source(&video->es);
      }
      al_destroy_path(video->filename);
      al_free(video);
   }
}
Пример #5
0
/* Function: al_destroy_audio_stream
 */
void al_destroy_audio_stream(ALLEGRO_AUDIO_STREAM *stream)
{
   if (stream) {
      if (stream->feed_thread) {
         stream->unload_feeder(stream);
      }
      /* See commented out call to _al_kcm_register_destructor. */
      /* _al_kcm_unregister_destructor(stream); */
      _al_kcm_detach_from_parent(&stream->spl);

      al_destroy_user_event_source(&stream->spl.es);
      al_free(stream->main_buffer);
      al_free(stream->used_bufs);
      al_free(stream);
   }
}
/* Function: al_close_native_text_log
 */
void al_close_native_text_log(ALLEGRO_TEXTLOG *textlog)
{
   ALLEGRO_NATIVE_DIALOG *dialog = (ALLEGRO_NATIVE_DIALOG *)textlog;

   if (!dialog)
      return;

   if (!dialog->tl_init_error) {
      dialog->tl_done = false;

      if (TEXT_LOG_EXTRA_THREAD) {
         al_lock_mutex(dialog->tl_text_mutex);
         _al_close_native_text_log(dialog);
         while (!dialog->tl_done) {
            al_wait_cond(dialog->tl_text_cond, dialog->tl_text_mutex);
         }
      }
      else {
         _al_close_native_text_log(dialog);
         al_lock_mutex(dialog->tl_text_mutex);
      }

      _al_unregister_destructor(_al_dtor_list, dialog);
   }

   al_ustr_free(dialog->title);
   al_ustr_free(dialog->tl_pending_text);

   al_destroy_user_event_source(&dialog->tl_events);

   al_unlock_mutex(dialog->tl_text_mutex);

   if (TEXT_LOG_EXTRA_THREAD) {
      al_destroy_thread(dialog->tl_thread);
   }
   al_destroy_cond(dialog->tl_text_cond);
   al_destroy_mutex(dialog->tl_text_mutex);
   al_free(dialog);
}
Пример #7
0
/*
Title: Widget

Section: Internal

Function: wz_widget_proc

Callback function that handles the operations of a general widget.
All widget procs call this function as their default handler.

Returns:

1 if the event was handled by the widget, 0 otherwise
*/
int wz_widget_proc(WZ_WIDGET* wgt, ALLEGRO_EVENT* event)
{
	int ret = 1;
	switch (event->type)
	{
		case WZ_HIDE:
		{
			wgt->flags |= WZ_STATE_HIDDEN;
			break;
		}
		case WZ_SHOW:
		{
			wgt->flags &= ~WZ_STATE_HIDDEN;
			break;
		}
		case WZ_DISABLE:
		{
			wgt->flags |= WZ_STATE_DISABLED;
			break;
		}
		case WZ_ENABLE:
		{
			wgt->flags &= ~WZ_STATE_DISABLED;
			break;
		}
		case WZ_UPDATE_POSITION:
		{
			if (wgt->parent)
			{
				wgt->local_x = wgt->parent->local_x + wgt->x;
				wgt->local_y = wgt->parent->local_y + wgt->y;
			}
			else
			{
				wgt->local_x = wgt->x;
				wgt->local_y = wgt->y;
			}
			break;
		}
		case WZ_DESTROY:
		{
			al_destroy_user_event_source(wgt->source);
			free(wgt->source);
			free(wgt);
			break;
		}
		case WZ_LOSE_FOCUS:
		{
			wgt->flags &= ~WZ_STATE_HAS_FOCUS;
			break;
		}
		case WZ_TAKE_FOCUS:
		{
			wz_focus(wgt, 0);
			wgt->flags |= WZ_STATE_HAS_FOCUS;
			if (wgt->first_child)
				wz_focus(wgt->first_child, 1);
			break;
		}
		case WZ_WANT_FOCUS:
		{
			WZ_WIDGET* child = wgt->first_child;
			while (child)
			{
				wz_focus(child, 0);
				child = child->next_sib;
			}
			{
			ALLEGRO_EVENT ev;
			wz_craft_event(&ev, WZ_TAKE_FOCUS, wgt, 0);
			
			child = wgt->first_child;
			wz_send_event((WZ_WIDGET*)event->user.data2, &ev);
			}
			break;
		}
		case ALLEGRO_EVENT_MOUSE_AXES:
		{
			if (wgt->flags & WZ_STATE_DISABLED)
			{
				ret = 0;
			}
			else if (event->mouse.dz != 0 && wgt->first_child == 0 && wgt->parent != 0)
			{
				if (event->mouse.dz > 0)
				{
					wz_ask_parent_to_focus_prev(wgt);
				}
				else
				{
					wz_ask_parent_to_focus_next(wgt);
				}
			}
			else
			{
				ret = 0;
			}
			break;
		}
		/* Switch through elements on Touch:
		case ALLEGRO_EVENT_TOUCH_BEGIN:
		{
			if (wgt->flags & WZ_STATE_DISABLED)
			{
				ret = 0;
			}
			else if (wgt->first_child == 0 && wgt->parent != 0)
			{
				wz_ask_parent_to_focus_next(wgt);
			}
			else
			{
				ret = 0;
			}
			break;
		}
		*/
		case ALLEGRO_EVENT_KEY_CHAR:
		{
			if(event->keyboard.keycode == wgt->shortcut.keycode && ((event->keyboard.modifiers & wgt->shortcut.modifiers) || wgt->shortcut.modifiers == 0))
			{
				ALLEGRO_EVENT ev;
				wz_craft_event(&ev, WZ_HANDLE_SHORTCUT, wgt, 0);
				wz_send_event(wgt, &ev);
			}
			else
			{
				switch (event->keyboard.keycode)
				{
					case ALLEGRO_KEY_TAB:
					{
						if (wgt->first_child != 0)
						{
							ret = 0;
						}
						else if (event->keyboard.modifiers & 1)
						{
							wz_ask_parent_to_focus_prev(wgt);
						}
						else
						{
							wz_ask_parent_to_focus_next(wgt);
						}
						break;
					}
					case ALLEGRO_KEY_UP:
					{
						if (wgt->first_child != 0)
						{
							ret = 0;
						}
						else if (wgt->parent != 0)
						{
							wz_ask_parent_for_focus(wz_get_widget_dir(wgt, 0));
						}
						else
							ret = 0;
						break;
					}
					case ALLEGRO_KEY_RIGHT:
					{
						if (wgt->first_child != 0)
						{
							ret = 0;
						}
						else if (wgt->parent != 0)
						{
							wz_ask_parent_for_focus(wz_get_widget_dir(wgt, 1));
						}
						else
							ret = 0;
						break;
					}
					case ALLEGRO_KEY_DOWN:
					{
						if (wgt->first_child != 0)
						{
							ret = 0;
						}
						else if (wgt->parent != 0)
						{
							wz_ask_parent_for_focus(wz_get_widget_dir(wgt, 2));
						}
						else
							ret = 0;
						break;
					}
					case ALLEGRO_KEY_LEFT:
					{
						if (wgt->first_child != 0)
						{
							ret = 0;
						}
						else if (wgt->parent != 0)
						{
							wz_ask_parent_for_focus(wz_get_widget_dir(wgt, 3));
						}
						else
							ret = 0;
						break;
					}
					default:
						ret = 0;
				}
			}
			break;
		}
		default:
			ret = 0;
	}
	return ret;
}
Пример #8
0
void AllegroEventSource::destroy()
{
    al_destroy_user_event_source(&event_source);
}
Пример #9
0
Mouse::~Mouse()
{
	al_unregister_event_source( EventQueue, &mouseEventSource );
	al_destroy_event_queue( mouseQueue );
	al_destroy_user_event_source( &mouseEventSource );
}
int main(void)
{
   ALLEGRO_TIMER *timer;
   ALLEGRO_EVENT_SOURCE user_src;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT user_event;
   ALLEGRO_EVENT event;

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

   timer = al_create_timer(0.5);
   if (!timer) {
      abort_example("Could not install timer.\n");
      return 1;
   }

   open_log();

   al_init_user_event_source(&user_src);

   queue = al_create_event_queue();
   al_register_event_source(queue, &user_src);
   al_register_event_source(queue, al_get_timer_event_source(timer));

   al_start_timer(timer);

   while (true) {
      al_wait_for_event(queue, &event);

      if (event.type == ALLEGRO_EVENT_TIMER) {
         int n = event.timer.count;

         log_printf("Got timer event %d\n", n);

         user_event.user.type = MY_SIMPLE_EVENT_TYPE;
         user_event.user.data1 = n;
         al_emit_user_event(&user_src, &user_event, NULL);

         user_event.user.type = MY_COMPLEX_EVENT_TYPE;
         user_event.user.data1 = (intptr_t)new_event(n);
         al_emit_user_event(&user_src, &user_event, my_event_dtor);
      }
      else if (event.type == MY_SIMPLE_EVENT_TYPE) {
         int n = (int) event.user.data1;
         ALLEGRO_ASSERT(event.user.source == &user_src);

         al_unref_user_event(&event.user);

         log_printf("Got simple user event %d\n", n);
         if (n == 5) {
            break;
         }
      }
      else if (event.type == MY_COMPLEX_EVENT_TYPE) {
         MY_EVENT *my_event = (void *)event.user.data1;
         ALLEGRO_ASSERT(event.user.source == &user_src);

         log_printf("Got complex user event %d\n", my_event->id);
         al_unref_user_event(&event.user);
      }
   }

   al_destroy_user_event_source(&user_src);
   al_destroy_event_queue(queue);
   al_destroy_timer(timer);

   log_printf("Done.\n");
   close_log(true);

   return 0;
}
Пример #11
0
void uninstall_network()
{
	al_destroy_user_event_source( &netEventSource );
	enet_deinitialize();
}
Пример #12
0
PlayingField::~PlayingField(void) {
	deleteBlockLines();
	al_destroy_user_event_source(getEventSource());
}