Search in sources :

Example 26 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.

the class Sprite method getBoundingBox.

@Override
public BoundingBox getBoundingBox() {
    double wide = 0;
    double high = 0;
    for (final BoundingBox bbox : m_frames) {
        wide = Math.max(wide, bbox.getWidth());
        high = Math.max(high, bbox.getHeight());
    }
    return new BoundingBox(0, 0, wide, high);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 27 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.

the class TextBoundsAndLineBreaksWrap method drawString.

@Override
public void drawString(final Context2D context, final Attributes attr, final IDrawString drawCommand) {
    final BoundingBox wrapBoundaries = getWrapBoundaries();
    final String[] textLines = attr.getText().split("\\r?\\n");
    if (textLines.length < 1) {
        return;
    }
    final ArrayList<String> lines = new ArrayList<>();
    for (final String line : textLines) {
        final String[] words = line.split("\\s");
        if (words.length < 1) {
            lines.add("");
            continue;
        }
        final StringBuilder nextLine = new StringBuilder(words[0]);
        for (int i = 1; i < words.length; i++) {
            if (getBoundingBoxForString(nextLine + " " + words[i]).getWidth() <= wrapBoundaries.getWidth()) {
                nextLine.append(" ").append(words[i]);
            } else {
                lines.add(nextLine.toString());
                nextLine.setLength(words[i].length());
                nextLine.replace(0, words[i].length(), words[i]);
            }
        }
        lines.add(nextLine.toString());
    }
    double xOffset = 0;
    switch(textAlignSupplier.get()) {
        case START:
        case LEFT:
            xOffset = 0;
            break;
        case CENTER:
            xOffset = wrapBoundaries.getWidth() / 2;
            break;
        case END:
        case RIGHT:
            xOffset = wrapBoundaries.getWidth();
            break;
    }
    final double yOffset = 0.8;
    for (int i = 0; i < lines.size(); i++) {
        String line = lines.get(i);
        final int toPad = (int) Math.round((wrapBoundaries.getWidth() - getBoundingBoxForString(line).getWidth()) / getBoundingBoxForString(" ").getWidth());
        line = TextUtils.padString(line, line.length() + toPad, ' ', textAlignSupplier.get());
        drawCommand.draw(context, line, xOffset, i + yOffset);
    }
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList)

Example 28 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.

the class Scene method toDataURL.

public final String toDataURL(final DataURLType mimetype) {
    if (LienzoCore.IS_CANVAS_SUPPORTED) {
        final ScratchPad scratch = new ScratchPad(getWidth(), getHeight());
        final Context2D context = scratch.getContext();
        final NFastArrayList<Layer> layers = getChildNodes();
        BoundingBox bbox = getStorageBounds();
        if (null == bbox) {
            final Viewport viewport = getViewport();
            if (null != viewport) {
                bbox = viewport.getStorageBounds();
            }
        }
        if (null != layers) {
            final int size = layers.size();
            final IPathClipper clip = getPathClipper();
            if ((null != clip) && (clip.isActive())) {
                context.save();
                clip.clip(context);
            }
            for (int i = size - 1; i >= 0; i--) {
                final Layer layer = layers.get(i);
                if ((null != layer) && (layer.isVisible())) {
                    layer.drawWithTransforms(context, 1, bbox);
                }
            }
            if ((null != clip) && (clip.isActive())) {
                context.restore();
            }
        }
        return scratch.toDataURL(mimetype, 1.0);
    } else {
        return "data:,";
    }
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 29 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.

the class Scene method toDataURL.

// package protected
final String toDataURL(final DataURLType mimetype, final Layer background) {
    if (LienzoCore.IS_CANVAS_SUPPORTED) {
        final ScratchPad scratch = new ScratchPad(getWidth(), getHeight());
        final Context2D context = scratch.getContext();
        final NFastArrayList<Layer> layers = getChildNodes();
        BoundingBox bbox = getStorageBounds();
        if (null == bbox) {
            final Viewport viewport = getViewport();
            if (null != viewport) {
                bbox = viewport.getStorageBounds();
            }
        }
        if (null != layers) {
            final int size = layers.size();
            if (null != background) {
                background.drawWithTransforms(context, 1, bbox);
            }
            final IPathClipper clip = getPathClipper();
            if ((null != clip) && (clip.isActive())) {
                context.save();
                clip.clip(context);
            }
            for (int i = size - 1; i >= 0; i--) {
                final Layer layer = layers.get(i);
                if ((null != layer) && (layer.isVisible())) {
                    layer.drawWithTransforms(context, 1, bbox);
                }
            }
            if ((null != clip) && (clip.isActive())) {
                context.restore();
            }
        }
        return scratch.toDataURL(mimetype, 1.0);
    } else {
        return "data:,";
    }
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 30 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project lienzo-core by ahome-it.

the class Scene method toDataURL.

// package protected
final String toDataURL(final Layer background) {
    if (LienzoCore.IS_CANVAS_SUPPORTED) {
        final ScratchPad scratch = new ScratchPad(getWidth(), getHeight());
        final Context2D context = scratch.getContext();
        final NFastArrayList<Layer> layers = getChildNodes();
        BoundingBox bbox = getStorageBounds();
        if (null == bbox) {
            final Viewport viewport = getViewport();
            if (null != viewport) {
                bbox = viewport.getStorageBounds();
            }
        }
        if (null != layers) {
            final int size = layers.size();
            if (null != background) {
                background.drawWithTransforms(context, 1, bbox);
            }
            final IPathClipper clip = getPathClipper();
            if ((null != clip) && (clip.isActive())) {
                context.save();
                clip.clip(context);
            }
            for (int i = size - 1; i >= 0; i--) {
                final Layer layer = layers.get(i);
                if ((null != layer) && (layer.isVisible())) {
                    layer.drawWithTransforms(context, 1, bbox);
                }
            }
            if ((null != clip) && (clip.isActive())) {
                context.restore();
            }
        }
        return scratch.toDataURL();
    } else {
        return "data:,";
    }
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) 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