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);
}
}
}
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);
}
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());
}
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;
}
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);
}
}
Aggregations