Managing Events: Accelerators
An accelerator manages a single user event that occurs in the container to which the accelerator is attached. An accelerator is the direct connection from this single user event to a function call. You can declare a given function to be called if an appropriate event occurs. If the appropriate event occurs, the accelerator triggers a visible response from the container to which it is attached.
You can also install an instance of the IlvContainerAccelerator class in an accelerator list. This instance contains the description of the event to be watched for, and a member function of this class is called when this event occurs.
For more details, see:
Member Functions
Several member functions deal with accelerators:
addAccelerator Installs a new accelerator in the container. In the example below, the function
Quit is triggered when one event matches the keyboard event “release Q key.”
static void Quit(IlvContainer* cont, IlvEvent&, IlAny) { IlvDisplay* d = cont->getDisplay(); delete d; IlvExit(0); }IlvRect size(0, 0, 300, 300); IlvContainer* cont = new IlvContainer(display, "Cont", "My Window", size, IlTrue, IlFalse); cont->addAccelerator(Quit, IlvKeyUp, ’Q’, 0); |
getAccelerator Queries a container for a particular accelerator action and user argument.
Implementing Accelerators: IlvContainerAccelerator
If you need to add parameters to a callback function, you can implement accelerators by means of class subtyping, through the IlvContainerAccelerator class.
The member functions dealing with this class are the following:
addAccelerator Installs an
IlvContainerAccelerator object in the container. The previous example can thus be written in the following way:
IlvContainerAccelerator* acc = new IlvContainerAccelerator(Quit, IlvKeyUp, 'Q', 0); cont->addAccelerator(acc); |
removeAccelerator Removes the given accelerator argument from the container list. The accelerator is not deleted.
getAccelerator Returns a pointer to the
IlvContainerAccelerator instance that matches the given event argument, or
0 if no matching accelerator exists.
Predefined Container Accelerators
Rogue Wave Views provides a number of predefined accelerators to allow your programs to easily manipulate the visible aspect of the objects that are stored in a container:
Table 9.1 Predefined Container Accelerators
Event Type | Key or Button | Action |
IlvKeyDown | i | Sets the transformer to identity. |
IlvKeyDown | <Right> | Moves the view to the left. |
IlvKeyDown | <Left> | Moves the view to the right. |
IlvKeyDown | <Down> | Moves the view to the top (decreasing x) |
IlvKeyDown | <Up> | Moves the view to the bottom. (increasing x) |
IlvKeyDown | Z | Zooms into the view. |
IlvKeyDown | U | Zooms out from the view. |
IlvKeyDown | R | Rotates the view 90 degrees counterclockwise. |
IlvKeyDown | f | Computes a new transformer so that every object can be seen. |
Version 5.7
Copyright © 2013, Rogue Wave Software, Inc. All Rights Reserved.