Beispiel #1
0
 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();
     }
 }
Beispiel #2
0
int TW_CALL TwEventMouseButtonGLFW(int glfwButton, int glfwAction)
{
	int handled = 0;
	TwMouseAction action = (glfwAction==GLFW_PRESS) ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED;

	if( glfwButton==GLFW_MOUSE_BUTTON_LEFT )
		handled = TwMouseButton(action, TW_MOUSE_LEFT);
	else if( glfwButton==GLFW_MOUSE_BUTTON_RIGHT )
		handled = TwMouseButton(action, TW_MOUSE_RIGHT);
	else if( glfwButton==GLFW_MOUSE_BUTTON_MIDDLE )
		handled = TwMouseButton(action, TW_MOUSE_MIDDLE);

	return handled;
}
bool ATB::MouseCB(OGLDEV_MOUSE Button, OGLDEV_KEY_STATE State, int , int )
{    
    TwMouseButtonID btn = (Button == OGLDEV_MOUSE_BUTTON_LEFT) ? TW_MOUSE_LEFT : TW_MOUSE_RIGHT;
    TwMouseAction ma = (State == OGLDEV_KEY_STATE_PRESS) ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED;
    
    return (TwMouseButton(ma, btn) == 1);
}
Beispiel #4
0
//------------------------------------------------------------------------------
void MyWindow::mouse(NVPWindow::MouseButton button, ButtonAction action, int mods, int x, int y)
{
    WindowInertiaCamera::mouse(button, action, mods, x, y);
#ifdef USEANTTWEAKBAR
    int res = TwMouseButton(action==BUTTON_PRESS? TW_MOUSE_PRESSED: TW_MOUSE_RELEASED, (TwMouseButtonID)(button+1));
    if(res) {
		postRedisplay();
        return;
	}
#endif
    WindowInertiaCamera::mouse(button, action, mods, x, y);
    switch(button)
    {
    case MOUSE_BUTTON_LEFT:
        if(action==BUTTON_PRESS) // Down
        {
            m_mouse[2] = (float)m_ptOriginalMousePosit.x;
            m_mouse[3] = (float)m_ptOriginalMousePosit.y;
            postRedisplay();
        }
        break;
    case MOUSE_BUTTON_RIGHT:
        if(action==BUTTON_PRESS)
        {
        }
        else if(action==BUTTON_REPEAT)
        {
        }
        else {
        }
        break;
    case MOUSE_BUTTON_MIDDLE:
        break;
    }
  }
Beispiel #5
0
// ----------------------------------------------------------- mouse_button ---
void mouse_button( GLFWwindow* window, int button, int action, int mods)
{
    TwMouseAction tw_action;
    TwMouseButtonID tw_button;

    if ( GLFW_RELEASE == action )
    {
        tw_action = TW_MOUSE_RELEASED;
    }
    else
    {
        tw_action = TW_MOUSE_PRESSED;
    }

    switch (button)
    {
        case GLFW_MOUSE_BUTTON_LEFT:
            tw_button = TW_MOUSE_LEFT;
            break;
        case GLFW_MOUSE_BUTTON_MIDDLE:
            tw_button = TW_MOUSE_MIDDLE;
            break;
        case GLFW_MOUSE_BUTTON_RIGHT:
            tw_button = TW_MOUSE_RIGHT;
            break;
        default:
            return;
    }

    TwMouseButton( tw_action, tw_button );
}
Beispiel #6
0
bool ControlUI::mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
	TwMouseButtonID btn = (id == OIS::MB_Left) ? TW_MOUSE_LEFT : TW_MOUSE_RIGHT;
	TwMouseAction ma = TW_MOUSE_RELEASED;

	return (TwMouseButton(ma, btn) == 1);
}
Beispiel #7
0
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;
    }
}
Beispiel #8
0
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);
        }
    }
}
Beispiel #9
0
//  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;
}
void GXBaseContext::OnMouseButton(MouseButton button, bool down)
{
	TwMouseAction twaction = down ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED;

	ETwMouseButtonID twbutton;

	switch (button){
		case gxbase::GLWindow::MBLeft:		twbutton = TW_MOUSE_LEFT;	break;
		case gxbase::GLWindow::MBMiddle:	twbutton = TW_MOUSE_MIDDLE;	break;
		case gxbase::GLWindow::MBRight:		twbutton = TW_MOUSE_RIGHT;	break;
		default: twbutton = TW_MOUSE_LEFT;	break;
	}

	if (!TwMouseButton(twaction, twbutton))
	{
		// Process mouse button inside application
		if (down) m_camera_drag = true;
		else m_camera_drag = false;
	}
}
    /**
     * 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;
    }
//  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;
}
Beispiel #14
0
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;
}
int TwMousePressQt(QMouseEvent *e)
{
    TwMouseMotion(e->x (), e->y ());
    return TwMouseButton(TW_MOUSE_PRESSED, Qt2TwMouseButtonId(e));
}
Beispiel #16
0
void GUI::onMouseClicked(int bt, int action) {
  TwMouseButtonID btn = (bt == 0) ? TW_MOUSE_LEFT : TW_MOUSE_RIGHT;
  TwMouseAction ma = (action == GLFW_PRESS) ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED;
  TwMouseButton(ma, btn);
}
Beispiel #17
0
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
static int _XButtonEvent(XEvent *event)
{
    TwMouseAction action = (event->type == ButtonPress) ? TW_MOUSE_PRESSED : TW_MOUSE_RELEASED;
    XButtonEvent *xbe = (XButtonEvent *)event;
    return TwMouseButton(action, xbe->button);
}
void ofxTweakbars::mousePressed(ofMouseEventArgs& rArgs) {
	TwMouseButtonID btn = (rArgs.button == 0) ? TW_MOUSE_LEFT : TW_MOUSE_RIGHT;
	TwMouseButton(TW_MOUSE_PRESSED, btn);
	//autoStore();
	changed();
}
int TwMouseReleaseQt(QWidget *qw, QMouseEvent *e)
{
    TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, e->y()));
    return TwMouseButton(TW_MOUSE_RELEASED, Qt2TwMouseButtonId(e));
}
int TwMouseReleaseQt(QMouseEvent *e)
{
    TwMouseMotion(e->x (), e->y ());
    return TwMouseButton(TW_MOUSE_RELEASED, Qt2TwMouseButtonId(e));
}
int TwMousePressQt(QWidget *qw, QMouseEvent *e)
{
    TwMouseMotion(QTLogicalToDevice(qw, e->x()), QTLogicalToDevice(qw, 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;
}
// 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;
}
void ofxTweakbars::mouseReleased(ofMouseEventArgs& rArgs) {
	TwMouseButtonID btn = (rArgs.button == 0) ? TW_MOUSE_LEFT : TW_MOUSE_RIGHT;
	TwMouseButton(TW_MOUSE_RELEASED, btn);
	//autoStore();
}
Beispiel #25
0
bool Tweaker::TranslateEvent(SDL_Event& event)
{
	if(!s_isInit || !s_enabled || s_doNotUseLib) {
		return false;
	}

	int handled = 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 != 0? true : false;
}