Navigation Menu

Skip to content

Commit

Permalink
-Added shape edge and center indexing, with snap and guideline support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Proctor committed Feb 11, 2015
1 parent 43d6e48 commit 0fc190f
Show file tree
Hide file tree
Showing 3 changed files with 1,110 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/com/ait/lienzo/client/core/shape/Rectangle.java
Expand Up @@ -18,10 +18,14 @@

import com.ait.lienzo.client.core.Attribute;
import com.ait.lienzo.client.core.Context2D;
import com.ait.lienzo.client.core.event.AttributesChangedEvent;
import com.ait.lienzo.client.core.shape.json.IFactory;
import com.ait.lienzo.client.core.shape.json.validators.ValidationContext;
import com.ait.lienzo.client.core.shape.json.validators.ValidationException;
import com.ait.lienzo.client.core.types.BoundingBox;
import com.ait.lienzo.client.core.util.EdgeAndCenterIndex;
import com.ait.lienzo.client.core.util.EdgeAndCenterIndex.EdgeAndCenterIndexHandler;
import com.ait.lienzo.client.core.util.EdgeAndCenterIndex.AlignmentCallback;
import com.ait.lienzo.shared.core.types.ShapeType;
import com.google.gwt.json.client.JSONObject;

Expand Down Expand Up @@ -212,4 +216,41 @@ public Rectangle create(final JSONObject node, final ValidationContext ctx) thro
return new Rectangle(node, ctx);
}
}

@Override
public EdgeAndCenterIndexHandler getEdgeAndCenterIndexHandler(EdgeAndCenterIndex edgeAndCenterIndex, AlignmentCallback alignmentCallback)
{
return new RectangleEdgeAndCenterIndexHandler(this, edgeAndCenterIndex, alignmentCallback);
}

public static class RectangleEdgeAndCenterIndexHandler extends EdgeAndCenterIndexHandler
{
public RectangleEdgeAndCenterIndexHandler(Rectangle rect, EdgeAndCenterIndex edgeAndCenterIndex, AlignmentCallback alignmentCallback)
{
super(rect, edgeAndCenterIndex, alignmentCallback, Attribute.X, Attribute.Y, Attribute.WIDTH, Attribute.HEIGHT);
}

public void doOnAttributesChanged(AttributesChangedEvent event)
{
boolean xChanged = event.has(Attribute.X);
boolean yChanged = event.has(Attribute.Y);
boolean wChanged = event.has(Attribute.WIDTH);
boolean hChanged = event.has(Attribute.HEIGHT);

if ( !xChanged && !yChanged && !wChanged && !hChanged) {
return ;
}

if ( ( xChanged && m_shape.getX() == m_x ) || ( yChanged && m_shape.getY() == m_y )) {
// this can happen when the event batching triggers after a drag has stopped, but the event change was due to the dragging.
// @dean REVIEW
return;
}

capturePositions( m_shape.getX(), m_shape.getY());
updateIndex(xChanged, xChanged || wChanged, xChanged || wChanged,
yChanged, yChanged || hChanged, yChanged || hChanged);
}
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/ait/lienzo/client/core/shape/Shape.java
Expand Up @@ -41,6 +41,7 @@
import com.ait.lienzo.client.core.types.Point2D;
import com.ait.lienzo.client.core.types.RadialGradient;
import com.ait.lienzo.client.core.types.Shadow;
import com.ait.lienzo.client.core.util.EdgeAndCenterIndex;
import com.ait.lienzo.client.widget.DefaultDragConstraintEnforcer;
import com.ait.lienzo.client.widget.DragConstraintEnforcer;
import com.ait.lienzo.shared.core.types.Color;
Expand All @@ -54,6 +55,7 @@
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.ait.lienzo.client.core.util.EdgeAndCenterIndex.EdgeAndCenterIndexHandler;

/**
* Shapes are objects that can be drawn on a canvas.
Expand Down Expand Up @@ -1490,6 +1492,10 @@ public T setDragConstraints(final DragConstraintEnforcer enforcer)
return cast();
}

public EdgeAndCenterIndexHandler getEdgeAndCenterIndexHandler(EdgeAndCenterIndex edgeAndCenterIndex, EdgeAndCenterIndex.AlignmentCallback alignmentCallback) {
throw new UnsupportedOperationException();
}

public static abstract class ShapeFactory<S extends Shape<S>> extends NodeFactory<S>
{
protected ShapeFactory(final ShapeType type)
Expand Down

0 comments on commit 0fc190f

Please sign in to comment.