Search in sources :

Example 16 with WidgetCompanion

use of com.android.tools.sherpa.structure.WidgetCompanion in project android by JetBrains.

the class SceneDraw method mouseReleased.

/**
     * Mouse handler on mouse release
     */
public void mouseReleased() {
    if (mCurrentAnimation != null) {
        mCurrentAnimation = mDarkToNormal;
        mCurrentAnimation.start();
    }
    mAnimationCandidateAnchors.clear();
    mChoreographer.removeAnimation(mAnimationCandidateAnchors);
    // Reset the widget looks on mouse release
    for (ConstraintWidget widget : mWidgetsScene.getWidgets()) {
        WidgetCompanion companion = (WidgetCompanion) widget.getCompanionWidget();
        WidgetDecorator decorator = companion.getWidgetDecorator(getCurrentStyle());
        if (decorator.getLook() == ColorTheme.Look.HIGHLIGHTED || decorator.getLook() == ColorTheme.Look.SUBDUED) {
            decorator.setLook(ColorTheme.Look.NORMAL);
        }
    }
}
Also used : WidgetCompanion(com.android.tools.sherpa.structure.WidgetCompanion) WidgetDecorator(com.android.tools.sherpa.drawing.decorator.WidgetDecorator)

Example 17 with WidgetCompanion

use of com.android.tools.sherpa.structure.WidgetCompanion in project android by JetBrains.

the class SceneDraw method animateInCandidateAnchors.

/**
     * Utility function. Given the currently selected anchor, gather all the
     * potential anchors that we could connect to and start an AnimatedCircle animation
     * where they are, to indicate them to the user.
     */
private void animateInCandidateAnchors(ConstraintAnchor selectedAnchor) {
    if (selectedAnchor == null) {
        return;
    }
    mAnimationCandidateAnchors.clear();
    for (ConstraintWidget widget : mWidgetsScene.getWidgets()) {
        boolean highlighted = false;
        for (ConstraintAnchor a : widget.getAnchors()) {
            if (selectedAnchor.isValidConnection(a) && selectedAnchor.isConnectionAllowed(a.getOwner(), a)) {
                ConstraintHandle constraintHandle = WidgetInteractionTargets.constraintHandle(a);
                if (constraintHandle == null) {
                    continue;
                }
                mAnimationCandidateAnchors.add(new AnimatedLine(constraintHandle));
                highlighted = true;
            }
        }
        WidgetCompanion companion = (WidgetCompanion) widget.getCompanionWidget();
        WidgetDecorator decorator = companion.getWidgetDecorator(getCurrentStyle());
        if (decorator.getLook() == ColorTheme.Look.NORMAL) {
            if (highlighted) {
                decorator.setLook(ColorTheme.Look.HIGHLIGHTED);
            } else {
                decorator.setLook(ColorTheme.Look.SUBDUED);
            }
        }
    }
    mChoreographer.addAnimation(mAnimationCandidateAnchors);
}
Also used : AnimatedLine(com.android.tools.sherpa.animation.AnimatedLine) ConstraintHandle(com.android.tools.sherpa.interaction.ConstraintHandle) WidgetCompanion(com.android.tools.sherpa.structure.WidgetCompanion) WidgetDecorator(com.android.tools.sherpa.drawing.decorator.WidgetDecorator)

Example 18 with WidgetCompanion

use of com.android.tools.sherpa.structure.WidgetCompanion in project android by JetBrains.

the class ConstraintUtilities method setRatio.

/**
   * Update the attributes Dimension Ratio
   *
   * @param attributes the attributes we work on
   * @param widget     the widget we use as a model
   */
static void setRatio(@NotNull NlAttributesHolder attributes, @NotNull ConstraintWidget widget) {
    WidgetCompanion companion = (WidgetCompanion) widget.getCompanionWidget();
    attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_DIMENSION_RATIO, companion.getWidgetProperties().getDimensionRatio());
}
Also used : WidgetCompanion(com.android.tools.sherpa.structure.WidgetCompanion)

Example 19 with WidgetCompanion

use of com.android.tools.sherpa.structure.WidgetCompanion in project android by JetBrains.

the class MouseInteraction method getDecorator.

/**
     * Utility function to retrieve a decorator
     *
     * @param widget the widget we look at
     * @return the decorator of the widget
     */
