Difference between revisions of "Programming Reference:Shape Class"
|Line 32:||Line 32:|
Latest revision as of 15:51, 11 September 2008
- 1 Location
- 2 Synopsis
- 3 Methods
- 4 Methods for Intersection Testing
- 5 Properties
- 6 Events
- 7 See also
The Shape class is a base class for geometric shapes, inheriting the GraphObject interface and adding its own interface for shape properties, and intersection testing.
Shape(GraphDisplay, int zOrder = ShapeZOrder)
The constructor takes the usual GraphDisplay reference argument, and an integer indicating the shape's z position.
Makes the object visible. Initially, objects are created in visible state.
Makes the object invisible.
Invalidates the object's bounding rectangle, i.e. marks it as needing to be repainted. Typically, this function is called from a derived class, indicating that a change in object properties has occurred that requires a repaint.
Asks an object to paint itself by calling its OnPaint event handler.
Notifies an object of a change in display properties by calling its OnChange event handler.
Tests whether the specified point is inside an object's bounding rectangle, and calls its OnClick event handler if this is the case.
Methods for Intersection Testing
Intersection test results have one of the following values:
- There is no intersection.
- There is an intersection.
- Intersection has not been determined.
Tests whether the specified point is part of the shape. Descendants of Shape should implement this function.
Tests for intersection with a second shape's area.
New descendants of Shape should use RTTI to test whether the argument is an existing descendant class, and provide intersection testing for all existing Shape descendants. For arguments that are not of a known type, the function is supposed to return undetermined.
This way, it is ensured that there exists an IntersectsArea() implementation for all pairs of Shape descendants, without modifying existing classes when creating new ones.
static bool AreaIntersection(Shape, Shape)
Tests for intersection between the two shapes specified.
The shape's center of mass, i.e. what would be considered its "position". For simple shapes, this coincides with the center of the shape's bounding rectangle.
The shape border's line width, in pixels.
The shape's filling color.
The color of the shape's border.
GraphDisplay Display (r)
The GraphDisplay object that was specified when the object was created.
bool Visible (r)
True if the object is visible, false if it is hidden. Use the Hide() and Show() methods to set this property.
float ZOrder (rw)
Determines the order in which GraphObjects are drawn. GraphObjects with smaller values of ZOrder are drawn on top of those with larger values, hiding these.
enum AspectRatioMode (rw)
One of the following options:
- No adjustment is made.
- The object's width is adapted to its contents, while keeping its height constant.
- The object's height is adapted to its contents, keeping its width constant.
- Both the object's height and width are adjusted to its content.
The exact behavior of aspect ratio adjustment depends on the object's type. E.g., for bitmap images, AdjustBoth will size the image such that one image pixel corresponds to one screen pixel; AdjustHeight and AdjustWidth will adjust such that the original aspect ratio is preserved.
GUI::Rect DisplayRect (rw)
The bounding rectangle of the space that is occupied by the object. This is given in coordinates relative to the size of the object's GraphDisplay; there, the upper left corner corresponds to (0,0), the lower right corner to (1,1). When a GraphObject is created, its display rectangle is empty.
This is where the actual shape is drawn. Descendants of Shape must provide their own implementation of the OnPaint event handler.