diff options
author | Jonas Kohl <gitlab@jonaskohl.de> | 2024-08-29 17:00:11 +0200 |
---|---|---|
committer | Jonas Kohl <gitlab@jonaskohl.de> | 2024-08-29 17:00:11 +0200 |
commit | 84ad096896e9948c722a957d07ed6868e252a9f7 (patch) | |
tree | b8ad1afadd89f1dc7599436cfb0f7f5fb0c177b6 /includes/rect.c |
Initial commit
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 |