| Online Eiffel Documentation

EiffelStudio

# Figures

The EiffelVision figure cluster can be considered a high-level way of drawing on an EV_DRAWABLE descendant. Here are some advantages:

- The model is separated from the representation by using projectors that take a world of figures and project it to any device, not just a drawing area.
- Instead of drawing with static API's like draw_line, real figure objects are used that can move, change color or morph.
- For projection devices that allow this, events may be caught and fired through the appropriate figure object.

## Figure classes

Every basic figure class inherits from EV_ATOMIC_FIGURE. An atomic figure has the property of having a representation. EV_FIGURE_GROUP on the other hand does not but is a collection of figures. On the top of those two stands EV_FIGURE as common ancestor. As EV_FIGURE_GROUP is a collection of EV_FIGUREs, it can contain subgroups.

As top-level group of a world of figures you must use EV_FIGURE_WORLD. It inherits from EV_FIGURE_GROUP but adds some features for grid and background color.

### Figures

class | open/closed | points | description
EV_FIGURE_ARC | open | 2 | a segment of an open ellipse
EV_FIGURE_DOT | open | 1 | a single point
EV_FIGURE_ELLIPSE | closed | 2 | ellipse inside imaginary rectangle
EV_FIGURE_EQUILATERAL | closed | 2 | a figure with any number of sides of the same length
EV_FIGURE_LINE | open | 2 | a straight line between two points
EV_FIGURE_PICTURE | open | 1 | an image positioned by its top-left point
EV_FIGURE_PIE_SLICE | closed | 2 | a part of a closed ellipse
EV_FIGURE_POLYGON | closed | * | a figure defined by any number of points
EV_FIGURE_POLYLINE | open | * | a figure consisting of any number of connecting lines
EV_FIGURE_RECTANGLE | closed | 2 | figure with four sides
EV_FIGURE_STAR | open | 2 | any number of lines emerging from a center point
EV_FIGURE_TEXT | open | 1 | a string positioned by its top-left point displayed in the specified font

A closed figure is a figure that has some area enclosed when drawn that can optionally be filled with a color. Closed figures inherit EV_CLOSED_FIGURE which gives them the property fill_color. Open figures inherit EV_ATOMIC_FIGURE directly just as EV_CLOSED_FIGURE.

### Points

Central in the design of the figures are points. Figures are built up as much from points as possible. For example, an ellipse is not a center point with two radii, but the biggest fitting ellipse inside an imaginary rectangle, so of two points.

As you can see in the table above, each figure has a certain number of points. These values can be 1, 2 or * (any number). For each value there is a class the figure inherits from. These classes are:

- 1 (a figure has one point): EV_SINGLE_POINTED_FIGURE.
- 2 (a figure has two points): EV_DOUBLE_POINTED_FIGURE.
- * (a figure has zero or more points): EV_MULTI_POINTED_FIGURE.

These classes offer features to handle the given number of points. EV_SINGLE_POINTED_FIGURE offers the feature:

    	point: EV_RELATIVE_POINT

EV_DOUBLE_POINTED_FIGURE inherits EV_SINGLE_POINTED_FIGURE for its first point, which is renamed topoint_a. It addspoint_b, so it has the features:

    	point_a: EV_RELATIVE_POINT
    	point_b: EV_RELATIVE_POINT

EV_MULTI_POINTED_FIGURE internally holds an array of points. Its most important feature is:

    	i_th_point (i: INTEGER): EV_RELATIVE_POINT

### Relative point

The points that the figures use are of type EV_RELATIVE_POINT. Each point is relative to another point, which is also relative. Each point is a set of coordinates and a reference point. The absolute coordinates are calculated only when needed by adding the absolute coordinates of the reference point to the relative coordinates.

## Figure worlds

In order to put the figures you want to display in a context, you have to insert them in a figure world object, an instance of EV_FIGURE_WORLD. This is a descendant of EV_FIGURE_GROUP and hence works in the same way. This figure world is later associated with one or more projectors.

EV_FIGURE_WORLD adds a number of features to EV_FIGURE_GROUP. These extra features are needed for the representation by a projector. One is the background color. This feature will be used to erase the canvas for a graphical projector in the specified color. The other features are to manage the grid.

## Projectors

A projector is an object that knows what a figure world should look like. The figure world itself is not more than a hint towards its representation. For example, if a line is "20" long, this unit might mean pixels, miles, centimeters or whatever. It is up to the projector to interpret units. Also, color might be interpreted as gray scale. Typically, a projector will do the best possible job projecting the world to its device.

With EiffelVision come these projectors:

- EV_POSTSCRIPT_PROJECTOR
- EV_DRAWING_AREA_PROJECTOR
- EV_PIXMAP_PROJECTOR

The first one maps figure worlds to a postscript file. The other two are descendants of EV_WIDGET_PROJECTOR, and can project on widgets that inherit EV_DRAWABLE: EV_DRAWING_AREA and EV_PIXMAP, eventually using double-buffering, which results in a more smooth animation but requires fast copying from memory to the video buffer (can be slow for a remote display).

## Events

The other features of drawing area and widget is that they generate pointer events. These events can be translated by projectors to map the figure world. These projectors send the event to the appropriate figure. Every figure has all common pointer action sequences:

- pointer_motion_actions
- pointer_button_press_actions
- pointer_double_press_actions
- pointer_button_release_actions
- pointer_enter_actions
- pointer_leave_actions
- pick_actions
- conforming_pick_actions
- drop_actions

There are no events for keyboard focus and no key press events. In case you wish to use these events, use the ones of the pixmap or drawing area.

When using events, keep the z-order in mind. This is the order in which the figures are stacked in the world. The first item of a figure group is the figure that is the farthest away. This means that the figure is obscured by any figures which are in front of it, and events will also not be propagated to this figure in that case.

## Rotation and scaling

The relative points also support rotation and scaling. These factors work just like coordinates, except scaling, which is multiplied instead of added in the chain of points. This means that when a relative point which is the root of a tree of several points is moved, the entire tree is moved, when it is scaled the entire tree is scaled and same for rotation.

The scaling factor is divided into a horizontal and vertical component. If the factor is 0.5, everything is displayed at half its size. The rotation factor is in radians.