Esempio n. 1
0
void InputWrapper::processEvent(SDL_Event *event){
    switch(event->type){
    case SDL_KEYDOWN:
        processKeyDownEvent(event);
        break;

    case SDL_KEYUP:
        processKeyUpEvent(event);
        break;

    case SDL_MOUSEMOTION:
        processMouseMoveEvent(event);
        break;

    case SDL_MOUSEBUTTONDOWN:
        processMouseDownEvent(event);
        break;

    case SDL_MOUSEBUTTONUP:
        processMouseUpEvent(event);
        break;
    }
}
void MouseToolHandler::onGLMouseButtonPress(wxMouseEvent& ev)
{
    // Filter out the button that was triggering this event
    unsigned int state = wxutil::MouseButton::GetButtonStateChangeForMouseEvent(ev);

    // For the active tool mapping, we need just the mouse button without modifiers
    unsigned int button = wxutil::MouseButton::GetButtonStateChangeForMouseEvent(ev) & wxutil::MouseButton::ALL_BUTTON_MASK;

    ui::MouseToolPtr activeToolToBeCleared;

    if (_activeMouseTools.find(button) != _activeMouseTools.end())
    {
        // Send the click event to the currently active tool. Some tools stay active after
        // mouse up and might choose to end their action along with the mouse down event
        // The FreeMoveTool with toggle mode activated is such an example.
        ui::MouseToolPtr tool = _activeMouseTools[button];

        switch (processMouseDownEvent(tool, Vector2(ev.GetX(), ev.GetY())))
        {
        case ui::MouseTool::Result::Finished:
            // Tool is done
            activeToolToBeCleared = tool;
            break;

        case ui::MouseTool::Result::Activated:
        case ui::MouseTool::Result::Continued:
            handleViewRefresh(tool->getRefreshMode());
            break;

        case ui::MouseTool::Result::Ignored:
            break;
        };
    }

    // Now consider all the available tools and send the event
    // Currently active tools are handled above, so don't send the event again

    // Get all mouse tools mapped to this button/modifier combination
    ui::MouseToolStack toolStack = GlobalMouseToolManager().getMouseToolsForEvent(_type, state);

    // Remove all active mouse tools from this stack
    toolStack.remove_if(std::bind(&MouseToolHandler::toolIsActive, this, std::placeholders::_1));

    // The candidates have been trimmed, so let's clear out any pending tools
    if (activeToolToBeCleared)
    {
        clearActiveMouseTool(activeToolToBeCleared);
        activeToolToBeCleared.reset();
    }

    // Check which one of the candidates responds to the mousedown event
    ui::MouseToolPtr activeTool;

    for (ui::MouseToolPtr tool : toolStack)
    {
        // Ask each tool to handle the event
        ui::MouseTool::Result result = processMouseDownEvent(tool, Vector2(ev.GetX(), ev.GetY()));

        if (result != ui::MouseTool::Result::Ignored && result != ui::MouseTool::Result::Finished)
        {
            // This tool is now activated
            activeTool = tool;
            break;
        }
    }

    if (!activeTool)
    {
        return;
    }

    // Store this tool in our map
    _activeMouseTools[button] = activeTool;

    unsigned int pointerMode = activeTool->getPointerMode();

    // Check if the mousetool requires pointer freeze
    if ((pointerMode & ui::MouseTool::PointerMode::Capture) != 0)
    {
        startCapture(activeTool);
    }

    if (!_escapeListener)
    {
        // Register a hook to capture the ESC key during the active phase
        _escapeListener.reset(new KeyEventFilter(WXK_ESCAPE,
            std::bind(&MouseToolHandler::handleEscapeKeyPress, this)));
    }
}