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>
|
2006-05-26 16:16:19 +04:00
|
|
|
#include <stdio.h>
|
2005-11-18 18:54:58 +03:00
|
|
|
#include <stdlib.h>
|
2006-04-03 17:52:05 +04:00
|
|
|
#include <cext.h>
|
2005-11-18 18:54:58 +03:00
|
|
|
|
|
|
|
#include "blitz.h"
|
|
|
|
|
2006-04-23 22:00:47 +04:00
|
|
|
BlitzAlign
|
2006-05-26 16:16:19 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-05-26 16:16:19 +04:00
|
|
|
Bool blitz_ispointinrect(int x, int y, XRectangle * r)
|
2005-11-18 18:54:58 +03:00
|
|
|
{
|
2006-05-26 16:16:19 +04: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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-26 16:16:19 +04: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)
|
2006-01-04 18:23:09 +03:00
|
|
|
return -1;
|
2005-11-18 18:54:58 +03:00
|
|
|
|
2006-05-26 16:16:19 +04:00
|
|
|
if(sscanf(val, "%hd %hd %hu %hu", &new.x, &new.y, &new.width, &new.height) != 4)
|
|
|
|
return -1;
|
2005-12-21 16:48:01 +03:00
|
|
|
|
2006-05-26 16:16:19 +04:00
|
|
|
*r = new;
|
2006-01-04 18:23:09 +03:00
|
|
|
return 0;
|
2005-11-18 18:54:58 +03:00
|
|
|
}
|