Search in sources :

Example 36 with ConstraintWidget

use of android.support.constraint.solver.widgets.ConstraintWidget in project android by JetBrains.

the class Selection method setSelectedResizeHandle.

/**
     * Setter for the selected resize handle
     *
     * @param handle the selected resize handle
     */
public void setSelectedResizeHandle(ResizeHandle handle) {
    mSelectedResizeHandle = handle;
    if (mSelectedResizeHandle != null) {
        ConstraintWidget widget = mSelectedResizeHandle.getOwner();
        mOriginalWidgetBounds.setBounds(widget.getDrawX(), widget.getDrawY(), widget.getWidth(), widget.getHeight());
    } else {
        mOriginalWidgetBounds.setBounds(0, 0, 0, 0);
    }
}
Also used : ConstraintWidget(android.support.constraint.solver.widgets.ConstraintWidget)

Example 37 with ConstraintWidget

use of android.support.constraint.solver.widgets.ConstraintWidget in project android by JetBrains.

the class AnimatedHoverAnchor method onPaint.

/**
     * Paint method for the animation. We simply draw an opaque circle at (x, y),
     * applying a transparency as the animation progresses.
     *
     * @param transform view transform
     * @param g         Graphics context
     */
@Override
public void onPaint(ViewTransform transform, Graphics2D g) {
    int x = transform.getSwingX(mAnchor.getDrawX());
    int y = transform.getSwingY(mAnchor.getDrawY());
    double progress = getProgress();
    int alpha = 255 - getPulsatingAlpha(progress);
    int anchorSize = (int) SceneDraw.getAnchorSize(transform.getScale());
    int radius = anchorSize + 4;
    boolean isNewConnection = mAnchor.getAnchor().getTarget() != null && mOriginalTarget != mAnchor.getAnchor().getTarget();
    Composite savedComposite = g.getComposite();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 255f));
    ConstraintWidget widget = mAnchor.getOwner();
    int l = transform.getSwingX(widget.getDrawX());
    int t = transform.getSwingY(widget.getDrawY());
    int w = transform.getSwingDimension(widget.getDrawWidth());
    if (mIsBaseline) {
        int extra = radius - 3;
        g.setColor(mColor);
        g.setStroke(sThinStroke);
        int handleWidth = mAnchor.getBaselineHandleWidth(transform);
        int padding = (w - handleWidth) / 2;
        g.drawRoundRect(l + padding, t + transform.getSwingDimension(widget.getBaselineDistance()) - extra / 2, handleWidth + 1, extra, radius, radius);
    } else {
        if (isNewConnection) {
            // use smaller circle
            radius = anchorSize + 3;
        }
        mCircle.setFrame(x - radius, y - radius, radius * 2, radius * 2);
        g.setColor(mFrame);
        g.setStroke(isNewConnection ? sThinStroke : sStroke);
        g.draw(mCircle);
        if (isNewConnection) {
            g.setColor(mColorSet.getBackground());
            g.fill(mCircle);
            g.setColor(mColorSet.getAnchorConnectionCircle());
            radius -= 4;
            mInnerCircle.setFrame(x - radius, y - radius, radius * 2, radius * 2);
            g.fill(mInnerCircle);
            g.draw(mInnerCircle);
        } else {
            mCircle.setFrame(x - radius, y - radius, radius * 2, radius * 2);
            g.setColor(mColor);
        }
        g.draw(mCircle);
    }
    g.setComposite(savedComposite);
    if (!mColorSet.useTooltips()) {
        return;
    }
    boolean showTooltip = mShowTooltip;
    boolean newConnection = mAnchor.getAnchor().getTarget() != mTargetAnchor;
    showTooltip |= newConnection;
    if (showTooltip && (System.currentTimeMillis() - mStartTime > WidgetDraw.TOOLTIP_DELAY)) {
        WidgetDraw.drawTooltip(g, mColorSet, getText(), x, y, true);
    }
}
Also used : ConstraintWidget(android.support.constraint.solver.widgets.ConstraintWidget)

Aggregations

ConstraintWidget (android.support.constraint.solver.widgets.ConstraintWidget)37 ConstraintAnchor (android.support.constraint.solver.widgets.ConstraintAnchor)11 Guideline (android.support.constraint.solver.widgets.Guideline)8 Rectangle (java.awt.Rectangle)7 ArrayList (java.util.ArrayList)7 WidgetCompanion (com.android.tools.sherpa.structure.WidgetCompanion)5 Point (java.awt.Point)5 ConstraintWidgetContainer (android.support.constraint.solver.widgets.ConstraintWidgetContainer)3 WidgetContainer (android.support.constraint.solver.widgets.WidgetContainer)3 ConstraintTableLayout (android.support.constraint.solver.widgets.ConstraintTableLayout)2 WidgetDecorator (com.android.tools.sherpa.drawing.decorator.WidgetDecorator)1 WidgetInteractionTargets (com.android.tools.sherpa.interaction.WidgetInteractionTargets)1 Ellipse2D (java.awt.geom.Ellipse2D)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 Iterator (java.util.Iterator)1