Search in sources :

Example 71 with BoundingBox

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

the class ConnectorGlyphLienzoRenderer method scaleTo.

private void scaleTo(final Group group, final double width, final double height) {
    final BoundingBox bb = group.getBoundingBox();
    final double w = bb.getWidth();
    final double h = bb.getHeight();
    final double sw = w > 0 ? (width / w) : 1;
    final double sh = h > 0 ? (height / h) : 1;
    group.setScale(sw, sh);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 72 with BoundingBox

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

the class LienzoMultipleSelectionControlTest method testOnShapeLocationsChanged.

@Test
public void testOnShapeLocationsChanged() {
    // Different canvas
    when(shapeLocationsChangedEvent.getCanvasHandler()).thenReturn(mock(CanvasHandler.class));
    tested.onShapeLocationsChanged(shapeLocationsChangedEvent);
    verify(selectedItems, never()).rebuildBoundingBox();
    verify(selectionManager, never()).drawSelectionShape(eq(MIN_WIDTH), eq(MIN_HEIGHT), eq(MAX_WIDTH), eq(MAX_HEIGHT), eq(overLayer));
    // Same canvas no selectedItems
    when(shapeLocationsChangedEvent.getCanvasHandler()).thenReturn(canvasHandler);
    when(shapeLocationsChangedEvent.getUuids()).thenReturn(new ArrayList<>());
    tested.onShapeLocationsChanged(shapeLocationsChangedEvent);
    verify(selectedItems, never()).rebuildBoundingBox();
    verify(selectionManager, never()).drawSelectionShape(eq(MIN_WIDTH), eq(MIN_HEIGHT), eq(MAX_WIDTH), eq(MAX_HEIGHT), eq(overLayer));
    // Same canvas with selected items
    when(shapeLocationsChangedEvent.getCanvasHandler()).thenReturn(canvasHandler);
    List<String> selectedUUIds = new ArrayList<>();
    selectedUUIds.add("ELEMENT");
    when(shapeLocationsChangedEvent.getUuids()).thenReturn(selectedUUIds);
    when(tested.getSelectedItems()).thenReturn(selectedUUIds);
    when(delegateShapeProvider.getShape()).thenReturn(mock(com.ait.lienzo.client.core.shape.Shape.class));
    when(selectionManager.getSelectedItems()).thenReturn(selectedItems);
    when(selectedItems.getBoundingBox()).thenReturn(new BoundingBox(MIN_WIDTH, MIN_HEIGHT, MAX_WIDTH, MAX_HEIGHT));
    when(shapeLocationsChangedEvent.getCanvasHandler()).thenReturn(canvasHandler);
    tested.onShapeLocationsChanged(shapeLocationsChangedEvent);
    verify(selectedItems, times(1)).rebuildBoundingBox();
    verify(selectionManager, times(1)).drawSelectionShapeForSelection();
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 73 with BoundingBox

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

the class EmptyStateLayer method updateCaption.

private void updateCaption() {
    BoundingBox captionBB = this.caption.getWrapper().getBoundingBox();
    double captionCenterX = captionBB.getWidth() / 2d;
    double captionCenterY = captionBB.getHeight() / 2d;
    double centerX = getWidth() / 2d;
    double centerY = getHeight() / 2d;
    caption.setX(centerX - captionCenterX);
    caption.setY(centerY + captionCenterY);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 74 with BoundingBox

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

the class EmptyStateLayer method updateMessage.

private void updateMessage() {
    BoundingBox captionBB = caption.getBoundingBox();
    double captionCenterY = captionBB.getHeight() / 2d;
    BoundingBox messageBB = message.getBoundingBox();
    double messageCenterX = messageBB.getWidth() / 2d;
    double centerX = getWidth() / 2d;
    double centerY = getHeight() / 2d;
    message.setX(centerX - messageCenterX);
    message.setY(centerY + captionCenterY + 25 + messageBB.getHeight());
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 75 with BoundingBox

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

the class LienzoLayerUtils method layerToDataURL.

public static String layerToDataURL(final LienzoLayer lienzoLayer, final DataURLType dataURLType, final int x, final int y, final int width, final int height, final String bgColor) {
    final com.ait.lienzo.client.core.shape.Layer layer = lienzoLayer.getLienzoLayer();
    final ScratchPad scratchPad = layer.getScratchPad();
    scratchPad.setPixelSize(width, height);
    if (null != bgColor) {
        scratchPad.getContext().setFillColor(bgColor);
        scratchPad.getContext().fillRect(0, 0, width, height);
    }
    layer.drawWithTransforms(scratchPad.getContext(), 1, new BoundingBox(x, y, width, height));
    final String data = scratchPad.toDataURL(dataURLType, 1);
    scratchPad.clear();
    return data;
}
Also used : ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

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