diff options
Diffstat (limited to 'includes/rect.c')
-rw-r--r-- | includes/rect.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/includes/rect.c b/includes/rect.c new file mode 100644 index 0000000..36abde7 --- /dev/null +++ b/includes/rect.c @@ -0,0 +1,43 @@ +#include <stdlib.h> +#include <stdio.h> +#include "rect.h" + +#define TYPE Rect + +DEFINE_OBJECT_STRUCTURE(TYPE) { + int left, top, width, height; +}; + +CONSTRUCTOR_IMPLEMENT(TYPE); + +void METHOD_ARG(TYPE, init, int l, int t, int w, int h) { + self->left = l; + self->top = t; + self->width = w; + self->height = h; +} + +int METHOD_ARG(TYPE, toString, char* buffer) { + return sprintf(buffer, NAMEOF(TYPE) " { left = %i, top = %i, width = %i, height = %i }", self->left, self->top, self->width, self->height); +} + +GETTER_IMPLEMENT(TYPE, int, left); +SETTER_IMPLEMENT(TYPE, int, left); + +GETTER_IMPLEMENT(TYPE, int, top); +SETTER_IMPLEMENT(TYPE, int, top); + +GETTER_IMPLEMENT(TYPE, int, width); +SETTER_IMPLEMENT(TYPE, int, width); + +GETTER_IMPLEMENT(TYPE, int, height); +SETTER_IMPLEMENT(TYPE, int, height); + +GETTER(TYPE, int, right) { + return self->left + self->width; +} +GETTER(TYPE, int, bottom) { + return self->top + self->height; +} + +#undef TYPE |