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; }
void Application::MouseWheelGL(int button, int dir, int x, int y) { float xx = (x * 1.f) / screen.Width() * screen.GLWidth(); float yy = screen.GLHeight() - (y * 1.f) / screen.Height() * screen.GLHeight(); if (dir != 0) { MouseWheel(dir, IPoint(xx, yy)); } }
/* Pointer event. */ int override DispatchPointer(const TASKMSG *msg) { RETURN_IF_NULL(msg); int cmd = msg->data1; switch (cmd) { case POINTER_UP: return MouseUp(msg->data2, msg->data3, msg->data4); case POINTER_DOWN: return MouseDown(msg->data2, msg->data3, msg->data4); case POINTER_MOVE: return MouseMove(msg->data2, msg->data3, msg->data4); case POINTER_WHEEL: return MouseWheel(msg->data2, msg->data3, msg->data4); } return 0; }
void WinInputManager::MouseWheelEvent(short Value) { if (m_curWheel == Value) return; m_curWheel = Value; for (auto i : m_listenerList) { if (i->IsMouseWheel(MouseWheel(m_curWheel, m_curX, m_curY)) == true) return; } }
static int GetMouseCmd( Mouse *mouse, bool isPressed, int useMouseMove, Vec2i pos) { int cmd = 0; bool (*mouseFunc)(const Mouse *, const int) = isPressed ? MouseIsPressed : MouseIsDown; if (useMouseMove) { cmd |= MouseGetMove(mouse, pos); } else { if (MouseWheel(mouse).y > 0) cmd |= CMD_UP; else if (MouseWheel(mouse).y < 0) cmd |= CMD_DOWN; } if (mouseFunc(mouse, SDL_BUTTON_LEFT)) cmd |= CMD_BUTTON1; if (mouseFunc(mouse, SDL_BUTTON_RIGHT)) cmd |= CMD_BUTTON2; if (mouseFunc(mouse, SDL_BUTTON_MIDDLE)) cmd |= CMD_MAP; return cmd; }
void C_Mod::loop() { continuer = true; click = keyboard = false; bool clickOnUI = false; sf::Clock camTimer; float previousX = 0, previousY = 0; sf::String str_fps; int compt_fps = 0; sf::Clock timer_fps; str_fps.SetScale(0.4f, 0.4f); str_fps.SetColor(sf::Color::White); str_fps.SetPosition(10, 10); _screen->PreserveOpenGLStates(true); while(continuer) { while(_screen->GetEvent(_event)) { ///EVENT if(_event.Type == sf::Event::Closed) continuer = false; else if(_event.Type == sf::Event::MouseButtonReleased && click) { click = false; float xxx = _screen->GetInput().GetMouseX(); float yyy = _screen->GetInput().GetMouseY(); for(unsigned int i=0;i<_widget.size();i++) _widget[i]->clicked(xxx, yyy); MouseReleased(); } else if(_event.Type == sf::Event::MouseButtonPressed) { click = true; clickOnUI = false; previousX = _screen->GetInput().GetMouseX(); previousY = _screen->GetInput().GetMouseY(); for(unsigned int i=0;i<_widget.size();i++) { if(_widget[i]->mouseOver(previousX, previousY)) { clickOnUI = true; break; } } if(!clickOnUI) _cam->SetMousePosition(previousX, previousY); MousePressed(); } else if(_event.Type == sf::Event::MouseMoved) { _cam->OnMouseMotion(_screen->GetInput().GetMouseX(), _screen->GetInput().GetMouseY()); _screen->SetCursorPosition(_screen->GetWidth()/2, _screen->GetHeight()/2); MouseMoved(); } else if(_event.Type == sf::Event::MouseWheelMoved) { MouseWheel(); _event.MouseWheel.Delta = 0; } else if(_event.Type == sf::Event::KeyPressed) { bool wigdetHasFocus = false; for(unsigned int i=0;i<_widget.size();i++) { if(_widget[i]->injectKey(_event.Key.Code, true)) { wigdetHasFocus = true; break; } } if(!wigdetHasFocus) { keyboard = true; _cam->OnKeyboard(_event); KeyPressed(); } } else if(_event.Type == sf::Event::KeyReleased) { for(unsigned int i=0;i<_widget.size();i++) _widget[i]->injectKey(_event.Key.Code, false); //if(keyboard) { keyboard = false; _cam->OnKeyboard(_event); KeyReleased(); } } } glDisable(GL_LIGHTING); _cam->animate(int(camTimer.GetElapsedTime()*10000)); camTimer.Reset(); TimerManagement(); ///DRAW _screen->SetActive(); if(click && !clickOnUI) _screen->SetCursorPosition(previousX, previousY); //_screen->GetWidth()/2, _screen->GetHeight()/2); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glViewport(0, 0, _screen->GetWidth(), _screen->GetHeight()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, float(_screen->GetWidth()) / float(_screen->GetHeight()), 0.1f, 5000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); _skydome.Draw(); _cam->look(); glPushMatrix(); Draw(); glPopMatrix(); DrawUI(); if(timer_fps.GetElapsedTime() > 1.0f) { str_fps.SetText("FPS : "+IntToString(compt_fps)); compt_fps = 0; timer_fps.Reset(); } compt_fps++; _screen->Draw(str_fps); _screen->Display(); } }
WMSG_RESULT CUIBase::MouseMessage(MSG* pMsg) { WMSG_RESULT ret = WMSG_FAIL; UINT16 x = LOWORD(pMsg->lParam); UINT16 y = HIWORD(pMsg->lParam); // 포커스가 있다면 먼저 처리하자 CUIBase* pUI = CUIFocus::getSingleton()->getUI(); switch (pMsg->message) { case WM_LBUTTONDOWN: { if (pUI) ret = pUI->LButtonDown(x, y); if (ret == WMSG_FAIL) ret = LButtonDown(x, y); } break; case WM_LBUTTONUP: { if (pUI) ret = pUI->LButtonUp(x, y); if (ret == WMSG_FAIL) ret = LButtonUp(x, y); } break; case WM_LBUTTONDBLCLK: { if (pUI) ret = pUI->LButtonDBLClick(x, y); if (ret == WMSG_FAIL) ret = LButtonDBLClick(x, y); } break; case WM_RBUTTONDOWN: { if (pUI) ret = pUI->RButtonDown(x, y); if (ret == WMSG_FAIL) ret = RButtonDown(x, y); } break; case WM_RBUTTONUP: { if (pUI) ret = pUI->RButtonUp(x, y); if (ret == WMSG_FAIL) ret = RButtonUp(x, y); } break; case WM_RBUTTONDBLCLK: { if (pUI) ret = pUI->RButtonDBLClick(x, y); if (ret == WMSG_FAIL) ret = RButtonDBLClick(x, y); } break; case WM_MOUSEMOVE: { if (pUI) ret = pUI->MouseMove(x, y, pMsg); if (ret == WMSG_FAIL) ret = MouseMove(x, y, pMsg); } break; case WM_MOUSEWHEEL: { int wheel = (short)HIWORD(pMsg->wParam); if (pUI) ret = pUI->MouseWheel(x, y, wheel); if (ret == WMSG_FAIL) ret = MouseWheel(x, y, wheel); } break; } return ret; }
LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_ERASEBKGND: break; case WM_SIZE: InvalidateRect(GraphicsWnd, NULL, false); break; case WM_PAINT: { // Actually paint the window, with gl. PaintGraphics(); // And make Windows happy. PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; } case WM_MOUSELEAVE: SS.GW.MouseLeave(); break; case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: { int x = LOWORD(lParam); int y = HIWORD(lParam); // We need this in order to get the WM_MOUSELEAVE TRACKMOUSEEVENT tme; ZERO(&tme); tme.cbSize = sizeof(tme); tme.dwFlags = TME_LEAVE; tme.hwndTrack = GraphicsWnd; TrackMouseEvent(&tme); // Convert to xy (vs. ij) style coordinates, with (0, 0) at center RECT r; GetClientRect(GraphicsWnd, &r); x = x - (r.right - r.left)/2; y = (r.bottom - r.top)/2 - y; LastMousePos.x = x; LastMousePos.y = y; if(msg == WM_LBUTTONDOWN) { SS.GW.MouseLeftDown(x, y); } else if(msg == WM_LBUTTONUP) { SS.GW.MouseLeftUp(x, y); } else if(msg == WM_LBUTTONDBLCLK) { SS.GW.MouseLeftDoubleClick(x, y); } else if(msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) { SS.GW.MouseMiddleOrRightDown(x, y); } else if(msg == WM_RBUTTONUP) { SS.GW.MouseRightUp(x, y); } else if(msg == WM_MOUSEMOVE) { SS.GW.MouseMoved(x, y, !!(wParam & MK_LBUTTON), !!(wParam & MK_MBUTTON), !!(wParam & MK_RBUTTON), !!(wParam & MK_SHIFT), !!(wParam & MK_CONTROL)); } else { oops(); } break; } case WM_MOUSEWHEEL: MouseWheel(GET_WHEEL_DELTA_WPARAM(wParam)); break; case WM_COMMAND: { if(HIWORD(wParam) == 0) { int id = LOWORD(wParam); if((id >= RECENT_OPEN && id < (RECENT_OPEN + MAX_RECENT))) { SolveSpaceUI::MenuFile(id); break; } if((id >= RECENT_IMPORT && id < (RECENT_IMPORT + MAX_RECENT))) { Group::MenuGroup(id); break; } int i; for(i = 0; SS.GW.menu[i].level >= 0; i++) { if(id == SS.GW.menu[i].id) { (SS.GW.menu[i].fn)((GraphicsWindow::MenuId)id); break; } } if(SS.GW.menu[i].level < 0) oops(); } break; } case WM_CLOSE: case WM_DESTROY: SolveSpaceUI::MenuFile(GraphicsWindow::MNU_EXIT); return 1; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 1; }
LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_ERASEBKGND: break; case WM_CLOSE: case WM_DESTROY: SolveSpaceUI::MenuFile(GraphicsWindow::MNU_EXIT); break; case WM_PAINT: { // Actually paint the text window, with gl. PaintTextWnd(GetDC(TextWnd)); // And then just make Windows happy. PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; } case WM_SIZING: { RECT *r = (RECT *)lParam; int hc = (r->bottom - r->top) - ClientIsSmallerBy; int extra = hc % (SS.TW.LINE_HEIGHT/2); switch(wParam) { case WMSZ_BOTTOM: case WMSZ_BOTTOMLEFT: case WMSZ_BOTTOMRIGHT: r->bottom -= extra; break; case WMSZ_TOP: case WMSZ_TOPLEFT: case WMSZ_TOPRIGHT: r->top += extra; break; } int tooNarrow = (SS.TW.MIN_COLS*SS.TW.CHAR_WIDTH) - (r->right - r->left); if(tooNarrow >= 0) { switch(wParam) { case WMSZ_RIGHT: case WMSZ_BOTTOMRIGHT: case WMSZ_TOPRIGHT: r->right += tooNarrow; break; case WMSZ_LEFT: case WMSZ_BOTTOMLEFT: case WMSZ_TOPLEFT: r->left -= tooNarrow; break; } } break; } case WM_MOUSELEAVE: SS.TW.MouseLeave(); break; case WM_LBUTTONDOWN: case WM_MOUSEMOVE: { // We need this in order to get the WM_MOUSELEAVE TRACKMOUSEEVENT tme; ZERO(&tme); tme.cbSize = sizeof(tme); tme.dwFlags = TME_LEAVE; tme.hwndTrack = TextWnd; TrackMouseEvent(&tme); // And process the actual message int x = LOWORD(lParam); int y = HIWORD(lParam); SS.TW.MouseEvent(msg == WM_LBUTTONDOWN, wParam & MK_LBUTTON, x, y); break; } case WM_SIZE: { RECT r; GetWindowRect(TextWndScrollBar, &r); int sw = r.right - r.left; GetClientRect(hwnd, &r); MoveWindow(TextWndScrollBar, r.right - sw, r.top, sw, (r.bottom - r.top), true); // If the window is growing, then the scrollbar position may // be moving, so it's as if we're dragging the scrollbar. HandleTextWindowScrollBar((WPARAM)-1, -1); InvalidateRect(TextWnd, NULL, false); break; } case WM_MOUSEWHEEL: MouseWheel(GET_WHEEL_DELTA_WPARAM(wParam)); break; case WM_VSCROLL: HandleTextWindowScrollBar(wParam, lParam); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 1; }