4 /** A rectangular part of a drawing surface, such as the screen. */
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
);
23 row_is_in_box(struct box
*box
, int y
)
25 return (y
>= box
->y
&& y
< box
->y
+ box
->height
);
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.
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.
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
;
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
);
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_)