Exemple #1
0
static void
HandleMouseEvent(MirPointerEvent const* pointer, SDL_Window* sdl_window)
{
    SDL_SetMouseFocus(sdl_window);

    switch (MIR_mir_pointer_event_action(pointer)) {
        case mir_pointer_action_button_down:
            HandleMouseButton(sdl_window, SDL_PRESSED, pointer);
            break;
        case mir_pointer_action_button_up:
            HandleMouseButton(sdl_window, SDL_RELEASED, pointer);
            break;
        case mir_pointer_action_motion: {
            int x, y;
            int hscroll, vscroll;
            SDL_Mouse* mouse = SDL_GetMouse();
            x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_x);
            y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_y);

            if (mouse) {
                if (mouse->relative_mode) {
                    int relative_x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_x);
                    int relative_y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_y);
                    HandleMouseMotion(sdl_window, relative_x, relative_y);
                }
                else if (mouse->x != x || mouse->y != y) {
                    HandleMouseMotion(sdl_window, x, y);
                }
            }

            hscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_hscroll);
            vscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_vscroll);
            if (vscroll != 0 || hscroll != 0)
                HandleMouseScroll(sdl_window, hscroll, vscroll);
        }
            break;
        case mir_pointer_action_leave:
            SDL_SetMouseFocus(NULL);
            break;
        case mir_pointer_action_enter:
        default:
            break;
    }
}
Exemple #2
0
void SpectraDocumentFrame::OnMouseMotionEvent(wxMouseEvent& event)
{
	try
	{
		HandleMouseMotion(event);
		event.Skip();
		Update();
		old_mouse_position = event.GetPosition();
	}
	catch(oglplus::MissingFunction& mfe) { parent_app.HandleError(mfe, this); }
	catch(oglplus::ProgramBuildError& pbe) { parent_app.HandleError(pbe, this); }
	catch(oglplus::LimitError& le) { parent_app.HandleError(le, this); }
	catch(oglplus::Error& err) { parent_app.HandleError(err, this); }
	catch(const std::exception& se) { parent_app.HandleError(se, this); }
}
TEST_F(EventDispatcherTest, eventsAreRedirectedToProperTool)
{
    testing::Sequence sequence;
    EXPECT_CALL(*tool2, OnSelect()).InSequence(sequence);
    EXPECT_CALL(canvas, HandleLeftMouseButtonClick(testing::_)).InSequence(sequence);
    EXPECT_CALL(*tool2, OnCanvasLeftMouseButtonClick(testing::_)).InSequence(sequence);
    EXPECT_CALL(*tool2, OnUnselect()).InSequence(sequence);
    EXPECT_CALL(*tool1, OnSelect()).InSequence(sequence);
    EXPECT_CALL(canvas, HandleMouseMotion(testing::_)).InSequence(sequence);
    EXPECT_CALL(*tool1, OnCanvasMouseMotion(testing::_)).InSequence(sequence);
    EXPECT_CALL(canvas, HandleRightMouseButtonRelease(testing::_)).InSequence(sequence);
    EXPECT_CALL(*tool1, OnCanvasRightMouseButtonRelease(testing::_)).InSequence(sequence);
    EXPECT_CALL(*tool1, OnUnselect()).InSequence(sequence);
    sut->Select(1);
    sut->OnCanvasLeftMouseButtonClick(dummyEvent);
    sut->Select(0);
    sut->OnCanvasMouseMotion(dummyEvent);
    sut->OnCanvasRightMouseButtonRelease(dummyEvent);
}
static void
HandleMouseEvent(MirMotionEvent const motion, int cord_index, SDL_Window* sdl_window)
{
    SDL_SetMouseFocus(sdl_window);

    switch (motion.action) {
    case mir_motion_action_down:
    case mir_motion_action_pointer_down:
        HandleMouseButton(sdl_window, SDL_PRESSED, motion.button_state);
        break;
    case mir_motion_action_up:
    case mir_motion_action_pointer_up:
        HandleMouseButton(sdl_window, SDL_RELEASED, motion.button_state);
        break;
    case mir_motion_action_hover_move:
    case mir_motion_action_move:
        HandleMouseMotion(sdl_window,
                          motion.pointer_coordinates[cord_index].x,
                          motion.pointer_coordinates[cord_index].y);
        break;
    case mir_motion_action_outside:
        SDL_SetMouseFocus(NULL);
        break;
    case mir_motion_action_scroll:
        HandleMouseScroll(sdl_window,
                          motion.pointer_coordinates[cord_index].hscroll,
                          motion.pointer_coordinates[cord_index].vscroll);
        break;
    case mir_motion_action_cancel:
    case mir_motion_action_hover_enter:
    case mir_motion_action_hover_exit:
        break;
    default:
        break;
    }
}
Exemple #5
0
void SDLEvent::HandleEvent( SDL_Event kEvent, unsigned int uiCurrentTime )
{
	gui_message msg;

	switch ( kEvent.type )
	{
/*
      case SDL_ACTIVEEVENT:
        //Something's happend with our focus
        //If we lost focus or we are iconified, we
        //shouldn't draw the screen
        if ( event.active.gain == 0 )
           isActive = false;
        else
            isActive = TRUE;
        break;
*/
	case SDL_VIDEORESIZE:
		// handle resize event
#ifndef WIN32
		// Do not reinitialize window in Win32
		SDLScreen::GetInstance()->m_kScreen = SDL_SetVideoMode( kEvent.resize.w, kEvent.resize.h, Config::GetBPP(), SDLScreen::GetInstance()->videoFlags );
        
		if ( !SDLScreen::GetInstance()->m_kScreen )
		{
			cerr << "Could not get a surface after resize: " <<
			SDL_GetError() << endl;
			// NOTE: This is bad programming, you should NEVER exit the program without dealocating stuff this should be m_bQuit = true
			exit( 1 );
		};
#endif
		SDLScreen::GetInstance()->ResizeWindow( kEvent.resize.w, kEvent.resize.h );
		break;

	case SDL_KEYDOWN:
		/* handle key presses */
		HandleKeyPress( &kEvent.key.keysym );
		break;

	case SDL_MOUSEMOTION:
		/* handle mouse movements */
		HandleMouseMotion( &kEvent.motion );
		break;

	case SDL_MOUSEBUTTONDOWN:
		if ( !Game::GetInstance()->IsPaused() )
		{
			if ( ( kEvent.button.button == 4 ) )
			{
				pCamera.ChangeZoom( -0.8f );    // Handle mouse wheel up
			}

			if ( ( kEvent.button.button == 5 ) )
			{
				pCamera.ChangeZoom( 0.8f );     // Handle mouse wheel down
			}
		}
		//break;	// ??

	case SDL_MOUSEBUTTONUP:
		if ( ( kEvent.button.button == 4 ) || ( kEvent.button.button == 5 ) )
		{
			break;                // Do nothing on mouse wheel event
		}

		if ( kEvent.type == SDL_MOUSEBUTTONDOWN )
		{
			msg.type = MESSAGE_MOUSEDOWN;
		}
		else
		{
			msg.type = MESSAGE_MOUSEUP;
			pUOGUI.SetDragging( false );
			m_bIsDragging = false;

			if ( Game::GetInstance()->CheckDragDrop( kEvent.button.x, kEvent.button.y ) )
			{
                break;
			}
		}

		msg.mouseevent.x = kEvent.button.x - pUOGUI.GetX ();
		msg.mouseevent.y = kEvent.button.y - pUOGUI.GetY ();
		msg.mouseevent.button = kEvent.button.button;

		if ( !pUOGUI.HandleMessage( &msg ) )
		{
			if ( kEvent.type == SDL_MOUSEBUTTONUP )
			{
				Game::GetInstance()->HandleMouseUp( kEvent.button.x, kEvent.button.y, kEvent.button.button );

				if ( !m_uiLastClick )
				{
					m_uiLastClick = uiCurrentTime;
					m_iLastX = kEvent.button.x;
					m_iLastY = kEvent.button.y;
					m_iLastButton = kEvent.button.button;
				}
				else
				{
					if ( ( uiCurrentTime - m_uiLastClick ) < CLICK_TIME )
					{
						Game::GetInstance()->HandleClick( m_iLastX, m_iLastY, kEvent.button.button, true );
						// printf( "Double Click!\n" );
					}

					m_uiLastClick = 0;
				}
			}
			else
			{
				Game::GetInstance()->HandleMouseDown( kEvent.button.x, kEvent.button.y, kEvent.button.button );
				m_iClickDownX = kEvent.button.x;
				m_iClickDownY = kEvent.button.y;
			}
		}
        break;

	case SDL_QUIT:
		/* handle quit requests */
		m_bQuit = true;
		break;

	default:
		break;
	}
}