示例#1
0
void GUI::onMouseWheel(double x, double y) {
  if(y > 0.0) {
    scroll_y += 1;
  }
  else {
    scroll_y -= 1;
  }
  TwMouseWheel(scroll_y);
}
示例#2
0
 void GLFW_App::s_mouseWheel(GLFWwindow* window,double offset_x, double offset_y)
 {
     GLFW_App* app = static_cast<GLFW_App*>(glfwGetWindowUserPointer(window));
     glm::ivec2 offset = glm::ivec2(offset_x, offset_y);
     app->m_lastWheelPos -= offset;
     if(app->displayTweakBar())
         TwMouseWheel(app->m_lastWheelPos.y);
     
     double posX, posY;
     glfwGetCursorPos(window, &posX, &posY);
     uint32_t buttonMod, keyModifiers = 0;
     s_getModifiers(window, buttonMod, keyModifiers);
     MouseEvent e(0, (int)posX, (int)posY, keyModifiers, offset);
     if(app->running()) app->mouseWheel(e);
 }
示例#3
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;
}
    /**
     * 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;
    }
示例#5
0
TW_API int TW_CDECL_CALL TwEventMouseWheelGLFWcdecl(int wheelPos)
{
    return TwMouseWheel(wheelPos);
}
示例#6
0
//  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;
}
示例#7
0
//  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;
}
示例#9
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;
}
// 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;
}
示例#11
0
int TW_CALL TwEventScrollGLFW3(GLFWwindow *window, double xoffset, double yoffset)
{
	static int wheelPos = 0;
	wheelPos += (int)yoffset;
	return TwMouseWheel(wheelPos);
}
int TW_CALL TwEventMouseWheelGLFW(GLFWwindow * glfwWindow, double xoffset, double yoffset){
	return TwMouseWheel((int)yoffset);
}
示例#13
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;
}