use of com.ait.lienzo.client.core.types.DashArray in project kie-wb-common by kiegroup.
the class AssociationView method createLine.
private static Object[] createLine(final double x1, final double y1, final double x2, final double y2) {
final MultiPath head = new MultiPath();
final MultiPath tail = new MultiPath();
final DirectionalLine line = new DirectionalLine(x1, y1, x2, y2);
line.setDashArray(new DashArray(2, 6));
line.setDraggable(true);
line.setSelectionStrokeOffset(SELECTION_OFFSET);
line.setHeadOffset(head.getBoundingBox().getHeight());
line.setTailOffset(tail.getBoundingBox().getHeight());
final MultiPathDecorator headDecorator = new MultiPathDecorator(head);
final MultiPathDecorator tailDecorator = new MultiPathDecorator(tail);
return new Object[] { line, headDecorator, tailDecorator };
}
use of com.ait.lienzo.client.core.types.DashArray in project kie-wb-common by kiegroup.
the class KnowledgeRequirementView method createLine.
private static Object[] createLine(final double x1, final double y1, final double x2, final double y2) {
final MultiPath head = new MultiPath();
final MultiPath tail = new MultiPath().M(0, DECORATOR_HEIGHT).L(DECORATOR_WIDTH / 2, 0).L(DECORATOR_WIDTH, DECORATOR_HEIGHT).setFillColor(ColorName.BLACK).setFillAlpha(1);
final DirectionalLine line = new DirectionalLine(x1, y1, x2, y2);
line.setDashArray(new DashArray(4, 4));
line.setDraggable(true);
line.setSelectionStrokeOffset(SELECTION_OFFSET);
line.setHeadOffset(head.getBoundingBox().getHeight());
line.setTailOffset(tail.getBoundingBox().getHeight());
final MultiPathDecorator headDecorator = new MultiPathDecorator(head);
final MultiPathDecorator tailDecorator = new MultiPathDecorator(tail);
return new Object[] { line, headDecorator, tailDecorator };
}
use of com.ait.lienzo.client.core.types.DashArray in project lienzo-core by ahome-it.
the class Line method prepare.
/**
* Draws this line
*
* @param context
*/
@Override
protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) {
final Point2DArray list = attr.getPoints();
if ((null != list) && (list.size() == 2)) {
if (attr.isDefined(Attribute.DASH_ARRAY)) {
if (false == LienzoCore.get().isNativeLineDashSupported()) {
final DashArray dash = attr.getDashArray();
if (dash != null) {
final double[] data = dash.getNormalizedArray();
if (data.length > 0) {
if (setStrokeParams(context, attr, alpha, false)) {
final Point2D p0 = list.get(0);
final Point2D p1 = list.get(1);
context.beginPath();
drawDashedLine(context, p0.getX(), p0.getY(), p1.getX(), p1.getY(), data, attr.getStrokeWidth() / 2);
context.restore();
}
return true;
}
}
}
}
context.beginPath();
final Point2D p0 = list.get(0);
context.moveTo(p0.getX(), p0.getY());
final Point2D p1 = list.get(1);
context.lineTo(p1.getX(), p1.getY());
return true;
}
return false;
}
use of com.ait.lienzo.client.core.types.DashArray in project lienzo-core by ahome-it.
the class Shape method setStrokeParams.
/**
* Sets the Shape Stroke parameters.
*
* @param context
* @param attr
* @return boolean
*/
protected boolean setStrokeParams(final Context2D context, final Attributes attr, double alpha, final boolean filled) {
double width = attr.getStrokeWidth();
String color = attr.getStrokeColor();
if (null == color) {
if (width > 0) {
color = LienzoCore.get().getDefaultStrokeColor();
}
} else if (width <= 0) {
width = LienzoCore.get().getDefaultStrokeWidth();
}
if ((null == color) && (width <= 0)) {
if (filled) {
return false;
}
color = LienzoCore.get().getDefaultStrokeColor();
width = LienzoCore.get().getDefaultStrokeWidth();
}
alpha = alpha * attr.getStrokeAlpha();
if (alpha <= 0) {
return false;
}
double offset = 0;
if (context.isSelection()) {
color = getColorKey();
if (null == color) {
return false;
}
context.save();
offset = getSelectionStrokeOffset();
} else {
context.save();
context.setGlobalAlpha(alpha);
}
context.setStrokeColor(color);
context.setStrokeWidth(width + offset);
if (false == attr.hasExtraStrokeAttributes()) {
return true;
}
boolean isdashed = false;
if (attr.isDefined(Attribute.DASH_ARRAY)) {
if (LienzoCore.get().isLineDashSupported()) {
final DashArray dash = attr.getDashArray();
if ((null != dash) && (dash.size() > 0)) {
context.setLineDash(dash);
if (attr.isDefined(Attribute.DASH_OFFSET)) {
context.setLineDashOffset(attr.getDashOffset());
}
isdashed = true;
}
}
}
if ((isdashed) || (doStrokeExtraProperties())) {
if (attr.isDefined(Attribute.LINE_JOIN)) {
context.setLineJoin(attr.getLineJoin());
}
if (attr.isDefined(Attribute.LINE_CAP)) {
context.setLineCap(attr.getLineCap());
}
if (attr.isDefined(Attribute.MITER_LIMIT)) {
context.setMiterLimit(attr.getMiterLimit());
}
}
return true;
}
use of com.ait.lienzo.client.core.types.DashArray in project lienzo-core by ahome-it.
the class GridLayer method drawWithoutTransforms.
@Override
protected void drawWithoutTransforms(final Context2D context, final double alpha, final BoundingBox bounds) {
if (false == isVisible()) {
return;
}
final Viewport vp = getViewport();
final int vw = vp.getWidth();
final int vh = vp.getHeight();
final Point2D a = new Point2D(0, 0);
final Point2D b = new Point2D(vw, vh);
double scaleX = 1, scaleY = 1;
Transform t = isTransformable() ? vp.getTransform() : null;
if (t != null) {
scaleX = t.getScaleX();
scaleY = t.getScaleY();
t = t.getInverse();
t.transform(a, a);
t.transform(b, b);
}
final double x1 = a.getX();
final double y1 = a.getY();
final double x2 = b.getX();
final double y2 = b.getY();
for (int direction = X; direction <= Y; direction++) {
final boolean vertical = (direction == X);
final double scale = vertical ? scaleX : scaleY;
final double min = vertical ? x1 : y1;
final double max = vertical ? x2 : y2;
for (int primSec = 0; primSec <= 1; primSec++) {
final int index = (primSec * 2) + direction;
final boolean isSecondary = (primSec == 1);
if (m_lines[index] == null) {
continue;
}
int n = 0;
if (isSecondary) {
// n = primarySize div secondary
// ASSUMPTION: primarySize is a multiple of secondarySize
n = (int) Math.round(m_sizes[direction] / m_sizes[index]);
}
final Line line = m_lines[index];
final double size = m_sizes[index];
final double previousLineWidth = line.getStrokeWidth();
line.setStrokeWidth(previousLineWidth / scale);
final DashArray previousDashes = line.getDashArray();
if (previousDashes != null) {
final double[] d = previousDashes.getNormalizedArray();
final DashArray dashes = new DashArray();
for (final double element : d) {
dashes.push(element / scale);
}
line.setDashArray(dashes);
}
long n1 = Math.round(min / size);
if ((n1 * size) < min) {
n1++;
}
long n2 = Math.round(max / size);
if ((n2 * size) > max) {
n2--;
}
final Point2DArray points = line.getPoints();
final Point2D p1 = points.get(0);
final Point2D p2 = points.get(1);
if (vertical) {
p1.setY(y1);
p2.setY(y2);
} else {
p1.setX(x1);
p2.setX(x2);
}
for (long ni = n1; ni <= n2; ni++) {
if (// skip primary lines
isSecondary && ((ni % n) == 0)) {
continue;
}
if (vertical) {
final double x = ni * size;
p1.setX(x);
p2.setX(x);
} else {
final double y = ni * size;
p1.setY(y);
p2.setY(y);
}
line.drawWithTransforms(context, alpha, bounds);
}
// restore stroke width
line.setStrokeWidth(previousLineWidth);
if (previousDashes != null) {
line.setDashArray(previousDashes);
}
}
}
// Draw children (if any)
super.drawWithoutTransforms(context, alpha, bounds);
}
Aggregations