Module: drawable
Synopsis
#include <core/drawable.h>
Automatic drawable objects.
This module allows creating automatic objects that draw theirselves into the screen and vanish once complete. They could be considered as lightweight alternatives to actions, however in contrast to them, drawables do have a position.
Macros
DRAWABLE_STACK_MAX
Maximum number of drawable in a unique drawable_stack.
#define DRAWABLE_STACK_MAX 128
Structs
drawable
Abstract drawable object.
Field | Access | Type |
---|---|---|
data | (+&?) | void * |
x | (+) | int |
y | (+) | int |
update | (+?) | bool (*)(struct drawable *, unsigned int) |
draw | (+?) | void (*)(struct drawable *) |
end | (+?) | void (*)(struct drawable *) |
finish | (+?) | void (*)(struct drawable *) |
data
Optional drawable data.
x, y
Position on screen.
update
Update the drawable self
with the ticks
since last frame. The callback
should return true if it is considered complete.
bool (*update)(struct drawable *self, unsigned int ticks)
draw
Draw the drawable self
.
void (*draw)(struct drawable *self)
end
Called with the drawable self
when it was completed.
This callback is mostly provided to allow the user doing something else once an drawable is complete. Predefined drawable should not use this callback by themselves.
void (*end)(struct drawable *self)
finish
Destroy internal resources for the drawable self
.
void (*finish)(struct drawable *self)
drawable_stack
Stack of drawable objects.
This stack of drawable object can be used to store drawable objects within a specific transition (state, battle, menu, etc).
You can add, clear, update and draw them.
Field | Access | Type |
---|---|---|
objects | (+&?) | struct drawable *[DRAWABLE_STACK_MAX] |
objects
Non-owning array of drawables to manage.
Functions
drawable_update
Invoke and return the dw
update callback with the given event ev
and ticks
since last frame if it is not NULL.
bool
drawable_update(struct drawable *dw, unsigned int ticks)
drawable_draw
Invoke the dw
draw callback if it is not NULL.
void
drawable_draw(struct drawable *dw)
drawable_end
Invoke the dw
end callback if it is not NULL.
void
drawable_end(struct drawable *dw)
drawable_finish
Invoke the dw
finish callback if it is not NULL.
void
drawable_finish(struct drawable *dw)
drawable_stack_init
Initalize the drawable stack st
.
Note
It is unnecessary if the object was zero'ed.
void
drawable_stack_init(struct drawable_stack *st)
drawable_stack_add
Add the drawable dw
to the stack pointed by st
. Returns true if there was
enough room to insert.
bool
drawable_stack_add(struct drawable_stack *st, struct drawable *dw)
drawable_stack_update
Update all drawables with ticks
since last frame in the stack st
.
bool
drawable_stack_update(struct drawable_stack *st, unsigned int ticks)
drawable_stack_draw
Draw all drawables in the stack st
.
void
drawable_stack_draw(const struct drawable_stack *st)
drawable_stack_completed
Tells if there is any pending drawable in the stack st
. Returns true if there
are no drawables or if they have all completed.
bool
drawable_stack_completed(const struct drawable_stack *st)
drawable_stack_finish
Terminate all drawables and clear the stack st
.
void
drawable_stack_finish(struct drawable_stack *st)