static void handleMouseEvent(const MirMotionEvent motion,
                             int cord_index,
                             _GLFWwindow* window)
{
    switch (motion.action)
    {
          case mir_motion_action_down:
          case mir_motion_action_pointer_down:
              handleMouseButton(window, GLFW_PRESS,
                                motion.modifiers, motion.button_state);
              break;
          case mir_motion_action_up:
          case mir_motion_action_pointer_up:
              handleMouseButton(window, GLFW_RELEASE,
                                motion.modifiers, motion.button_state);
              break;
          case mir_motion_action_hover_move:
          case mir_motion_action_move:
              handleMouseMotion(window,
                                motion.pointer_coordinates[cord_index].x,
                                motion.pointer_coordinates[cord_index].y);
              break;
          case mir_motion_action_outside:
              break;
          case mir_motion_action_scroll:
              handleMouseScroll(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;

    }
}
Example #2
0
bool System::handle_event(event e)
{
    static EventArgs::MouseButtons mouse_button_maping[] = {
        EventArgs::Left, EventArgs::Middle, EventArgs::Right
    };

    int event_type = e.type & event_type_filter;
    int mouse_event = e.mouse.type & mouse_event_filter;

    switch(event_type)
    {
    case event_mouse:
    {
        switch(mouse_event)
        {
        case mouse_move:
            return handleMouseMove(e.mouse.x, e.mouse.y);
            break;
        case mouse_wheel:
            return handleMouseWheel(e.mouse.delta);
            break;
        case mouse_button:
            return handleMouseButton(mouse_button_maping[e.mouse.button],
                                     e.mouse.type & event_key_down ? EventArgs::Down : EventArgs::Up);
            break;
        case mouse_dbclick:
            return handleMouseDouble(mouse_button_maping[e.mouse.button]);
            break;
        }
    }
    break;
    case event_keyboard:
        return handleKeyboard(e.keyboard.key,
                              e.keyboard.type & event_key_down ? EventArgs::Down : EventArgs::Up);
        break;
    case event_char:
        return handleChar(e.text.code);
        break;
    case event_focus:
        handleFocusLost();
        break;
    case event_viewport_resize:
        handleViewportChange();
        break;
    }
    return false;
}
void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
{
    bool motion = false, buttonEvents = false;
    boost::optional<TOOL_EVENT> evt;

    int type = aEvent.GetEventType();

    // Mouse handling
    if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL ||
        type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP ||
        type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP ||
        type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ||
        type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK ||
        // Event issued whem mouse retains position in screen coordinates,
        // but changes in world coordinates (e.g. autopanning)
        type == KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE )
    {
        wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent );
        int mods = decodeModifiers<wxMouseEvent>( me );

        VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetMousePosition();
        VECTOR2D pos = getView()->ToWorld( screenPos );

        if( pos != m_lastMousePos )
        {
            motion = true;
            m_lastMousePos = pos;
            m_editFrame->UpdateStatusBar();
        }

        for( unsigned int i = 0; i < m_buttons.size(); i++ )
            buttonEvents |= handleMouseButton( aEvent, i, motion );

        if( !buttonEvents && motion )
        {
            evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_MOTION, mods );
            evt->SetMousePosition( pos );
        }
    }

    // Keyboard handling
    else if( type == wxEVT_CHAR )
    {
        wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent );
        int key = ke->GetKeyCode();
        int mods = decodeModifiers<wxKeyEvent>( ke );

        if( mods & MD_CTRL )
        {
#if !wxCHECK_VERSION( 2, 9, 0 )
            // I really look forward to the day when we will use only one version of wxWidgets..
            const int WXK_CONTROL_A = 1;
            const int WXK_CONTROL_Z = 26;
#endif

            // wxWidgets have a quirk related to Ctrl+letter hot keys handled by CHAR_EVT
            // http://docs.wxwidgets.org/trunk/classwx_key_event.html:
            // "char events for ASCII letters in this case carry codes corresponding to the ASCII
            // value of Ctrl-Latter, i.e. 1 for Ctrl-A, 2 for Ctrl-B and so on until 26 for Ctrl-Z."
            if( key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
                key += 'A' - 1;
        }

        if( key == WXK_ESCAPE ) // ESC is the special key for cancelling tools
            evt = TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL );
        else
            evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_PRESSED, key | mods );
    }

    if( evt )
        m_toolMgr->ProcessEvent( *evt );

    // pass the event to the GUI, it might still be interested in it
    aEvent.Skip();
}
void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
{
    bool motion = false, buttonEvents = false;
    boost::optional<TOOL_EVENT> evt;

    int type = aEvent.GetEventType();

    // Mouse handling
    if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL ||
#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
        type == wxEVT_MAGNIFY ||
#endif
        type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP ||
        type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP ||
        type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ||
        type == wxEVT_LEFT_DCLICK || type == wxEVT_MIDDLE_DCLICK || type == wxEVT_RIGHT_DCLICK ||
        // Event issued whem mouse retains position in screen coordinates,
        // but changes in world coordinates (e.g. autopanning)
        type == KIGFX::WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE )
    {
        wxMouseEvent* me = static_cast<wxMouseEvent*>( &aEvent );
        int mods = decodeModifiers( me );

        VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetMousePosition();
        VECTOR2D pos = getView()->ToWorld( screenPos );

        if( pos != m_lastMousePos )
        {
            motion = true;
            m_lastMousePos = pos;
        }

        for( unsigned int i = 0; i < m_buttons.size(); i++ )
            buttonEvents |= handleMouseButton( aEvent, i, motion );

        if( !buttonEvents && motion )
        {
            evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_MOTION, mods );
            evt->SetMousePosition( pos );
        }

