123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #ifndef RECT_H
- #define RECT_H
- #include "typedef.h"
- #define AT_UI_RAM AT(.ui_ram)
- struct position {
- int x;
- int y;
- };
- struct rect {
- int left;
- int top;
- int width;
- int height;
- };
- #define rect_left(r) ((r)->left)
- #define rect_top(r) ((r)->top)
- #define rect_right(r) ((r)->left + (r)->width)
- #define rect_bottom(r) ((r)->top + (r)->height)
- //#define rect_height(v) ((v)->bottom - (v)->top)
- //#define rect_width(v) ((v)->right - (v)->left)
- static inline int in_rect(const struct rect *rect, struct position *pos)
- {
- if (rect->left <= pos->x && rect_right(rect) > pos->x) {
- if (rect->top <= pos->y && rect_bottom(rect) > pos->y) {
- return true;
- }
- }
- return false;
- }
- AT_UI_RAM
- static inline bool get_rect_cover(const struct rect *a, const struct rect *b, struct rect *c)
- {
- int right, bottom;
- c->top = MAX(a->top, b->top);
- c->left = MAX(a->left, b->left);
- right = MIN(rect_right(a), rect_right(b));
- bottom = MIN(rect_bottom(a), rect_bottom(b));
- if ((c->top < bottom) && (c->left < right)) {
- c->width = right - c->left;
- c->height = bottom - c->top;
- return true;
- }
- return false;
- }
- static inline bool get_rect_nocover_l(const struct rect *a, const struct rect *b, struct rect *c)
- {
- int right, bottom;
- c->left = MIN(rect_left(a), rect_left(b));
- c->top = MIN(rect_top(a), rect_top(b));
- right = MAX(rect_left(a), rect_left(b));
- bottom = MAX(rect_bottom(a), rect_bottom(b));
- if ((c->top < bottom) && (c->left < right)) {
- c->width = right - c->left;
- c->height = bottom - c->top;
- return true;
- }
- return false;
- }
- static inline bool get_rect_nocover_r(const struct rect *a, const struct rect *b, struct rect *c)
- {
- int right, bottom;
- c->left = MIN(rect_right(a), rect_right(b));
- c->top = MIN(rect_top(a), rect_top(b));
- right = MAX(rect_right(a), rect_right(b));
- bottom = MAX(rect_bottom(a), rect_bottom(b));
- if ((c->top < bottom) && (c->left < right)) {
- c->width = right - c->left;
- c->height = bottom - c->top;
- return true;
- }
- return false;
- }
- static inline bool get_rect_nocover_t(const struct rect *a, const struct rect *b, struct rect *c)
- {
- int right, bottom;
- c->left = MIN(rect_left(a), rect_left(b));
- c->top = MIN(rect_top(a), rect_top(b));
- right = MAX(rect_right(a), rect_right(b));
- bottom = MAX(rect_top(a), rect_top(b));
- if ((c->top < bottom) && (c->left < right)) {
- c->width = right - c->left;
- c->height = bottom - c->top;
- return true;
- }
- return false;
- }
- static inline bool get_rect_nocover_b(const struct rect *a, const struct rect *b, struct rect *c)
- {
- int right, bottom;
- c->left = MIN(rect_left(a), rect_left(b));
- c->top = MIN(rect_bottom(a), rect_bottom(b));
- right = MAX(rect_right(a), rect_right(b));
- bottom = MAX(rect_bottom(a), rect_bottom(b));
- if ((c->top < bottom) && (c->left < right)) {
- c->width = right - c->left;
- c->height = bottom - c->top;
- return true;
- }
- return false;
- }
- #endif
|