Search in sources :

Example 11 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Rectangular method paint.

@Override
public void paint(Graphics g, HandleGesture gesture) {
    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;
        }
        if (y1 < y0) {
            int t = y0;
            y0 = y1;
            y1 = t;
        }
        draw(g, x0, y0, x1 - x0, y1 - y0);
    }
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Handle(com.cburch.draw.model.Handle)

Example 12 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Rectangular method getHandleArray.

private Handle[] getHandleArray(HandleGesture gesture) {
    Bounds bds = bounds;
    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);
                if (w > h) {
                    // reduce width to 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);
                if (w > h) {
                    // reduce width to h
                    if (x0 == hx) {
                        newX0 = newX1 + (newX0 > newX1 ? 1 : -1) * h;
                    }
                    if (x1 == hx) {
                        newX1 = newX0 + (newX1 > newX0 ? 1 : -1) * h;
                    }
                } else {
                    // reduce height to w
                    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) };
    }
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Handle(com.cburch.draw.model.Handle)

Example 13 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Rectangular method moveHandle.

@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;
    for (Handle h : newHandles) {
        i++;
        if (oldHandles[i].equals(moved)) {
            result = h;
        }
        int hx = h.getX();
        int hy = h.getY();
        if (hx < x0)
            x0 = hx;
        if (hx > x1)
            x1 = hx;
        if (hy < y0)
            y0 = hy;
        if (hy > y1)
            y1 = hy;
    }
    bounds = Bounds.create(x0, y0, x1 - x0, y1 - y0);
    return result;
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 14 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class SvgCreator method createPoly.

public static Element createPoly(Document doc, Poly poly) {
    Element elt;
    if (poly.isClosed()) {
        elt = doc.createElement("polygon");
    } else {
        elt = doc.createElement("polyline");
    }
    StringBuilder points = new StringBuilder();
    boolean first = true;
    for (Handle h : poly.getHandles(null)) {
        if (!first)
            points.append(" ");
        points.append(h.getX() + "," + h.getY());
        first = false;
    }
    elt.setAttribute("points", points.toString());
    populateFill(elt, poly);
    return elt;
}
Also used : Element(org.w3c.dom.Element) Handle(com.cburch.draw.model.Handle)

Example 15 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Selection method setHandleSelected.

public void setHandleSelected(Handle handle) {
    Handle cur = selectedHandle;
    boolean same = cur == null ? handle == null : cur.equals(handle);
    if (!same) {
        selectedHandle = handle;
        curHandleGesture = null;
        Collection<CanvasObject> objs;
        if (handle == null) {
            objs = Collections.emptySet();
        } else {
            objs = Collections.singleton(handle.getObject());
        }
        fireChanged(SelectionEvent.ACTION_HANDLE, objs);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Handle(com.cburch.draw.model.Handle)

Aggregations

Handle (com.cburch.draw.model.Handle)39 CanvasObject (com.cburch.draw.model.CanvasObject)9 Location (com.cburch.logisim.data.Location)9 Selection (com.cburch.draw.canvas.Selection)7 HandleGesture (com.cburch.draw.model.HandleGesture)7 Bounds (com.cburch.logisim.data.Bounds)5 ModelDeleteHandleAction (com.cburch.draw.actions.ModelDeleteHandleAction)1 ModelInsertHandleAction (com.cburch.draw.actions.ModelInsertHandleAction)1 ModelMoveHandleAction (com.cburch.draw.actions.ModelMoveHandleAction)1 ModelTranslateAction (com.cburch.draw.actions.ModelTranslateAction)1 CanvasModel (com.cburch.draw.model.CanvasModel)1 Circuit (com.cburch.logisim.circuit.Circuit)1 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)1 Project (com.cburch.logisim.proj.Project)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 Map (java.util.Map)1 Element (org.w3c.dom.Element)1