diff options
Diffstat (limited to 'rect.c')
-rw-r--r-- | rect.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -19,6 +19,24 @@ Rect* rect_clip(Rect* r, const Rect* c) { return r; } +Rect* rect_clipr(Rect* r, const int* c) { + int n; + int x = r->x, y = r->y; + if ((n = c[0] - r->x) > 0) { + r->w -= n; + r->x += n; + } + if ((n = c[1] - r->y) > 0) { + r->h -= n; + r->y += n; + } + if ((n = x + r->w - c[2]) > 0) + r->w -= n; + if ((n = y + r->h - c[3]) > 0) + r->h -= n; + return r; +} + Rect* rect_clips(Rect* r, Rect* s, const Rect* c) { int n; int x = r->x, y = r->y; @@ -44,3 +62,29 @@ Rect* rect_clips(Rect* r, Rect* s, const Rect* c) { } return r; } + +Rect* rect_clipsr(Rect* r, Rect* s, const int* c) { + int n; + int x = r->x, y = r->y; + if ((n = c[0] - r->x) > 0) { + r->w -= n; + r->x += n; + s->w -= n; + s->x += n; + } + if ((n = c[1] - r->y) > 0) { + r->h -= n; + r->y += n; + s->h -= n; + s->y += n; + } + if ((n = x + r->w - c[2]) > 0) { + r->w -= n; + s->w -= n; + } + if ((n = y + r->h - c[3]) > 0) { + r->h -= n; + s->h -= n; + } + return r; +} |