1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-01-03 14:57:44 -05:00
elinks/src/util/box.h

67 lines
1.4 KiB
C
Raw Normal View History

#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. */
struct box {
int x;
int y;
int width;
int height;
};
2007-07-27 07:14:00 -04:00
/** @relates box */
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 */
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 */
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);
}
2007-07-27 07:14:00 -04:00
/** @relates box */
static inline void
set_box(struct box *box, int x, int y, int width, int height)
{
box->x = int_max(0, x);
box->y = int_max(0, y);
box->width = int_max(0, width);
box->height = int_max(0, height);
}
2007-07-27 07:14:00 -04:00
/** @relates box */
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