|
2D Graphics
This step demonstrates interaction with graphic objects. We will use a new class: an interactor. The interactors are used to manage the interactions with graphic objects. One of them will be shown here (the selection interactor), but more than 50 other interactors are available with the product, and developers can define their own.
If you run the sample and click on
the rectangle, you should now see this:
The only changes from the previous
step are the following:
| IlvSelectInteractor* selector = new IlvSelectInteractor(manager,
view); |
This line of code creates a selection
interactor,
by providing the manager and the view where we want to have
the selection behavior. An interactor is dedicated to a specific manager
in a specific view.
| manager->setInteractor(selector, view); |
You can now set the interactor
on the view. It will be applied to every object displayed in this
view. With the selection interactor, every object will be
selectable, moveable, resizable and destroyable. You can select any object
by clicking on it (you see eight handles around it), resize it using the
handles, and destroy it by pressing the "Del" key.
| manager->addAccelerator(QuitAccel, IlvKeyDown, 'q'); |
This new accelerator allows the
user to trigger an action by pressing the 'q' key. This is done with the
addAccelerator
method, by providing the following information:
The function to be called when the action
is triggered: the QuitAccel function is described below.
The event type: here you use a keyboard
key (event type is IlvKeyDown). Other types are available for other
kinds of events.
The event data: for an IlvKeyDown
event, the data is the keyboard key that will trigger the action.
Now let's examine the QuitAccel
function:
static void QuitAccel(IlvManager* mgr, IlvView* view, IlvEvent&
event, IlvAny userArg)
{
IlvDisplay* display = mgr->getDisplay();
delete display;
IlvExit(0);
} |
This function receives the manager
and the view where the event took place, the event itself, and a
user argument that can be provided when the accelerator is defined.
The body of this function simply gets the display from the manager,
deletes it and exits the application. Pressing the 'q' key now exits the
application at any time.
Conclusion
At this point, you can see how easy
it is to develop interactive applications. This example is still very simple
(less than 30 lines of code), but it shows how ILOG Views manages graphic
objects and user interactions.
Download
source code.
|