void updateEvents() const { unsigned int size = _eventsToHandle.size(); for ( unsigned int i=0; i<size; ++i ) { const osgGA::GUIEventAdapter& ea = *(_eventsToHandle.front()); float x = ea.getX(), y = ea.getWindowHeight() - ea.getY(); switch ( ea.getEventType() ) { case osgGA::GUIEventAdapter::PUSH: TwMouseMotion( x, y ); TwMouseButton( TW_MOUSE_PRESSED, getTwButton(ea.getButton()) ); break; case osgGA::GUIEventAdapter::RELEASE: TwMouseMotion( x, y ); TwMouseButton( TW_MOUSE_RELEASED, getTwButton(ea.getButton()) ); break; case osgGA::GUIEventAdapter::DRAG: case osgGA::GUIEventAdapter::MOVE: TwMouseMotion( x, y ); break; case osgGA::GUIEventAdapter::KEYDOWN: { bool useCtrl = false; if ( ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL ) useCtrl = true; TwKeyPressed( getTwKey(ea.getKey(), useCtrl), getTwModKeyMask(ea.getModKeyMask()) ); } break; default: break; } const_cast<TwGUIManager*>(this)->_eventsToHandle.pop(); } }
void mouseMove(int x, int y) { // update deltaAngle int twMove = TwMouseMotion(x, y); if(!twMove){ int delta = lastX - x; int deltaY = lastY - y; //needs to be redone if(delta < -1) { _camera->deltaAngle = +0.02f; } else if(delta > 1) { _camera->deltaAngle = -0.02f; } else _camera->deltaAngle = 0.0f; if(deltaY < -1) { _camera->deltaAnglev = -0.02f; } else if(deltaY > 1) { _camera->deltaAnglev = +0.02f; } else _camera->deltaAnglev = 0.0f; lastX = x; lastY = y; } }
bool ControlUI::mouseMoved(const OIS::MouseEvent &arg) { int x = arg.state.X.abs; int y = arg.state.Y.abs; return (TwMouseMotion(x, y)); }
void GLWidget::mouseMoveEvent (QMouseEvent * e) { if (e->buttons ()) { track.MouseMove (e->x (), height () - e->y ()); updateGL (); } TwMouseMotion(e->x (), e->y ()); }
// TwEventSDL12 returns zero if msg has not been handled, // and a non-zero value if it has been handled by the AntTweakBar library. int TW_CALL TwEventSDL12(const void *sdlEvent) { int handled = 0; const SDL_Event *event = (const SDL_Event *)sdlEvent; if( event==NULL ) return 0; switch( event->type ) { case SDL_KEYDOWN: if( event->key.keysym.unicode!=0 && (event->key.keysym.unicode & 0xFF00)==0 ) { if( (event->key.keysym.unicode & 0xFF)<32 && (event->key.keysym.unicode & 0xFF)!=event->key.keysym.sym ) handled = TwKeyPressed((event->key.keysym.unicode & 0xFF)+'a'-1, event->key.keysym.mod); else handled = TwKeyPressed(event->key.keysym.unicode & 0xFF, event->key.keysym.mod); } else handled = TwKeyPressed(event->key.keysym.sym, event->key.keysym.mod); break; case SDL_MOUSEMOTION: handled = TwMouseMotion(event->motion.x, event->motion.y); break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: if( event->type==SDL_MOUSEBUTTONDOWN && (event->button.button==4 || event->button.button==5) ) // mouse wheel { static int s_WheelPos = 0; if( event->button.button==4 ) ++s_WheelPos; else --s_WheelPos; handled = TwMouseWheel(s_WheelPos); } else handled = TwMouseButton((event->type==SDL_MOUSEBUTTONUP)?TW_MOUSE_RELEASED:TW_MOUSE_PRESSED, (TwMouseButtonID)event->button.button); break; case SDL_VIDEORESIZE: // tell the new size to TweakBar TwWindowSize(event->resize.w, event->resize.h); // do not set 'handled', SDL_VIDEORESIZE may be also processed by the calling application break; } return handled; }
int TW_GLUT_CALL TwEventMouseButtonGLUT(int glutButton, int glutState, int mouseX, int mouseY) { TwMouseAction action = (glutState==GLUT_DOWN) ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED; TwMouseMotion(mouseX, mouseY); switch( glutButton ) { case GLUT_LEFT_BUTTON: return TwMouseButton(action, TW_MOUSE_LEFT); case GLUT_RIGHT_BUTTON: return TwMouseButton(action, TW_MOUSE_RIGHT); case GLUT_MIDDLE_BUTTON: return TwMouseButton(action, TW_MOUSE_MIDDLE); default: return 0; } }
void GLFWCALL mouseMoveListener( int x, int y ) { if( !running ) { mx0 = x; my0 = y; return; } if(app->_mouseFree) { app->mouseMoveEvent( (float)(x - mx0), (float)(my0 - y) ); mx0 = x; my0 = y; } else { TwMouseMotion(x,y); } }
void ofxTweakbars::mouseMoved(ofMouseEventArgs& rArgs) { int x = rArgs.x; //Jon alterations: //Alter the mouse value if we're using a stereo setup if(Globals::useStereoGUI){ //Treat the right half of the screen as input for the left half if(x > ofGetWidth() / 2){ x -= (ofGetWidth() / 2); //Compensate for toe-in x += Globals::GUIConvergence; } else{ //Compensate for toe-in x -= Globals::GUIConvergence; } } TwMouseMotion(x, rArgs.y); }
void MyWindow::motion(int x, int y) { WindowInertiaCamera::motion(x, y); #ifdef USEANTTWEAKBAR if(!(ViewerStates::mousingMode || ViewerStates::mousingModeM || ViewerStates::mousingModeR) ) { int ret = TwMouseMotion(x, y); if(ret) { postRedisplay(); return; } } #endif //---------------------------- LEFT if(m_bMousing) { m_mouse[0] = (float)m_ptCurrentMousePosit.x; m_mouse[1] = (float)m_ptCurrentMousePosit.y; } }
void GXBaseContext::OnMouseMove(int x, int y) { if (!TwMouseMotion(x, Height() - y)) { float2 mouse_pos = float2(Width() - x, y); float2 windows_size = float2(Width(), Height()); // Process mouse movement inside application if (m_camera_drag) { float2 mouse_offset = mouse_pos - m_mouse_old; float2 mouse_offset_normalized = mouse_offset / windows_size; float2 mouse_offset_zoomed = mouse_offset_normalized; m_camera->m_pos -= mouse_offset_zoomed; } m_mouse_old = float2(Width() - x, y); } }
void Gui::Update(const Input& input) { if (m_show) { m_tweaker->Update(); if (input.IsMouseMovedThisTick()) { TwMouseMotion(input.GetMouseX(), input.GetMouseY()); } else if (input.IsLeftMousePressedThisTick()) { TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_LEFT); } else if (input.IsLeftMouseReleasedThisTick()) { TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_LEFT); } } }
/** * Handles mouse input. * @param buttonAction mouse action flags, see RAWMOUSE.usButtonFlags * @param mouseWheelDelta the scroll wheel delta * @param sender the window that send the keyboard messages * @return whether the message was handled */ bool ApplicationBase::HandleMouse(unsigned int buttonAction, float mouseWheelDelta, BaseGLWindow* sender) { auto handled = 0; auto handledMovement = 0; if (sender->HadPositionUpdate()) { handledMovement = TwMouseMotion(static_cast<int>(sender->GetMouseAbsolute().x), static_cast<int>(sender->GetMouseAbsolute().y)); sender->HandledPositionUpdate(); } if (handled == 0 && buttonAction & RI_MOUSE_LEFT_BUTTON_DOWN) handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_LEFT); if (handled == 0 && buttonAction & RI_MOUSE_LEFT_BUTTON_UP) handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_LEFT); if (handled == 0 && buttonAction & RI_MOUSE_RIGHT_BUTTON_DOWN) handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_RIGHT); if (handled == 0 && buttonAction & RI_MOUSE_RIGHT_BUTTON_UP) handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_RIGHT); if (handled == 0 && buttonAction & RI_MOUSE_MIDDLE_BUTTON_DOWN) handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_MIDDLE); if (handled == 0 && buttonAction & RI_MOUSE_MIDDLE_BUTTON_UP) handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_MIDDLE); static auto s_WheelPos = 0; s_WheelPos += static_cast<int>(mouseWheelDelta); if (handled == 0) handled = TwMouseWheel(s_WheelPos); if (handled == 0 && IsRunning() && !IsPaused()) handled = HandleMouseApp(buttonAction, mouseWheelDelta, sender); // if (handledM) if (handled == 0 && handledMovement == 0 && IsRunning() && !IsPaused()) handled = cameraView->HandleMouse(buttonAction, mouseWheelDelta, sender); return handled == 1; }
int TwMouseReleaseQt(QWidget *qw, QMouseEvent *e) { TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, e->y())); return TwMouseButton(TW_MOUSE_RELEASED, Qt2TwMouseButtonId(e)); }
// ------------------------------------------------------------- cursor_pos --- void cursor_pos( GLFWwindow* window, double x, double y ) { TwMouseMotion( x, y ); }
// TwEventSFML returns zero if msg has not been handled, // and a non-zero value if it has been handled by the AntTweakBar library. int TW_CALL TwEventSFML(const void *sfmlEvent, unsigned char majorVersion, unsigned char minorVersion) { // Assume version 1.6 (will possibly not work for version != 1.6, but give it a chance) /* if (majorVersion > 1 || (majorVersion == 1 && minorVersion > 6) { static const char *g_ErrBadSFMLVersion = "Unsupported SFML version"; TwSetLastError(g_ErrBadSFMLVersion); return 0; } */ (void)majorVersion, (void)minorVersion; int handled = 0; const sf::Event *event = (const sf::Event *)sfmlEvent; TwMouseAction mouseAction; int key = 0; static int s_KMod = 0; static bool s_PreventTextHandling = false; static int s_WheelPos = 0; if (event == NULL) return 0; switch (event->Type) { case sf::Event::KeyPressed: s_PreventTextHandling = false; s_KMod = 0; if (event->Key.Shift) s_KMod |= TW_KMOD_SHIFT; if (event->Key.Alt) s_KMod |= TW_KMOD_ALT; if (event->Key.Control) s_KMod |= TW_KMOD_CTRL; key = 0; switch (event->Key.Code) { case sf::Key::Escape: key = TW_KEY_ESCAPE; break; case sf::Key::Return: key = TW_KEY_RETURN; break; case sf::Key::Tab: key = TW_KEY_TAB; break; case sf::Key::Back: key = TW_KEY_BACKSPACE; break; case sf::Key::PageUp: key = TW_KEY_PAGE_UP; break; case sf::Key::PageDown: key = TW_KEY_PAGE_DOWN; break; case sf::Key::Up: key = TW_KEY_UP; break; case sf::Key::Down: key = TW_KEY_DOWN; break; case sf::Key::Left: key = TW_KEY_LEFT; break; case sf::Key::Right: key = TW_KEY_RIGHT; break; case sf::Key::End: key = TW_KEY_END; break; case sf::Key::Home: key = TW_KEY_HOME; break; case sf::Key::Insert: key = TW_KEY_INSERT; break; case sf::Key::Delete: key = TW_KEY_DELETE; break; case sf::Key::Space: key = TW_KEY_SPACE; break; default: if (event->Key.Code >= sf::Key::F1 && event->Key.Code <= sf::Key::F15) key = TW_KEY_F1 + event->Key.Code - sf::Key::F1; else if (s_KMod & TW_KMOD_ALT) { if (event->Key.Code >= sf::Key::A && event->Key.Code <= sf::Key::Z) { if (s_KMod & TW_KMOD_SHIFT) key = 'A' + event->Key.Code - sf::Key::A; else key = 'a' + event->Key.Code - sf::Key::A; } } } if (key != 0) { handled = TwKeyPressed(key, s_KMod); s_PreventTextHandling = true; } break; case sf::Event::KeyReleased: s_PreventTextHandling = false; s_KMod = 0; break; case sf::Event::TextEntered: if (!s_PreventTextHandling && event->Text.Unicode != 0 && (event->Text.Unicode & 0xFF00) == 0) { if ((event->Text.Unicode & 0xFF) < 32) // CTRL+letter handled = TwKeyPressed((event->Text.Unicode & 0xFF)+'a'-1, TW_KMOD_CTRL|s_KMod); else handled = TwKeyPressed(event->Text.Unicode & 0xFF, 0); } s_PreventTextHandling = false; break; case sf::Event::MouseMoved: handled = TwMouseMotion(event->MouseMove.X, event->MouseMove.Y); break; case sf::Event::MouseButtonPressed: case sf::Event::MouseButtonReleased: mouseAction = (event->Type==sf::Event::MouseButtonPressed) ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED; switch (event->MouseButton.Button) { case sf::Mouse::Left: handled = TwMouseButton(mouseAction, TW_MOUSE_LEFT); break; case sf::Mouse::Middle: handled = TwMouseButton(mouseAction, TW_MOUSE_MIDDLE); break; case sf::Mouse::Right: handled = TwMouseButton(mouseAction, TW_MOUSE_RIGHT); break; default: break; } break; case sf::Event::MouseWheelMoved: s_WheelPos += event->MouseWheel.Delta; handled = TwMouseWheel(s_WheelPos); break; case sf::Event::Resized: // tell the new size to TweakBar TwWindowSize(event->Size.Width, event->Size.Height); // do not set 'handled', sf::Event::Resized may be also processed by the client application break; default: break; } return handled; }
// TwEventWin32 returns zero if msg has not been handled, // and a non-zero value if it has been handled by the AntTweakBar library. int TW_CALL TwEventWin32(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam) { int handled = 0; switch( msg ) { case WM_MOUSEMOVE: // send signed! mouse coordinates handled = TwMouseMotion((short)LOWORD(lParam), (short)HIWORD(lParam)); break; case WM_LBUTTONDOWN: SetCapture(wnd); handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_LEFT); break; case WM_LBUTTONUP: ReleaseCapture(); handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_LEFT); break; case WM_MBUTTONDOWN: SetCapture(wnd); handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_MIDDLE); break; case WM_MBUTTONUP: ReleaseCapture(); handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_MIDDLE); break; case WM_RBUTTONDOWN: SetCapture(wnd); handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_RIGHT); break; case WM_RBUTTONUP: ReleaseCapture(); handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_RIGHT); break; case WM_CHAR: case WM_SYSCHAR: { int key = (int)(wParam&0xff); int kmod = 0; if( GetAsyncKeyState(VK_SHIFT)<0 ) kmod |= TW_KMOD_SHIFT; if( GetAsyncKeyState(VK_CONTROL)<0 ) { kmod |= TW_KMOD_CTRL; if( key>0 && key<27 ) key += 'a'-1; } if( GetAsyncKeyState(VK_MENU)<0 ) kmod |= TW_KMOD_ALT; if( key>0 && key<256 ) handled = TwKeyPressed(key, kmod); } break; case WM_KEYDOWN: case WM_SYSKEYDOWN: { int kmod = 0; int testkp = 0; int k = 0; if( GetAsyncKeyState(VK_SHIFT)<0 ) kmod |= TW_KMOD_SHIFT; if( GetAsyncKeyState(VK_CONTROL)<0 ) { kmod |= TW_KMOD_CTRL; testkp = 1; } if( GetAsyncKeyState(VK_MENU)<0 ) { kmod |= TW_KMOD_ALT; testkp = 1; } if( wParam>=VK_F1 && wParam<=VK_F15 ) k = TW_KEY_F1 + ((int)wParam-VK_F1); else if( testkp && wParam>=VK_NUMPAD0 && wParam<=VK_NUMPAD9 ) k = '0' + ((int)wParam-VK_NUMPAD0); else { switch( wParam ) { case VK_UP: k = TW_KEY_UP; break; case VK_DOWN: k = TW_KEY_DOWN; break; case VK_LEFT: k = TW_KEY_LEFT; break; case VK_RIGHT: k = TW_KEY_RIGHT; break; case VK_INSERT: k = TW_KEY_INSERT; break; case VK_DELETE: k = TW_KEY_DELETE; break; case VK_PRIOR: k = TW_KEY_PAGE_UP; break; case VK_NEXT: k = TW_KEY_PAGE_DOWN; break; case VK_HOME: k = TW_KEY_HOME; break; case VK_END: k = TW_KEY_END; break; case VK_DIVIDE: if( testkp ) k = '/'; break; case VK_MULTIPLY: if( testkp ) k = '*'; break; case VK_SUBTRACT: if( testkp ) k = '-'; break; case VK_ADD: if( testkp ) k = '+'; break; case VK_DECIMAL: if( testkp ) k = '.'; break; default: if( (kmod&TW_KMOD_CTRL) && (kmod&TW_KMOD_ALT) ) k = MapVirtualKey( (UINT)wParam, 2 ) & 0x0000FFFF; } } if( k!=0 ) handled = TwKeyPressed(k, kmod); } break; case WM_MOUSEWHEEL: { static int s_WheelPos = 0; s_WheelPos += ((short)HIWORD(wParam))/WHEEL_DELTA; handled = TwMouseWheel(s_WheelPos); } break; case WM_SIZE: // tell the new size to TweakBar TwWindowSize(LOWORD(lParam), HIWORD(lParam)); // do not set 'handled', WM_SIZE may be also processed by the calling application break; } return handled; }
int TW_CALL TwEventSDL20(const void *sdlEvent) { int handled = 0; const SDL_Event *event = (const SDL_Event *)sdlEvent; if (event == NULL) return 0; switch (event->type) { case SDL_KEYDOWN: if (event->key.keysym.sym & SDLK_SCANCODE_MASK) { int key = 0; switch (event->key.keysym.sym) { case SDLK_UP: key = TW_KEY_UP; break; case SDLK_DOWN: key = TW_KEY_DOWN; break; case SDLK_RIGHT: key = TW_KEY_RIGHT; break; case SDLK_LEFT: key = TW_KEY_LEFT; break; case SDLK_INSERT: key = TW_KEY_INSERT; break; case SDLK_HOME: key = TW_KEY_HOME; break; case SDLK_END: key = TW_KEY_END; break; case SDLK_PAGEUP: key = TW_KEY_PAGE_UP; break; case SDLK_PAGEDOWN: key = TW_KEY_PAGE_DOWN; break; default: if (event->key.keysym.sym >= SDLK_F1 && event->key.keysym.sym <= SDLK_F12) { key = event->key.keysym.sym + TW_KEY_F1 - SDLK_F1; } break; } if (key != 0) { handled = TwKeyPressed(key, event->key.keysym.mod); } } else { handled = TwKeyPressed(event->key.keysym.sym /*& 0xFF*/, event->key.keysym.mod); } break; case SDL_MOUSEMOTION: handled = TwMouseMotion(event->motion.x, event->motion.y); break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: if (event->type == SDL_MOUSEBUTTONDOWN && (event->button.button == 4 || event->button.button == 5)) { // mouse wheel static int s_WheelPos = 0; if (event->button.button == 4) ++s_WheelPos; else --s_WheelPos; handled = TwMouseWheel(s_WheelPos); } else { handled = TwMouseButton( (event->type == SDL_MOUSEBUTTONUP) ? TW_MOUSE_RELEASED : TW_MOUSE_PRESSED, (TwMouseButtonID)event->button.button); } break; case SDL_WINDOWEVENT: if (event->window.event == SDL_WINDOWEVENT_RESIZED) { // tell the new size to TweakBar TwWindowSize(event->window.data1, event->window.data2); // do not set 'handled' // SDL_VIDEORESIZE may be also processed by the calling application } break; } return handled; }
TW_API int TW_CDECL_CALL TwEventCursorPosGLFW3cdecl(GLFWwindow *window, double xpos, double ypos) { return TwMouseMotion((int)xpos, (int)ypos); }
void TwEventMousePosGLFW3(GLFWwindow* window, double xpos, double ypos){TwMouseMotion(int(xpos), int(ypos));}
void ofxTweakbars::mouseDragged(ofMouseEventArgs& rArgs) { TwMouseMotion(rArgs.x, rArgs.y); //autoStore(); }
// ---------------------------------------------------------------------- // ---------------------------------------------------------------------- static int _XMotionEvent(XEvent *event) { XMotionEvent *xme = (XMotionEvent *)event; return TwMouseMotion(xme->x, xme->y); }
int TW_CALL TwEventMousePosGLFW(GLFWwindow * glfwWindow, double xpos, double ypos){ return TwMouseMotion((int)xpos, (int)ypos); }
int TwMousePressQt(QMouseEvent *e) { TwMouseMotion(e->x (), e->y ()); return TwMouseButton(TW_MOUSE_PRESSED, Qt2TwMouseButtonId(e)); }
// TwEventSDL returns zero if msg has not been handled, // and a non-zero value if it has been handled by the AntTweakBar library. int TW_CALL TwEventSDL(const void *sdlEvent, unsigned char sdlMajorVersion, unsigned char sdlMinorVersion) { int handled = 0; static int s_KeyMod = 0; const SDL_Event *event = (const SDL_Event *)sdlEvent; if( event==NULL ) return 0; switch( event->type ) { case SDL_TEXTINPUT: if( event->text.text[0]!=0 && event->text.text[1]==0 ) { if( s_KeyMod & TW_KMOD_CTRL && event->text.text[0]<32 ) handled = TwKeyPressed(event->text.text[0]+'a'-1, s_KeyMod); else { if (s_KeyMod & KMOD_RALT) s_KeyMod &= ~KMOD_CTRL; handled = TwKeyPressed(event->text.text[0], s_KeyMod); } } s_KeyMod = 0; break; case SDL_KEYDOWN: if( event->key.keysym.sym & SDLK_SCANCODE_MASK ) { int key = 0; switch( event->key.keysym.sym ) { case SDLK_UP: key = TW_KEY_UP; break; case SDLK_DOWN: key = TW_KEY_DOWN; break; case SDLK_RIGHT: key = TW_KEY_RIGHT; break; case SDLK_LEFT: key = TW_KEY_LEFT; break; case SDLK_INSERT: key = TW_KEY_INSERT; break; case SDLK_HOME: key = TW_KEY_HOME; break; case SDLK_END: key = TW_KEY_END; break; case SDLK_PAGEUP: key = TW_KEY_PAGE_UP; break; case SDLK_PAGEDOWN: key = TW_KEY_PAGE_DOWN; break; default: if( event->key.keysym.sym>=SDLK_F1 && event->key.keysym.sym<=SDLK_F12 ) key = event->key.keysym.sym + TW_KEY_F1 - SDLK_F1; } if( key!=0 ) handled = TwKeyPressed(key, event->key.keysym.mod); } else if( event->key.keysym.mod & TW_KMOD_ALT ) handled = TwKeyPressed(event->key.keysym.sym & 0xFF, event->key.keysym.mod); else s_KeyMod = event->key.keysym.mod; break; case SDL_KEYUP: s_KeyMod = 0; break; case SDL_MOUSEMOTION: handled = TwMouseMotion(event->motion.x, event->motion.y); break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: if( event->type==SDL_MOUSEBUTTONDOWN && (event->button.button==4 || event->button.button==5) ) // mouse wheel { static int s_WheelPos = 0; if( event->button.button==4 ) ++s_WheelPos; else --s_WheelPos; handled = TwMouseWheel(s_WheelPos); } else handled = TwMouseButton((event->type==SDL_MOUSEBUTTONUP)?TW_MOUSE_RELEASED:TW_MOUSE_PRESSED, (TwMouseButtonID)event->button.button); break; case SDL_WINDOWEVENT: switch( event->window.event ) { case SDL_WINDOWEVENT_SIZE_CHANGED: // tell the new size to TweakBar TwWindowSize(event->window.data1, event->window.data2); // do not set 'handled', SDL_VIDEORESIZE may be also processed by the calling application break; } break; } return handled; }
int TwMousePressQt(QWidget *qw, QMouseEvent *e) { TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, e->y())); return TwMouseButton(TW_MOUSE_PRESSED, Qt2TwMouseButtonId(e)); }
int TwMouseReleaseQt(QMouseEvent *e) { TwMouseMotion(e->x (), e->y ()); return TwMouseButton(TW_MOUSE_RELEASED, Qt2TwMouseButtonId(e)); }
TW_API int TW_CDECL_CALL TwEventMousePosGLFWcdecl(int mouseX, int mouseY) { return TwMouseMotion(mouseX, mouseY); }
// TwEventWin returns zero if msg has not been handled, // and a non-zero value if it has been handled by the AntTweakBar library. int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned PARAM_INT _W64 wParam, PARAM_INT _W64 lParam) { int handled = 0; static unsigned PARAM_INT s_PrevKeyDown = 0; static PARAM_INT s_PrevKeyDownMod = 0; static int s_PrevKeyDownHandled = 0; switch( msg ) { case WM_MOUSEMOVE: // send signed! mouse coordinates handled = TwMouseMotion((short)LOWORD(lParam), (short)HIWORD(lParam)); break; case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: SetCapture(wnd); handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_LEFT); break; case WM_LBUTTONUP: ReleaseCapture(); handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_LEFT); break; case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: SetCapture(wnd); handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_MIDDLE); break; case WM_MBUTTONUP: ReleaseCapture(); handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_MIDDLE); break; case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: SetCapture(wnd); handled = TwMouseButton(TW_MOUSE_PRESSED, TW_MOUSE_RIGHT); break; case WM_RBUTTONUP: ReleaseCapture(); handled = TwMouseButton(TW_MOUSE_RELEASED, TW_MOUSE_RIGHT); break; case WM_CHAR: case WM_SYSCHAR: { int key = (int)(wParam&0xff); int kmod = 0; if( GetAsyncKeyState(VK_SHIFT)<0 ) kmod |= TW_KMOD_SHIFT; if( GetAsyncKeyState(VK_CONTROL)<0 ) { kmod |= TW_KMOD_CTRL; if( key>0 && key<27 ) key += 'a'-1; } if( GetAsyncKeyState(VK_MENU)<0 ) kmod |= TW_KMOD_ALT; if( key>0 && key<256 ) handled = TwKeyPressed(key, kmod); } break; case WM_KEYDOWN: case WM_SYSKEYDOWN: { int kmod = 0; int testkp = 0; int k = 0; if( GetAsyncKeyState(VK_SHIFT)<0 ) kmod |= TW_KMOD_SHIFT; if( GetAsyncKeyState(VK_CONTROL)<0 ) { kmod |= TW_KMOD_CTRL; testkp = 1; } if( GetAsyncKeyState(VK_MENU)<0 ) { kmod |= TW_KMOD_ALT; testkp = 1; } if( wParam>=VK_F1 && wParam<=VK_F15 ) k = TW_KEY_F1 + ((int)wParam-VK_F1); else if( testkp && wParam>=VK_NUMPAD0 && wParam<=VK_NUMPAD9 ) k = '0' + ((int)wParam-VK_NUMPAD0); else { switch( wParam ) { case VK_UP: k = TW_KEY_UP; break; case VK_DOWN: k = TW_KEY_DOWN; break; case VK_LEFT: k = TW_KEY_LEFT; break; case VK_RIGHT: k = TW_KEY_RIGHT; break; case VK_INSERT: k = TW_KEY_INSERT; break; case VK_DELETE: k = TW_KEY_DELETE; break; case VK_PRIOR: k = TW_KEY_PAGE_UP; break; case VK_NEXT: k = TW_KEY_PAGE_DOWN; break; case VK_HOME: k = TW_KEY_HOME; break; case VK_END: k = TW_KEY_END; break; case VK_DIVIDE: if( testkp ) k = '/'; break; case VK_MULTIPLY: if( testkp ) k = '*'; break; case VK_SUBTRACT: if( testkp ) k = '-'; break; case VK_ADD: if( testkp ) k = '+'; break; case VK_DECIMAL: if( testkp ) k = '.'; break; default: if( (kmod&TW_KMOD_CTRL) && (kmod&TW_KMOD_ALT) ) k = MapVirtualKey( (UINT)wParam, 2 ) & 0x0000FFFF; } } if( k!=0 ) handled = TwKeyPressed(k, kmod); else { // if the key will be handled at next WM_CHAR report this event as handled int key = (int)(wParam&0xff); if( kmod&TW_KMOD_CTRL && key>0 && key<27 ) key += 'a'-1; if( key>0 && key<256 ) handled = TwKeyTest(key, kmod); } s_PrevKeyDown = wParam; s_PrevKeyDownMod = kmod; s_PrevKeyDownHandled = handled; } break; case WM_KEYUP: case WM_SYSKEYUP: { int kmod = 0; if( GetAsyncKeyState(VK_SHIFT)<0 ) kmod |= TW_KMOD_SHIFT; if( GetAsyncKeyState(VK_CONTROL)<0 ) kmod |= TW_KMOD_CTRL; if( GetAsyncKeyState(VK_MENU)<0 ) kmod |= TW_KMOD_ALT; // if the key has been handled at previous WM_KEYDOWN report this event as handled if( s_PrevKeyDown==wParam && s_PrevKeyDownMod==kmod ) handled = s_PrevKeyDownHandled; else { // if the key would have been handled report this event as handled int key = (int)(wParam&0xff); if( kmod&TW_KMOD_CTRL && key>0 && key<27 ) key += 'a'-1; if( key>0 && key<256 ) handled = TwKeyTest(key, kmod); } // reset previous keydown s_PrevKeyDown = 0; s_PrevKeyDownMod = 0; s_PrevKeyDownHandled = 0; } break; case WM_MOUSEWHEEL: { static int s_WheelPos = 0; s_WheelPos += ((short)HIWORD(wParam))/WHEEL_DELTA; handled = TwMouseWheel(s_WheelPos); } break; case WM_SIZE: // tell the new size to AntTweakBar TwWindowSize(LOWORD(lParam), HIWORD(lParam)); // do not set 'handled', WM_SIZE may be also processed by the calling application break; } if( handled ) // Event has been handled by AntTweakBar, so we invalidate the window // content to send a WM_PAINT which will redraw the tweak bar(s). InvalidateRect(wnd, NULL, FALSE); return handled; }
int TW_GLUT_CALL TwEventMouseMotionGLUT(int mouseX, int mouseY) { return TwMouseMotion(mouseX, mouseY); }
void ofxTweakbars::mouseMoved(ofMouseEventArgs& rArgs) { TwMouseMotion(rArgs.x, rArgs.y); }