1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
/* -*- mode: C++; tab-width: 4 -*- */
/* ===================================================================== *\
Copyright (c) 2000-2001 Palm, Inc. or its subsidiaries.
All rights reserved.
This file is part of the Palm OS Emulator.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
\* ===================================================================== */
#ifndef EmPoint_h
#define EmPoint_h
/*
Contains classes for working with points:
EmPointTempl<coord>: Generic template class. The type of point
coordinate is provided by the client.
EmPoint: Specific specialization of EmPointTempl for EmCoord.
For flexibility, the x/y ordering of coordinates within the object
is controlled by the XYPoint pre-processor symbol. Choosing a
particular order enables certain conversion operations; choosing the
other order enables other conversion operations. For instance, when
using long coordinates and XY ordering, we can produce a POINT*
(Win32 point), but not a VPoint* (MacApp point).
EmPoint offers no new operations. What it does offer is constructors
for creation from a platform-specific point (like Point, POINT, CPoint,
VPoint, etc.) or for producing some variant of a platform-specific
point. The different kinds of points that EmPoint attempts to convert
to/from are:
SIZE SDimension16 Point
CSize SDimension32 VPoint
POINT SPoint16
CPoint SPoint32
Where possible, EmPoint produces pointers, const pointers, references,
and const references to the above types.
Note that there are no virtual functions. These point classes are
not intended to be used polymorphically.
*/
#if PLATFORM_WINDOWS
#define XYPoint 1
#else
#define XYPoint 0
#endif
template <class coord>
class EmPointTempl
{
public:
EmPointTempl (void)
{}
EmPointTempl (coord x, coord y) :
#if XYPoint
fX (x),
fY (y)
#else
fY (y),
fX (x)
#endif
{}
EmPointTempl (const EmPointTempl<coord>& pt) :
#if XYPoint
fX (pt.fX),
fY (pt.fY)
#else
fY (pt.fY),
fX (pt.fX)
#endif
{}
// ~EmPointTempl (void) {};
// Constructors/Destructor. The default constructor doesn't do anything,
// including setting its members to zero. There is no destructor to cut
// down on the amount of code generated for this lightweight class.
void Offset (coord x, coord y);
// Add x and y to the point's coordinates. Same as operator+=()
// except that you specify coordinates, not another point.
EmPointTempl<coord> operator+ (const EmPointTempl<coord>& pt) const;
EmPointTempl<coord> operator- (const EmPointTempl<coord>& pt) const;
// Add or subtract the two points with each other, producing a
// new EmPointTempl<coord>.
EmPointTempl<coord> operator- (void) const;
// Unary minus. Negate our coordinates.
EmPointTempl<coord>& operator+= (const EmPointTempl<coord>& pt);
EmPointTempl<coord>& operator-= (const EmPointTempl<coord>& pt);
// Add or subtract the coordinates of the given point from
// ourselves.
EmPointTempl<coord> operator* (const EmPointTempl<coord>& pt) const;
EmPointTempl<coord> operator/ (const EmPointTempl<coord>& pt) const;
EmPointTempl<coord>& operator*= (const EmPointTempl<coord>& pt);
EmPointTempl<coord>& operator/= (const EmPointTempl<coord>& pt);
// Scale up or down the controlled point by the given point.
Boolean operator!= (const EmPointTempl<coord>& pt) const;
Boolean operator== (const EmPointTempl<coord>& pt) const;
// (In)equality operators. Returns whether or not the coordinates
// of the two points are equal to each other.
// Directly accessible data members.
#if XYPoint
coord fX;
coord fY;
#else
coord fY;
coord fX;
#endif
};
// ----------------------------------------------------------------------
// Types we interoperate with
// ----------------------------------------------------------------------
struct tagSIZE;
typedef struct tagSIZE SIZE;
class CSize;
struct tagPOINT;
typedef struct tagPOINT POINT;
class CPoint;
struct SDimension16;
struct SDimension32;
struct Point;
typedef Point SPoint16;
struct SPoint32;
struct VPoint;
/* ----------------------------------------------------------------------
Macros to help with creating the massive number of constructors and
conversion operators we support:
POINT_LIST_XY_SHORT: List of point-types using x/y coordinate
ordering and short coordinates.
POINT_LIST_XY_LONG: List of point-types using x/y coordinate
ordering and long coordinates.
POINT_LIST_YX_SHORT: List of point-types using y/x coordinate
ordering and short coordinates.
POINT_LIST_YX_LONG: List of point-types using y/x coordinate
ordering and long coordinates.
POINT_LIST_SHORT: List of point-types using short coordinates.
Only point-types using the same x/y ordering
as indicated by XYPoint are included.
POINT_LIST_LONG: List of point-types using long coordinates.
Only point-types using the same x/y ordering
as indicated by XYPoint are included.
Each of the above lists includes a reference to a point-type using a
FOR_POINT macro. The FOR_POINT macro takes as parameters the
point-type, the size of coordinates, and offsets to each coordinate.
This information is all that's needed for constructing all of
constructors and convertion operators, both declarations and
implementations. To perform the actual construction, FOR_POINT is
defined to expand to the appropriate code for a single constructor
or conversion, and then the appropriate POINT_LIST macro from above
is "invoked" to expand the list as needed.
---------------------------------------------------------------------- */
#define POINT_LIST_XY_SHORT \
FOR_POINT(SDimension16, short, 0, 1)\
FOR_POINT(PointType, short, 0, 1)
#define POINT_LIST_XY_LONG \
FOR_POINT(SIZE, long, 0, 1) \
FOR_POINT(CSize, long, 0, 1) \
FOR_POINT(SDimension32, long, 0, 1) \
FOR_POINT(POINT, long, 0, 1) \
FOR_POINT(CPoint, long, 0, 1) \
FOR_POINT(SPoint32, long, 0, 1)
#define POINT_LIST_YX_SHORT \
FOR_POINT(Point, short, 1, 0)
#define POINT_LIST_YX_LONG \
FOR_POINT(VPoint, long, 1, 0)
#if XYPoint
#define POINT_LIST_LONG POINT_LIST_XY_LONG
#define POINT_LIST_SHORT POINT_LIST_XY_SHORT
#else
#define POINT_LIST_LONG POINT_LIST_YX_LONG
#define POINT_LIST_SHORT POINT_LIST_YX_SHORT
#endif
// ----------------------------------------------------------------------
// * EmPoint
// ----------------------------------------------------------------------
class EmPoint : public EmPointTempl<EmCoord>
{
public:
EmPoint() {};
EmPoint(EmCoord x, EmCoord y) : EmPointTempl<EmCoord>(x, y) {};
EmPoint(const EmPointTempl<EmCoord>& pt) : EmPointTempl<EmCoord>(pt) {};
// ~EmPoint() {};
//
// Construct from another kind of point
// Assigned from another kind of point
// !!! Move functionality inline?
//
#undef FOR_POINT
#define FOR_POINT(cls, size, x, y) \
EmPoint(const cls&); \
const EmPoint& operator=(const cls&);
POINT_LIST_XY_SHORT
POINT_LIST_XY_LONG
POINT_LIST_YX_SHORT
POINT_LIST_YX_LONG
//
// Return another kind of point
// !!! Move functionality inline?
//
#undef FOR_POINT
#define FOR_POINT(cls, size, x, y) \
operator cls() const;
POINT_LIST_XY_LONG
POINT_LIST_YX_LONG
POINT_LIST_XY_SHORT
POINT_LIST_YX_SHORT
//
// Return a [const] (* | &) to another kind of point
// !!! Move functionality inline?
//
#undef FOR_POINT
#define FOR_POINT(cls, size, x, y) \
operator const cls*() const; \
operator cls*(); \
operator const cls&() const; \
operator cls&();
POINT_LIST_LONG
};
#endif // EmPoint_h
|