Application Framework > The Bitmap Editor Application > Step 3: Modifying and Saving a Bitmap > Defining the DrawBitmapInteractor
 
Defining the DrawBitmapInteractor
The DrawBitmapInteractor class is a subclass of IlvInteractor. It is declared in drawinter.h and defined in drawinter.cpp. The purpose of the DrawBitmapInteractor class is to handle interactions that occur in a BitmapView object. When the mouse is clicked and dragged, it generates DrawRectangleCommands to modify the document. Here is the code of the handleEvent method:
IlvBoolean
DrawBitmapInteractor::handleEvent(IlvGraphic* g,
IlvEvent& event,
const IlvTransformer* t)
{
switch (event.getType()) {
case IlvButtonDown:
case IlvButtonDragged: {
IlvPoint point(event.x(),event.y());
if (t)
t->inverse(point);
_document->drawRectangle(point, 2, _document->getPalette());
return IlTrue;
}
default:
return IlFalse;
}
}
The interactor calls the BitmapDocument::drawRectangle method to draw in the document bitmap. This method simply creates a DrawRectangleCommand and executes it:
void
BitmapDocument::drawRectangle(const IlvPoint& point,
IlvDim size,
IlvPalette* palette)
{
doCommand(new DrawRectangleCommand(this,
point,
size,
palette,
"drawRectangle"));
}
The interactor is set on the IlvZoomableIcon object that displays the document bitmap in a BitmapView object. This is done in the BitmapView::initializeView method. The code for this method is the same as in Step 2. The interactor is set at the end of the method by calling:
_icon->setInteractor(new DrawBitmapInteractor(document));

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.