home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / point.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  3KB  |  173 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. /*
  7.  *
  8.  *          Copyright (C) 1994, M. A. Sridhar
  9.  *  
  10.  *
  11.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  12.  *     to copy, modify or distribute this software  as you see fit,
  13.  *     and to use  it  for  any  purpose, provided   this copyright
  14.  *     notice and the following   disclaimer are included  with all
  15.  *     copies.
  16.  *
  17.  *                        DISCLAIMER
  18.  *
  19.  *     The author makes no warranties, either expressed or implied,
  20.  *     with respect  to  this  software, its  quality, performance,
  21.  *     merchantability, or fitness for any particular purpose. This
  22.  *     software is distributed  AS IS.  The  user of this  software
  23.  *     assumes all risks  as to its quality  and performance. In no
  24.  *     event shall the author be liable for any direct, indirect or
  25.  *     consequential damages, even if the  author has been  advised
  26.  *     as to the possibility of such damages.
  27.  *
  28.  */
  29.  
  30.  
  31.  
  32.  
  33.  
  34. #if defined(__GNUC__)
  35. #pragma implementation
  36. #endif
  37.  
  38. #include "ui/point.h"
  39.  
  40.  
  41. #if defined(__GNUC__)
  42. #include "base/basicops.h"
  43. template class CL_Basics<UI_Point>;
  44. #endif
  45.  
  46. //
  47. //------------------Construction-----------------------------
  48. //
  49.  
  50.  
  51. UI_Point::UI_Point(long px,long py)
  52. {
  53.     x = px;
  54.     y = py;
  55. }
  56.  
  57.  
  58. UI_Point::UI_Point(const UI_Point& p)
  59. {
  60.     x = p.x;
  61.     y = p.y;
  62. }
  63.  
  64.  
  65. UI_Point UI_Point::operator+ (const UI_Point& p) const
  66. {
  67.     return UI_Point (x + p.x, y + p.y);
  68. }
  69.  
  70.  
  71.  
  72. //
  73. //-----------Other member Functions--------------------------
  74. //
  75.  
  76. void UI_Point::operator= (const CL_Object& p) 
  77. {
  78.     if (!IsA (p))
  79.         return;
  80.     *this = (const UI_Point&) p; // The op= does the notification
  81. }
  82.  
  83.  
  84. void UI_Point::operator= (const UI_Point& q)
  85. {
  86.     if (this == &q || !PrepareToChange())
  87.         return;
  88.     x = q.x;
  89.     y = q.y;
  90.     Notify ();
  91. }
  92.  
  93.  
  94. //
  95. //---------------Virtual member functions from CL_Object-------
  96. //
  97.  
  98. bool UI_Point::operator== (const CL_Object& p) const
  99. {
  100.     if (!IsA (p))
  101.         return FALSE;
  102.     register const UI_Point& q = (const UI_Point&) p;
  103.     if (q.x != x || q.y != y)
  104.         return FALSE;
  105.     return TRUE;
  106. }
  107.  
  108.  
  109. bool UI_Point::operator== (const UI_Point& q) const
  110. {
  111.     if (q.x != x || q.y != y)
  112.         return FALSE;
  113.     return TRUE;
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. //
  121. //---------------Virtual member functions from CL_Object----------
  122. //
  123.  
  124. // bool UI_Point::operator< (const CL_Object& p) const
  125. // {
  126. //     if (!IsA (p))
  127. //         return (this < &p ? -1 : 1);
  128. //     if(x < ((const UI_Point&)p).x) return TRUE;
  129. //     if(x == ((const UI_Point&)p).x && y < ((const UI_Point&)p).y)
  130. //          return TRUE;
  131. // 
  132. //     return FALSE;
  133. // }
  134.  
  135. CL_String UI_Point::AsString() const
  136. {
  137.     CL_String s;
  138.     s.AssignWithFormat ("(%ld, %ld)", x, y);
  139.     return s;
  140. }
  141.  
  142.  
  143.  
  144. void  UI_Point::AddToX (long value)
  145. {
  146.     if (!PrepareToChange())
  147.         return;
  148.     x += value;
  149.     Notify ();
  150. }
  151.  
  152. void  UI_Point::AddToY (long value)
  153. {
  154.     if (!PrepareToChange())
  155.         return;
  156.     y += value;
  157.     Notify ();
  158. }
  159.  
  160.  
  161. UI_Point UI_Point::operator- (const UI_Point& p) const
  162. {
  163.     return UI_Point (x - p.x, y - p.y);
  164. }
  165.  
  166.  
  167.  
  168. long  UI_Point::operator* (const UI_Point& p) const
  169. {
  170.     return  (x * p.y -  y * p.x);
  171. }
  172.  
  173.