When the end user selects a menu item from the Tool menu and selects a point on the canvas (either to select or draw a canvas graphic), the canvas view creates a tool negotiator to work with the Input system to prepare for the type of mouse interaction (simple or delegating) about to take place.
In Mars, simple mouse tools work on a target of type MCanvasSelection. The user-selected point and the tool type chosen from the menu (polygon creation, line creation, ellipse creation, and so on) are passed to the TCanvasView::CreateToolTarget function so it can create the target. The Cursor tools framework calls the CreateInteractor function for the creation tool (which is specified in the code to create the Tool menu) to create the correct interactor for drawing the chosen canvas graphic.
In Mars the delegating mouse tool is the Arrow tool, which the end user uses to select canvas graphics and transform, rotate, or scale selected graphics. The code for the Arrow tool is the same as the code for the graphics creation tools. The only difference is that a TStandardArrowTool is instantiated instead of a graphic creation tool. The Cursor tools framework calls on the application to create the interactor because the application provides the information on how the delegating tool is to behave.
The Tool menu appears to the right of the Edit menu. The following code creates the Tool menu and specifies kTopBottom which means the items will be listed from top to bottom on the menu. Each menu item is added with AdoptLast to put it after the last item on the menu.
The attribute bundle has white fill, black frame, and 1 world coordinate unit pen style for basic canvas graphics. To set the background fill color of a graphic to white, its frame to black with a pen width of 1 world coordinate, create an attribute bundle with the following parameters. The bundle is passed into the graphic's constructor to set the initial fill, frame, and pen style for that graphic.
The Rect tool is created from a basic canvas graphic and the above bundle:
The Ellipse tool is created from a basic canvas graphic and the above bundle.
The menu is created by specifying the menu text and a tool. The Arrow, Line, Polyline, Polygon, Curve and Text items use their respective tools. The Rect and Ellipse items are constructed from a basic canvas graphic tool and an attribute bundle. The framework supplies the appropriate commands and interactors. // Copyright (C) 1995 Taligent, Inc. All rights reserved.
if (!TMarsPresenter::gToolSubMenuItem) {
TMenu *toolsMenu = new TMenu ();
toolsMenu->SetControlLayout(MControl::kTopToBottom);
Arrow tool item with separator line below
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TStandardArrowTool()));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Arrow"))));
popup->SetSeparator (MMenuItem::kAfter);
toolsMenu->AdoptLast (popup);
Line tool
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasLineCreationTool()));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Line"))));
toolsMenu->AdoptLast (popup);
Attribute bundle
TRGBColor black (0.,0.,0.), white (1.,1.,1.);
TGrafBundle* bundle = new TGrafBundle (new TColorPaint(white), new TColorPaint(black), TAttributeState::kFillAndFrame);
bundle->AdoptFramePen ( new TSolidPen(1.) );
Rect tool
TPolygon rect (TGRect(0.,0.,1.,1.), ::Copy(*bundle) );
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TBasicCanvasGraphicCreationTool(rect)));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Rectangle"))));
toolsMenu->AdoptLast (popup);
Ellipse tool
TEllipse ellipse (TGRect(0.,0.,1.,1.), bundle );
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TBasicCanvasGraphicCreationTool(ellipse)));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Ellipse"))));
toolsMenu->AdoptLast (popup);
Polyline tool
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasPolylineCreationTool()));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Polyline"))));
toolsMenu->AdoptLast (popup);
Polygon tool
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasPolygonCreationTool()));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Polygon"))));
toolsMenu->AdoptLast (popup);
Curve tool
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasCurveCreationTool()));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Curve"))));
toolsMenu->AdoptLast (popup);
Text tool
popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasTextGraphicCreationTool()));
popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Text"))));
toolsMenu->AdoptLast (popup);
Labelling the menu
TMarsPresenter::gToolSubMenuItem = new TSubMenuItem (toolsMenu,
new TTextLabel(*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Tools"))));
}
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Generated with WebMaker