Manager Grid
Most editors provide a snapping grid that forces mouse events to occur at specified locations. Usually, the coordinates where the user can move the pointing device are located at grid points. If the manager is configured to allow standard mouse events, all event locations can be automatically modified so they occur only at specific locations. Thus, the effect of filtering user events by a manager grid is to modify their locations to the closest grid point.
The
IlvManagerGrid class is responsible for the conversion to a valid grid point of the coordinates of an event that occurs in a view.
You can set or remove a snapping grid in each of the views handled by a manager. You can configure these grids to make them:
visible or not visible,
active or inactive.
You can also make the grid take on different shapes by subtyping the
IlvManagerGrid class. The default implementation is a rectangular grid for which you can set the origin and the horizontal and vertical spacing values.
When a grid is made visible, it draws dots with the color specified as the foreground color of the palette parameter.
The grid can be made invisible when it is created by setting the visible parameter to IlFalse. To make the grid initially inactive, set the active parameter to IlFalse.
To display only a subset of the grid points, use the last two IlvDim-typed parameters. These indicate the nature of the subset, that is, one out of every quantity of dots along the horizontal and vertical axes is displayed in the given direction. However, the event location snapping takes place on each of the grid points, whether shown or not.
Example: Using a Grid
This code sets a new grid to the view view associated with the manager:
// Get the previous grid IlvManagerGrid* previousGrid = manager->getGrid(view); // Create a new instance of IlvManagerGrid IlvManagerGrid* newGrid = new IlvManagerGrid(display->getPalette(), IlvPoint(0, 0), 10, 10); // Set the new grid to the view manager->setGrid(view, newGrid); // If a previous grid existed then delete it if (previousGrid) delete previousGrid; |
Usually, it is not necessary to delete a previous grid, since by default none is associated with the view.
The following code shows how to create an
IlvLine whose ends are on the grid:
static void AddSnappedLine(IlvManager* manager, const IlvView* view, const IlvPoint& start, const IlvPoint& end) { IlvPoint p1 = start; IlvPoint p2 = end; // Compute the new coordinates manager->snapToGrid(view, p1); manager->snapToGrid(view, p2); // Create an object IlvLine IlvGraphic* object = new IlvLine(manager->getDisplay(), p1, p2); // Add the object to the manager manager->addObject(object); } |
All the standard interactors of Views that create graphic objects use
IlvManager::snapToGrid.
Published date: 05/24/2022
Last modified date: 02/24/2022