use of com.android.tools.sherpa.interaction.ConstraintHandle in project android by JetBrains.
the class WidgetDecorator method onPaintConstraints.
/**
* Paint the constraints of this widget
*
* @param transform the view transform
* @param g the graphics context
*/
public void onPaintConstraints(ViewTransform transform, Graphics2D g) {
if (mColorSet == null) {
return;
}
if (mWidget.getVisibility() == ConstraintWidget.GONE) {
return;
}
g.setColor(mConstraintsColor.getColor());
if (mIsSelected || isShowAllConstraints() || getLook() == ColorTheme.Look.HIGHLIGHTED) {
if (mWidget.getVisibility() == ConstraintWidget.INVISIBLE) {
g.setStroke(SnapDraw.sDashedStroke);
}
ArrayList<ConstraintAnchor.Type> anchors = new ArrayList<>();
if (mWidget.hasBaseline() && (mShowBaseline.isDone() || mWidget.getAnchor(ConstraintAnchor.Type.BASELINE).isConnected())) {
anchors.add(ConstraintAnchor.Type.BASELINE);
}
anchors.add(ConstraintAnchor.Type.LEFT);
anchors.add(ConstraintAnchor.Type.TOP);
anchors.add(ConstraintAnchor.Type.RIGHT);
anchors.add(ConstraintAnchor.Type.BOTTOM);
Color currentColor = g.getColor();
Stroke currentStroke = g.getStroke();
for (ConstraintAnchor.Type type : anchors) {
ConstraintAnchor anchor = mWidget.getAnchor(type);
if (anchor == null) {
continue;
}
if (anchor.isConnected()) {
ConstraintAnchor target = anchor.getTarget();
if (target.getOwner().getVisibility() == ConstraintWidget.GONE) {
continue;
}
ConstraintHandle startHandle = WidgetInteractionTargets.constraintHandle(anchor);
if (startHandle.getAnchor().isConnected() && startHandle.getAnchor().getConnectionCreator() == ConstraintAnchor.AUTO_CONSTRAINT_CREATOR) {
g.setColor(mColorSet.getSoftConstraintColor());
g.setStroke(mColorSet.getSoftConstraintStroke());
} else {
g.setColor(currentColor);
g.setStroke(currentStroke);
}
boolean painted = false;
if (startHandle.isLocking()) {
float progress = startHandle.getLockingProgress();
if (progress > 0) {
startHandle.drawConnection(transform, g, mColorSet, mIsSelected, true, startHandle.getAnchor().getConnectionCreator(), progress);
painted = true;
repaint();
}
}
if (!painted) {
startHandle.drawConnection(transform, g, mColorSet, mIsSelected);
}
}
}
g.setStroke(SnapDraw.sNormalStroke);
paintBias(transform, g);
}
}
use of com.android.tools.sherpa.interaction.ConstraintHandle in project android by JetBrains.
the class WidgetDecorator method onPaintAnchors.
/**
* Paint the anchors of this object
*
* @param transform the view transform
* @param g the graphics context
*/
public void onPaintAnchors(ViewTransform transform, Graphics2D g) {
if (mColorSet == null) {
return;
}
if (mWidget.getVisibility() == ConstraintWidget.GONE) {
return;
}
ConstraintAnchor leftAnchor = mWidget.getAnchor(ConstraintAnchor.Type.LEFT);
ConstraintAnchor rightAnchor = mWidget.getAnchor(ConstraintAnchor.Type.RIGHT);
ConstraintAnchor topAnchor = mWidget.getAnchor(ConstraintAnchor.Type.TOP);
ConstraintAnchor bottomAnchor = mWidget.getAnchor(ConstraintAnchor.Type.BOTTOM);
boolean leftAnchorIsConnected = leftAnchor != null ? leftAnchor.isConnected() : false;
boolean rightAnchorIsConnected = rightAnchor != null ? rightAnchor.isConnected() : false;
boolean topAnchorIsConnected = topAnchor != null ? topAnchor.isConnected() : false;
boolean bottomAnchorIsConnected = bottomAnchor != null ? bottomAnchor.isConnected() : false;
boolean displayAllAnchors = mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.ALL);
boolean showLeftAnchor = displayAllAnchors || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.LEFT) || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.HORIZONTAL);
boolean showRightAnchor = displayAllAnchors || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.RIGHT) || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.HORIZONTAL);
boolean showTopAnchor = displayAllAnchors || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.TOP) || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.VERTICAL);
boolean showBottomAnchor = displayAllAnchors || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.BOTTOM) || mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.VERTICAL);
if (!mDisplayAnchorsPolicy.contains(WidgetDraw.ANCHORS_DISPLAY.NONE)) {
showLeftAnchor |= leftAnchorIsConnected;
showRightAnchor |= rightAnchorIsConnected;
showTopAnchor |= topAnchorIsConnected;
showBottomAnchor |= bottomAnchorIsConnected;
}
WidgetCompanion widgetCompanion = (WidgetCompanion) mWidget.getCompanionWidget();
WidgetInteractionTargets interactionTargets = widgetCompanion.getWidgetInteractionTargets();
// Let's draw all the anchors
g.setColor(mConstraintsColor.getColor());
// Draw the baseline first, if needed
if (mWidget.hasBaseline()) {
ConstraintAnchor baseline = mWidget.getAnchor(ConstraintAnchor.Type.BASELINE);
if (baseline.isConnected() || (mIsSelected && mShowResizeHandles)) {
Color c = g.getColor();
float progress = 1;
if (!baseline.isConnected()) {
progress = mShowBaseline.getProgress();
if (progress > 0) {
int alpha = (int) (255 * progress);
g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha));
}
}
if (progress > 0) {
ConstraintHandle handle = interactionTargets.getConstraintHandle(baseline);
handle.draw(transform, g, mColorSet, mIsSelected);
}
g.setColor(c);
}
}
if (mIsSelected) {
g.setColor(mColorSet.getSelectedConstraints());
}
if (showLeftAnchor) {
ConstraintHandle handle = interactionTargets.getConstraintHandle(leftAnchor);
if (handle != null) {
handle.draw(transform, g, mColorSet, mIsSelected);
}
}
if (showRightAnchor) {
ConstraintHandle handle = interactionTargets.getConstraintHandle(rightAnchor);
if (handle != null) {
handle.draw(transform, g, mColorSet, mIsSelected);
}
}
if (showTopAnchor) {
ConstraintHandle handle = interactionTargets.getConstraintHandle(topAnchor);
if (handle != null) {
handle.draw(transform, g, mColorSet, mIsSelected);
}
}
if (showBottomAnchor) {
ConstraintHandle handle = interactionTargets.getConstraintHandle(bottomAnchor);
if (handle != null) {
handle.draw(transform, g, mColorSet, mIsSelected);
}
}
}
use of com.android.tools.sherpa.interaction.ConstraintHandle 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.interaction.ConstraintHandle in project android by JetBrains.
the class AnimatedConnection method onPaint.
@Override
public void onPaint(ViewTransform transform, Graphics2D g) {
double progress = getProgress();
int alpha = getPulsatingAlpha(progress);
Color highlight = new Color(mColor.getRed(), mColor.getGreen(), mColor.getBlue(), alpha);
g.setColor(highlight);
ConstraintHandle sourceHandle = WidgetInteractionTargets.constraintHandle(mAnchor);
ConstraintHandle targetHandle = WidgetInteractionTargets.constraintHandle(mAnchor.getTarget());
if (sourceHandle != null && targetHandle != null && progress >= 0.05) {
float p = (float) (progress * 2);
if (p > 1) {
p = 1;
}
sourceHandle.drawConnection(transform, g, mColorSet, true, false, mOriginalCreator, p);
}
}
use of com.android.tools.sherpa.interaction.ConstraintHandle in project android by JetBrains.
the class SnapDraw method drawSnapVerticalIndicator.
/**
* Draw a snap indicator for vertical anchors
*
* @param transform view transform
* @param g Graphics context
* @param candidate the snap candidate
*/
private static void drawSnapVerticalIndicator(ViewTransform transform, Graphics2D g, SnapCandidate candidate) {
ConstraintAnchor source = candidate.source;
ConstraintAnchor target = candidate.target;
ConstraintHandle sourceHandle = WidgetInteractionTargets.constraintHandle(source);
ConstraintHandle targetHandle = WidgetInteractionTargets.constraintHandle(target);
int y = transform.getSwingY(candidate.y);
if (targetHandle != null) {
y = transform.getSwingY(targetHandle.getDrawY());
}
int x1 = transform.getSwingX(source.getOwner().getDrawX());
int x2 = transform.getSwingX(source.getOwner().getDrawX() + source.getOwner().getDrawWidth());
int x3 = transform.getSwingX(target.getOwner().getDrawX());
int x4 = transform.getSwingX(target.getOwner().getDrawX() + target.getOwner().getDrawWidth());
int minX = Math.min(x1, x3);
int maxX = Math.max(x2, x4);
if (candidate.margin != 0) {
int y2 = transform.getSwingY(sourceHandle.getDrawY());
String textMargin = "" + Math.abs(candidate.margin);
int xS = x2;
int xT = x4 + OVER_MARGIN / 2;
int mX = xS + OVER_MARGIN;
if (x1 < x3) {
xS = x1;
xT = x3 - OVER_MARGIN / 2;
mX = xS - OVER_MARGIN;
}
drawSnapVerticalMargin(transform, g, mX, y, y2, textMargin);
Graphics2D g2 = (Graphics2D) g.create();
g2.setStroke(sDashedStroke);
g2.drawLine(xS, y, xT, y);
g2.dispose();
} else {
Graphics2D g2 = (Graphics2D) g.create();
boolean insideIndicator = (source.getOwner().getParent() == candidate.target.getOwner()) || (candidate.target.getOwner() instanceof Guideline);
if (insideIndicator) {
g2.setStroke(sLongDashedStroke);
g2.drawLine(minX, y, maxX, y);
} else {
g2.setStroke(sDashedStroke);
g2.drawLine(minX - OVER, y, maxX + OVER, y);
}
g2.dispose();
}
}
Aggregations