Search in sources :

Example 21 with BoundingBox

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);
    }
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 22 with BoundingBox

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;
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 23 with BoundingBox

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());
    }
}
Also used : MultiPath(com.ait.lienzo.client.core.shape.MultiPath) Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Direction(com.ait.lienzo.shared.core.types.Direction)

Example 24 with BoundingBox

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;
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) JSONString(com.google.gwt.json.client.JSONString)

Example 25 with BoundingBox

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;
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) JSONString(com.google.gwt.json.client.JSONString)

Aggregations

BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)79 Point2D (com.ait.lienzo.client.core.types.Point2D)24 Test (org.junit.Test)16 ScratchPad (com.ait.lienzo.client.core.util.ScratchPad)8 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)7 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)7 Context2D (com.ait.lienzo.client.core.Context2D)6 ArrayList (java.util.ArrayList)6 Direction (com.ait.lienzo.shared.core.types.Direction)5 Group (com.ait.lienzo.client.core.shape.Group)4 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)4 Text (com.ait.lienzo.client.core.shape.Text)3 Transform (com.ait.lienzo.client.core.types.Transform)3 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)3 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)3 MultiPathDecorator (com.ait.lienzo.client.core.shape.MultiPathDecorator)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)2 WiresConnector (com.ait.lienzo.client.core.shape.wires.WiresConnector)2 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)2 BoundingPoints (com.ait.lienzo.client.core.types.BoundingPoints)2