//////////////////////////////////////////////////////////// /// Update the current joystick and return its new state //////////////////////////////////////////////////////////// JoystickState Joystick::UpdateState() { if (myDescriptor > 0) { js_event JoyState; while (read(myDescriptor, &JoyState, sizeof(JoyState)) > 0) { switch (JoyState.type & ~JS_EVENT_INIT) { // An axis has been moved case JS_EVENT_AXIS : { switch (myAxesMapping[JoyState.number]) { case ABS_X : myState.Axis[Joy::AxisX] = JoyState.value * 100.f / 32767.f; break; case ABS_Y : myState.Axis[Joy::AxisY] = JoyState.value * 100.f / 32767.f; break; case ABS_Z : case ABS_THROTTLE : myState.Axis[Joy::AxisZ] = JoyState.value * 100.f / 32767.f; break; case ABS_RZ: case ABS_RUDDER: myState.Axis[Joy::AxisR] = JoyState.value * 100.f / 32767.f; break; case ABS_RX : myState.Axis[Joy::AxisU] = JoyState.value * 100.f / 32767.f; break; case ABS_RY : myState.Axis[Joy::AxisV] = JoyState.value * 100.f / 32767.f; break; case ABS_HAT0X : myPovX = JoyState.value; break; case ABS_HAT0Y : myPovY = JoyState.value; break; default : break; } // Compute the new POV angle if (myPovX > 0) { if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 135.f; else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 45.f; else myState.Axis[Joy::AxisPOV] = 90.f; } else if (myPovX < 0) { if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 225.f; else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 315.f; else myState.Axis[Joy::AxisPOV] = 270.f; } else { if (myPovY > 0) myState.Axis[Joy::AxisPOV] = 180.f; else if (myPovY < 0) myState.Axis[Joy::AxisPOV] = 0.f; else myState.Axis[Joy::AxisPOV] = -1.f; } break; } // A button has been pressed case JS_EVENT_BUTTON : { if (JoyState.number < GetButtonsCount()) myState.Buttons[JoyState.number] = (JoyState.value != 0); break; } } } } return myState; }
//////////////////////////////////////////////////////////// /// Update the current joystick and return its new state //////////////////////////////////////////////////////////// JoystickState Joystick::UpdateState() { JoystickState State; if (myIsConnected) { // Get the joystick caps (for range conversions) JOYCAPS Caps; if (joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) == JOYERR_NOERROR) { // Get the current joystick state JOYINFOEX Pos; Pos.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV | JOY_RETURNBUTTONS; Pos.dwFlags |= myHasContinuousPOV ? JOY_RETURNPOVCTS : JOY_RETURNPOV; Pos.dwSize = sizeof(JOYINFOEX); if (joyGetPosEx(myIndex, &Pos) == JOYERR_NOERROR) { // Axes State.Axis[Joy::AxisX] = (Pos.dwXpos - (Caps.wXmax + Caps.wXmin) / 2.f) * 200.f / (Caps.wXmax - Caps.wXmin); State.Axis[Joy::AxisY] = (Pos.dwYpos - (Caps.wYmax + Caps.wYmin) / 2.f) * 200.f / (Caps.wYmax - Caps.wYmin); State.Axis[Joy::AxisZ] = (Pos.dwZpos - (Caps.wZmax + Caps.wZmin) / 2.f) * 200.f / (Caps.wZmax - Caps.wZmin); State.Axis[Joy::AxisR] = (Pos.dwRpos - (Caps.wRmax + Caps.wRmin) / 2.f) * 200.f / (Caps.wRmax - Caps.wRmin); State.Axis[Joy::AxisU] = (Pos.dwUpos - (Caps.wUmax + Caps.wUmin) / 2.f) * 200.f / (Caps.wUmax - Caps.wUmin); State.Axis[Joy::AxisV] = (Pos.dwVpos - (Caps.wVmax + Caps.wVmin) / 2.f) * 200.f / (Caps.wVmax - Caps.wVmin); // POV if (Pos.dwPOV != 0xFFFF) State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f; else State.Axis[Joy::AxisPOV] = -1.f; // Buttons for (unsigned int i = 0; i < GetButtonsCount(); ++i) State.Buttons[i] = (Pos.dwButtons & (1 << i)) != 0; } } } return State; }
BOOL CExtThemeSwitcherToolControlBar::PreTranslateMessage( MSG * pMsg ) { if( m_bCommandProfileInitialized && GetSafeHwnd() != NULL && pMsg->message == CExtPopupMenuWnd::g_nMsgPrepareOneMenuLevel ) { CExtPopupMenuWnd::MsgPrepareMenuData_t * pData = reinterpret_cast < CExtPopupMenuWnd::MsgPrepareMenuData_t * > ( pMsg->wParam ); ASSERT( pData != NULL ); CExtPopupMenuWnd * pPopup = pData->m_pPopup; ASSERT( pPopup != NULL ); #if (!defined __EXT_MFC_NO_CUSTOMIZE) bool bCustomizeMode = false; CExtPopupMenuWnd * pTestPopup = pPopup; for( ; pTestPopup != NULL ; pTestPopup = pTestPopup->GetParentMenuWnd() ) { if( (pPopup->TrackFlagsGet()&TPMX_CUSTOMIZE_MODE) != 0 ) { bCustomizeMode = true; break; } } if( ! bCustomizeMode ) { CExtCustomizeSite * pSite = CExtCustomizeSite::GetCustomizeSite( m_hWnd ); if( pSite != NULL ) { bCustomizeMode = pSite->IsCustomizeMode(); if( ! bCustomizeMode ) bCustomizeMode = ( pSite->DraggedNodeGet() != NULL ) ? true : false; } } if( ! bCustomizeMode ) #endif // (!defined __EXT_MFC_NO_CUSTOMIZE) { for( ; true; ) { INT nReplacePos = pPopup->ItemFindPosForCmdID( m_nMenuMarkerID ); if( nReplacePos < 0 ) break; pData->m_bMenuChanged = true; pPopup->ItemRemove( nReplacePos ); INT nIndex, nCount = GetButtonsCount(); for( nIndex = 0; nIndex < nCount; nIndex++ ) { CExtBarButton * pQueueTBB = GetButton( nIndex ); ASSERT_VALID( pQueueTBB ); CExtThemeSwitcherToolButton * pTBB = DYNAMIC_DOWNCAST( CExtThemeSwitcherToolButton, pQueueTBB ); if( pTBB == NULL ) continue; ThemeSwitcher_OnButtonUpdate( pTBB ); pTBB->PutToPopupMenu( pPopup ); } // for( nIndex = 0; nIndex < nCount; nIndex++ ) } } } return FALSE; }