protected void scaleShape(final S shape, final double width, final double height) { scale(shape, width, height); } }
@Override public void addChild(final T child, final Layout layout) { children.add(child); super.addChild((IPrimitive<?>) child.getContainer(), LienzoShapeUtils.getWiresLayout(layout)); }
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]); }
@Override public T setDragBounds(final Bounds bounds) { ifLocationBoundsConstraintsSupported(() -> LienzoShapeUtils.translateBounds(bounds)); return cast(); }
@SuppressWarnings("unchecked") public T updateFillGradient(final double width, final double height) { if (this.fillGradientType != null && this.fillGradientStartColor != null && this.fillGradientEndColor != null) { final LinearGradient gradient = LienzoShapeUtils.getLinearGradient(fillGradientStartColor, fillGradientEndColor, width, height); getShape().setFillGradient(gradient); } return cast(); }
@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; }
private static void scaleViewIcon(final SVGShapeView<?> view, final Picture picture) { scale(picture, WID_ICON_WIDTH, WID_ICON_HEIGHT); view.refresh(); }
protected void scale(final int width, final int height, final int toWidth, final int toHeight, final boolean keepAspectRatio) { if (null != getHandler() && null != getHandler().getDiagram()) { final double[] sfactor = LienzoShapeUtils.getScaleFactor(width, height, toWidth, toHeight); if (0 != Double.compare(1, sfactor[0]) || 0 != Double.compare(1, sfactor[1])) { final double[] factor = getScaleFactor(sfactor, keepAspectRatio); // Scale the canvas/layer using scale method from the zoom control. getZoomControl().scale(factor[0], factor[1]); // Scale the panel widget - delegated to implementations. scalePanel(toWidth, toHeight); } } else { LOGGER.log(Level.WARNING, "Nothing to scale!"); } }
protected void scaleShape(final Image image, final double width, final double height) { final double iWidth = image.getWidth(); final double iHeight = image.getHeight(); if (width != iWidth || height != iHeight) { scale(image, width, height); } } }
public PictureShapeView(final String uri, final double width, final double height) { super(ShapeViewSupportedEvents.DESKTOP_NO_RESIZE_EVENT_TYPES, new MultiPath() .rect(0, 0, width, height) .setStrokeAlpha(0) .setFillAlpha(0)); this.picture = new Picture(uri, picture -> { scale(picture, width, height); addChild(picture); refresh(); }); super.setResizable(false); }