Search in sources :

Example 1 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class AbstractGroupItem method computeAbsoluteBoundingBox.

private BoundingBox computeAbsoluteBoundingBox(final double pad) {
    final BoundingBox bb = getBoundingBox().get();
    final Point2D computedLocation = asPrimitive().getComputedLocation();
    return new BoundingBox(computedLocation.getX() - pad, computedLocation.getY() - pad, computedLocation.getX() + bb.getWidth() + pad, computedLocation.getY() + bb.getHeight() + pad);
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 2 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class ButtonGridItemImpl method positionArrow.

private void positionArrow() {
    // Attach the arrow that indicates drop direction, into the button group.
    final BoundingBox buttonbb = this.button.getBoundingBox().get();
    final BoundingBox arrowbb = this.arrow.getBoundingBox();
    final double buttonw = buttonbb.getWidth();
    final double buttonh = buttonbb.getHeight();
    final double arroww = arrowbb.getWidth();
    final double arrowh = arrowbb.getHeight();
    this.arrow.setX(isDropDown() ? (buttonw / 2) - (arroww / 2) : buttonw + arroww).setY(isDropDown() ? buttonh + (arrowh * 2) : (buttonh / 2) + arrowh);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 3 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class Tooltip method refresh.

private void refresh() {
    final boolean isH = isHorizontal(direction);
    // Dimensions for text.
    final BoundingBox textBB = text.getBoundingBox();
    final double tw = textBB.getWidth();
    final double th = textBB.getHeight();
    // Head dimensions.
    final double fontSize = text.getFontSize();
    final double hw = isH ? fontSize / 2 : fontSize;
    final double hl = !isH ? fontSize / 2 : fontSize;
    // Body dimensions.
    final double cbw = (isH ? hl : 0) + tw + (padding * 2);
    final double cbh = (!isH ? hl : 0) + th + (padding * 2);
    final double bw = isH ? cbw : cbh;
    final double bh = isH ? cbh : cbw;
    final double br = 5;
    // Some pre-calculations.
    final double hd = (bh - hw) / 2;
    final double y = -(bh / 2);
    path.clear().M(hl + br, y + 0).L(bw - br, y + 0).A(bw, y + 0, bw, y + br, br).L(bw, y + (bh - br)).A(bw, y + bh, bw - br, y + bh, br).L(hl + br, y + bh).A(hl, y + bh, hl, y + (bh - br), br).L(hl, y + (bh - hd)).L(0, y + (bh / 2)).L(hl, y + hd).L(hl, y + br).A(hl, y + 0, hl + br, y + 0, br).Z();
    // Direction.
    final double tpw = (bw - tw - (padding * 2)) > 0 ? padding : 0;
    final double tph = (bh - th - (padding * 2)) > 0 ? padding : 0;
    final Point2D textLoc = new Point2D();
    switch(direction) {
        case WEST:
            path.setRotationDegrees(180);
            textLoc.setX(-hl - tpw - tw).setY((th / 2) - tph);
            break;
        case NORTH:
            path.setRotationDegrees(270);
            textLoc.setX(-tpw - (tw / 2)).setY(-tph - hl);
            break;
        case SOUTH:
            path.setRotationDegrees(90);
            textLoc.setX(-tpw - (tw / 2)).setY(hl + th + tph);
            break;
        default:
            path.setRotationDegrees(0);
            textLoc.setX(hl + tpw).setY((th / 2) - tph);
    }
    // Location.
    text.setLocation(textLoc);
    group.moveToTop();
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 4 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class AutoGridTest method testUpdateSize.

@Test
public void testUpdateSize() {
    final double size = 2.5;
    final double padding = 0.5;
    final double shapeSize = 100;
    final Direction direction = Direction.SOUTH;
    final BoundingBox boundingBox = new BoundingBox(0d, 0d, shapeSize, shapeSize);
    tested = new AutoGrid.Builder().forBoundingBox(boundingBox).withIconSize(size).withPadding(padding).towards(direction).build();
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getDirection());
    assertEquals(shapeSize, tested.getMaxSize(), 0);
    assertEquals((size + padding) / 2, tested.getMargin(), 0);
    final List<Point2D> expectedPoints = new ArrayList<>();
    final Iterator<Point2D> points = tested.iterator();
    int count = 5;
    for (int i = 0; i < count; i++) {
        final Point2D point = points.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, 0d), expectedPoints.get(0));
    assertEquals(new Point2D(0d, 3d), expectedPoints.get(1));
    assertEquals(new Point2D(0d, 6d), expectedPoints.get(2));
    assertEquals(new Point2D(0d, 9d), expectedPoints.get(3));
    assertEquals(new Point2D(0d, 12d), expectedPoints.get(4));
    tested.setSize(6, 6);
    assertEquals(6, tested.getMaxSize(), 0);
    expectedPoints.clear();
    final Iterator<Point2D> points2 = tested.iterator();
    for (int i = 0; i < count; i++) {
        final Point2D point = points2.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, 0d), expectedPoints.get(0));
    assertEquals(new Point2D(0d, 3d), expectedPoints.get(1));
    assertEquals(new Point2D(3d, 0d), expectedPoints.get(2));
    assertEquals(new Point2D(3d, 3d), expectedPoints.get(3));
    assertEquals(new Point2D(6d, 0d), expectedPoints.get(4));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 5 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class AutoGridTest method testGrid1.

@Test
public void testGrid1() {
    final double size = 10;
    final double padding = 5;
    final Direction direction = Direction.EAST;
    final BoundingBox boundingBox = new BoundingBox(0d, 0d, 100d, 100d);
    tested = new AutoGrid.Builder().forBoundingBox(boundingBox).withIconSize(size).withPadding(padding).towards(direction).build();
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getDirection());
    assertEquals(100, tested.getMaxSize(), 0);
    assertEquals((size + padding) / 2, tested.getMargin(), 0);
    final List<Point2D> expectedPoints = new ArrayList<>();
    final Iterator<Point2D> points = tested.iterator();
    int count = 5;
    for (int i = 0; i < count; i++) {
        final Point2D point = points.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, -15d), expectedPoints.get(0));
    assertEquals(new Point2D(15d, -15d), expectedPoints.get(1));
    assertEquals(new Point2D(30d, -15d), expectedPoints.get(2));
    assertEquals(new Point2D(45d, -15d), expectedPoints.get(3));
    assertEquals(new Point2D(60d, -15d), expectedPoints.get(4));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

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