# HG changeset patch # User David Demelier # Date 1580126659 -3600 # Node ID 7187c0d9b9c074df1f5c70057d89e2ecda53edd1 # Parent 9435a53adab4db96b1a3d386a17c427063ed4907 core: implement message action, closes #2467 diff -r 9435a53adab4 -r 7187c0d9b9c0 src/core/message.c --- a/src/core/message.c Mon Jan 27 13:03:39 2020 +0100 +++ b/src/core/message.c Mon Jan 27 13:04:19 2020 +0100 @@ -17,18 +17,56 @@ */ #include +#include +#include +#include "action.h" #include "event.h" #include "font.h" #include "message.h" #include "painter.h" #include "sprite.h" #include "texture.h" +#include "util.h" #include "window.h" #define MESSAGE_SPEED 200 /* Time delay for animations */ #define MESSAGE_TIMEOUT 5000 /* Time for auto-closing */ +static void +action_handle(struct action *action, const union event *ev) +{ + assert(action); + assert(ev); + + message_handle(action->data, ev); +} + +static bool +action_update(struct action *action, unsigned int ticks) +{ + assert(action); + + return message_update(action->data, ticks); +} + +static void +action_draw(struct action *action) +{ + assert(action); + + message_draw(action->data); +} + +static void +action_finish(struct action *action) +{ + assert(action); + + message_finish(action->data); + free(action->data); +} + static unsigned int average(const struct message *msg) { @@ -220,9 +258,23 @@ } void -message_close(struct message *msg) +message_finish(struct message *msg) { assert(msg); clear(msg); } + +void +message_action(const struct message *msg, struct action *action) +{ + assert(msg); + assert(action); + + memset(action, 0, sizeof (struct action)); + action->data = ememdup(msg, sizeof (struct message)); + action->handle = action_handle; + action->update = action_update; + action->draw = action_draw; + action->finish = action_finish; +} diff -r 9435a53adab4 -r 7187c0d9b9c0 src/core/message.h --- a/src/core/message.h Mon Jan 27 13:03:39 2020 +0100 +++ b/src/core/message.h Mon Jan 27 13:04:19 2020 +0100 @@ -26,8 +26,9 @@ #include +struct action; +struct font; struct texture; -struct font; union event; @@ -138,4 +139,15 @@ void message_finish(struct message *msg); +/** + * Convert message into an action. + * + * \pre msg != NULL + * \pre action != NULL + * \param msg the message to copy from + * \param action the action to fill + */ +void +message_action(const struct message *msg, struct action *action); + #endif /* !MOLKO_MESSAGE_H */