@Override public void onStart( final IAnimation iAnimation, final IAnimationHandle iAnimationHandle ) { //Reposition nodes. First we store the WiresBaseTreeNode together with its current position and target position transformations.clear(); for ( Map.Entry<WiresBaseShape, Point2D> e : layout.entrySet() ) { final Point2D origin = e.getKey().getLocation(); final Point2D destination = e.getValue(); transformations.put( e.getKey(), new Pair<Point2D, Point2D>( origin, destination ) ); } WiresLayoutUtilities.resizeViewPort( canvasBounds, canvasLayer.getViewport() ); }
boolean clear = isClearLayerBeforeDraw(); clear(); if (isVisible()) Context2D context = getContext(); if (isTransformable()) transform = getViewport().getTransform(); drawWithTransforms(context); if (isListening()) SelectionLayer selection = getSelectionLayer(); drawWithTransforms(context);
@Override public void execute(double time) { final FastArrayList<Layer> list = m_layers; m_layers = new FastArrayList<Layer>(); final int leng = list.length(); for (int i = 0; i < leng; i++) { list.get(i).draw(); } } };
public void onDragPreviewHandler( @Observes ShapeDragPreviewEvent shapeDragPreviewEvent ) { //We can only connect WiresTreeNodes to each other if ( !( shapeDragPreviewEvent.getShape() instanceof WiresBaseTreeNode ) ) { dropContext.setContext( null ); return; } //Find a Parent Node to attach the Shape to final double cx = getX( shapeDragPreviewEvent.getX() ); final double cy = getY( shapeDragPreviewEvent.getY() ); final WiresBaseTreeNode child = (WiresBaseTreeNode) shapeDragPreviewEvent.getShape(); final WiresBaseTreeNode prospectiveParent = getParentNode( child, cx, cy ); //If there is a prospective parent show the line between child and parent if ( prospectiveParent != null ) { if ( connector == null ) { connector = new WiresTreeNodeConnector(); canvasLayer.add( connector ); connector.moveToBottom(); } connector.getPoints().getPoint( 0 ).set( prospectiveParent.getLocation() ); connector.getPoints().getPoint( 1 ).set( new Point2D( cx, cy ) ); } else if ( connector != null ) { canvasLayer.remove( connector ); connector = null; } dropContext.setContext( prospectiveParent ); canvasLayer.draw(); }
@Override public void onClose( final IAnimation iAnimation, final IAnimationHandle iAnimationHandle ) { for ( Group ctrl : controls ) { WiresBaseShape.this.getLayer().remove( ctrl ); } } } );
/** * Adds a {@link Layer} to the Scene. * A draw will be invoked after the layer is added. */ @Override public void add(Layer layer) { if ((null != layer) && (LienzoGlobals.getInstance().isCanvasSupported())) { CanvasElement element = layer.getCanvasElement(); layer.setPixelSize(m_wide, m_high); element.getStyle().setPosition(Position.ABSOLUTE); element.getStyle().setDisplay(Display.INLINE_BLOCK); getElement().appendChild(element); super.add(layer); layer.draw(); } }
@Override public void onStart( final IAnimation iAnimation, final IAnimationHandle iAnimationHandle ) { //Store required transformations: Control, Current location, Target location transformations.clear(); for ( int index = 0; index < controls.size(); index++ ) { final Group ctrl = controls.get( index ); final Point2D origin = new Point2D( 0, 0 ); final Point2D target = getControlTarget( ctrl ); transformations.put( ctrl, new Pair<Point2D, Point2D>( origin, target ) ); WiresBaseShape.this.getLayer().add( ctrl ); ctrl.setOffset( WiresBaseShape.this.getLocation() ); ctrl.setLocation( origin ); ctrl.setAlpha( 0.0 ); } }
private final void doDragMove(INodeXYEvent event) { m_dragContext.dragUpdate(event); if (m_dragging_dispatch_move) { m_dragnode.fireEvent(new NodeDragMoveEvent(m_dragContext)); } // Draw after processing the drag move event // First the graphics on the drag layer m_lienzo.getDragLayer().draw(); // ... then the node that is being moved m_dragContext.drawNode(m_lienzo.getDragLayer().getContext()); }
private final void doDragCancel(INodeXYEvent event) { if (m_dragging) { doDragMove(event); m_lienzo.setCursor(Cursor.DEFAULT); m_dragnode.setVisible(true); m_dragContext.dragDone(); m_dragnode.getLayer().draw(); m_lienzo.getDragLayer().clear(); m_dragnode.fireEvent(new NodeDragEndEvent(m_dragContext)); m_dragnode = null; m_dragging = false; m_dragging_dispatch_move = false; m_dragging_using_touches = false; } }
final String toDataURL(Layer background) { if (LienzoGlobals.getInstance().isCanvasSupported()) { ScratchCanvas scratch = new ScratchCanvas(m_wide, m_high); FastArrayList<Layer> layers = getChildNodes(); if (null != layers) { final int size = layers.length(); if (null != background) { background.drawWithTransforms(scratch.getContext()); } for (int i = size - 1; i >= 0; i--) { Layer layer = layers.get(i); if ((null != layer) && (layer.isVisible())) { layer.drawWithTransforms(scratch.getContext()); } } } return scratch.toDataURL(); } else { return "data:,"; } }
/** * Detaches this Shape from the Layers Color Map */ @Override public void detachFromLayerColorMap() { Layer layer = getLayer(); if (null != layer) { layer.detachShapeFromColorMap(this); } }
/** * Attaches this Shape to the Layers Color Map */ @Override public void attachToLayerColorMap() { Layer layer = getLayer(); if (null != layer) { layer.attachShapeToColorMap(this); } }
@Override public Layer create(JSONObject node, ValidationContext ctx) throws ValidationException { Layer g = new Layer(node); JSONDeserializer.getInstance().deserializeChildren(g, node, this, ctx); return g; }
@Override public void onNodeDragMove( final NodeDragMoveEvent nodeDragMoveEvent ) { updateMagnetOffsets(); updateControlPointOffsets(); getLayer().draw(); } } );
@Override public void onClose( final IAnimation iAnimation, final IAnimationHandle iAnimationHandle ) { isControlsVisible = !controls.isEmpty(); for ( Group ctrl : controlsToRemove ) { WiresBaseShape.this.getLayer().remove( ctrl ); } } } );
ctrl.setAlpha( 0.0 ); ctrl.setOffset( WiresBaseShape.this.getLocation() ); WiresBaseShape.this.getLayer().add( ctrl );
final String toDataURL(DataURLType mimetype, Layer background) { if (LienzoGlobals.getInstance().isCanvasSupported()) { ScratchCanvas scratch = new ScratchCanvas(m_wide, m_high); FastArrayList<Layer> layers = getChildNodes(); if (null != layers) { final int size = layers.length(); if (null != background) { background.drawWithTransforms(scratch.getContext()); } for (int i = size - 1; i >= 0; i--) { Layer layer = layers.get(i); if ((null != layer) && (layer.isVisible())) { layer.drawWithTransforms(scratch.getContext()); } } } return scratch.toDataURL(mimetype); } else { return "data:,"; } }