contrib/brl/bbas/bgui3d/bgui3d_translate_event.cxx
Go to the documentation of this file.
00001 // This is brl/bbas/bgui3d/bgui3d_translate_event.cxx
00002 #include "bgui3d_translate_event.h"
00003 //:
00004 // \file
00005 
00006 #include <Inventor/events/SoKeyboardEvent.h>
00007 #include <Inventor/events/SoMouseButtonEvent.h>
00008 #include <Inventor/events/SoLocation2Event.h>
00009 
00010 #include <vul/vul_get_timestamp.h>
00011 
00012 //: Translate a \p vgui_event to an \p SoEvent*
00013 SoEvent*
00014 bgui3d_translate_event(const vgui_event& v_event)
00015 {
00016   SoEvent* i_event = NULL;
00017   switch (v_event.type)
00018   {
00019    case vgui_BUTTON_DOWN: {
00020     SoMouseButtonEvent * temp = new SoMouseButtonEvent;
00021     temp->setButton(SoMouseButtonEvent::Button(v_event.button));
00022     temp->setState(SoButtonEvent::DOWN);
00023     i_event = temp;
00024     break; }
00025    case vgui_BUTTON_UP: {
00026     SoMouseButtonEvent * temp = new SoMouseButtonEvent;
00027     temp->setButton(SoMouseButtonEvent::Button(v_event.button));
00028     temp->setState(SoButtonEvent::UP);
00029     i_event = temp;
00030     break; }
00031    case vgui_MOTION:
00032     i_event = new SoLocation2Event;
00033     break;
00034    case vgui_KEY_PRESS: {
00035     SoKeyboardEvent * temp = new SoKeyboardEvent;
00036     temp->setKey(SoKeyboardEvent::Key(v_event.key));
00037     temp->setState(SoButtonEvent::DOWN);
00038     i_event = temp;
00039     break; }
00040    case vgui_KEY_RELEASE: {
00041     SoKeyboardEvent * temp = new SoKeyboardEvent;
00042     temp->setKey(SoKeyboardEvent::Key(v_event.key));
00043     temp->setState(SoButtonEvent::UP);
00044     i_event = temp;
00045     break; }
00046    default:
00047     i_event = new SoEvent;
00048     break;
00049   }
00050 
00051   // Compute the absolute timestamp since vgui_events only store
00052   // time relative to the start of the application
00053   int secs_now, msecs_now;
00054   vul_get_timestamp(secs_now, msecs_now);
00055   // adjust for time since this event was constructed (usually very small)
00056   long usecs_now = long(msecs_now)*1000 + v_event.usecs_since(vgui_event());
00057   i_event->setTime(SbTime(secs_now, usecs_now));
00058 
00059   i_event->setPosition(SbVec2s(v_event.wx,v_event.wy));
00060 
00061   switch (v_event.modifier)
00062   {
00063    case vgui_CTRL:
00064     i_event->setCtrlDown(true);
00065     break;
00066    case vgui_SHIFT:
00067     i_event->setShiftDown(true);
00068     break;
00069    case vgui_ALT:
00070     i_event->setAltDown(true);
00071     break;
00072    default:
00073     break;
00074   }
00075 
00076   return i_event;
00077 }