2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__UTIL_BOX_H
|
|
|
|
#define EL__UTIL_BOX_H
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** A rectangular part of a drawing surface, such as the screen. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct box {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
};
|
|
|
|
|
2007-07-27 07:14:00 -04:00
|
|
|
/** @relates box */
|
2005-09-15 09:58:31 -04:00
|
|
|
static inline int
|
|
|
|
is_in_box(struct box *box, int x, int y)
|
|
|
|
{
|
|
|
|
return (x >= box->x && y >= box->y
|
|
|
|
&& x < box->x + box->width
|
|
|
|
&& y < box->y + box->height);
|
|
|
|
}
|
|
|
|
|
2007-07-27 07:14:00 -04:00
|
|
|
/** @relates box */
|
2005-09-15 09:58:31 -04:00
|
|
|
static inline int
|
|
|
|
row_is_in_box(struct box *box, int y)
|
|
|
|
{
|
|
|
|
return (y >= box->y && y < box->y + box->height);
|
|
|
|
}
|
|
|
|
|
2007-07-27 07:14:00 -04:00
|
|
|
/** @relates box */
|
2005-09-15 09:58:31 -04:00
|
|
|
static inline int
|
|
|
|
col_is_in_box(struct box *box, int x)
|
|
|
|
{
|
|
|
|
return (x >= box->x && x < box->x + box->width);
|
|
|
|
}
|
|
|
|
|
2007-07-27 05:35:13 -04:00
|
|
|
/** Check whether a span of columns is in @a box.
|
2007-07-27 07:14:00 -04:00
|
|
|
* Mainly intended for use with double-width characters.
|
|
|
|
* @relates box */
|
2006-09-02 12:05:26 -04:00
|
|
|
static inline int
|
|
|
|
colspan_is_in_box(struct box *box, int x, int span)
|
|
|
|
{
|
|
|
|
return (x >= box->x && x + span <= box->x + box->width);
|
|
|
|
}
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2007-07-27 07:14:00 -04:00
|
|
|
/** @relates box */
|
2005-09-15 09:58:31 -04:00
|
|
|
static inline void
|
|
|
|
set_box(struct box *box, int x, int y, int width, int height)
|
|
|
|
{
|
2007-04-27 11:55:12 -04:00
|
|
|
box->x = int_max(0, x);
|
|
|
|
box->y = int_max(0, y);
|
|
|
|
box->width = int_max(0, width);
|
|
|
|
box->height = int_max(0, height);
|
2005-09-15 09:58:31 -04:00
|
|
|
}
|
|
|
|
|
2007-07-27 07:14:00 -04:00
|
|
|
/** @relates box */
|
2005-09-15 09:58:31 -04:00
|
|
|
static inline void
|
|
|
|
copy_box(struct box *dst, struct box *src)
|
|
|
|
{
|
|
|
|
copy_struct(dst, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define dbg_show_box(box) DBG("x=%i y=%i width=%i height=%i", (box)->x, (box)->y, (box)->width, (box)->height)
|
|
|
|
#define dbg_show_xy(x_, y_) DBG("x=%i y=%i", x_, y_)
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|