A controller allows interaction with a view. It translates the low-level user interactions into higher-level operations on
ILcdGXYPainter
objects, ILcdGXYEditor
objects, ILcdGXYLayer
objects, and so on. The following sections describe how to use and customize the main implementations of ILcdGXYController
.
Using and customizing a TLcdGXYEditController2
TLcdGXYEditController2
is an extension of TLcdGXYSelectController2
with additional editing capabilities. It allows a user to graphically edit objects on an ILcdGXYView
using the mouse.
The selected objects are translated by moving the mouse pointer over them and dragging them to a new location. Selecting and
dragging can be performed as one operation. If the Ctrl-key is pressed during the drag, the single object that is touched
by the mouse pointer is reshaped. Note that the meaning of translating and reshaping is defined by the implementations of
ILcdGXYPainter
instances and ILcdGXYEditor
instances.
Both the objects themselves (bodies) and their labels can be edited. Editing an object requires that an
ILcdGXYEditor
is available from the layer, editing the labels requires that an ILcdGXYLabelEditor
and an ILcdGXYLabelPainter2
(not just ILcdGXYLabelPainter
) are available from the layer.
You can customize all editing-related logic by setting a custom TLcdGXYEditControllerModel2
using the method setEditControllerModel
. For example, to change the behavior of modifier keys, disable editing of labels, influence which objects should be edited,
and so on. The controller model for the edit controller has a similar structure as the TLcdGXYSelectControllerModel2
. Refer to the API reference of TLcdGXYEditControllerModel2
for more information.
TLcdGXYEditController2
supports undo and snapping capabilities. Refer to Adding undo/redo support in GXY views and Snapping explained respectively for more information.
When passing an TLcdGXYContext
to the TLcdGXYEditController2
instead of an ILcdGXYContext
, it is possible to provide multiple input points at once. This allows to edit multiple points at the same time as illustrated
in the touch.multiEdit
sample.
Using and customizing a TLcdGXYNewController2
TLcdGXYNewController2
allows a user to graphically create objects on an ILcdGXYView
using the
mouse. The controller needs a controller model extending from ALcdGXYNewControllerModel2
to translate
mouse events to the steps necessary for creating and initializing a new object. The default controller
model uses the object’s target layer’s ILcdGXYPainter
and ILcdGXYEditor
, which already
offer most of the functionality for creating new objects and visualizing the creation. To instantiate the
ALcdGXYNewControllerModel2
, you only need to implement two more methods:
-
getGXYLayer
to retrieve a relevantILcdGXYLayer
to insert the object into. By default, the controller model delegates painting and editing steps to the layer’sILcdGXYPainter
andILcdGXYEditor
, and commits the object to the layer when the object is successfully initialized. -
create
to create a new object ready to be initialized by the mouse.
You can further customize the creation process in the following two ways:
-
customize the key actions involved in the creation process:
-
edit: to perform a mouse-based initialization step
-
cancel: to cancel the creation process
-
revert: to go back a step in the creation process
-
paint: to paint the creation in progress
-
commit: to insert the object into the target layer
-
-
customize the translation of mouse events into the above actions
Refer to the API reference of ALcdGXYNewControllerModel2
for more information on customizing the creation process. Creating a shape with TLcdGXYNewController2 explains the implementation of a controller model to create a hippodrome shape. It includes a diagram showing the interaction
between the controller and the controller model.
TLcdGXYNewController2
supports undo and snapping capabilities. Refer to Adding undo/redo support in GXY views and Snapping explained respectively for more information.