bool InputManager::injectMouseRelease(int _absx, int _absy, MouseButton _id) { if (isFocusMouse()) { // если активный элемент заблокирован if (!mWidgetMouseFocus->getInheritedEnabled()) return true; if (_id != MouseButton::None && _id != MouseButton::MAX) { if (mMouseCapture[_id.getValue()]) { // drop capture mMouseCapture[_id.getValue()] = false; } } IntPoint point (_absx, _absy); if (mLayerMouseFocus != nullptr) point = mLayerMouseFocus->getPosition(_absx, _absy); mWidgetMouseFocus->_riseMouseButtonReleased(point.left, point.top, _id); // после вызова, виджет может быть сброшен if (nullptr != mWidgetMouseFocus) { if (MouseButton::Left == _id) { if (mTimerDoubleClick < INPUT_TIME_DOUBLE_CLICK) { mWidgetMouseFocus->_riseMouseButtonClick(); // после вызова, виджет может быть сброшен if (nullptr != mWidgetMouseFocus) mWidgetMouseFocus->_riseMouseButtonDoubleClick(); } else { // проверяем над тем ли мы окном сейчас что и были при нажатии Widget* item = LayerManager::getInstance().getWidgetFromPoint(_absx, _absy); if ( item == mWidgetMouseFocus) { mWidgetMouseFocus->_riseMouseButtonClick(); } mTimerDoubleClick = 0; } } } // для корректного отображения injectMouseMove(_absx, _absy, mOldAbsZ); return true; } return false; }
void BerkeliumWidget::onMouseButtonReleased(int _left, int _top, MouseButton _id) { if (mWindow != nullptr) mWindow->mouseButton(_id.toValue(), false); Base::onMouseButtonReleased(_left, _top, _id); }
void MouseButton::mouse_handler(const SDL_Event& event, void* userdata) { if (event.type != SDL_MOUSEBUTTONDOWN && event.type != SDL_MOUSEBUTTONUP) return; MouseButton* mb = (MouseButton*)userdata; switch (mb->button) { case 1: if (event.button.button == SDL_BUTTON_LEFT) { if (event.button.state == SDL_PRESSED) { mb->pressed = true; mb->button_down(); } else { mb->pressed = false; mb->button_up(); } } break; case 2: if (event.button.button == SDL_BUTTON_MIDDLE) { if (event.button.state == SDL_PRESSED) { mb->pressed = true; mb->button_down(); } else { mb->pressed = false; mb->button_up(); } } break; case 3: if (event.button.button == SDL_BUTTON_RIGHT) { if (event.button.state == SDL_PRESSED) { mb->pressed = true; mb->button_down(); } else { mb->pressed = false; mb->button_up(); } } break; default: // only three buttons support so far break; } }
bool InputManager::injectMousePress(int _absx, int _absy, MouseButton _id) { injectMouseMove(_absx, _absy, mOldAbsZ); // если мы щелкнули не на гуй if (!isFocusMouse()) { resetKeyFocusWidget(); return false; } // если активный элемент заблокирован //FIXME if (!mWidgetMouseFocus->getInheritedEnabled()) return true; if (MouseButton::None != _id && MouseButton::MAX != _id) { // start capture mMouseCapture[_id.getValue()] = true; // remember last pressed position if (mLayerMouseFocus != nullptr) { IntPoint point = mLayerMouseFocus->getPosition(_absx, _absy); mLastPressed[_id.getValue()] = point; } } // ищем вверх тот виджет который может принимать фокус Widget* item = mWidgetMouseFocus; while ((item != nullptr) && (!item->getNeedKeyFocus())) item = item->getParent(); // устанавливаем перед вызовом т.к. возможно внутри ктонить поменяет фокус под себя setKeyFocusWidget(item); if (isFocusMouse()) { IntPoint point (_absx, _absy); if (mLayerMouseFocus != nullptr) point = mLayerMouseFocus->getPosition(_absx, _absy); mWidgetMouseFocus->_riseMouseButtonPressed(point.left, point.top, _id); // после пресса может сброситься if (mWidgetMouseFocus) { // поднимаем виджет, надо подумать что делать если поменялся фокус клавы LayerManager::getInstance().upLayerItem(mWidgetMouseFocus); // поднимаем пикинг Overlapped окон Widget* pick = mWidgetMouseFocus; do { // если оверлаппед, то поднимаем пикинг if (pick->getWidgetStyle() == WidgetStyle::Overlapped) { if (pick->getParent()) pick->getParent()->_forcePick(pick); } pick = pick->getParent(); } while (pick); } } return true; }
inline MouseButton operator&(MouseButton a, MouseButton b) { return MouseButton(a.code() & b.code()); }
inline bool operator==(MouseButton a, MouseButton b) { return a.code() == b.code(); }