Search in sources :

Example 76 with BoundingBox

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

the class WiresScalableContainer method scaleTo.

public void scaleTo(final double x, final double y, final double width, final double height) {
    if (scaleRequired) {
        if (null != transformableContainer) {
            transformableContainer.setX(x).setY(y);
            if (null == scaleRatio) {
                final BoundingBox bb = transformableContainer.getBoundingBox();
                final double sx = width / bb.getWidth();
                final double sy = height / bb.getHeight();
                scaleRatio = new Point2D(sx, sy);
                transformableContainer.setScale(scaleRatio);
            }
        }
        for (int i = 0; i < scalableChildren.size(); i++) {
            final IPrimitive<?> child = scalableChildren.get(i);
            scaleChildTo(child, x, y, width, height);
        }
        scaleRequired = false;
    }
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) WiresLayoutContainerNoTextBoundingBox(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.ext.WiresLayoutContainerNoTextBoundingBox) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 77 with BoundingBox

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

the class LienzoShapeUtils method scale.

public static void scale(final Shape shape, final double width, final double height) {
    final BoundingBox bb = shape.getBoundingBox();
    final double[] scale = getScaleFactor(bb.getWidth(), bb.getHeight(), width, height);
    shape.setScale(scale[0], scale[1]);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 78 with BoundingBox

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

the class LienzoShapeGlyphRenderer method render.

@Override
@SuppressWarnings("unchecked")
public Group render(final ShapeGlyph glyph, final double width, final double height) {
    final String definitionId = glyph.getDefinitionId();
    final Supplier<ShapeFactory> factorySupplier = glyph.getFactorySupplier();
    final Shape shape = factorySupplier.get().newShape(factoryManager.newDefinition(definitionId));
    final ShapeView<?> view = shape.getShapeView();
    final BoundingBox bb = boundingBoxProvider.apply(view);
    Group group = groupProvider.apply(view);
    if (null == group) {
        throw new RuntimeException("Shape view [" + view.toString() + "] not supported for " + "this shape glyph builder [" + this.getClass().getName());
    }
    if (view instanceof HasTitle) {
        final HasTitle hasTitle = (HasTitle) view;
        hasTitle.setTitle(null);
    }
    // Create a copy of this view.
    group = group.copy();
    // Scale, if necessary, to the given glyph size.
    final double[] scale = LienzoShapeUtils.getScaleFactor(bb.getWidth(), bb.getHeight(), width, height);
    group.setScale(scale[0], scale[1]);
    return group;
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) HasTitle(org.kie.workbench.common.stunner.core.client.shape.view.HasTitle) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory)

Example 79 with BoundingBox

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

the class CustomTaskShapeViewHandlerTest method checkIconLoad.

private void checkIconLoad(final String IconData) {
    when(imageProxy.isLoaded()).thenReturn(true);
    when(icon.getBoundingBox()).thenReturn(new BoundingBox(0d, 0d, CustomTaskShapeViewHandler.WID_ICON_WIDTH * 2, CustomTaskShapeViewHandler.WID_ICON_HEIGHT * 2));
    tested.handle(task, view);
    ArgumentCaptor<ImageShapeLoadedHandler> loadedHandlerArgumentCaptor = ArgumentCaptor.forClass(ImageShapeLoadedHandler.class);
    verify(imageProxy, times(1)).setImageShapeLoadedHandler(loadedHandlerArgumentCaptor.capture());
    verify(imageProxy, times(1)).load(eq(IconData));
    ImageShapeLoadedHandler loadedHandler = loadedHandlerArgumentCaptor.getValue();
    loadedHandler.onImageShapeLoaded(icon);
    verify(icon, times(1)).setScale(eq(0.5d), eq(0.5d));
    verify(width, times(1)).setValue(WIDTH);
    verify(height, times(1)).setValue(HEIGHT);
    verify(view, never()).refresh();
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ImageShapeLoadedHandler(com.ait.lienzo.client.core.image.ImageShapeLoadedHandler)

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