home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / VCW411.ZIP / SHAPE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-10  |  2.7 KB  |  135 lines

  1. // -[Keep_Heading]-
  2.  
  3.  
  4. // -[Copyright_Mesg]-
  5. // --------------------------------------------------------------- //
  6. // (c) Copyright 1993-1994. Step Ahead Software Pty Limited. All rights reserved.
  7. // Class Source Filename: SHAPE.cpp
  8. // Description: 
  9. // Base class for all shapes. The pure virtual function Show is redefined in
  10. // derived classes for their individual needs.
  11. // Future enhancements - double click on an object to change its colour, drag
  12. // the corners to size the object.
  13. // --------------------------------------------------------------- //
  14.  
  15.  
  16. #include "SHAPE.h"
  17.  
  18.  
  19. // -[Keep_cpp_Extras]-
  20.  
  21.  
  22. // -[Module_Function_Decs]-
  23.  
  24.  
  25. // -[Module_Data_Decs_Def]-
  26.  
  27.  
  28. // -[Global_Data_Defs]-
  29.  
  30.  
  31. // -[Static_Member_Data_Defs]-
  32.  
  33.  
  34. // -[Function_Defs]-
  35.  
  36. void
  37. Shape::write(Ropstream os)
  38. {
  39.   // Call to base class write functions
  40.   os << Colour;
  41.   os << Height;
  42.   os << HomeX;
  43.   os << HomeY;
  44.   os << Width;
  45.   os << X;
  46.   os << Y;
  47. }
  48.  
  49. Pvoid
  50. Shape::read(Ripstream is)
  51. {
  52.   // Call to base class read functions
  53.   is >> Colour;
  54.   is >> Height;
  55.   is >> HomeX;
  56.   is >> HomeY;
  57.   is >> Width;
  58.   is >> X;
  59.   is >> Y;
  60.   return this;
  61. }
  62.  
  63. // Constructs the object before a stream input operation
  64. Shape::Shape(StreamableInit s)
  65. {
  66. }
  67.  
  68.  
  69. // Returns TRUE if the point falls within the shape's bounding rectangle.
  70. BOOL
  71. Shape::isIn(POINT Pnt)
  72. {
  73.     RECT BR = {X, Y, X+Width, Y+Height};
  74.  
  75.     return PtInRect(&BR, Pnt);
  76. }
  77.  
  78. // Returns TRUE if shape is currently at home coordinates.
  79. BOOL
  80. Shape::isHome() const
  81. {
  82.     return ((HomeX == X) && (HomeY == Y));
  83. }
  84.  
  85. // Moves a shape back home.
  86. void
  87. Shape::GoHome(HWND HWindow)
  88. {
  89.     // Move the object back home
  90.     MoveTo(HWindow, HomeX, HomeY);
  91. }
  92.  
  93. // Erases the object at the current position and Shows it at the new position.
  94. void
  95. Shape::MoveTo(HWND HWindow, int NewX, int NewY)
  96. {
  97.     // Invalidate shape's bounding rectangle at its current position    
  98.     RECT BR = {X, Y, X + Width, Y + Height};
  99.  
  100.     InvalidateRect(HWindow, &BR, TRUE);
  101.  
  102.     // Adjust shapes position
  103.     X = NewX;
  104.     Y = NewY;
  105.  
  106.     // Invalidate shape's bounding rectangle at its new position
  107.     BR.left =  X;
  108.     BR.top = Y;
  109.     BR.right = X + Width;
  110.   BR.bottom = Y + Height;
  111.  
  112.     InvalidateRect(HWindow, &BR, TRUE);
  113. }
  114.  
  115. // Constructs an object and sets its X, Y, HomeX and HomeY values. Colour is
  116. // initialised to blue (0x00FF0000)
  117. Shape::Shape(int XCoordinate, int YCoordinate)
  118. {
  119.     X = HomeX = XCoordinate;
  120.     Y = HomeY = YCoordinate;
  121. }
  122.  
  123. // Sets the new colour of the shape. It returns the previous colour. By default
  124. // the Colour is Black (0x00000000)
  125. COLORREF
  126. Shape::SetColour(COLORREF NewColour)
  127. {
  128.     COLORREF OldCol = Colour;
  129.     Colour = NewColour;
  130.  
  131.     return OldCol; 
  132. }
  133.  
  134.  
  135. // -[Persistent]-