home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / gamesystem / includes / gs_point.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-11  |  5.4 KB  |  235 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    gsCPoint
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    12/03/00
  8. //
  9. // Base:    gsCObject
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #ifndef _INCLUDE_GS_POINT_H
  16. #define _INCLUDE_GS_POINT_H
  17.  
  18. #include "gs_object.h"
  19. #include "gs_vector.h"
  20.  
  21. //-------------------------------------------------------------
  22. // Point
  23.  
  24. class gsCPoint : public gsCObject
  25. {
  26.     private:
  27.         POINT m_point;
  28.  
  29.     public:
  30.         gsCPoint();
  31.         gsCPoint(int x,int y);
  32.         gsCPoint(const gsCPoint& point);
  33.         gsCPoint(const gsCVector& vector);
  34.         ~gsCPoint();
  35.  
  36.         int getX() const;
  37.         int getY() const;
  38.  
  39.         void setX(int x);
  40.         void setY(int y);
  41.  
  42.         gsCPoint operator - ();
  43.  
  44.         const gsCPoint& operator += (const gsCPoint& a);
  45.         const gsCPoint& operator -= (const gsCPoint& a);
  46.  
  47.         friend gsCPoint operator + (const gsCPoint& a,const gsCPoint& b);
  48.         friend gsCPoint operator - (const gsCPoint& a,const gsCPoint& b);
  49.         friend gsCPoint operator * (const gsCPoint& a,const gsCPoint& b);
  50.         friend gsCPoint operator / (const gsCPoint& a,const gsCPoint& b);
  51.  
  52.         friend gsCPoint operator * (int a,const gsCPoint& b);
  53.         friend gsCPoint operator * (const gsCPoint& a,int b);
  54.         friend gsCPoint operator / (const gsCPoint& a,int b);
  55.  
  56.         friend bool operator == (const gsCPoint& a,const gsCPoint& b);
  57.         friend bool operator != (const gsCPoint& a,const gsCPoint& b);
  58.  
  59.         operator POINT() const;
  60.         operator LPPOINT();
  61. };
  62.  
  63. //-------------------------------------------------------------
  64.  
  65. inline gsCPoint::gsCPoint()
  66. {
  67.     m_point.x = m_point.y = 0;
  68. }
  69.  
  70. //-------------------------------------------------------------
  71.  
  72. inline gsCPoint::gsCPoint(int x,int y)
  73. {
  74.     m_point.x = x;
  75.     m_point.y = y;
  76. }
  77.  
  78. //-------------------------------------------------------------
  79.  
  80. inline gsCPoint::gsCPoint(const gsCPoint& point)
  81. {
  82.     m_point.x = point.m_point.x;
  83.     m_point.y = point.m_point.y;
  84. }
  85.  
  86. //-------------------------------------------------------------
  87.  
  88. inline gsCPoint::gsCPoint(const gsCVector& vector)
  89. {
  90.     m_point.x = (int) vector.m_x;
  91.     m_point.y = (int) vector.m_y;
  92. }
  93.  
  94. //-------------------------------------------------------------
  95.  
  96. inline int gsCPoint::getX() const
  97. {
  98.     return m_point.x;
  99. }
  100.  
  101. //-------------------------------------------------------------
  102.  
  103. inline int gsCPoint::getY() const
  104. {
  105.     return m_point.y;
  106. }
  107.  
  108. //-------------------------------------------------------------
  109.  
  110. inline void gsCPoint::setX(int x)
  111. {
  112.     m_point.x = x;
  113. }
  114.  
  115. //-------------------------------------------------------------
  116.  
  117. inline void gsCPoint::setY(int y)
  118. {
  119.     m_point.y = y;
  120. }
  121.  
  122. //-------------------------------------------------------------
  123.  
  124. inline gsCPoint gsCPoint::operator - ()
  125. {
  126.     return gsCPoint(-m_point.x,-m_point.y);
  127. }
  128.  
  129. //-------------------------------------------------------------
  130.  
  131. inline const gsCPoint& gsCPoint::operator += (const gsCPoint& a)
  132. {
  133.     m_point.x += a.m_point.x;
  134.     m_point.y += a.m_point.y;
  135.  
  136.     return *this;
  137. }
  138.  
  139. //-------------------------------------------------------------
  140.  
  141. inline const gsCPoint& gsCPoint::operator -= (const gsCPoint& a)
  142. {
  143.     m_point.x -= a.m_point.x;
  144.     m_point.y -= a.m_point.y;
  145.  
  146.     return *this;
  147. }
  148.  
  149. //-------------------------------------------------------------
  150.  
  151. inline gsCPoint operator + (const gsCPoint& a,const gsCPoint& b)
  152. {
  153.     return gsCPoint(a.m_point.x + b.m_point.x,a.m_point.y + b.m_point.y);
  154. }
  155.  
  156. //-------------------------------------------------------------
  157.  
  158. inline gsCPoint operator - (const gsCPoint& a,const gsCPoint& b)
  159. {
  160.     return gsCPoint(a.m_point.x - b.m_point.x,a.m_point.y - b.m_point.y);
  161. }
  162.  
  163. //-------------------------------------------------------------
  164.  
  165. inline gsCPoint operator * (const gsCPoint& a,const gsCPoint& b)
  166. {
  167.     return gsCPoint(a.m_point.x * b.m_point.x,a.m_point.y * b.m_point.y);
  168. }
  169.  
  170. //-------------------------------------------------------------
  171.  
  172. inline gsCPoint operator / (const gsCPoint& a,const gsCPoint& b)
  173. {
  174.     return gsCPoint(a.m_point.x / b.m_point.x,a.m_point.y / b.m_point.y);
  175. }
  176.  
  177. //-------------------------------------------------------------
  178.  
  179. inline gsCPoint operator * (int a,const gsCPoint& b)
  180. {
  181.     return gsCPoint(b.m_point.x * a,b.m_point.y * a);
  182. }
  183.  
  184. //-------------------------------------------------------------
  185.  
  186. inline gsCPoint operator * (const gsCPoint& a,int b)
  187. {
  188.     return gsCPoint(a.m_point.x * b,a.m_point.y * b);
  189. }
  190.  
  191. //-------------------------------------------------------------
  192.  
  193. inline gsCPoint operator / (const gsCPoint& a,int b)
  194. {
  195.     return gsCPoint(a.m_point.x / b,a.m_point.y / b);
  196. }
  197.  
  198. //-------------------------------------------------------------
  199.  
  200. inline bool operator == (const gsCPoint& a,const gsCPoint& b)
  201. {
  202.     return (a.m_point.x == b.m_point.x) && (a.m_point.y == b.m_point.y);
  203. }
  204.  
  205. //-------------------------------------------------------------
  206.  
  207. inline bool operator != (const gsCPoint& a,const gsCPoint& b)
  208. {
  209.     return (a.m_point.x != b.m_point.x) || (a.m_point.y == b.m_point.y);
  210. }
  211.  
  212. //-------------------------------------------------------------
  213.  
  214. inline gsCPoint::operator POINT() const
  215. {
  216.     return m_point;
  217. }
  218.  
  219. //-------------------------------------------------------------
  220.  
  221. inline gsCPoint::operator LPPOINT()
  222. {
  223.     return &m_point;
  224. }
  225.  
  226. //-------------------------------------------------------------
  227.  
  228. inline gsCPoint::~gsCPoint()
  229. {
  230. }
  231.  
  232. //-------------------------------------------------------------
  233.  
  234. #endif
  235.