This example shows how to create and register an event processor.
This event processor bypasses the key mapping system. It toggles wireframe mode on or off whenever the F key is pressed, regardless of any key mapping to the contrary.
Note: Any functions mapped to the F key in a key map will not be executed, because the event processor returns true, indicating that the event has been handled.
- Create the new event processor class derived from DtEventProcessorInterface. We provide a reference to DtDisplayEngine, since we will need this to toggle wireframe mode.
class MyEventProcessor : public DtEventProcessorInterface
{
public:
MyEventProcessor( DtDe& de )
: myDe( de )
, myClassName( "MyEventProcessor" )
{
}
- The destructor is trivial, as is the processMouseEvent(), since we do not care about those. It is important that processMouseEvent return false, otherwise our processor will block all mouse messages. classname() simply returns the name of our class; this can be used to remove a processor from the event processor queue if desired.
virtual ~MyEventProcessor()
{
}
virtual bool processMouseEvent( const DtMouseEvent& ev, DtChannel& channel)
{
return false;
}
- The processKeyboardEvent() method does the work for this event processor. It checks to see if the event is a KEY_DOWN event, and if so, if the key pressed was KEY_R. It also makes sure that the modifiers are NO_MODIFIER, so that it will not mistakenly process SHIFT-F, CTRL-F, etc. Note that if we didn't check for the KEY_DOWN event explicitly, our processor would process the KEY_DOWN and KEY_UP events, which would provide us with a momentary key; pressing F would turn on wireframe mode, and releasing it would turn it back off.
virtual bool processKeyboardEvent( const DtKeyEvent& ev, DtChannel& channel)
{
if ( ev.eventType() == DtKeyEvent::KEY_DOWN &&
ev.keyState().keyType() == DtKeyState::KEY_F &&
ev.keyState().modifiers() == DtKeyState::NO_MODIFIER )
{
return true;
}
return false;
}
- Declare the member variables, and the class is complete.
- Now we need to register our new event processor with the input driver. To do so, we add the following code after initialization. Note that we create the processor on the heap (using 'new') rather than on the stack, since the input processor takes control of the resource and deletes it when it is destroyed.
MyEventProcessor* captureF = new MyEventProcessor( igApp.de() );
DtInputDriver& inputDriver =
igApp.de().driverManager().inputDriver();
Building the Example
VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is an application. You can run it by running ./bin/exampleEventProcessor.exe (on Windows) or ./bin/exampleEventProcessor (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleEventProcessor.cxx
#include <boost/bind.hpp>
using namespace makVrv;
{
public:
MyEventProcessor(
DtDe& de )
: myDe( de )
, myClassName( "MyEventProcessor" )
{
}
virtual ~MyEventProcessor()
{
}
{
return false;
}
{
{
myDe.sharedState().setWireframeMode(!myDe.sharedState().wireframeMode());
return true;
}
return false;
}
{
return myClassName;
}
protected:
};
int main(int argc,char** argv)
{
MyEventProcessor* captureF =
new MyEventProcessor( igApp.
de() );
}