Package com.cburch.draw.model

Examples of com.cburch.draw.model.Handle


        switch (curAction) {
        case MOVE_HANDLE:
            HandleGesture gesture = curGesture;
            if (ctrl) {
                Handle h = gesture.getHandle();
                dx = canvas.snapX(h.getX() + dx) - h.getX();
                dy = canvas.snapY(h.getY() + dy) - h.getY();
            }
            curGesture = new HandleGesture(gesture.getHandle(), dx, dy, mods);
            canvas.getSelection().setHandleGesture(curGesture);
            break;
        case MOVE_ALL:
View Full Code Here


                    y = (int) Math.round(zoom * y);
                    gCopy.clearRect(x - offs, y - offs, size, size);
                    gCopy.drawRect(x - offs, y - offs, size, size);
                }
            }
            Handle selHandle = selection.getSelectedHandle();
            if (selHandle != null) {
                int x = selHandle.getX();
                int y = selHandle.getY();
                if (action == MOVE_ALL && dragEffective) {
                    Location delta = selection.getMovingDelta();
                    x += delta.getX();
                    y += delta.getY();
                }
View Full Code Here

    @Override
    public List<Handle> getHandles(HandleGesture gesture) {
        Location c = getLocation();
        Location end = c.translate(facing, RADIUS + INDICATOR_LENGTH);
        return UnmodifiableList.decorate(Arrays.asList(new Handle[] { new Handle(this, c),
                new Handle(this, end) }));
    }
View Full Code Here

    public List<Handle> getHandles(HandleGesture gesture) {
        Location loc = getLocation();

        int r = isInput() ? INPUT_RADIUS : OUTPUT_RADIUS;
        return UnmodifiableList.decorate(Arrays.asList(new Handle[] {
                new Handle(this, loc.translate(-r, -r)),
                new Handle(this, loc.translate(r, -r)),
                new Handle(this, loc.translate(r, r)),
                new Handle(this, loc.translate(-r, r)) }));
    }
View Full Code Here

        int x0 = bds.getX();
        int y0 = bds.getY();
        int x1 = x0 + bds.getWidth();
        int y1 = y0 + bds.getHeight();
        if (gesture == null) {
            return new Handle[] { new Handle(this, x0, y0),
                    new Handle(this, x1, y0), new Handle(this, x1, y1),
                    new Handle(this, x0, y1) };
        } else {
            int hx = gesture.getHandle().getX();
            int hy = gesture.getHandle().getY();
            int dx = gesture.getDeltaX();
            int dy = gesture.getDeltaY();
            int newX0 = x0 == hx ? x0 + dx : x0;
            int newY0 = y0 == hy ? y0 + dy : y0;
            int newX1 = x1 == hx ? x1 + dx : x1;
            int newY1 = y1 == hy ? y1 + dy : y1;
            if (gesture.isShiftDown()) {
                if (gesture.isAltDown()) {
                    if (x0 == hx) {
                      newX1 -= dx;
                    }
                    if (x1 == hx) {
                      newX0 -= dx;
                    }
                    if (y0 == hy) {
                      newY1 -= dy;
                    }
                    if (y1 == hy) {
                      newY0 -= dy;
                    }

                    int w = Math.abs(newX1 - newX0);
                    int h = Math.abs(newY1 - newY0);
                    // reduce width to h
                    if (w > h) {
                        int dw = (w - h) / 2;
                        newX0 -= (newX0 > newX1 ? 1 : -1) * dw;
                        newX1 -= (newX1 > newX0 ? 1 : -1) * dw;
                    } else {
                        int dh = (h - w) / 2;
                        newY0 -= (newY0 > newY1 ? 1 : -1) * dh;
                        newY1 -= (newY1 > newY0 ? 1 : -1) * dh;
                    }
                } else {
                    int w = Math.abs(newX1 - newX0);
                    int h = Math.abs(newY1 - newY0);
                    // reduce width to h
                    if (w > h) {
                        if (x0 == hx) {
                            newX0 = newX1 + (newX0 > newX1 ? 1 : -1) * h;
                        }
                        if (x1 == hx) {
                            newX1 = newX0 + (newX1 > newX0 ? 1 : -1) * h;
                        }
                    // reduce height to w
                    } else {
                        if (y0 == hy) {
                            newY0 = newY1 + (newY0 > newY1 ? 1 : -1) * w;
                        }
                        if (y1 == hy) {
                            newY1 = newY0 + (newY1 > newY0 ? 1 : -1) * w;
                        }
                    }
                }
            } else {
                if (gesture.isAltDown()) {
                    if (x0 == hx) {
                      newX1 -= dx;
                    }
                    if (x1 == hx) {
                      newX0 -= dx;
                    }
                    if (y0 == hy) {
                      newY1 -= dy;
                    }
                    if (y1 == hy) {
                      newY0 -= dy;
                    }
                } else {
                    // already handled
                    ;
                }
            }
            return new Handle[] { new Handle(this, newX0, newY0),
                new Handle(this, newX1, newY0), new Handle(this, newX1, newY1),
                new Handle(this, newX0, newY1) };
        }
    }
View Full Code Here

    @Override
    public Handle moveHandle(HandleGesture gesture) {
        Handle[] oldHandles = getHandleArray(null);
        Handle[] newHandles = getHandleArray(gesture);
        Handle moved = gesture == null ? null : gesture.getHandle();
        Handle result = null;
        int x0 = Integer.MAX_VALUE;
        int x1 = Integer.MIN_VALUE;
        int y0 = Integer.MAX_VALUE;
        int y1 = Integer.MIN_VALUE;
        int i = -1;
View Full Code Here

        if (gesture == null) {
            Bounds bds = bounds;
            draw(g, bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
        } else {
            Handle[] handles = getHandleArray(gesture);
            Handle p0 = handles[0];
            Handle p1 = handles[2];
            int x0 = p0.getX();
            int y0 = p0.getY();
            int x1 = p1.getX();
            int y1 = p1.getY();
            if (x1 < x0) {
              int t = x0;
              x0 = x1;
              x1 = t;
            }
View Full Code Here

    public Poly(boolean closed, List<Location> locations) {
        Handle[] hs = new Handle[locations.size()];
        int i = -1;
        for (Location loc : locations) {
            i++;
            hs[i] = new Handle(this, loc.getX(), loc.getY());
        }

        this.closed = closed;
        handles = hs;
        recomputeBounds();
View Full Code Here

        newHandle = model.moveHandle(gesture);
    }

    @Override
    void undoSub(CanvasModel model) {
        Handle oldHandle = gesture.getHandle();
        int dx = oldHandle.getX() - newHandle.getX();
        int dy = oldHandle.getY() - newHandle.getY();
        HandleGesture reverse = new HandleGesture(newHandle, dx, dy, 0);
        model.moveHandle(reverse);
    }
View Full Code Here

    @Override
    public Poly clone() {
        Poly ret = (Poly) super.clone();
        Handle[] hs = this.handles.clone();
        for (int i = 0, n = hs.length; i < n; i++) {
            Handle oldHandle = hs[i];
            hs[i] = new Handle(ret, oldHandle.getX(), oldHandle.getY());
        }
        ret.handles = hs;
        return ret;
    }
View Full Code Here

TOP

Related Classes of com.cburch.draw.model.Handle

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.