Search in sources :

Example 61 with BoundingBox

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

the class TextUtils method getBoundingBox.

public static BoundingBox getBoundingBox(final String text, final double size, final String style, final String family, final TextUnit unit, final TextBaseLine baseline, final TextAlign align) {
    if ((null == text) || (text.isEmpty()) || (false == (size > 0))) {
        return new BoundingBox(0, 0, 0, 0);
    }
    final String font = getFontString(size, unit, style, family);
    final String base = font + " " + baseline.getValue();
    NFastDoubleArrayJSO offs = OFFSCACHE.get(base);
    if (null == offs) {
        OFFSCACHE.put(base, offs = getTextOffsets(font, baseline));
    }
    if (null == offs) {
        return new BoundingBox(0, 0, 0, 0);
    }
    FORBOUNDS.getContext().setTextFont(font);
    FORBOUNDS.getContext().setTextAlign(TextAlign.LEFT);
    FORBOUNDS.getContext().setTextBaseline(TextBaseLine.ALPHABETIC);
    final double wide = FORBOUNDS.getContext().measureText(text).getWidth();
    final BoundingBox bbox = new BoundingBox().addY(offs.get(0)).addY(offs.get(1));
    switch(align) {
        case LEFT:
        case START:
            bbox.addX(0).addX(wide);
            break;
        case END:
        case RIGHT:
            bbox.addX(0).addX(0 - wide);
            break;
        case CENTER:
            bbox.addX(wide / 2).addX(0 - (wide / 2));
            break;
    }
    return bbox;
}
Also used : NFastDoubleArrayJSO(com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 62 with BoundingBox

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

the class Layer method draw.

public Layer draw(Context2D context) {
    if (LienzoCore.IS_CANVAS_SUPPORTED) {
        if (isClearLayerBeforeDraw()) {
            clear();
        }
        if (isVisible()) {
            boolean draw = true;
            if (null != m_olbd) {
                draw = m_olbd.onLayerBeforeDraw(this);
            }
            if (draw) {
                Transform transform = null;
                final Viewport viewport = getViewport();
                if ((isTransformable()) && (null != viewport)) {
                    transform = viewport.getTransform();
                }
                context.save();
                if (null != transform) {
                    context.transform(transform);
                }
                final BoundingBox bbox = getStorageBounds();
                IPathClipper vclp = null;
                if (null != viewport) {
                    vclp = viewport.getPathClipper();
                    if ((null != vclp) && (vclp.isActive())) {
                        vclp.clip(context);
                    }
                }
                final IPathClipper lclp = getPathClipper();
                if ((null != lclp) && (lclp.isActive())) {
                    lclp.clip(context);
                }
                drawWithTransforms(context, 1, bbox);
                context.restore();
                if (null != m_olad) {
                    m_olad.onLayerAfterDraw(this);
                }
                final SelectionLayer selection = getSelectionLayer();
                if (null != selection) {
                    selection.clear();
                    context = selection.getContext();
                    context.save();
                    if (null != transform) {
                        context.transform(transform);
                    }
                    if ((null != vclp) && (vclp.isActive())) {
                        vclp.clip(context);
                    }
                    if ((null != lclp) && (lclp.isActive())) {
                        lclp.clip(context);
                    }
                    drawWithTransforms(context, 1, bbox);
                    context.restore();
                }
            }
        }
    }
    return this;
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Transform(com.ait.lienzo.client.core.types.Transform)

Example 63 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() {
    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();
    } 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 64 with BoundingBox

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

the class ToolTip method show.

private ToolTip show(final double x, final double y, final boolean force) {
    m_autoHider = null;
    if ((false == force) && (false == m_show)) {
        return this;
    }
    if (false == m_show) {
        hide();
    }
    m_oldx = x;
    m_oldy = y;
    m_show = false;
    double th = 0;
    double tw = 0;
    double lh = 0;
    double lw = 0;
    final double pd = getPadding();
    if ((null == m_textValue) || (m_textValue.isEmpty())) {
        m_text.setText("").setVisible(false);
    } else {
        m_text.setText(m_textValue).setVisible(true);
        final BoundingBox bb = m_text.getBoundingBox();
        tw = bb.getWidth();
        th = bb.getHeight();
    }
    if ((null == m_lablValue) || (m_lablValue.isEmpty())) {
        m_labl.setText("").setVisible(false);
    } else {
        m_labl.setText(m_lablValue).setVisible(true);
        final BoundingBox bb = m_labl.getBoundingBox();
        lw = bb.getWidth();
        lh = bb.getHeight();
    }
    final double p2 = pd * 2;
    final double rw = Math.max(tw, lw) + p2 + 2;
    final double rh = th + lh + p2 + 4;
    final double w2 = rw / 2;
    final double h2 = rh / 2;
    m_body.setWidth(rw).setHeight(rh).setCornerRadius(5);
    final double tv = getTailValue();
    if (tv > 1) {
        m_tail.setPoints(new Point2D(w2 - tv, rh), new Point2D(w2, rh + tv), new Point2D(w2 + tv, rh)).setVisible(true);
        m_mask.setPoints(new Point2D(w2 - tv - 3, rh - 3), new Point2D(w2, (rh + tv) - 3), new Point2D(w2 + tv + 3, rh - 3)).setVisible(true);
    } else {
        m_tail.setVisible(false);
        m_mask.setVisible(false);
    }
    if (th > 0) {
        m_text.setX(w2);
        if (lh > 0) {
            m_labl.setY(h2 - (th / 2) - 2);
            m_text.setY(h2 + (lh / 2) + 2);
        } else {
            m_text.setY(h2);
        }
    }
    if (lh > 0) {
        m_labl.setX(w2);
        if (th > 0) {
            m_labl.setY(h2 - (th / 2) - 2);
            m_text.setY(h2 + (lh / 2) + 2);
        } else {
            m_labl.setY(h2);
        }
    }
    setX(x - w2);
    setY(y - rh);
    if ((false == force) && (getAutoHideTime() > 0)) {
        m_autoHider = new RepeatingCommand() {

            @Override
            public boolean execute() {
                if ((this == m_autoHider) && (isShowing())) {
                    hide();
                }
                return false;
            }
        };
        Scheduler.get().scheduleFixedDelay(m_autoHider, getAutoHideTime());
    }
    setVisible(true);
    return draw();
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand)

Example 65 with BoundingBox

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

the class AbstractMultiPathPartShape method getBoundingBox.

@Override
public BoundingBox getBoundingBox() {
    NFastArrayList<PathPartList> points = m_points;
    if (getCornerRadius() > 0) {
        points = m_cornerPoints;
    }
    final int size = points.size();
    if (size < 1) {
        return new BoundingBox(0, 0, 0, 0);
    }
    final BoundingBox bbox = new BoundingBox();
    for (int i = 0; i < size; i++) {
        bbox.add(points.get(i).getBoundingBox());
    }
    return bbox;
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) PathPartList(com.ait.lienzo.client.core.types.PathPartList)

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