wmii/liblitz/geometry.c

52 lines
924 B
C
Raw Normal View History

2005-11-18 18:54:58 +03:00
/*
2006-01-20 17:20:24 +03:00
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
2005-11-18 18:54:58 +03:00
* See LICENSE file for license details.
*/
#include <math.h>
#include <stdio.h>
2005-11-18 18:54:58 +03:00
#include <stdlib.h>
#include <cext.h>
2005-11-18 18:54:58 +03:00
#include "blitz.h"
BlitzAlign
blitz_quadofcoord(XRectangle *rect, int x, int y)
2006-04-12 12:44:07 +04:00
{
2006-06-02 03:56:42 +04:00
BlitzAlign ret = 0;
x -= rect->x;
y -= rect->y;
if(x <= rect->width * .5)
ret |= EAST;
if(x >= rect->width * .5)
ret |= WEST;
if(y <= rect->height * .5)
ret |= NORTH;
if(y >= rect->height * .5)
ret |= SOUTH;
return ret;
2006-04-12 12:44:07 +04:00
}
Bool blitz_ispointinrect(int x, int y, XRectangle * r)
2005-11-18 18:54:58 +03:00
{
return (x >= r->x) && (x <= r->x + r->width)
&& (y >= r->y) && (y <= r->y + r->height);
2005-11-18 18:54:58 +03:00
}
/* Syntax: <x> <y> <width> <height> */
int blitz_strtorect(XRectangle *r, const char *val)
{
XRectangle new;
2005-11-18 18:54:58 +03:00
if (!val)
return -1;
2005-11-18 18:54:58 +03:00
if(sscanf(val, "%hd %hd %hu %hu", &new.x, &new.y, &new.width, &new.height) != 4)
return -1;
*r = new;
return 0;
2005-11-18 18:54:58 +03:00
}