Search in sources :

Example 6 with WidgetDecorator

use of com.android.tools.sherpa.drawing.decorator.WidgetDecorator 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 7 with WidgetDecorator

use of com.android.tools.sherpa.drawing.decorator.WidgetDecorator 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 8 with WidgetDecorator

use of com.android.tools.sherpa.drawing.decorator.WidgetDecorator 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 9 with WidgetDecorator

use of com.android.tools.sherpa.drawing.decorator.WidgetDecorator in project android by JetBrains.

the class SceneDraw method paintWidgets.

/**
     * Utility function to paint the given widget container and its children
     *
     * @param transform            the view transform
     * @param g                    the graphics context
     * @param rootDrawComponent    the component that is the root of the draw call
     * @param container            the container to paint
     * @param selectedWidget       the selected widget if any
     * @param selectedAnchor       the selected anchor if any
     * @param selectedResizeHandle the selected resize handle if any
     * @return true if we need to be repainted, false otherwise
     */
private boolean paintWidgets(ViewTransform transform, Graphics2D g, ConstraintWidget rootDrawComponent, WidgetContainer container, ConstraintWidget selectedWidget, ConstraintAnchor selectedAnchor, ResizeHandle selectedResizeHandle) {
    if (container.getVisibility() == ConstraintWidget.GONE) {
        return false;
    }
    boolean needsRepaint = false;
    WidgetDecorator decorator = getDecorator(container, selectedWidget, selectedAnchor, selectedResizeHandle);
    decorator.setRepaintableSurface(mRepaintableSurface);
    if (!decorator.isVisible()) {
        return needsRepaint;
    }
    if (DRAW_ENTIRE_TREE || (container == rootDrawComponent || container.getParent() == rootDrawComponent)) {
        needsRepaint |= decorator.onPaint(transform, g);
        if (container == rootDrawComponent) {
            // || container == mWidgetsScene.getRoot()) {
            int xr = transform.getSwingX(container.getDrawX());
            int yr = transform.getSwingY(container.getDrawY());
            int wr = transform.getSwingDimension(container.getDrawWidth());
            int hr = transform.getSwingDimension(container.getDrawHeight());
            if (mDrawOutsideShade && mColorSet.drawBackground()) {
                g.setColor(mColorSet.getSubduedBackground());
                g.fillRect((int) transform.getTranslateX(), (int) transform.getTranslateY(), mViewWidth, yr);
                g.fillRect((int) transform.getTranslateX(), yr + hr, mViewWidth, mViewHeight - yr - hr);
                g.fillRect((int) transform.getTranslateX(), yr, xr, hr);
                g.fillRect(wr + xr, yr, mViewWidth - xr - wr, hr);
                g.setStroke(SnapDraw.sLongDashedStroke);
                g.setColor(mColorSet.getHighlightedFrames());
                g.drawRect(xr, yr, wr, hr);
            }
            if (mDrawResizeHandle) {
                g.setColor(mColorSet.getHighlightedFrames());
                int resizeHandleSize = 10;
                int gap = 8;
                g.setStroke(new BasicStroke(3));
                g.drawLine(xr + wr - resizeHandleSize, yr + hr + gap, xr + wr + gap, yr + hr + gap);
                g.drawLine(xr + wr + gap, yr + hr - resizeHandleSize, xr + wr + gap, yr + hr + gap);
                g.setStroke(new BasicStroke(1));
            }
        }
    }
    container.updateDrawPosition();
    for (ConstraintWidget widget : container.getChildren()) {
        if (widget.getVisibility() == ConstraintWidget.GONE) {
            continue;
        }
        if (widget instanceof WidgetContainer) {
            needsRepaint |= paintWidgets(transform, g, rootDrawComponent, (WidgetContainer) widget, selectedWidget, selectedAnchor, selectedResizeHandle);
        } else {
            WidgetDecorator widgetDecorator = getDecorator(widget, selectedWidget, selectedAnchor, selectedResizeHandle);
            if (widget == rootDrawComponent || widget.getParent() == rootDrawComponent) {
                needsRepaint |= widgetDecorator.onPaint(transform, g);
                widgetDecorator.setRepaintableSurface(mRepaintableSurface);
            }
        }
    }
    if (needsRepaint) {
        repaint();
    }
    return needsRepaint;
}
Also used : WidgetDecorator(com.android.tools.sherpa.drawing.decorator.WidgetDecorator)

Example 10 with WidgetDecorator

use of com.android.tools.sherpa.drawing.decorator.WidgetDecorator in project android by JetBrains.

the class SceneDraw method getDecorator.

/**
     * Utility function to get the decorator of the widget and set the correct
     * anchor and resize indicators
     *
     * @param widget               the widget to draw
     * @param selectedWidget       the selected widget if any
     * @param selectedAnchor       the selected anchor if any
     * @param selectedResizeHandle the selected resize handle if any
     * @return the widget decorator
     */
private WidgetDecorator getDecorator(ConstraintWidget widget, ConstraintWidget selectedWidget, ConstraintAnchor selectedAnchor, ResizeHandle selectedResizeHandle) {
    WidgetCompanion companion = (WidgetCompanion) widget.getCompanionWidget();
    WidgetDecorator decorator = companion.getWidgetDecorator(getCurrentStyle());
    if (!decorator.isSelected()) {
        decorator.updateShowAnchorsPolicy(selectedWidget, selectedAnchor);
    } else {
        decorator.setShowResizeHandles(mWidgetMotion.needToShowDecorations());
        decorator.setShowSizeIndicator(selectedResizeHandle != null);
    }
    if (mMoveOnlyMode) {
        decorator.setShowResizeHandles(false);
    }
    return decorator;
}
Also used : WidgetCompanion(com.android.tools.sherpa.structure.WidgetCompanion) WidgetDecorator(com.android.tools.sherpa.drawing.decorator.WidgetDecorator)

Aggregations

WidgetDecorator (com.android.tools.sherpa.drawing.decorator.WidgetDecorator)15 WidgetCompanion (com.android.tools.sherpa.structure.WidgetCompanion)8 WidgetInteractionTargets (com.android.tools.sherpa.interaction.WidgetInteractionTargets)4 ConstraintHandle (com.android.tools.sherpa.interaction.ConstraintHandle)2 ResizeHandle (com.android.tools.sherpa.interaction.ResizeHandle)2 ArrayList (java.util.ArrayList)2 ConstraintAnchor (android.support.constraint.solver.widgets.ConstraintAnchor)1 ConstraintWidget (android.support.constraint.solver.widgets.ConstraintWidget)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 SnapCandidate (com.android.tools.sherpa.interaction.SnapCandidate)1 Selection (com.android.tools.sherpa.structure.Selection)1 WidgetsScene (com.android.tools.sherpa.structure.WidgetsScene)1 Rectangle (java.awt.Rectangle)1 Ellipse2D (java.awt.geom.Ellipse2D)1