private WidgetDecorator getDecorator(ConstraintWidget widget) {
    WidgetCompanion companion = (WidgetCompanion) widget.getCompanionWidget();
    WidgetDecorator decorator = companion.getWidgetDecorator(mSceneDraw.getCurrentStyle());
    return decorator;
}
Also used : WidgetCompanion(com.android.tools.sherpa.structure.WidgetCompanion) WidgetDecorator(com.android.tools.sherpa.drawing.decorator.WidgetDecorator)

Example 20 with WidgetCompanion

use of com.android.tools.sherpa.structure.WidgetCompanion in project android by JetBrains.

the class ConstraintHandle method drawConnection.

/**
     * Implements the drawing of the connection from this anchor to its target
     *
     * @param transform  the view transform
     * @param g          the graphics context
     * @param colorSet   the current colorset
     * @param isSelected if the connection is selected
     */
public void drawConnection(ViewTransform transform, Graphics2D g, ColorSet colorSet, boolean isSelected, boolean showMargin, int originalCreator, float progress) {
    if (!mAnchor.isConnected()) {
        return;
    }
    if (mAnchor != null && mAnchor.getConnectionCreator() == ConstraintAnchor.AUTO_CONSTRAINT_CREATOR) {
        startLock();
    }
    ConnectionDrawing drawing = new ConnectionDrawing();
    ConstraintWidget targetWidget = mAnchor.getTarget().getOwner();
    WidgetCompanion targetCompanion = (WidgetCompanion) targetWidget.getCompanionWidget();
    if (targetCompanion == null) {
        return;
    }
    WidgetInteractionTargets interactionTargets = targetCompanion.getWidgetInteractionTargets();
    ConstraintHandle targetHandle = interactionTargets.getConstraintHandle(mAnchor.getTarget());
    if (targetHandle == null) {
        // TODO fix -- sometimes triggered with guideline and inference
        return;
    }
    g.setStroke(sSimpleStroke);
    int sx = transform.getSwingFX(mX);
    int sy = transform.getSwingFY(mY);
    int tx = transform.getSwingFX(targetHandle.getDrawX());
    int ty = transform.getSwingFY(targetHandle.getDrawY());
    if (targetHandle.getOwner().isRootContainer()) {
        if (mAnchor.isVerticalAnchor()) {
            tx = sx;
        } else {
            ty = sy;
        }
    }
    int minimum = (int) (1.5 * ConnectionDraw.CONNECTION_ANCHOR_SIZE);
    if (Math.abs(sx - tx) < minimum && Math.abs(sy - ty) < minimum) {
        switch(mAnchor.getType()) {
            case LEFT:
                {
                    drawShadowedArrow(g, colorSet, ConnectionDraw.getLeftArrow(), sx, sy);
                }
                break;
            case TOP:
                {
                    drawShadowedArrow(g, colorSet, ConnectionDraw.getTopArrow(), sx, sy);
                }
                break;
            case RIGHT:
                {
                    drawShadowedArrow(g, colorSet, ConnectionDraw.getRightArrow(), sx, sy);
                }
                break;
            case BOTTOM:
                {
                    drawShadowedArrow(g, colorSet, ConnectionDraw.getBottomArrow(), sx, sy);
                }
                break;
        }
        return;
    }
    if (mAnchor.getOpposite() != null && mAnchor.getOpposite().isConnected()) {
        // Draw centered connections
        if (mAnchor.getOpposite().getTarget() == mAnchor.getTarget()) {
            // Center connection on same anchor
            addPathCenteredConnectionOnSameAnchor(transform, g, isSelected, drawing, targetHandle, targetWidget);
        } else if ((mAnchor.getOpposite().getTarget().getOwner() == mAnchor.getTarget().getOwner()) && targetWidget != getOwner().getParent()) {
            if (mAnchor.getConnectionCreator() == ConstraintAnchor.AUTO_CONSTRAINT_CREATOR) {
                g.setStroke(colorSet.getSoftConstraintStroke());
            }
            // Center connection on same widget (save our parent)
            addPathCenteredConnectionOnSameWidget(transform, g, isSelected, drawing, colorSet, targetHandle, targetWidget);
        } else {
            if (mAnchor.getConnectionCreator() == ConstraintAnchor.AUTO_CONSTRAINT_CREATOR) {
                g.setStroke(colorSet.getSoftConstraintStroke());
            }
            // Center connection on different widgets (or our parent)
            addPathCenteredConnection(transform, g, isSelected, drawing, colorSet, targetHandle, targetWidget);
        }
    } else {
        addPathConnection(transform, g, isSelected, showMargin, drawing, colorSet, targetHandle.getDrawX(), targetHandle.getDrawY(), mAnchor.isConnected(), targetHandle.getAnchor().isConnected());
    }
    // If a lock timer is active, draw the path a second time
    if (progress <= 1 && progress >= 0.1) {
        int distance = lengthOfPath(drawing.mPath);
        int dashFull = (int) (distance * progress);
        int dashEmpty = (int) (distance * (1 - progress));
        if (dashFull > 0 || dashEmpty > 0) {
            Stroke s = g.getStroke();
            if (originalCreator == ConstraintAnchor.AUTO_CONSTRAINT_CREATOR || originalCreator == ConstraintAnchor.SCOUT_CREATOR) {
                if (originalCreator != ConstraintAnchor.SCOUT_CREATOR) {
                    g.setColor(colorSet.getSoftConstraintColor());
                    g.setStroke(colorSet.getSoftConstraintStroke());
                    drawing.draw(g);
                }
                Stroke progressStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { dashFull, dashEmpty }, 0);
                g.setStroke(progressStroke);
                if (progress != 1) {
                    drawing.mDrawArrow = false;
                }
                if (originalCreator != ConstraintAnchor.SCOUT_CREATOR) {
                    g.setColor(colorSet.getSelectedConstraints());
                }
                drawing.draw(g);
            } else {
                g.setColor(colorSet.getSoftConstraintColor());
                g.setStroke(colorSet.getSoftConstraintStroke());
                drawing.draw(g);
                Stroke progressStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { dashEmpty, dashFull }, 0);
                g.setColor(colorSet.getSelectedConstraints());
                g.setStroke(progressStroke);
                if (progress == 1) {
                    drawing.mDrawArrow = false;
                }
                drawing.draw(g);
            }
            int distanceCircle = (int) (2 * Math.PI * 10);
            Color prev = g.getColor();
            int solidCircle = (int) (distanceCircle * progress);
            int emptyCircle = (int) (distanceCircle * (1 - progress));
            Stroke circleProgressStrokeOuter = new BasicStroke(4, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { solidCircle, emptyCircle }, 0);
            g.setColor(colorSet.getBackground());
            g.setStroke(circleProgressStrokeOuter);
            int d = 2 * sCountDownRadius;
            g.drawRoundRect(sx - sCountDownRadius, sy - sCountDownRadius, d, d, d, d);
            Stroke circleProgressStroke = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { solidCircle, emptyCircle }, 0);
            g.setColor(prev);
            g.setStroke(circleProgressStroke);
            g.drawRoundRect(sx - sCountDownRadius, sy - sCountDownRadius, d, d, d, d);
            g.setStroke(s);
        }
    } else {
        paintShadow(g, colorSet, drawing);
        drawing.draw(g);
    }
}
Also used : ConstraintWidget(android.support.constraint.solver.widgets.ConstraintWidget) WidgetCompanion(com.android.tools.sherpa.structure.WidgetCompanion)

