[wip] show_image(): Introduce struct screen_image with complete but abstract on-scree...
[elinks/images.git] / src / util / box.h
blob411be087e6041fff5fbce0744255e201f9daf04b
1 #ifndef EL__UTIL_BOX_H
2 #define EL__UTIL_BOX_H
4 /** A rectangular part of a drawing surface, such as the screen. */
5 struct box {
6 int x;
7 int y;
8 int width;
9 int height;
12 /** @relates box */
13 static inline int
14 is_in_box(struct box *box, int x, int y)
16 return (x >= box->x && y >= box->y
17 && x < box->x + box->width
18 && y < box->y + box->height);
21 /** @relates box */
22 static inline int
23 row_is_in_box(struct box *box, int y)
25 return (y >= box->y && y < box->y + box->height);
28 /** @relates box */
29 static inline int
30 col_is_in_box(struct box *box, int x)
32 return (x >= box->x && x < box->x + box->width);
35 /** Check whether a span of columns is in @a box.
36 * Mainly intended for use with double-width characters.
37 * @relates box */
38 static inline int
39 colspan_is_in_box(struct box *box, int x, int span)
41 return (x >= box->x && x + span <= box->x + box->width);
44 /** For two intersecting boxes, set boxi to represent the intersect.
45 * The behavior is kind of undefined for non-intersecting boxes, but
46 * width and height of boxi are guaranteed to be negative.
47 * @relates box */
48 static inline void
49 box_intersect(struct box *boxi, struct box *box1, struct box *box2)
51 boxi->x = int_max(box1->x, box2->x);
52 boxi->y = int_max(box1->y, box2->y);
53 boxi->width = int_min(box1->x + box1->width, box2->x + box2->width) - boxi->x;
54 boxi->height = int_min(box1->y + box1->height, box2->y + box2->height) - boxi->y;
58 /** @relates box */
59 static inline void
60 set_box(struct box *box, int x, int y, int width, int height)
62 box->x = int_max(0, x);
63 box->y = int_max(0, y);
64 box->width = int_max(0, width);
65 box->height = int_max(0, height);
68 /** @relates box */
69 static inline void
70 copy_box(struct box *dst, struct box *src)
72 copy_struct(dst, src);
75 #define dbg_show_box(box) DBG("x=%i y=%i width=%i height=%i", (box)->x, (box)->y, (box)->width, (box)->height)
76 #define dbg_show_xy(x_, y_) DBG("x=%i y=%i", x_, y_)
79 #endif