ET++: A sample application: iconedit
ET++ application implement their actions using a Command class, which, like the standard
Command pattern, supports undo, redo, etc.
iconedit implements a number of commands to do things like copy, paste, draw rectangles,
and move selections. Below is part of the code to the BitMover command, which
moves the portion of the icon currently selected, and is a fairly standard example of
an ET++ mouse-based command. Basic Do/Undo support is provided in the superclass
ImageCommand, which is superclass to most iconedit commands.
BitMover::BitMover(FatIconView *iv, Rectangle sel, bool cp)
: ImageCommand(iv, cp ? "Copy Bits" : "Move Bits")
{
selection= sel;
copy= cp;
}
void BitMover::TrackFeedback(Point, Point, bool)
{
GrSetPenSize(2);
Rectangle r(selection+delta);
r.Clip(Rectangle(im->Size()));
GrStrokeRect(iconview->PixelToRect(r));
}
Command *BitMover::TrackMouse(TrackPhase atp, Point ap, Point, Point np)
{
delta= iconview->PointToPixel(np)-iconview->PointToPixel(ap);
if (atp == eTrackRelease && delta == gPoint0)
return gNoChanges;
return this;
}
[ ... constrain movement to the icon ... ]
void BitMover::BitDoIt()
{
iconview->SetSelection(selection+delta);
if (!copy)
im->FillRect(selection, bgpixel);
im->CopyPixel(selection+delta, savebm, selection.origin);
}
Back to the top of the IconEdit description
Back to the top of the ET++ pages