Package org.joshy.gfx.node

Examples of org.joshy.gfx.node.Bounds


        Bounds finalBounds = calcFinalBounds();
        return Math.max(finalBounds.getWidth()*getScale(),width);
    }

    public double getFullHeight(double width, double height) {
        Bounds finalBounds = calcFinalBounds();
        return Math.max(finalBounds.getHeight()*getScale(),height);
    }
View Full Code Here


    }

    public void drawSelection(GFX g, SNode shape) {
        if(shape == null) return;
        g.setPaint(new FlatColor(1.0,0.5,0.5,0.5));
        Bounds bounds = shape.getTransformedBounds();
        bounds = transformToDrawing(bounds);
        g.setStrokeWidth(3);
        g.drawRect(bounds.getX(),bounds.getY(),bounds.getWidth(),bounds.getHeight());
        g.setStrokeWidth(1);
        g.setPaint(new FlatColor(0.5,0.2,0.2,1.0));
        g.drawRect(bounds.getX(),bounds.getY(),bounds.getWidth(),bounds.getHeight());
    }
View Full Code Here

    public Bounds getMaxExtent() {
        return maxExtent;
    }

    private void recalcMaxExtent() {
        maxExtent = new Bounds(0,0,0,0);
        for(SNode n : document.getCurrentPage().getNodes()) {
            maxExtent = maxExtent.union(n.getTransformedBounds());
        }
    }
