void OnMouseEvent(USHORT buttsFlags, WPARAM wParam, LPARAM lParam, USHORT buttonData) { Vector<DAVA::UIEvent> touches; Vector<DAVA::UIEvent> emptyTouches; int32 touchPhase = -1; if (HIWORD(wParam) || mouseButtonsDownMask > 0) // isPoint inside window or some clicks already captured { HandleMouseButtonsPressed(buttsFlags); } if(buttsFlags & RI_MOUSE_WHEEL) { UIEvent newTouch; newTouch.tid = 0; newTouch.physPoint.x = 0; newTouch.physPoint.y = ((SHORT)buttonData) / (float32)(WHEEL_DELTA); newTouch.phase = touchPhase = UIEvent::PHASE_WHEEL; touches.push_back(newTouch); } else { if(HIWORD(wParam) || mouseButtonsDownMask > 0) // HIWORD(wParam) - isPoint inside window { touchPhase = MoveTouchsToVector(buttsFlags, wParam, lParam, &touches); } } if(touchPhase != -1) UIControlSystem::Instance()->OnInput(touchPhase, emptyTouches, touches); if (RenderManager::Instance()->GetCursor() != 0 && mouseCursorShown) { ShowCursor(false); mouseCursorShown = false; } if (RenderManager::Instance()->GetCursor() == 0 && !mouseCursorShown) { ShowCursor(false); mouseCursorShown = false; } HandleMouseButtonsReleased(buttsFlags); }
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 //Event event; //event.MouseEvent.RelativeX = 0; //event.MouseEvent.RelativeY = 0; 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_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: // case WM_XBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: // case WM_XBUTTONUP: case WM_MOUSEMOVE: { //Logger::Debug("ms: %d %d", GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); Vector<DAVA::UIEvent> touches; Vector<DAVA::UIEvent> emptyTouches; int32 touchPhase = MoveTouchsToVector(message, wParam, lParam, &touches); UIControlSystem::Instance()->OnInput(touchPhase, emptyTouches, touches); touches.clear(); } // if (mouseShow) // { // ShowCursor(false); // mouseShow = false; // } if (RenderManager::Instance()->GetCursor() != 0 && mouseCursorShown) { ShowCursor(false); mouseCursorShown = false; } if (RenderManager::Instance()->GetCursor() == 0 && !mouseCursorShown) { ShowCursor(false); mouseCursorShown = false; } break; case WM_NCMOUSEMOVE: if (!mouseCursorShown) { ShowCursor(true); mouseCursorShown = true; } break; case WM_NCMOUSELEAVE: //ShowCursor(false); break; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_ACTIVATE: { ApplicationCore * core = Core::Instance()->GetApplicationCore(); WORD loWord = LOWORD(wParam); WORD hiWord = HIWORD(wParam); if(!loWord || hiWord) { Logger::Debug("[PlatformWin32] deactivate application"); RenderResource::SaveAllResourcesToSystemMem(); if(core) { core->OnSuspend(); } else { Core::Instance()->SetIsActive(false); } } else { Logger::Debug("[PlatformWin32] activate application"); if(core) { core->OnResume(); } else { Core::Instance()->SetIsActive(true); } } }; break; case WM_SYSCOMMAND: // prevent screensaver or monitor powersave mode from starting if (wParam == SC_SCREENSAVE || wParam == SC_MONITORPOWER) return 0; break; } return DefWindowProc(hWnd, message, wParam, lParam); }