Jump to content

Programming Reference:Shape Class

From BCI2000 Wiki

Location

src/shared/gui/Shapes

Synopsis

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.

Methods

Shape(GraphDisplay, int zOrder = ShapeZOrder)

The constructor takes the usual GraphDisplay reference argument, and an integer indicating the shape's z position.

Show()

Makes the object visible. Initially, objects are created in visible state.

Hide()

Makes the object invisible.

Invalidate()

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.

Paint()

Asks an object to paint itself by calling its OnPaint event handler.

Change()

Notifies an object of a change in display properties by calling its OnChange event handler.

bool Click(GUI::Point)

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

enum TestResult

Intersection test results have one of the following values:

false_
There is no intersection.
true_
There is an intersection.
undetermined
Intersection has not been determined.

TestResult Contains(Point)

Tests whether the specified point is part of the shape. Descendants of Shape should implement this function.

TestResult IntersectsArea(Shape)

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.

Properties

GUI::Point Center

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.

float LineWidth

The shape border's line width, in pixels.

RGBColor FillColor

The shape's filling color.

RGBColor Color

The color of the shape's border.

GUI::DrawContext Context (rw)

The draw context into which a GraphDisplay is supposed to render the GraphObjects it contains. A draw context consists of a handle to an output device context (HDC in Windows), and a rectangle within that device context's area.

RGBColor Color (rw)

The GraphDisplay's background color.

Events

OnPaint(GUI::DrawContext)

This is where the actual shape is drawn. Descendants of Shape must provide their own implementation of the OnPaint event handler.

See also

Programming Reference:GraphObject Class, Programming Reference:GraphDisplay Class