home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
yacl-012.zip
/
ui
/
rectangl.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-08
|
6KB
|
206 lines
#ifndef _rectangle_h_
#define _rectangle_h_
/*
*
* Copyright (C) 1994, M. A. Sridhar
*
*
* This software is Copyright M. A. Sridhar, 1994. You are free
* to copy, modify or distribute this software as you see fit,
* and to use it for any purpose, provided this copyright
* notice and the following disclaimer are included with all
* copies.
*
* DISCLAIMER
*
* The author makes no warranties, either expressed or implied,
* with respect to this software, its quality, performance,
* merchantability, or fitness for any particular purpose. This
* software is distributed AS IS. The user of this software
* assumes all risks as to its quality and performance. In no
* event shall the author be liable for any direct, indirect or
* consequential damages, even if the author has been advised
* as to the possibility of such damages.
*
*/
#if defined(__GNUC__)
#pragma interface
#endif
#include "ui/point.h"
#include "ui/graphic.h"
#include "base/sequence.h"
// This is an abstraction of a rectangle at a given position in
// two-dimensional space.
// A convenient definition of a rectangle
struct UI_RectangleStruct {
long x, y, w, h; // h = height, w = width
};
class CL_EXPORT UI_DrawingSurface;
class CL_EXPORT UI_Rectangle: public UI_GraphicObject {
public:
//
//-------------------Construction------------------
//
UI_Rectangle (const UI_Point& topLeft, long width, long height);
UI_Rectangle (long x, long y, long width, long height);
UI_Rectangle (const UI_RectangleStruct&);
UI_Rectangle ();
UI_Rectangle (const UI_Rectangle& );
~UI_Rectangle ();
//
// --------------------Query-------------------------
//
UI_Rectangle BoundingRectangle() const {return *this; };
UI_Point Center () const;
long TopLeftX () const {return _origin.XCoord();};
long TopLeftY () const {return _origin.YCoord();};
long BottomRightX () const {return _origin.XCoord() + _width - 1;};
long BottomRightY () const {return _origin.YCoord() + _height - 1;};
long Top () const {return _origin.YCoord();}
long Left () const {return _origin.XCoord();}
long Bottom () const {return _origin.YCoord() + _height - 1;}
long Right () const {return _origin.XCoord() + _width - 1;}
const UI_Point& Origin () const {return _origin;};
UI_Point TopLeft () const {return _origin;}
UI_Point TopRight () const {return _origin + UI_Point (_width-1, 0);};
UI_Point BottomLeft () const {return _origin + UI_Point (0, _height-1);};
UI_Point BottomRight () const
{return _origin + UI_Point (_width-1, _height-1);};
long Height () const;
long Width () const;
long Area () const;
UI_HitTest HitTest (const UI_Point& p) const;
// Override inherited virtual method.
bool OnBoundary (const UI_Point& p) const;
// Return TRUE if {\tt p} is on the boundary of this rectangle, and
// FALSE otherwise.
bool Includes (const UI_Point& p) const;
// Return TRUE if {\tt p} is inside or on the boundary of this
// rectangle, and FALSE otherwise.
bool IntersectsBoundary (const UI_Rectangle& r) const;
bool IsContainedIn (const UI_Rectangle& r) const;
CL_Sequence<UI_Point> RowMajor (long m, long n) const;
// Imagine that the surface of this rectangle is ``tiled'' by a matrix
// of sub-rectangles, each of which is $m$ units wide and $n$ units
// high, and that the top left corner of the top left rectangle in the
// matrix coincides with the top left corner of this rectangle. Return
// the top left corners of the sub-rectangles, in row-major order, as a
// sequence of points. The width of this rectangle must be divisible by
// $m$, and the height must be divisible by $n$.
// ------------------------ Geometric operations -----------------
void Origin (const UI_Point& o);
// Set the origin to the given point, thus moving the rectangle.
void AddToHeight (long increment);
// Add this value to the height. The parameter may be negative. This
// method will refuse any change that causes the height to fall below zero.
void AddToWidth (long increment);
// Add this value to the width. The parameter may be negative. This
// method will refuse a change that causes the width to fall below zero.
UI_Rectangle operator+ (const UI_Point&) const;
void operator+= (const UI_Point& p) {*this = *this + p;};
bool ReshapeTo (const UI_Point& p1, const UI_Point& p2);
// ------------------------- Drawing -------------------------------
bool DrawOn (UI_DrawingSurface& sfc,
const UI_Point& p = UI_Point (0, 0)) const;
// Override the method inherited from GraphicObject.
bool Fill (UI_DrawingSurface& s) const;
// ----------------------- Basic operations ------------------
void operator= (const CL_Object& );
void operator= (const UI_Rectangle& rect);
bool operator== (const CL_Object& r) const;
bool operator== (const UI_Rectangle& r) const;
CL_String AsString () const;
// Return a string that looks like \verb|"(23, 15, 2, 3)"| (for x, y,
// w, h).
const char* ClassName () const {return "UI_Rectangle";};
protected:
UI_Point _origin;
long _height;
long _width;
public:
#if defined(__MS_WINDOWS__)
struct tagRECT AsMSRect () const;
// [MS-Windows-specific: internal use only]
#endif
};
#endif