Aggregations

WidgetCompanion (com.android.tools.sherpa.structure.WidgetCompanion)27 WidgetDecorator (com.android.tools.sherpa.drawing.decorator.WidgetDecorator)8 ConstraintWidget (android.support.constraint.solver.widgets.ConstraintWidget)5 WidgetInteractionTargets (com.android.tools.sherpa.interaction.WidgetInteractionTargets)5 ConstraintAnchor (android.support.constraint.solver.widgets.ConstraintAnchor)3 ConstraintHandle (com.android.tools.sherpa.interaction.ConstraintHandle)3 ArrayList (java.util.ArrayList)3 Selection (com.android.tools.sherpa.structure.Selection)2 Nullable (org.jetbrains.annotations.Nullable)2 Guideline (android.support.constraint.solver.widgets.Guideline)1 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 Configuration (com.android.tools.idea.configurations.Configuration)1 SceneComponent (com.android.tools.idea.uibuilder.scene.SceneComponent)1 AnimatedLine (com.android.tools.sherpa.animation.AnimatedLine)1 TextWidget (com.android.tools.sherpa.drawing.decorator.TextWidget)1 ResizeHandle (com.android.tools.sherpa.interaction.ResizeHandle)1 SnapCandidate (com.android.tools.sherpa.interaction.SnapCandidate)1 WidgetsScene (com.android.tools.sherpa.structure.WidgetsScene)1 Point (java.awt.Point)1 Ellipse2D (java.awt.geom.Ellipse2D)1