//----------------------------------------------------------------------------- // Test if a message comes from the SpaceNavigator device. If yes, dispatch // it appropriately and return true. Otherwise, do nothing and return false. //----------------------------------------------------------------------------- static bool ProcessSpaceNavigatorMsg(MSG *msg) { if(SpaceNavigator == SI_NO_HANDLE) return false; SiGetEventData sged; SiSpwEvent sse; SiGetEventWinInit(&sged, msg->message, msg->wParam, msg->lParam); int ret = SiGetEvent(SpaceNavigator, 0, &sged, &sse); if(ret == SI_NOT_EVENT) return false; // So the device is a SpaceNavigator event, or a SpaceNavigator error. if(ret == SI_IS_EVENT) { if(sse.type == SI_MOTION_EVENT) { // The Z axis translation and rotation are both // backwards in the default mapping. double tx = sse.u.spwData.mData[SI_TX]*1.0, ty = sse.u.spwData.mData[SI_TY]*1.0, tz = -sse.u.spwData.mData[SI_TZ]*1.0, rx = sse.u.spwData.mData[SI_RX]*0.001, ry = sse.u.spwData.mData[SI_RY]*0.001, rz = -sse.u.spwData.mData[SI_RZ]*0.001; SS.GW.SpaceNavigatorMoved(tx, ty, tz, rx, ry, rz, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); } else if(sse.type == SI_BUTTON_EVENT) { int button; button = SiButtonReleased(&sse); if(button == SI_APP_FIT_BUTTON) SS.GW.SpaceNavigatorButtonUp(); } } return true; }
/* translates a Win32 event to a SPW_InputEvent. */ int SPW_TranslateEventWin32(MSG * msg, SPW_InputEvent * sbEvent) { SiSpwEvent spwEvent; SiGetEventData eventdata; if (Spw_DeviceHandle != SI_NO_HANDLE) { SiGetEventWinInit (&eventdata, msg->message, msg->wParam, msg->lParam); if (SiGetEvent (Spw_DeviceHandle, 0, &eventdata, &spwEvent) == SI_IS_EVENT) { int i; switch(spwEvent.type) { case SI_MOTION_EVENT: sbEvent->type = SPW_InputMotionEvent; for(i=0; i<6; i++) { sbEvent->sData[i] = (short)spwEvent.u.spwData.mData[i]; } break; case SI_BUTTON_EVENT: sbEvent->type = SPW_InputButtonPressEvent; sbEvent->buttonState.pressed = (SiButtonPressed(&spwEvent) != SI_NO_BUTTON); sbEvent->buttonState.released = (SiButtonReleased(&spwEvent) != SI_NO_BUTTON); break; } return TRUE; } } return FALSE; }
/*-------------------------------------------------------------------------- * Function: DispatchLoopNT() * * Description: * This function contains the main message loop which constantly checks for * SpaceBall Events and handles them apropriately. * * Args: None * * * Return Value: * int msg.wparam // event passed to window * *--------------------------------------------------------------------------*/ int DispatchLoopNT() { int num; /* number of button pressed */ MSG msg; /* incoming message to be evaluated */ BOOL handled; /* is message handled yet */ SiSpwEvent Event; /* SpaceWare Event */ SiGetEventData EData; /* SpaceWare Event Data */ handled = SPW_FALSE; /* init handled */ /* start message loop */ while ( GetMessage( &msg, NULL, 0, 0 ) ) { handled = SPW_FALSE; /* init Window platform specific data for a call to SiGetEvent */ SiGetEventWinInit(&EData, msg.message, msg.wParam, msg.lParam); /* check whether msg was a Spaceball event and process it */ if (SiGetEvent (devHdl, 0, &EData, &Event) == SI_IS_EVENT) { if (Event.type == SI_MOTION_EVENT) { SbMotionEvent(&Event); /* process Spaceball motion event */ } if (Event.type == SI_ZERO_EVENT) { SbZeroEvent(); /* process Spaceball zero event */ } if (Event.type == SI_BUTTON_EVENT) { if ((num = SiButtonPressed (&Event)) != SI_NO_BUTTON) { SbButtonPressEvent(num); /* process Spaceball button event */ } if ((num = SiButtonReleased (&Event)) != SI_NO_BUTTON) { SbButtonReleaseEvent(num); /* process Spaceball button event */ } } handled = SPW_TRUE; /* spaceball event handled */ } /* not a Spaceball event, let windows handle it */ if (handled == SPW_FALSE) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } return( msg.wParam ); }
int SbButtonEvent(SiOpenData *pOData, SiGetEventData *pEData, SiSpwEvent *pEvent, void *pUData) { int button; if ((button = SiButtonReleased (pEvent)) != SI_NO_BUTTON) SbButtonReleaseEvent(button, pUData); if ((button = SiButtonPressed (pEvent)) != SI_NO_BUTTON) SbButtonPressEvent(button, pUData); return (0); }