void Engine::_ProcessEvents(void) { SDL_Event evt; while(!s_quit && SDL_PollEvent(&evt)) { if(!OnRawEvent(evt)) continue; switch(evt.type) { case SDL_KEYDOWN: OnKeyDown(evt.key.keysym.sym, evt.key.keysym.mod); break; case SDL_KEYUP: OnKeyUp(evt.key.keysym.sym, evt.key.keysym.mod); break; case SDL_JOYAXISMOTION: OnJoystickEvent(evt.jaxis.type, evt.jaxis.which, evt.jaxis.axis, evt.jaxis.value); break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: OnJoystickEvent(evt.jbutton.type, evt.jbutton.which, evt.jbutton.button, evt.jbutton.state); break; case SDL_JOYHATMOTION: OnJoystickEvent(evt.jhat.type, evt.jhat.which, evt.jhat.hat, evt.jhat.value); break; case SDL_ACTIVEEVENT: OnWindowEvent(evt.active.gain); break; case SDL_VIDEORESIZE: OnWindowResize(evt.resize.w, evt.resize.h); break; case SDL_MOUSEMOTION: OnMouseEvent(evt.type, 0, evt.motion.state, evt.motion.x, evt.motion.y, evt.motion.xrel, evt.motion.yrel); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: OnMouseEvent(evt.type, evt.button.button, evt.button.state, evt.button.x, evt.button.y, 0, 0); break; case SDL_QUIT: SetQuit(true); break; } } }
EVENT_RESULT CGUIControlGroup::SendMouseEvent(const CPoint &point, const CMouseEvent &event) { // transform our position into child coordinates CPoint childPoint(point); m_transform.InverseTransformPosition(childPoint.x, childPoint.y); if (CGUIControl::CanFocus()) { CPoint pos(GetPosition()); // run through our controls in reverse order (so that last rendered is checked first) for (rControls i = m_children.rbegin(); i != m_children.rend(); ++i) { CGUIControl *child = *i; EVENT_RESULT ret = child->SendMouseEvent(childPoint - pos, event); if (ret) { // we've handled the action, and/or have focused an item return ret; } } // none of our children want the event, but we may want it. EVENT_RESULT ret; if (HitTest(childPoint) && (ret = OnMouseEvent(childPoint, event))) return ret; } m_focusedControl = 0; return EVENT_RESULT_UNHANDLED; }
EVENT_RESULT CGUIControlGroupList::SendMouseEvent(const CPoint &point, const CMouseEvent &event) { // transform our position into child coordinates CPoint childPoint(point); m_transform.InverseTransformPosition(childPoint.x, childPoint.y); if (CGUIControl::CanFocus()) { float pos = 0; float alignOffset = GetAlignOffset(); for (ciControls i = m_children.begin(); i != m_children.end(); ++i) { CGUIControl *child = *i; if (child->IsVisible()) { if (IsControlOnScreen(pos, child)) { // we're on screen float offsetX = m_orientation == VERTICAL ? m_posX : m_posX + alignOffset + pos - m_scroller.GetValue(); float offsetY = m_orientation == VERTICAL ? m_posY + alignOffset + pos - m_scroller.GetValue() : m_posY; EVENT_RESULT ret = child->SendMouseEvent(childPoint - CPoint(offsetX, offsetY), event); if (ret) { // we've handled the action, and/or have focused an item return ret; } } pos += Size(child) + m_itemGap; } } // none of our children want the event, but we may want it. EVENT_RESULT ret; if (HitTest(childPoint) && (ret = OnMouseEvent(childPoint, event))) return ret; } m_focusedControl = 0; return EVENT_RESULT_UNHANDLED; }
void AButton::OnCaptureLost(wxMouseCaptureLostEvent & WXUNUSED(event)) { wxMouseEvent e(wxEVT_LEFT_UP); e.m_x = -1; e.m_y = -1; OnMouseEvent(e); }
EVENT_RESULT CGUIControl::SendMouseEvent(const CPoint &point, const CMouseEvent &event) { CPoint childPoint(point); m_transform.InverseTransformPosition(childPoint.x, childPoint.y); if (!CanFocusFromPoint(childPoint)) return EVENT_RESULT_UNHANDLED; bool handled = OnMouseOver(childPoint); EVENT_RESULT ret = OnMouseEvent(childPoint, event); if (ret) return ret; return (handled && (event.m_id == ACTION_MOUSE_MOVE)) ? EVENT_RESULT_HANDLED : EVENT_RESULT_UNHANDLED; }
LRESULT CWkeWebkitWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { if ( uMsg != WM_CREATE && m_pWebView == NULL) return -1; LRESULT lRes = 0; BOOL bHandled = TRUE; switch (uMsg) { case WM_PAINT: lRes = OnPaint(uMsg, wParam, lParam, bHandled); break; case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break; case WM_DESTROY: lRes = OnDestroy(uMsg, wParam, lParam, bHandled); break; case WM_MOUSEWHEEL: lRes = OnMouseWheel(uMsg, wParam, lParam, bHandled); break; case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break; case WM_CHAR: lRes = OnChar(uMsg, wParam, lParam, bHandled); break; case WM_KEYDOWN: lRes = OnKeyDown(uMsg, wParam, lParam, bHandled); break; case WM_KEYUP: lRes = OnKeyUp(uMsg, wParam, lParam, bHandled); break; case WM_KILLFOCUS: lRes = OnKillFocus(uMsg, wParam, lParam, bHandled); break; case WM_SETFOCUS: lRes = OnSetFocus(uMsg, wParam, lParam, bHandled); break; case WM_TIMER: lRes = OnTimer(uMsg, wParam, lParam, bHandled); break; case WM_IME_STARTCOMPOSITION: lRes = OnImeStartComposition(uMsg, wParam, lParam, bHandled); break; case WM_CONTEXTMENU: lRes= OnContextMenu(uMsg, wParam, lParam, bHandled); break; case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_MBUTTONUP: case WM_RBUTTONUP: case WM_LBUTTONDBLCLK: case WM_MBUTTONDBLCLK: case WM_RBUTTONDBLCLK: case WM_MOUSEMOVE: case WM_MOUSELEAVE: lRes = OnMouseEvent(uMsg, wParam, lParam, bHandled); break; default: bHandled = FALSE; break; } if (bHandled) return lRes; return CWindowWnd::HandleMessage(uMsg, wParam, lParam); }
void CInputAdapter::OnNotify( CORE::CNotifier* notifier , const CORE::CEvent& eventid , CORE::CICloneable* eventdata ) {GUCEF_TRACE; if ( NULL != m_rocketContext ) { INPUT::CAbstractInputDevice* inputDevice = static_cast< INPUT::CAbstractInputDevice* >( notifier ); if ( inputDevice->IsDeviceType( INPUT::CMouse::DeviceType ) ) { OnMouseEvent( static_cast< INPUT::CMouse* >( notifier ) , eventid , eventdata ); } else if ( inputDevice->IsDeviceType( INPUT::CKeyboard::DeviceType ) ) { OnKeyboardEvent( static_cast< INPUT::CKeyboard* >( notifier ) , eventid , eventdata ); } } }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { #ifndef WM_MOUSEWHEEL #define WM_MOUSEWHEEL 0x020A #endif #ifndef WHEEL_DELTA #define WHEEL_DELTA 120 #endif switch (message) { case WM_ERASEBKGND: return 0; case WM_KEYUP: { InputSystem::Instance()->GetKeyboard()->OnSystemKeyUnpressed((int32)wParam); }; break; case WM_KEYDOWN: { BYTE allKeys[256]; GetKeyboardState(allKeys); if ((allKeys[VK_MENU] & 0x80) && (allKeys[VK_TAB] & 0x80)) { ShowWindow(hWnd, SW_MINIMIZE); } Vector<DAVA::UIEvent> touches; Vector<DAVA::UIEvent> emptyTouches; for(Vector<DAVA::UIEvent>::iterator it = activeTouches.begin(); it != activeTouches.end(); it++) { touches.push_back(*it); } DAVA::UIEvent ev; ev.keyChar = 0; ev.phase = DAVA::UIEvent::PHASE_KEYCHAR; ev.tapCount = 1; ev.tid = InputSystem::Instance()->GetKeyboard()->GetDavaKeyForSystemKey((int32)wParam); touches.push_back(ev); UIControlSystem::Instance()->OnInput(0, emptyTouches, touches); touches.pop_back(); UIControlSystem::Instance()->OnInput(0, emptyTouches, touches); InputSystem::Instance()->GetKeyboard()->OnSystemKeyPressed((int32)wParam); }; break; case WM_CHAR: { if(wParam > 27) //TODO: remove this elegant check { Vector<DAVA::UIEvent> touches; Vector<DAVA::UIEvent> emptyTouches; for(Vector<DAVA::UIEvent>::iterator it = activeTouches.begin(); it != activeTouches.end(); it++) { touches.push_back(*it); } DAVA::UIEvent ev; ev.keyChar = (char16)wParam; ev.phase = DAVA::UIEvent::PHASE_KEYCHAR; ev.tapCount = 1; ev.tid = 0; touches.push_back(ev); UIControlSystem::Instance()->OnInput(0, emptyTouches, touches); touches.pop_back(); UIControlSystem::Instance()->OnInput(0, emptyTouches, touches); } } break; case WM_INPUT: { UINT dwSize; GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)); LPBYTE lpb = new BYTE[dwSize]; if (lpb == NULL) return 0; if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize ) OutputDebugString (TEXT("GetRawInputData does not return correct size !\n")); RAWINPUT* raw = (RAWINPUT*)lpb; if(raw->header.dwType == RIM_TYPEMOUSE && raw->data.mouse.usFlags == 0) { LONG x = raw->data.mouse.lLastX; LONG y = raw->data.mouse.lLastY; bool isMove = x || y; if(InputSystem::Instance()->IsCursorPining()) { RECT wndRect; GetWindowRect(hWnd, &wndRect); int centerX = (int)((wndRect.left + wndRect.right) >> 1); int centerY = (int)((wndRect.bottom + wndRect.top) >> 1); SetCursorPos(centerX, centerY); } else { POINT p; GetCursorPos(&p); ScreenToClient(hWnd, &p); x += p.x; y += p.y; } RECT clientRect; GetClientRect(hWnd, &clientRect); bool isInside = (x > clientRect.left && x < clientRect.right && y > clientRect.top && y < clientRect.bottom) || InputSystem::Instance()->IsCursorPining(); OnMouseEvent(raw->data.mouse.usButtonFlags, MAKEWPARAM(isMove, isInside), MAKELPARAM(x, y), raw->data.mouse.usButtonData); // only move, drag and wheel events }
void CheckEvents(float & mouseX, float & mouseY) { SDL_Event event; bool mouseDown; int mouseBtn; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: DoQuit(); break; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_MAXIMIZED: if (event.window.data1 == 0 || event.window.data2 == 0) continue; ScreenW = event.window.data1; ScreenH = event.window.data2; SDL_SetWindowSize(Screen, ScreenW, ScreenH); glViewport(0, 0, ScreenW, ScreenH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, ScreenW, ScreenH, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); break; } break; case SDL_MOUSEMOTION: if (sIni.Mouse) { mouseDown = false; mouseBtn = 0; } sDisplay.MoveCursor((float) event.button.x * RenderW * Screens / ScreenW, (float) event.button.y * RenderH / ScreenH); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (sIni.Mouse) { mouseDown = (event.type == SDL_MOUSEBUTTONDOWN); mouseBtn = event.button.button; if (mouseBtn == SDL_BUTTON_LEFT || mouseBtn == SDL_BUTTON_RIGHT) sDisplay.OnMouseButton(mouseDown); } break; case SDL_WINDOWEVENT_RESIZED: break; case SDL_KEYDOWN: OnKeyDownEvent(event.key.keysym.sym); break; case SDL_MOUSEWHEEL: if (event.wheel.y == 0) continue; mouseDown = true; mouseBtn = (event.wheel.y < 0 ? SDL_BUTTON_WHEELDOWN : SDL_BUTTON_WHEELUP); break; case SDL_JOYAXISMOTION: break; case SDL_JOYBUTTONDOWN: break; case SDL_TEXTINPUT: case SDL_TEXTEDITING: OnTextInputEvent(&event); break; case MAINTHREAD_EXEC_EVENT: break; } switch (event.type) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: case SDL_MOUSEMOTION: mouseX = (float) event.button.x; mouseY = (float) event.button.y; OnMouseEvent(mouseBtn, mouseDown, mouseX, mouseY); break; case SDL_MOUSEWHEEL: OnMouseEvent(mouseBtn, mouseDown, mouseX, mouseY); break; } } }
INT_PTR Dialog::DialogProcDefault(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: { return OnClose(); } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDOK: OnOK(); return TRUE; case IDCANCEL: OnCancel(); return TRUE; default: return OnCommand(wParam, lParam); } break; } case WM_CONTEXTMENU: { POINT pt = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; OnContextMenu(reinterpret_cast<HWND>(wParam), pt); break; } case WM_DESTROY: { OnDestroy(); break; } case WM_INITDIALOG: { #ifdef TAIGA_WIN_DIALOG_REMEMBER_LAST_POSITION_AND_SIZE if (pos_last_.x && pos_last_.y) SetPosition(nullptr, pos_last_.x, pos_last_.y, 0, 0, SWP_NOSIZE); if (size_last_.cx && size_last_.cy) SetPosition(nullptr, 0, 0, size_last_.cx, size_last_.cy, SWP_NOMOVE); #endif return OnInitDialog(); } case WM_DROPFILES: { OnDropFiles(reinterpret_cast<HDROP>(wParam)); break; } case WM_ENTERSIZEMOVE: case WM_EXITSIZEMOVE: { SIZE size = {0}; OnSize(uMsg, 0, size); break; } case WM_GETMINMAXINFO: { LPMINMAXINFO mmi = reinterpret_cast<LPMINMAXINFO>(lParam); SetMinMaxInfo(mmi); OnGetMinMaxInfo(mmi); break; } case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_RBUTTONUP: case WM_MOUSEACTIVATE: case WM_MOUSEHOVER: case WM_MOUSEHWHEEL: case WM_MOUSELEAVE: case WM_MOUSEMOVE: case WM_MOUSEWHEEL: { LRESULT result = OnMouseEvent(uMsg, wParam, lParam); if (result != -1) { ::SetWindowLongPtrW(hwnd, DWL_MSGRESULT, result); return TRUE; } break; } case WM_MOVE: { POINTS pts = MAKEPOINTS(lParam); OnMove(&pts); break; } case WM_NOTIFY: { LRESULT result = OnNotify(wParam, reinterpret_cast<LPNMHDR>(lParam)); if (result) { ::SetWindowLongPtr(hwnd, DWL_MSGRESULT, result); return TRUE; } break; } case WM_PAINT: { if (::GetUpdateRect(hwnd, nullptr, FALSE)) { PAINTSTRUCT ps; HDC hdc = ::BeginPaint(hwnd, &ps); OnPaint(hdc, &ps); ::EndPaint(hwnd, &ps); } else { HDC hdc = ::GetDC(hwnd); OnPaint(hdc, nullptr); ::ReleaseDC(hwnd, hdc); } break; } case WM_SIZE: { SIZE size = {LOWORD(lParam), HIWORD(lParam)}; OnSize(uMsg, static_cast<UINT>(wParam), size); break; } case WM_TIMER: { OnTimer(static_cast<UINT_PTR>(wParam)); break; } case WM_WINDOWPOSCHANGING: { LPWINDOWPOS window_pos = reinterpret_cast<LPWINDOWPOS>(lParam); SnapToEdges(window_pos); OnWindowPosChanging(window_pos); break; } default: { if (uMsg == WM_TASKBARCREATED || uMsg == WM_TASKBARBUTTONCREATED || uMsg == WM_TASKBARCALLBACK) { OnTaskbarCallback(uMsg, lParam); return FALSE; } break; } } return FALSE; }