Package org.joshy.gfx.node

Examples of org.joshy.gfx.node.Bounds


        );
    }

    @Override
    public Bounds getInputBounds() {
        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


        return selection;
    }


    private Bounds calcFinalBounds() {
        Bounds maxExtent = getMaxExtent();
        //u.p("max = " + maxExtent);
        //Bounds docbounds = new Bounds(0,0,document.getWidth(),document.getHeight());
        //Bounds finalBounds = maxExtent.union(docbounds);
        Bounds finalBounds = maxExtent;

        double extra = 500;
        finalBounds = new Bounds(
                finalBounds.getX()-extra,
                finalBounds.getY()-extra,
                finalBounds.getWidth()+extra*2,
                finalBounds.getHeight()+extra*2
        );

        offsetX = finalBounds.getX()*getScale();
        offsetY = finalBounds.getY()*getScale();
        double nvx = -(offsetX+panX);
        double nvy = -(offsetY+panY);
        scrollPane.getHorizontalScrollBar().setValue(nvx);
        scrollPane.getVerticalScrollBar().setValue(nvy);
        return finalBounds;
View Full Code Here

            return super.duplicate(dupe);
        }

        @Override
        public Bounds getBounds() {
            return new Bounds(x,y,width,height);
        }
View Full Code Here

        }
        return false;
    }

    private boolean snapHorizontalPosition(Point2D.Double cursor, double position) {
        Bounds selb = calculateUnSnappedSelectionBounds(cursor);
        double threshold = 15;
        if(Math.abs(selb.getX()-position) < threshold) {
            for(SNode n : context.getSelection().items()) {
                Point2D start = starts.get(n);
                double dx = start.getX() + cursor.getX()-startX;
                dx = dx-selb.getX();
                n.setTranslateX(position+dx);
            }
            context.getCanvas().showHSnap(position);
            return true;
        }
        if(Math.abs(selb.getX()+selb.getWidth()-position) < 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(position-selb.getWidth()+dx);
            }
            context.getCanvas().showHSnap(position);
            return true;
        }
View Full Code Here

        scrollPane.getVerticalScrollBar().setValue(nvy);
        return finalBounds;
    }

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

        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 Bounds getMaxExtent() {
        int width = Math.max((document.getMaxTileX()+1)*256,1000);
        int height = Math.max((document.getMaxTileY()+1)*256,1000);
        return new Bounds(0,0,width, height);
    }
View Full Code Here

        return shape.getBounds();
    }

    @Override
    public Bounds getTransformedBounds() {
        Bounds b =  shape.getTransformedBounds();
        return new Bounds(b.getX()+getTranslateX(),b.getY()+getTranslateY(),b.getWidth(),b.getHeight());
    }
View Full Code Here

        return false;
    }

    private boolean snapVerticalBounds(Point2D.Double cursor, Bounds doc) {
        Bounds selb = calculateUnSnappedSelectionBounds(cursor);
        double threshold = 15;
        //u.p("selb = " + selb);
        //snap to top of doc bounds
        if(Math.abs(selb.getY()-doc.getY()) < 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();
                n.setTranslateY(doc.getY()+dy);
            }
            context.getCanvas().showVSnap(doc.getY());
            return true;
        }

        //snap to bottom of target bounds
        if(Math.abs(selb.getY()+selb.getHeight()-doc.getY2()) < 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(doc.getY2()-selb.getHeight()+dy);
            }
            context.getCanvas().showVSnap(doc.getY2());
            return true;
        }

        //snap to center height of target bounds
        if(Math.abs(selb.getCenterY()-doc.getCenterY()) < 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(doc.getCenterY()-selb.getHeight()/2+dy);
            }
            context.getCanvas().showVSnap(doc.getCenterY());
            return true;
        }
View Full Code Here

        listView.setRenderer(new ListView.ItemRenderer<SNode>(){
            public void draw(GFX gfx, ListView listView, SNode item, int index, double x, double y, double width, double height) {
                if(item == null) return;
                gfx.translate(x,y);
                if(item instanceof SelfDrawable) {
                    Bounds bounds = item.getBounds();
                    double scaleX = size/bounds.getWidth();
                    double scaleY = size/bounds.getHeight();
                    double scale = Math.min(scaleX,scaleY);
                    scale = Math.max(scale,0.2)//don't scale down by more than a factor of 5
                    Bounds oldClip = gfx.getClipRect();
                    gfx.setClipRect(new Bounds(0,0,size,size));
                    gfx.scale(scale,scale);
                    gfx.translate(-bounds.getX(),-bounds.getY());
                    SelfDrawable sd = (SelfDrawable) item;
                    sd.draw(gfx);
                    gfx.translate(bounds.getX(),bounds.getY());
                    gfx.scale(1/scale,1/scale);
                    gfx.setClipRect(oldClip);
                }
                gfx.setPaint(FlatColor.BLACK);
                gfx.drawRect(0,0,width,height);
                if(listView.getSelectedIndex() == index) {
                    gfx.setPaint(new FlatColor(0.8,0.8,1.0,0.5));
                    gfx.fillRect(0,0,width,height);
                }
                gfx.translate(-x,-y);
            }
        });

        symbolPane = new ScrollPane();
        symbolPane.setContent(listView);
        symbolPane.setHorizontalVisiblePolicy(ScrollPane.VisiblePolicy.Never);

        symbolAddButton = new Button(getString("sidebar.insertSymbol"));
        symbolAddButton.onClicked(new Callback<ActionEvent>() { public void call(ActionEvent event) {
            if(listView.getSelectedIndex() < 0) return;
            SNode node = listView.getModel().get(listView.getSelectedIndex());
            SketchDocument sd = context.getDocument();
            sd.getCurrentPage().add(node.duplicate(null));
            context.redraw();
        }});


        EventBus.getSystem().addListener(listView, MouseEvent.MouseAll, new Callback<MouseEvent>() {
            public double prevx;
            public boolean created;
            public SNode dupe;

            public void call(MouseEvent event) {
                if(event.getType() == MouseEvent.MousePressed) {
                    ContextMenu.hideAll();
                    if(event.getButton() == 3) { // check for right clicks to open the context menu
                        showContextMenu(event);
                        return;
                    }
                }
                if(event.getType() == MouseEvent.MouseDragged) {
                    if(created && dupe != null) {
                        Point2D pt = event.getPointInNodeCoords(context.getCanvas());
                        pt = context.getSketchCanvas().transformToCanvas(pt);
                        Bounds b = dupe.getBounds();
                        dupe.setTranslateX(pt.getX()-b.getWidth()/2);
                        dupe.setTranslateY(pt.getY()-b.getHeight()/2);
                        context.redraw();
                    }
                    if(event.getX() < 0 && prevx >= 0 && !created) {
                        created = true;
                        if(listView.getSelectedIndex() < 0) return;
                        SNode node = listView.getModel().get(listView.getSelectedIndex());
                        SketchDocument sd = context.getDocument();
                        dupe = node.duplicate(null);
                        Bounds b = dupe.getBounds();
                        sd.getCurrentPage().add(dupe);
                        Point2D pt = event.getPointInNodeCoords(context.getCanvas());
                        pt = context.getSketchCanvas().transformToCanvas(pt);
                        dupe.setTranslateX(pt.getX()-b.getWidth()/2);
                        dupe.setTranslateY(pt.getY()-b.getHeight()/2);
                        context.redraw();
                    }
                    prevx = event.getX();
                }
                if(event.getType() == MouseEvent.MouseReleased) {
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.