Subversion Repositories WindowManager

Compare Revisions

Ignore whitespace Rev 11 → Rev 12

/trunk/wimp/os_box.h
New file
0,0 → 1,173
// This file is part of the free Window Manager module.
// Copyright © 2007 Graham Shaw.
// Redistribution and modification are permitted within the terms of the
// GNU General Public License (version 2 or any later version).
 
#ifndef WINDOWMANAGER_OS_BOX
#define WINDOWMANAGER_OS_BOX
 
#include "oslib/os.h"
 
/** Construct a box from its components.
* @param x0 the minimum x coordinate
* @param y0 the minimum y coordinate
* @param x1 the maximum x coordinate
* @param y1 the maximum y coordinate
* @return the constructed box
*/
inline os_box make_os_box(int x0,int y0,int x1,int y1)
{
os_box result;
result.x0=x0;
result.y0=y0;
result.x1=x1;
result.y1=y1;
return result;
}
 
/** Move a box through a given displacement
* @param lhs the box to be displaced
* @param rhs the displacement
* @return the displaced box
*/
inline os_box operator+(const os_box& lhs,const os_coord& rhs)
{
os_box result;
result.x0=lhs.x0+rhs.x;
result.y0=lhs.y0+rhs.y;
result.x1=lhs.x1+rhs.x;
result.y1=lhs.y1+rhs.y;
return result;
}
 
/** Move a box through the reverse of a given displacement
* @param lhs the box to be displaced
* @param rhs the displacement
* @return the displaced box
*/
inline os_box operator-(const os_box& lhs,const os_coord& rhs)
{
os_box result;
result.x0=lhs.x0-rhs.x;
result.y0=lhs.y0-rhs.y;
result.x1=lhs.x1-rhs.x;
result.y1=lhs.y1-rhs.y;
return result;
}
 
/** Find the intersection of two boxes.
* @param lhs the first box
* @param rhs the second box
* @return the intersection
*/
inline os_box operator&(os_box lhs,const os_box& rhs)
{
if (rhs.x0>lhs.x0) lhs.x0=rhs.x0;
if (rhs.y0>lhs.y0) lhs.y0=rhs.y0;
if (rhs.x1<lhs.x1) lhs.x1=rhs.x1;
if (rhs.y1<lhs.y1) lhs.y1=rhs.y1;
return lhs;
}
 
/** Find the union of two boxes.
* @param lhs the first box
* @param rhs the second box
* @return the union
*/
inline os_box operator|(os_box lhs,const os_box& rhs)
{
if (rhs.x0<lhs.x0) lhs.x0=rhs.x0;
if (rhs.y0<lhs.y0) lhs.y0=rhs.y0;
if (rhs.x1>lhs.x1) lhs.x1=rhs.x1;
if (rhs.y1>lhs.y1) lhs.y1=rhs.y1;
return lhs;
}
 
/** Move a box through a given displacement
* @param lhs the box to be displaced
* @param rhs the displacement
* @return the displaced box
*/
inline os_box& operator+=(os_box& lhs,const os_coord& rhs)
{
lhs.x0+=rhs.x;
lhs.y0+=rhs.y;
lhs.x1+=rhs.x;
lhs.y1+=rhs.y;
return lhs;
}
 
/** Move a box through the reverse of a given displacement
* @param lhs the box to be displaced
* @param rhs the displacement
* @return the displaced box
*/
inline os_box& operator-=(os_box& lhs,const os_coord& rhs)
{
lhs.x0-=rhs.x;
lhs.y0-=rhs.y;
lhs.x1-=rhs.x;
lhs.y1-=rhs.y;
return lhs;
}
 
/** Determine whether a point lies within a given box
* @param lhs the point
* @param rhs the box
* @return true if the point lies within or on the boundary of the box,
* otherwise false
*/
inline bool operator<=(const os_coord& lhs,const os_box& rhs)
{
return (lhs.x>=rhs.x0)&&(lhs.y>=rhs.y0)&&(lhs.x<rhs.x1)&&(lhs.y<rhs.y1);
}
 
/** Find the bottom left-hand corner of a box.
* @param box the box
* @return the bottom left-hand corner
*/
inline os_coord x0y0(const os_box& box)
{
os_coord result;
result.x=box.x0;
result.y=box.y0;
return result;
}
 
/** Find the top left-hand corner of a box.
* @param box the box
* @return the top left-hand corner
*/
inline os_coord x0y1(const os_box& box)
{
os_coord result;
result.x=box.x0;
result.y=box.y1;
return result;
}
 
/** Find the bottom right-hand corner of a box.
* @param box the box
* @return the bottom right-hand corner
*/
inline os_coord x1y0(const os_box& box)
{
os_coord result;
result.x=box.x1;
result.y=box.y0;
return result;
}
 
/** Find the top right-hand corner of a box.
* @param box the box
* @return the top right-hand corner
*/
inline os_coord x1y1(const os_box& box)
{
os_coord result;
result.x=box.x1;
result.y=box.y1;
return result;
}
 
#endif
/trunk/wimp/os_coord.h
New file
0,0 → 1,50
// This file is part of the free Window Manager module.
// Copyright © 2007 Graham Shaw.
// Redistribution and modification are permitted within the terms of the
// GNU General Public License (version 2 or any later version).
 
#ifndef WINDOWMANAGER_OS_COORD
#define WINDOWMANAGER_OS_COORD
 
#include "oslib/os.h"
 
/** Construct a point from its coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @return the constructed point
*/
inline os_coord make_os_coord(int x,int y)
{
os_coord result;
result.x=x;
result.y=y;
return result;
}
 
/** Move a point through a given displacement
* @param lhs the point to be displaced
* @param rhs the displacement
* @return the displaced point
*/
inline os_coord operator+(const os_coord& lhs,const os_coord& rhs)
{
os_coord result;
result.x=lhs.x+rhs.x;
result.y=lhs.y+rhs.y;
return result;
}
 
/** Move a point through the reverse of a given displacement
* @param lhs the point to be displaced
* @param rhs the displacement
* @return the displaced point
*/
inline os_coord operator-(const os_coord& lhs,const os_coord& rhs)
{
os_coord result;
result.x=lhs.x-rhs.x;
result.y=lhs.y-rhs.y;
return result;
}
 
#endif