Example #1
0
void DebugCameraController::Update(float timeStep)
{
    // Do not move if the UI has a focused element
    if (GetUI()->GetFocusElement())
        return;

    // Do not move if interacting with UI controls
    if (GetSystemUI()->IsAnyItemActive())
        return;

    Input* input = GetInput();

    // Movement speed as world units per second
    float moveSpeed_ = speed_;
    if (input->GetKeyDown(KEY_SHIFT))
    {
        moveSpeed_ *= 2;

        if (input->GetKeyPress(KEY_KP_PLUS))
            speed_ += 1.f;
        else if (input->GetKeyPress(KEY_KP_MINUS))
            speed_ -= 1.f;
    }

    if (input->GetMouseButtonDown(MOUSEB_RIGHT))
    {
        IntVector2 delta = input->GetMouseMove();

        if (input->IsMouseVisible() && delta != IntVector2::ZERO)
            input->SetMouseVisible(false);

        auto yaw = GetNode()->GetRotation().EulerAngles().x_;
        if ((yaw > -90.f && yaw < 90.f) || (yaw <= -90.f && delta.y_ > 0) || (yaw >= 90.f && delta.y_ < 0))
            GetNode()->RotateAround(Vector3::ZERO, Quaternion(mouseSensitivity_ * delta.y_, Vector3::RIGHT), TS_LOCAL);
        GetNode()->RotateAround(GetNode()->GetPosition(), Quaternion(mouseSensitivity_ * delta.x_, Vector3::UP), TS_WORLD);
    }
    else if (!input->IsMouseVisible())
        input->SetMouseVisible(true);

    // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
    if (input->GetKeyDown(KEY_W))
        GetNode()->Translate(Vector3::FORWARD * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_S))
        GetNode()->Translate(Vector3::BACK * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_A))
        GetNode()->Translate(Vector3::LEFT * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_D))
        GetNode()->Translate(Vector3::RIGHT * moveSpeed_ * timeStep);
}
Example #2
0
void Console::SetVisible(bool enable)
{
    Input* input = GetSubsystem<Input>();
    background_->SetVisible(enable);
    closeButton_->SetVisible(enable);
    if (enable)
    {
        // Check if we have receivers for E_CONSOLECOMMAND every time here in case the handler is being added later dynamically
        bool hasInterpreter = PopulateInterpreter();
        commandLine_->SetVisible(hasInterpreter);
        if (hasInterpreter && focusOnShow_)
            GetSubsystem<UI>()->SetFocusElement(lineEdit_);

        // Ensure the background has no empty space when shown without the lineedit
        background_->SetHeight(background_->GetMinHeight());

        // Show OS mouse
        savedMouseVisibility_ = input->IsMouseVisible();
        input->SetMouseVisible(true);
    }
    else
    {
        rowContainer_->SetFocus(false);
        interpreters_->SetFocus(false);
        lineEdit_->SetFocus(false);

        // Restore OS mouse visibility
        input->SetMouseVisible(savedMouseVisibility_);
    }
}
void UIDragDrop::HandleMouseDown(StringHash eventType, VariantMap& eventData)
{
    using namespace MouseButtonDown;

    Input* input = GetSubsystem<Input>();

    if (!input->IsMouseVisible())
        return;

    if ((eventData[P_BUTTONS].GetUInt() & MOUSEB_LEFT) && TBWidget::hovered_widget)
    {
        // see if we have a widget
        TBWidget* tbw = TBWidget::hovered_widget;

        while(tbw && !tbw->GetDelegate())
        {
            tbw = tbw->GetParent();
        }

        if (!tbw)
            return;

        UIWidget* widget = (UIWidget*) tbw->GetDelegate();

        currentTargetWidget_ = widget;
        dragSourceWidget_ = widget;

    }

}
Example #4
0
void DebugCameraController2D::Update(float timeStep)
{
    // Do not move if the UI has a focused element
    if (GetUI()->GetFocusElement())
        return;

    // Do not move if interacting with UI controls
    if (GetSystemUI()->IsAnyItemActive())
        return;

    Input* input = GetInput();

    // Movement speed as world units per second
    float moveSpeed_ = speed_;
    if (input->GetKeyDown(KEY_SHIFT))
    {
        moveSpeed_ *= 2;

        if (input->GetKeyPress(KEY_KP_PLUS))
            speed_ += 1.f;
        else if (input->GetKeyPress(KEY_KP_MINUS))
            speed_ -= 1.f;
    }

    if (input->GetMouseButtonDown(MOUSEB_RIGHT))
    {
        IntVector2 delta = input->GetMouseMove();

        if (input->IsMouseVisible() && delta != IntVector2::ZERO)
            input->SetMouseVisible(false);
        GetNode()->Translate2D(Vector2{(float)delta.x_ * -1.f, (float)delta.y_} * moveSpeed_ * timeStep);
    }
    else if (!input->IsMouseVisible())
        input->SetMouseVisible(true);

    // Read WASD keys and move the camera scene node to the corresponding direction if they are pressed
    if (input->GetKeyDown(KEY_W))
        GetNode()->Translate(Vector3::UP * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_S))
        GetNode()->Translate(Vector3::DOWN * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_A))
        GetNode()->Translate(Vector3::LEFT * moveSpeed_ * timeStep);
    if (input->GetKeyDown(KEY_D))
        GetNode()->Translate(Vector3::RIGHT * moveSpeed_ * timeStep);
}
void UIDragDrop::HandleMouseDown(StringHash eventType, VariantMap& eventData)
{
    using namespace MouseButtonDown;

    Input* input = GetSubsystem<Input>();

    if (!input->IsMouseVisible())
        return;

    if ((eventData[P_BUTTONS].GetUInt() & MOUSEB_LEFT) && TBWidget::hovered_widget)
    {
        // see if we have a widget with a drag object

        TBWidget* tbw = TBWidget::hovered_widget;
        UIWidget* widget = nullptr;

        while(tbw)
        {
            if (tbw->GetDelegate())
            {
                widget = (UIWidget*) tbw->GetDelegate();

                if (widget->GetDragObject())
                {
                    // TODO: check if we're in widget bounds
                    // this is going to need to be updated for drag/drop multiselect
                    break;
                }

                widget = nullptr;
            }

            tbw = tbw->GetParent();
        }

        if (!widget)
            return;

        currentTargetWidget_ = widget;
        dragSourceWidget_ = widget;
        mouseDownPosition_ = input->GetMousePosition();

    }

}
void SceneView3D::HandleMouseMove(StringHash eventType, VariantMap& eventData)
{
    if (dragNode_.Null())
        return;

    Input* input = GetSubsystem<Input>();

    if (!input->IsMouseVisible())
        return;

    using namespace MouseMove;

    int x = eventData[P_X].GetInt();
    int y = eventData[P_Y].GetInt();

    UpdateDragNode(x, y);

}