int CUI::DoButtonLogic(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { // logic int ReturnValue = 0; int Inside = MouseInside(pRect); static int ButtonUsed = 0; if(ActiveItem() == pID) { if(!MouseButton(ButtonUsed)) { if(Inside && Checked >= 0) ReturnValue = 1+ButtonUsed; SetActiveItem(0); } } else if(HotItem() == pID) { for(int i = 0; i < 3; ++i) { if(MouseButton(i)) { SetActiveItem(pID); ButtonUsed = i; } } } if(Inside) SetHotItem(pID); return ReturnValue; }
int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY) { int Inside = MouseInside(pRect); if(ActiveItem() == pID) { if(!MouseButton(0)) SetActiveItem(0); } else if(HotItem() == pID) { if(MouseButton(0)) SetActiveItem(pID); } else if(Inside) SetHotItem(pID); if(ActiveItem() != pID || !Inside) return 0; if(pX) *pX = (m_MouseX - pRect->x) / Scale(); if(pY) *pY = (m_MouseY - pRect->y) / Scale(); return 1; }
int CUI::DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY) { int Inside = MouseInside(pRect); if(CheckActiveItem(pID)) { if(!MouseButton(0)) SetActiveItem(0); } else if(HotItem() == pID) { if(MouseButton(0)) SetActiveItem(pID); } else if(Inside) SetHotItem(pID); if(!CheckActiveItem(pID)) return 0; if(pX) *pX = clamp(m_MouseX - pRect->x, 0.0f, pRect->w) / Scale(); if(pY) *pY = clamp(m_MouseY - pRect->y, 0.0f, pRect->h) / Scale(); return 1; }
void GLFWCALL Application::mouseButtonCallback(int button, int action) { if(!stateStack_.empty()) { if(action == GLFW_PRESS) { stateStack_.top()->onMouseButtonPress(MouseButton(button)); } else { stateStack_.top()->onMouseButtonRelease(MouseButton(button)); } } }
bool CAndroidMouse::onMouseEvent(AInputEvent* event) { if (event == NULL) return false; int32_t eventAction = AMotionEvent_getAction(event); int8_t mouseAction = eventAction & AMOTION_EVENT_ACTION_MASK; size_t mousePointerIdx = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; int32_t mousePointerId = AMotionEvent_getPointerId(event, mousePointerIdx); #ifdef DEBUG_VERBOSE CXBMCApp::android_printf("%s idx:%i, id:%i", __PRETTY_FUNCTION__, mousePointerIdx, mousePointerId); #endif CPoint in(AMotionEvent_getX(event, mousePointerIdx), AMotionEvent_getY(event, mousePointerIdx)); CPoint out = in * m_droid2guiRatio; switch (mouseAction) { case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_DOWN: MouseButton(out.x, out.y, mouseAction, AMotionEvent_getButtonState(event)); return true; case AMOTION_EVENT_ACTION_SCROLL: MouseWheel(out.x, out.y, AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, mousePointerIdx)); return true; default: MouseMove(out.x, out.y); return true; } return false; }
bool CAndroidMouse::onMouseEvent(AInputEvent* event) { if (event == NULL) return false; int32_t eventAction = AMotionEvent_getAction(event); int8_t mouseAction = eventAction & AMOTION_EVENT_ACTION_MASK; size_t mousePointer = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; CXBMCApp::android_printf("%s pointer:%i", __PRETTY_FUNCTION__, mousePointer); float x = AMotionEvent_getX(event, mousePointer); float y = AMotionEvent_getY(event, mousePointer); switch (mouseAction) { case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_DOWN: MouseButton(x,y,mouseAction); return true; default: MouseMove(x,y); return true; } return false; }
void GlutViewer::glut_mouseclick(int btn, int state, int x, int y) { get_modifiers(); MouseButton button = MouseButton(btn+1); if (state == 0) { // XOR state of three mouse buttons to the mouseState variable if (button <= RightButton) self->mouseState ^= (int)pow(2,button+1); self->mousePress(button, true, x, y); } else { // Release self->mouseState = 0; self->mousePress(button, false, x, y); } glutPostRedisplay(); }
bool InputManager::Update() { SDL_Event event; std::vector< Key > keys; std::vector< MouseButton > mouseButtons; while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_QUIT: return true; break; case SDL_KEYDOWN: { keyStates[ event.key.keysym.sym ] = 'd'; keys.push_back( Key(event.key.keysym.sym) ); } break; case SDL_KEYUP: { keyStates[ event.key.keysym.sym ] = 'u'; keys.push_back( Key(event.key.keysym.sym) ); } break; case SDL_MOUSEBUTTONDOWN: { mouseButtonStates[ event.button.button ] = 'd'; mouseButtons.push_back( MouseButton(event.button.button) ); } break; case SDL_MOUSEBUTTONUP: { mouseButtonStates[ event.button.button ] = 'u'; mouseButtons.push_back( MouseButton(event.button.button) ); } break; default: break; } } for ( std::map<int, char>::iterator itr = keyStates.begin(); itr != keyStates.end(); itr++ ) { // puts no status flag if ( itr->second == 'u' ) { bool keyFound = false; for ( int i = 0; i < int(keys.size()); i++ ) { if ( keys[ i ] == itr->first ) { keyFound = true; break; } } if ( !keyFound ) { itr->second = 'n'; } } else if ( itr->second == 'd' ) { bool keyFound = false; for ( int i = 0; i < int(keys.size()); i++ ) { if ( keys[ i ] == itr->first ) { keyFound = true; break; } } if ( !keyFound ) { itr->second = 'h'; } } } for ( std::map<int, char>::iterator itr = mouseButtonStates.begin(); itr != mouseButtonStates.end(); itr++ ) { // puts no status flag if ( itr->second == 'u' ) { bool buttonFound = false; for ( int i = 0; i < int(mouseButtons.size()); i++ ) { if ( mouseButtons[ i ] == itr->first ) { buttonFound = true; break; } } if ( !buttonFound ) { itr->second = 'n'; } } else if ( itr->second == 'd' ) { bool buttonFound = false; for ( int i = 0; i < int(mouseButtons.size()); i++ ) { if ( mouseButtons[ i ] == itr->first ) { buttonFound = true; break; } } if ( !buttonFound ) { itr->second = 'h'; } } } return false; }
inline MouseButton operator~(MouseButton a) { return MouseButton(~a.code()); }
inline MouseButton operator&(MouseButton a, MouseButton b) { return MouseButton(a.code() & b.code()); }