11.4. SoWinTouchScreen through SoWinDevice and SoQtTouchScreen through SoQtDevice

SoWinDevice SoWinDevice and SoQtDevice are abstract base classes for Windows and Qt devices in the Open Inventor Windows component. When a device is registered with a SoWinRenderArea SoWinRenderArea (respectively SoQtRenderArea ), the device is able to generate messages in the render area window.

SoWinTouchScreen SoWinTouchScreen and SoQtTouchScreen use SoTouchManager SoTouchManager SoTouchManager to translate specific events into SoTouchEvent SoTouchEvent SoTouchEvent . On each operating system, translateEvent() keeps needed information and calls updateAndProcessTouchEvent(). In this way, the update is independent of the operating system and the only purpose of a specific touch screen is to collect information on specific events from the operating system.

Example 11.1.  SoWinTouchScreen registering

int main(int, char **argv)
{
Widget appWindow = SoWin::init(argv[0]);
myRenderArea = new SoWinRenderArea(appWindow);
[…]
SoWinTouchScreen touchScreenDevice(appWindow);
myRenderArea->registerDevice(&touchScreenDevice);
[…]
}


First, we call init() to initialize Open Inventor and Windows and bind Open Inventor with Windows message handling. Then, an SoWinRenderArea SoWinRenderArea is created to provide Open Inventor rendering and message handling inside the window. Finally, we create the touch screen device and register it in the render area. Now, messages from that device will be processed by the render area and passed into the scene graph.

As explained inChapter 11, Creating an Event and Device there are two functions implemented in each device that enable and disable the device for the given widget.

In the Windows case, enable() verifies if the current operating system is Windows 7, the state of the device and the type of digitizer input supported. It also saves the maximum number of contacts supported by every digitizer in the system in its touch manager.

In the Qt case the enable() function just allows the widget to accept touch event.

When the device is ready to receive touch event, it has to translate them into the Open Inventor event model.

translateEvent():

The device looks at the type of each event and updates the SoTouchManager SoTouchManager SoTouchManager table of events using updateAndProcessTouchEvent(). This function takes the finger identifier, its current state, position and current time and updates the corresponding event and the identifiers table. If position has changed, this method processes the event in the render area and sends it in every recognizer registered in the recognizer list.