use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class SelectionManager method drawSelectionShapeForSelection.
private void drawSelectionShapeForSelection() {
if (m_selected.isEmpty()) {
return;
}
if (!m_selected.m_shapes.isEmpty() || (m_selected.m_connectors.size() != m_selected.m_externallyConnected.size())) {
final BoundingBox bbox = m_selected.getBoundingBox();
m_startBoundingBox = new BoundingBox(bbox);
drawSelectionShape(bbox.getX(), bbox.getY(), bbox.getWidth(), bbox.getHeight(), m_layer);
} else {
// There are no shapes and no non-externally connected connectors, so set startBoundingBox to null
// use an initial arbitrary rectangle x,y,w,h the updateRectangleForExternallyConnectedConnectors will correct this, as it'll ignore the existing x,y,w,h
drawSelectionShape(0, 0, 20, 20, m_layer);
}
if (!m_selected.m_externallyConnected.isEmpty()) {
m_selectionDragHandler.updateSelectionShapeForExternallyConnectedConnectors(0, 0, m_startBoundingBox);
}
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class WiresConnector method getMagnetsOnAutoConnection.
/**
* This is making some assumptions that will have to be fixed for anythign other than 8 Magnets at compass ordinal points.
* If there is no shape overlap, and one box is in the corner of the other box, then use nearest corner connections, else use nearest mid connection.
* Else there is overlap. This is now much more difficult, so just pick which every has the the shortest distanceto connections not contained by the other shape.
*/
public WiresMagnet[] getMagnetsOnAutoConnection(final WiresShape headS, final WiresShape tailS) {
final WiresConnection headC = getHeadConnection();
final WiresConnection tailC = getTailConnection();
if (!(headC.isAutoConnection() || tailC.isAutoConnection())) {
// at least one side must be connected with auto connection on
return null;
}
WiresMagnet[] magnets;
final BoundingBox headBox = (headS != null) ? headS.getGroup().getComputedBoundingPoints().getBoundingBox() : null;
final BoundingBox tailBox = (tailS != null) ? tailS.getGroup().getComputedBoundingPoints().getBoundingBox() : null;
if (getLine().getPoint2DArray().size() > 2) {
magnets = getMagnetsWithMidPoint(headC, tailC, headS, tailS, headBox, tailBox);
} else {
if ((headBox != null) && (tailBox != null) && !headBox.intersects(tailBox)) {
magnets = getMagnetsNonOverlappedShapes(headS, tailS, headBox, tailBox);
} else {
magnets = getMagnetsOverlappedShapesOrNoShape(headC, tailC, headS, tailS, headBox, tailBox);
}
}
return magnets;
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class WiresConnector method updateForCenterConnection.
public static void updateForCenterConnection(final WiresConnector connector, final WiresConnection connection, final int pointIndex) {
if ((connection.getMagnet() != null) && (connection.getMagnet().getIndex() == 0)) {
final MultiPath path = connection.getMagnet().getMagnets().getWiresShape().getPath();
final BoundingBox box = path.getBoundingBox();
final Point2D c = Geometry.findCenter(box);
Point2D intersectPoint = Geometry.getPathIntersect(connection, path, c, pointIndex);
if (null == intersectPoint) {
intersectPoint = new Point2D();
}
final Direction d = MagnetManager.getDirection(intersectPoint, box);
final Point2D loc = path.getComputedLocation().copy();
connection.setXOffset(intersectPoint.getX() - c.getX());
connection.setYOffset(intersectPoint.getY() - c.getY());
if (connector.getHeadConnection() == connection) {
connector.getLine().setHeadDirection(d);
} else {
connector.getLine().setTailDirection(d);
}
connection.move(loc.getX() + c.getX(), loc.getY() + c.getY());
}
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class Shape method dofillBoundsForSelection.
protected boolean dofillBoundsForSelection(final Context2D context, final Attributes attr, final double alpha) {
if (attr.isFillBoundsForSelection()) {
if ((alpha * attr.getFillAlpha()) > 0) {
final String color = getColorKey();
if (null != color) {
final BoundingBox bbox = getBoundingBox();
if (null != bbox) {
final double wide = bbox.getWidth();
if (wide > 0) {
final double high = bbox.getHeight();
if (high > 0) {
context.setFillColor(color);
final double offset = getSelectionBoundsOffset();
context.fillRect(bbox.getX() - offset, bbox.getY() - offset, wide + offset, high + offset);
}
}
}
}
}
return true;
}
return false;
}
use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.
the class Sprite method prepare.
@Override
protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) {
if ((null != m_frames) && (null != m_sprite) && (m_index < m_frames.length)) {
final BoundingBox bbox = m_frames[m_index];
if (null != bbox) {
if (false == m_inited) {
m_inited = true;
if (attr.isAutoPlay()) {
play();
}
}
if (context.isSelection()) {
final String color = getColorKey();
if (null != color) {
context.save();
context.setFillColor(color);
context.fillRect(0, 0, bbox.getWidth(), bbox.getHeight());
context.restore();
}
} else {
context.save();
context.setGlobalAlpha(alpha);
context.drawImage(m_sprite, bbox.getX(), bbox.getY(), bbox.getWidth(), bbox.getHeight(), 0, 0, bbox.getWidth(), bbox.getHeight());
context.restore();
}
}
}
return false;
}
Aggregations