/**
 * Overridden from UMLWidgetController.
 * Modifies the value of the diffX and diffY variables used to move the
 * widgets.
 * The values are constrained using constrainPosition.
 * @see constrainPosition
 *
 * @param diffX The difference between current X position and new X position.
 * @param diffY The difference between current Y position and new Y position.
 */
void FloatingTextWidgetController::constrainMovementForAllWidgets(int &diffX, int &diffY)
{
    QPoint constrainedPosition = constrainPosition(diffX, diffY);

    diffX = constrainedPosition.x() - m_floatingTextWidget->getX();
    diffY = constrainedPosition.y() - m_floatingTextWidget->getY();
}
Esempio n. 2
0
/*************************************************************************
	Set the current mouse cursor position
*************************************************************************/
void MouseCursor::setPosition(const Point& position)
{
    d_position = position;
	constrainPosition();

    d_geometry->setTranslation(Vector3(d_position.d_x, d_position.d_y, 0));
}
Esempio n. 3
0
/*************************************************************************
	Offset the mouse cursor position by the deltas specified in 'offset'.
*************************************************************************/
void MouseCursor::offsetPosition(const Point& offset)
{
	d_position.d_x += offset.d_x;
	d_position.d_y += offset.d_y;
	constrainPosition();

    d_geometry->setTranslation(Vector3(d_position.d_x, d_position.d_y, 0));
}
/**
 * Overridden from UMLWidgetController.
 * Moves the widget to a new position using the difference between the
 * current position and the new position.
 * If the floating text widget is part of a sequence message, and the
 * message widget is selected, it does nothing: the message widget will
 * update the text position when it's moved.
 * In any other case, the floating text widget constrains its move using
 * constrainPosition. When the position of the floating text is constrained,
 * it's kept at that position until it can be moved to another valid
 * position (m_unconstrainedPositionX/Y and m_movementDirectionX/Y are
 * used for that).
 * Moreover, if is part of a sequence message (and the message widget
 * isn't selected), it updates the position of the message widget.
 * @see constrainPosition
 *
 * @param diffX The difference between current X position and new X position.
 * @param diffY The difference between current Y position and new Y position.
 */
void FloatingTextWidgetController::moveWidgetBy(int diffX, int diffY)
{
    if (m_floatingTextWidget->textRole() == Uml::TextRole::Seq_Message_Self)
        return;

    if (m_floatingTextWidget->textRole() == Uml::TextRole::Seq_Message
                    && ((MessageWidget*)m_floatingTextWidget->link())->getSelected()) {
        return;
    }

    m_unconstrainedPositionX += diffX;
    m_unconstrainedPositionY += diffY;
    QPoint constrainedPosition = constrainPosition(diffX, diffY);

    int newX = constrainedPosition.x();
    int newY = constrainedPosition.y();

    if (!m_movementDirectionX) {
        if (m_unconstrainedPositionX != constrainedPosition.x()) {
            m_movementDirectionX = (diffX > 0)? 1: -1;
        }
    } else if ((m_movementDirectionX < 0 && m_unconstrainedPositionX > m_floatingTextWidget->getX()) ||
               (m_movementDirectionX > 0 && m_unconstrainedPositionX < m_floatingTextWidget->getX()) ) {
        newX = m_unconstrainedPositionX;
        m_movementDirectionX = 0;
    }

    if (!m_movementDirectionY) {
        if (m_unconstrainedPositionY != constrainedPosition.y()) {
            m_movementDirectionY = (diffY > 0)? 1: -1;
        }
    } else if ((m_movementDirectionY < 0 && m_unconstrainedPositionY > m_floatingTextWidget->getY()) ||
               (m_movementDirectionY > 0 && m_unconstrainedPositionY < m_floatingTextWidget->getY()) ) {
        newY = m_unconstrainedPositionY;
        m_movementDirectionY = 0;
    }

    m_floatingTextWidget->setX(newX);
    m_floatingTextWidget->setY(newY);

    if (m_floatingTextWidget->link()) {
        m_floatingTextWidget->link()->calculateNameTextSegment();
        if (m_floatingTextWidget->textRole() == Uml::TextRole::Seq_Message) {
            MessageWidget* messageWidget = (MessageWidget*)m_floatingTextWidget->link();
            messageWidget->setY(newY + m_floatingTextWidget->getHeight());

            //TODO This should be moved to somewhere in MessageWidget, refactor with messagewidgetcontroller.cpp:44
            if (messageWidget->sequenceMessageType() == Uml::sequence_message_creation) {
                const int objWidgetHalfHeight = messageWidget->objectWidget(Uml::B)->getHeight() / 2;
                messageWidget->objectWidget(Uml::B)->UMLWidget::setY(messageWidget->getY() - objWidgetHalfHeight);
            }
        }
    }
}
Esempio n. 5
0
/*************************************************************************
	Set the area that the mouse cursor is constrained to.
*************************************************************************/
void MouseCursor::setUnifiedConstraintArea(const URect* area)
{
    Rect renderer_area = System::getSingleton().getRenderer()->getRect();

    if (area)
    {
        d_constraints = *area;
    }
    else
    {
        d_constraints.d_min.d_x = cegui_reldim(renderer_area.d_left / renderer_area.getWidth());
        d_constraints.d_min.d_y = cegui_reldim(renderer_area.d_top / renderer_area.getHeight());
        d_constraints.d_max.d_x = cegui_reldim(renderer_area.d_right / renderer_area.getWidth());
        d_constraints.d_max.d_y = cegui_reldim(renderer_area.d_bottom / renderer_area.getHeight());
    }

    constrainPosition();
}
Esempio n. 6
0
/*************************************************************************
	Set the area that the mouse cursor is constrained to.
*************************************************************************/
void MouseCursor::setConstraintArea(const Rect* area)
{
    Rect renderer_area = System::getSingleton().getRenderer()->getRect();

    if (area == NULL)
    {
        d_constraints.d_min.d_x = cegui_reldim(renderer_area.d_left / renderer_area.getWidth());
        d_constraints.d_min.d_y = cegui_reldim(renderer_area.d_top / renderer_area.getHeight());
        d_constraints.d_max.d_x = cegui_reldim(renderer_area.d_right / renderer_area.getWidth());
        d_constraints.d_max.d_y = cegui_reldim(renderer_area.d_bottom / renderer_area.getHeight());
    }
    else
    {
        Rect finalArea(area->getIntersection(renderer_area));
        d_constraints.d_min.d_x = cegui_reldim(finalArea.d_left / renderer_area.getWidth());
        d_constraints.d_min.d_y = cegui_reldim(finalArea.d_top / renderer_area.getHeight());
        d_constraints.d_max.d_x = cegui_reldim(finalArea.d_right / renderer_area.getWidth());
        d_constraints.d_max.d_y = cegui_reldim(finalArea.d_bottom / renderer_area.getHeight());
    }

    constrainPosition();
}
Esempio n. 7
0
/*************************************************************************
	Offset the mouse cursor position by the deltas specified in 'offset'.
*************************************************************************/
void MouseCursor::offsetPosition(const Point& offset)
{
    d_position.d_x += offset.d_x;
    d_position.d_y += offset.d_y;
    constrainPosition();
}
Esempio n. 8
0
/*************************************************************************
	Set the current mouse cursor position
*************************************************************************/
void MouseCursor::setPosition(const Point& position)
{
    d_position.d_x = position.d_x;
    d_position.d_y = position.d_y;
    constrainPosition();
}