#ifdef __APPLE__
        // TODO That's a big ugly workaround, somehow DRAWPANEL_GAL loses focus
        // after second LMB click and currently I have no means to do better debugging
        if( type == wxEVT_LEFT_UP )
            static_cast<PCB_BASE_FRAME*>( m_toolMgr->GetEditFrame() )->GetGalCanvas()->SetFocus();
#endif /* __APPLE__ */
    }

    // Keyboard handling
    else if( type == wxEVT_CHAR )
    {
        wxKeyEvent* ke = static_cast<wxKeyEvent*>( &aEvent );
        int key = ke->GetKeyCode();
        int mods = decodeModifiers( ke );

        if( mods & MD_CTRL )
        {
#if !wxCHECK_VERSION( 2, 9, 0 )
            // I really look forward to the day when we will use only one version of wxWidgets..
            const int WXK_CONTROL_A = 1;
            const int WXK_CONTROL_Z = 26;
#endif

            // wxWidgets have a quirk related to Ctrl+letter hot keys handled by CHAR_EVT
            // http://docs.wxwidgets.org/trunk/classwx_key_event.html:
            // "char events for ASCII letters in this case carry codes corresponding to the ASCII
            // value of Ctrl-Latter, i.e. 1 for Ctrl-A, 2 for Ctrl-B and so on until 26 for Ctrl-Z."
            if( key >= WXK_CONTROL_A && key <= WXK_CONTROL_Z )
                key += 'A' - 1;
        }

        if( key == WXK_ESCAPE ) // ESC is the special key for cancelling tools
            evt = TOOL_EVENT( TC_COMMAND, TA_CANCEL_TOOL );
        else
            evt = TOOL_EVENT( TC_KEYBOARD, TA_KEY_PRESSED, key | mods );
    }

    if( evt )
        m_toolMgr->ProcessEvent( *evt );

    // pass the event to the GUI, it might still be interested in it
#ifdef __APPLE__
    // On OS X, key events are always meant to be caught.  An uncaught key event is assumed
    // to be a user input error by OS X (as they are pressing keys in a context where nothing
    // is there to catch the event).  This annoyingly makes OS X beep and/or flash the screen
    // in pcbnew and the footprint editor any time a hotkey is used.  The correct procedure is
    // to NOT pass key events to the GUI under OS X.

    if( type != wxEVT_CHAR )
        aEvent.Skip();
#else
    aEvent.Skip();
#endif

    updateUI();
}