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