[A5] how to trigger expose event programmatically?
axilmar

Hi all. Is there a way in Allegro 5 to trigger an expose event programmatically? I need this for my GUI in order to avoid redrawing the whole widget tree each time there is a change in a widget.

I do not want to make a user expose event, because it is dumb to have two events doing the same thing.

It would be optional, of course. The default would be to redraw the whole GUI each time, as this is more appropriate for games.

Elias
#include <allegro5/internal/aintern_events.h> // for _al_event_source_emit_event
ALLEGRO_EVENT_DISPLAY_EXPOSE event;
event.display.x = x;
event.display.y = y;
event.display.w = w;
event.display.h = h;
_al_event_source_emit_event(al_get_display_event_source(display), &event);

axilmar

I cannot compile the code after inserting the internal events header. The error is that the symbol ALLEGRO_INTERNAL_THREAD_HEADER is not found.

Elias

You always need to include allegro5/allegro.h first. Possibly also allegro5/internal/alconfig.h.

axilmar

Now I have another error, after including allegro5/allegro.h first: the macro ASSERT is not found.

EDIT:

ALLEGRO_EVENT_DISPLAY_EXPOSE is also not found.

Elias

Guess you need some more internal headers in the right order then.
Since they aren't really supposed to be used that way they don't include dependencies it seems.

Evert

I think you can just create a general event, fill in the fields mentioned by Elias in the first post (and set the event type, I think you need to do that regardless) and emit the event. Shouldn't need too many internal headers for that.

axilmar
Evert said:

I think you can just create a general event, fill in the fields mentioned by Elias in the first post (and set the event type, I think you need to do that regardless) and emit the event. Shouldn't need too many internal headers for that.

So, can I do the following?

ALLEGRO_EVENT event;
event.display.type = ALLEGRO_EVENT_DISPLAY_EXPOSE;
event.display.x = update_x;
event.display.y = update_y;
event.display.width = update_width;
event.display.height = update_height;
al_emit_user_event(al_get_display_event_source(my_display), &ev, NULL);

Evert

I think so. It depends on whether al_emit_user_event sets the evernt type for you or not, but that should be easy to check.
Mind you, the only time I made my own "user events" predates the official user events in A5, so there may be a nuance I'm missing.

Elias

Hm, not sure you can emit anything but user events with al_emit_user_event. I don't see a reason why not though so even if it doesn't work right now we probably should make it work.

Thread #608513. Printed from Allegro.cc