// Copyright status: this file is in the public domain. #include "lx.h" int lx_apply_geometry(const LX_GEOMETRY *gp, int pw, int ph, int bw, int *xp, int *yp, int *wp, int *hp) { int v; if ( (pw < 1) || (pw > 65535) || (ph < 1) || (ph > 65535) || (bw < 0) || (bw > 65535) ) return(LX_GEOM_ERR_RANGE); if ( ((gp->flags & (LX_GEOM_PX|LX_GEOM_NX)) == (LX_GEOM_PX|LX_GEOM_NX)) || ((gp->flags & (LX_GEOM_PY|LX_GEOM_NY)) == (LX_GEOM_PY|LX_GEOM_NY)) ) return(LX_GEOM_ERR_INVALID); if (gp->flags & LX_GEOM_W) { if ((gp->w < 1) || (gp->w > 65535)) return(LX_GEOM_ERR_RANGE); *wp = gp->w; } if (gp->flags & LX_GEOM_H) { if ((gp->h < 1) || (gp->h > 65535)) return(LX_GEOM_ERR_RANGE); *hp = gp->h; } if (gp->flags & LX_GEOM_PX) { if ((gp->x < -32767) || (gp->x > 32768)) return(LX_GEOM_ERR_RANGE); *xp = gp->x; } if (gp->flags & LX_GEOM_PY) { if ((gp->y < -32767) || (gp->y > 32768)) return(LX_GEOM_ERR_RANGE); *yp = gp->y; } if (gp->flags & LX_GEOM_NX) { if ((*wp < 1) || (*wp > 65535)) return(LX_GEOM_ERR_RANGE); v = pw - gp->x - (*wp + (2 * bw)); if ((v < -32768) || (v > 32767)) return(LX_GEOM_ERR_RANGE); *xp = v; } if (gp->flags & LX_GEOM_NY) { if ((*hp < 1) || (*hp > 65535)) return(LX_GEOM_ERR_RANGE); v = ph - gp->y - (*hp + (2 * bw)); if ((v < -32768) || (v > 32767)) return(LX_GEOM_ERR_RANGE); *yp = v; } return(0); }