home *** CD-ROM | disk | FTP | other *** search
- // -[Keep_Heading]-
-
-
- // -[Copyright_Mesg]-
- // --------------------------------------------------------------- //
- // (c) Copyright 1993-1994. Step Ahead Software Pty Limited. All rights reserved.
- // Class Source Filename: SHAPE.cpp
- // Description:
- // Base class for all shapes. The pure virtual function Show is redefined in
- // derived classes for their individual needs.
- // Future enhancements - double click on an object to change its colour, drag
- // the corners to size the object.
- // --------------------------------------------------------------- //
-
-
- #include "SHAPE.h"
-
-
- // -[Keep_cpp_Extras]-
-
-
- // -[Module_Function_Decs]-
-
-
- // -[Module_Data_Decs_Def]-
-
-
- // -[Global_Data_Defs]-
-
-
- // -[Static_Member_Data_Defs]-
-
-
- // -[Function_Defs]-
-
- void
- Shape::write(Ropstream os)
- {
- // Call to base class write functions
- os << Colour;
- os << Height;
- os << HomeX;
- os << HomeY;
- os << Width;
- os << X;
- os << Y;
- }
-
- Pvoid
- Shape::read(Ripstream is)
- {
- // Call to base class read functions
- is >> Colour;
- is >> Height;
- is >> HomeX;
- is >> HomeY;
- is >> Width;
- is >> X;
- is >> Y;
- return this;
- }
-
- // Constructs the object before a stream input operation
- Shape::Shape(StreamableInit s)
- {
- }
-
-
- // Returns TRUE if the point falls within the shape's bounding rectangle.
- BOOL
- Shape::isIn(POINT Pnt)
- {
- RECT BR = {X, Y, X+Width, Y+Height};
-
- return PtInRect(&BR, Pnt);
- }
-
- // Returns TRUE if shape is currently at home coordinates.
- BOOL
- Shape::isHome() const
- {
- return ((HomeX == X) && (HomeY == Y));
- }
-
- // Moves a shape back home.
- void
- Shape::GoHome(HWND HWindow)
- {
- // Move the object back home
- MoveTo(HWindow, HomeX, HomeY);
- }
-
- // Erases the object at the current position and Shows it at the new position.
- void
- Shape::MoveTo(HWND HWindow, int NewX, int NewY)
- {
- // Invalidate shape's bounding rectangle at its current position
- RECT BR = {X, Y, X + Width, Y + Height};
-
- InvalidateRect(HWindow, &BR, TRUE);
-
- // Adjust shapes position
- X = NewX;
- Y = NewY;
-
- // Invalidate shape's bounding rectangle at its new position
- BR.left = X;
- BR.top = Y;
- BR.right = X + Width;
- BR.bottom = Y + Height;
-
- InvalidateRect(HWindow, &BR, TRUE);
- }
-
- // Constructs an object and sets its X, Y, HomeX and HomeY values. Colour is
- // initialised to blue (0x00FF0000)
- Shape::Shape(int XCoordinate, int YCoordinate)
- {
- X = HomeX = XCoordinate;
- Y = HomeY = YCoordinate;
- }
-
- // Sets the new colour of the shape. It returns the previous colour. By default
- // the Colour is Black (0x00000000)
- COLORREF
- Shape::SetColour(COLORREF NewColour)
- {
- COLORREF OldCol = Colour;
- Colour = NewColour;
-
- return OldCol;
- }
-
-
- // -[Persistent]-