View Full Code Here

                    if(h instanceof MouseEventHandle) {
                        ((MouseEventHandle)h).mousePressed(event,cursor);
                    }
                    if(r instanceof SResizeableNode) {
                        SResizeableNode sn = (SResizeableNode) r;
                        resizeStartBounds = new Bounds(sn.getX(),sn.getY(),sn.getWidth(),sn.getHeight());
                        selectedHandle = h;
                        fadeInIndicator();
                        return;
                    }
                    if(r instanceof SArrow) {
                        //SArrow a = (SArrow) r;
                        selectedHandle = h;
                        fadeInIndicator();
                        return;
                    }
                    selectedHandle = h;
                    fadeInIndicator();
                    return;
                }
            }
        }

        //process link button
        for(SNode node : doc.getCurrentPage().getNodes()) {
            if(node.isLink()) {
                Bounds b1 = node.getTransformedBounds();
                Bounds b2 = new Bounds(b1.getX2(),b1.getY2(),30,15);
                if(b2.contains(cursor)) {
                    String target = node.getLinkTarget();
                    context.getDocument().setCurrentPageById(target);
                    context.getSelection().clear();
                    return;
                }
View Full Code Here

        if(!pressed) return;

        // process drag rect
        if(dragRectStartPoint != null) {
            dragRectEndPoint = cursor;
            Bounds dragRectBounds = new Bounds(dragRectStartPoint,dragRectEndPoint);
            tempSelection.clear();
            for(SNode node : context.getDocument().getCurrentPage().getNodes()) {
                if(dragRectBounds.intersects(node.getTransformedBounds())) {
                    if(!tempSelection.contains(node)) {
                        tempSelection.add(node);
                    }
                }
            }
            context.getDocument().setDirty(true);
            context.redraw();
            return;
        }

        // process handle if handle has been selected.
        if(selectedHandle != null) {
            double nx = cursor.getX();
            double ny = cursor.getY();
            SketchDocument doc = context.getDocument();
            if(doc.isSnapGrid()) {
                nx = ((int)(nx/doc.getGridWidth()))*doc.getGridWidth();
                ny = ((int)(ny/doc.getGridHeight()))*doc.getGridHeight();
            }
            if(selectedHandle instanceof MouseEventHandle) {
                ((MouseEventHandle)selectedHandle).mouseDragged(nx, ny, event.isShiftPressed(), cursor);
            } else {
                selectedHandle.setX(nx,event.isShiftPressed());
                selectedHandle.setY(ny,event.isShiftPressed());
                selectedHandle.setXY(nx,ny,event.isShiftPressed());
            }
            context.getDocument().setDirty(true);
            context.redraw();
            return;
        }

        // do nothing if no selection
        if(context.getSelection().isEmpty()) return;

        // move selected nodes 
        moved = true;


        boolean hsnap = false;
        boolean vsnap = false;
        //snap with other nodes first
        if(context.getDocument().isSnapNodeBounds()) {
            for(SNode node : context.getDocument().getCurrentPage().getNodes()) {
                if(!context.getSelection().contains(node)) {
                    if(snapHorizontalBounds(cursor, node.getTransformedBounds())) {
                        hsnap = true;
                    }
                    if(snapVerticalBounds(cursor, node.getTransformedBounds())) {
                        vsnap = true;
                    }
                }
            }
        }

        //snap with doc bounds next if not already snapped
        if(context.getDocument().isSnapDocBounds()) {
            Bounds docBounds = new Bounds(0,0,context.getDocument().getWidth(),context.getDocument().getHeight());
            if(!hsnap) {
                hsnap = snapHorizontalBounds(cursor, docBounds);
            }
            if(!vsnap) {
                vsnap = snapVerticalBounds(cursor,docBounds);
View Full Code Here

            if(!vsnap) r.setTranslateY(ny);       
        }
    }

    private boolean snapHorizontalBounds(Point2D.Double cursor, Bounds doc) {
        Bounds selb = calculateUnSnappedSelectionBounds(cursor);
        double threshold = 15;
        //u.p("selb = " + selb);
        //snap to left side of doc bounds
        if(Math.abs(selb.getX()-doc.getX()) < threshold) {
            for(SNode n : context.getSelection().items()) {
                //bounds.x + offset within the bounds
                Point2D start = starts.get(n);
                //calc where the edge would be with no snapping
                double dx = start.getX() + cursor.getX()-startX;
                dx = dx-selb.getX();
                n.setTranslateX(doc.getX()+dx);
            }
            context.getCanvas().showHSnap(doc.getX());
            return true;
        }

        //snap to right side of doc bounds
        if(Math.abs(selb.getX()+selb.getWidth()-doc.getX2()) < threshold) {
            for(SNode n : context.getSelection().items()) {
                //bounds.x + offset within the bounds
                Point2D start = starts.get(n);
                //calc where the edge would be with no snapping
                double dx = start.getX() + cursor.getX()-startX;
                dx = dx-selb.getX(); //calc x within the bounds of the selection
                n.setTranslateX(doc.getX2()-selb.getWidth()+dx);
            }
            context.getCanvas().showHSnap(doc.getX2());
            return true;
        }

        //snap to center width of target bounds
        if(Math.abs(selb.getCenterX()-doc.getCenterX()) < threshold) {
            for(SNode n : context.getSelection().items()) {
                Point2D start = starts.get(n);
                //calc where the edge would be with no snapping
                double dx = start.getX() + cursor.getX()-startX;
                dx = dx-selb.getX(); // calc x within the bounds of the selection
                n.setTranslateX(doc.getCenterX()-selb.getWidth()/2+dx);
            }
            context.getCanvas().showHSnap(doc.getCenterX());
            return true;
        }
        return false;
View Full Code Here

        }

        private void setBackgroundFill(Paint paint, SketchDocument doc) {
            if(paint instanceof LinearGradientFill) {
                LinearGradientFill grad = (LinearGradientFill) paint;
                grad = resizeTo(grad, new Bounds(0, 0, doc.getWidth(), doc.getHeight()));
                doc.setBackgroundFill(grad);
                return;
            }

            doc.setBackgroundFill(paint);
View Full Code Here

        fireUpdate();
    }

    @Override
    public Bounds getBounds() {
        return new Bounds(
                getX()-getStrokeWidth()/2,
                getY()-getStrokeWidth()/2,
                getWidth()+getStrokeWidth(),
                getHeight()+getStrokeWidth());
    }
View Full Code Here

        }
        return false;
    }

    private boolean snapVerticalPosition(Point2D.Double cursor, double position) {
        Bounds selb = calculateUnSnappedSelectionBounds(cursor);
        double threshold = 15;
        if(Math.abs(selb.getY()-position) < threshold) {
            for(SNode n : context.getSelection().items()) {
                Point2D start = starts.get(n);
                double dy = start.getY() + cursor.getY()-startY;
                dy = dy-selb.getY();
                n.setTranslateY(position+dy);
            }
            context.getCanvas().showVSnap(position);
            return true;
        }
        if(Math.abs(selb.getY()+selb.getHeight()-position) < threshold) {
            for(SNode n : context.getSelection().items()) {
                Point2D start = starts.get(n);
                //calc where the edge would be with no snapping
                double dy = start.getY() + cursor.getY()-startY;
                dy = dy-selb.getY(); // calc y within the bounds of the selection
                n.setTranslateY(position-selb.getHeight()+dy);
            }
            context.getCanvas().showVSnap(position);
            return true;
        }
        return false;
View Full Code Here

        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Bounds getVisualBounds() {
        return new Bounds(
                getTranslateX()
                ,getTranslateY()
                ,Math.max((document.getMaxTileX()+1)*256,1000)*getScale()
                ,Math.max((document.getMaxTileY()+1)*256,1000)*getScale()
        );
View Full Code Here

TOP

Related Classes of org.joshy.gfx.node.Bounds

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.