What’s in a command? Since
we’re in a piece of CAD software, we expect many forms of input like text,
points and object selection. You’d expect a command class to reflect that.
You might also want to
replace standard functionality, perhaps assign different meaning for mouse
button etc. Let’s continue the FSM Sample. Here the class for
the createstate command:
class CommandCreateState : public CommandStd
{
public:
CommandCreateState(const StoredId &view);
virtual ~CommandCreateState();
virtual bool PostCreate();
virtual void OnWorldPointClick(const gePoint &pt);
virtual void OnWorldPointMove(const gePoint &pt);
private:
FsmState *state_;
};
There’s a special function
here: PostCreate. If it returns true, it’s assumed
that the command will continue. If it return false, its
considered delete.
When exiting a command
you’re expected to do two things:
Call Commit() or Cancel()
Call Quit()
Think of the Quit call as
a delete this: after you call it – never touch any members again. Just return!
The mouse callbacks
include:
virtual void OnScreenPointClick(const CPoint &pt);
virtual void OnScreenPointRelease(const CPoint &pt);
virtual void OnWorldPointClick(const gePoint &pt);
virtual void OnWorldPointRelease(const gePoint &pt);
virtual void OnScreenPointMiddleClick(const CPoint &pt);
virtual void OnScreenPointMiddleRelease(const CPoint &pt);
virtual void OnScreenPointRightClick(const CPoint &pt);
virtual void OnScreenPointRightRelease(const CPoint &pt);
virtual void OnScreenPointMove(const CPoint &pt);
virtual void OnWorldPointMove(const gePoint &pt);
virtual void OnMouseScroll(UINT nFlags, short zDelta, CPoint pt);
virtual bool QueryContextMenu(UIMenu &menu);
The CPoint
(not portable) usage will be replaced by UIPoint.