ImageGear ART Forms provides 3 classes to support the end user’s interaction and UI for custom marks. You must take one of them as a base class and implement a custom annotator controller in your application, just like you did for the custom class and custom controller. The custom annotator controller is responsible for:
- Interactive mark creation (with pre-drawing)
- Mark resizing
- Creating the mark’s property window when requested by annotator
- Representing the custom mark on the annotator’s toolbar
Base classes are as follows:
- ImGearARTFormsMarkController - This class defines an API which must be implemented by the user. This class does not implement any functionality and is recommended only if the custom mark is not similar to a rectangle or a set of points when created/resized.
- ImGearARTFormsRectangleController - This class implements default resize/creation behavior for rectangular marks. The user will have to override the mark creation code to support the rectangular mark.
- ImGearARTFormsPolyController - This class implements default resize/creation behavior for marks similar to polyline/polygon. The user will have to override the mark creation code and some members related to resizing to support the mark.
This topic provides information about the following:
Create Custom Marks
Custom mark creation is processed by two overridden methods: CanCreateMark and CreateMark.
The annotator calls CanCreateMark each time the user releases a mouse button. The annotator passes a set of already entered points as parameters, along with some data that can be used in CanCreateMark method (see ImGearARTFormsCreateMarkData class description). It is the controller’s responsibility to analyze if already entered points are enough for creating a mark (and/or by some conditions in the creation data). For example, all rectangular annotations can be created by 2 points, so default implementation in ImGearARTFormsRectangleController returns true without any checks (when MouseUp occurs, point list contains exactly two points). As another example, in PolyController default, implementation checks if the last mouse click event was a double-click. This behavior is overridden in SectorMark, which needs 3 points for creation, and it is checked in SectorEditController.CanCreateMark.
CreateMark is a public controller’s method. It is called by the annotator if the last call to CanCreateMark was successful. This method should be overridden in all custom controllers. It creates a new instance of the custom mark by a given set of points.
Resize Custom Marks
To process resizing of marks that are rectangular, the user must override the UpdateBounds method. It takes a rectangle containing new bounds for mark, and updates the custom mark’s properties with it. It is necessary because there is no common properties for custom mark that determines custom mark’s bounds. All other functionality, including cursor handling, is implemented in the ImGearARTFormsRectangleController class.
To process resizing of marks that are not rectangular, the user must override at least the Resize method, which takes a point, a point identifier, and updates one of the mark’s points with a given point. It will work for marks that are similar to the Polyline mark, i.e., marks based on a list of points. For more complex marks (for example, if custom mark is similar to Art Callout mark), the user may also want to override the ManageCursor method. Here the user is able to:
- Define a custom way to identify points (in this case Resize override must use same way)
- Test single points using UpdateCursor protected method
- Customize the cursor management
ManageCursor is called by the annotator every time the mouse hovers over the mark which is selected. Default ManageCursor implementation method analyzes if the mouse is over one of mark’s resizing points, and, if yes, sets up the cursor and stores a point ID in the data structure passed by annotator. Resize method is called by the annotator if the mouse moved while the mouse button is pressed, and appropriate resizing cursor and point identifier was set up during previous call of ManageCursor. The overridden Resize must update the internal point with new passed coordinates, using the point identifier passed by the annotator (see ImGearARTFormsMarkControllerData in API Reference).
Implement a Custom Property Window
To implement a custom property window for the custom mark, the user must override the GetPropertiesWindow method in the custom mark edit controller. The annotator calls this method when the “Properties” menu item is selected in the annotator UI, and passes a mark for which property window is requested, and a current ImGearPageView object. In the overridden method the user must create a Form-derived window which will display and modify the mark’s properties.
It is not necessary to implement your property window for custom mark if you are not going to use it. If the edit controller returns null instead of a form, the annotator does not display anything.
Create a Toolbar
When the annotator creates a toolbar, it iterates a list of registered custom mark edit controllers and gets ToolbarInfo property for each. ToolbarInfo is a read-only edit controller’s property of public type ImGearARTFormsToolbarButtonInfo.
This class has fields that are necessary for creating a toolbar button which will be associated with the custom mark/edit controller. In the user has overridden the ToolbarInfo property, then the user must create a new ImGearARTFormsToolbarButtonInfo object and fill its fields with the button’s icon, tooltip string and user type identifier (string, same as was used when the controller is registered).