Creating the move command

Like the TChangeColorCommand created in Step 3, TMoveCommand derives from TCommandOn<TTilesSelection>, the Basic Document framework template class for commands. As required for TCommandOn<ATarget> derived classes, TMoveCommand overrides HandleDoBegin. Because TMoveCommand is an incremental command, it also needs to override HandleDoIncrement, the function invoked by messages from the interactor as the mouse is moved. HandleDoBegin saves the original position of the tile; HandleDoIncrement moves the tile by the amount of the delta between the original position of the tile and the current mouse position.

To enable undo and redo, TMoveCommand maintains both the original position of the tile and the delta between the original position and the current position. The original position is stored once when the command begins executing. The delta is updated incrementally as the command continues to execute--TMoveCommand has a MoveBy function that HandleDoIncrement calls to update the delta. Note that although the command's original execution is incremental, Undo and Redo are not incremental:

TMoveCommand changes the position of the selected tile by changing the position information stored by the TTile instance. Two functions are added to TTilesSelection--SetPosition and GetPosition. These functions retrieve the specified tile from the model and access the position data. These functions also provide the interface for TMoveCommand functions to update the model.


NOTE TMoveCommand works only on a selection representing a single tile.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker