Search in sources :

Example 91 with Bounds

use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.

the class DotMatrix method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
    Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
    boolean drawSquare = painter.getAttributeValue(ATTR_DOT_SHAPE) == SHAPE_SQUARE;
    State data = getState(painter);
    long ticks = painter.getTickCount();
    Bounds bds = painter.getBounds();
    boolean showState = painter.getShowState();
    Graphics g = painter.getGraphics();
    int rows = data.rows;
    int cols = data.cols;
    for (int j = 0; j < rows; j++) {
        for (int i = 0; i < cols; i++) {
            int x = bds.getX() + 10 * i;
            int y = bds.getY() + 10 * j;
            if (showState) {
                Value val = data.get(j, i, ticks);
                Color c;
                if (val == Value.TRUE)
                    c = onColor;
                else if (val == Value.FALSE)
                    c = offColor;
                else
                    c = Value.ERROR_COLOR;
                g.setColor(c);
                if (drawSquare)
                    g.fillRect(x, y, 10, 10);
                else
                    g.fillOval(x + 1, y + 1, 8, 8);
            } else {
                g.setColor(Color.GRAY);
                g.fillOval(x + 1, y + 1, 8, 8);
            }
        }
    }
    g.setColor(Color.BLACK);
    GraphicsUtil.switchToWidth(g, 2);
    g.drawRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    GraphicsUtil.switchToWidth(g, 1);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) InstanceState(com.cburch.logisim.instance.InstanceState) Color(java.awt.Color) Bounds(com.cburch.logisim.data.Bounds) Value(com.cburch.logisim.data.Value)

Example 92 with Bounds

use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.

the class Led method paintGhost.

@Override
public void paintGhost(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    GraphicsUtil.switchToWidth(g, 2);
    g.drawOval(bds.getX() + 1, bds.getY() + 1, bds.getWidth() - 2, bds.getHeight() - 2);
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds)

Example 93 with Bounds

use of com.cburch.logisim.data.Bounds 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 94 with Bounds

use of com.cburch.logisim.data.Bounds 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 95 with Bounds

use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.

the class AbstractCanvasObject method overlaps.

public boolean overlaps(CanvasObject other) {
    Bounds a = this.getBounds();
    Bounds b = other.getBounds();
    Bounds c = a.intersect(b);
    Random rand = new Random();
    if (c.getWidth() == 0 || c.getHeight() == 0) {
        return false;
    } else if (other instanceof AbstractCanvasObject) {
        AbstractCanvasObject that = (AbstractCanvasObject) other;
        for (int i = 0; i < OVERLAP_TRIES; i++) {
            if (i % 2 == 0) {
                Location loc = this.getRandomPoint(c, rand);
                if (loc != null && that.contains(loc, false))
                    return true;
            } else {
                Location loc = that.getRandomPoint(c, rand);
                if (loc != null && this.contains(loc, false))
                    return true;
            }
        }
        return false;
    } else {
        for (int i = 0; i < OVERLAP_TRIES; i++) {
            Location loc = this.getRandomPoint(c, rand);
            if (loc != null && other.contains(loc, false))
                return true;
        }
        return false;
    }
}
Also used : Random(java.util.Random) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Aggregations

Bounds (com.cburch.logisim.data.Bounds)199 Graphics (java.awt.Graphics)71 Direction (com.cburch.logisim.data.Direction)29 Location (com.cburch.logisim.data.Location)29 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics2D (java.awt.Graphics2D)20 Font (java.awt.Font)19 Component (com.cburch.logisim.comp.Component)14 Color (java.awt.Color)14 FontMetrics (java.awt.FontMetrics)12 Value (com.cburch.logisim.data.Value)9 Circuit (com.cburch.logisim.circuit.Circuit)7 Port (com.cburch.logisim.instance.Port)7 Instance (com.cburch.logisim.instance.Instance)6 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)6 Handle (com.cburch.draw.model.Handle)5 RadixOption (com.cburch.logisim.circuit.RadixOption)5 CanvasObject (com.cburch.draw.model.CanvasObject)3 Wire (com.cburch.logisim.circuit.Wire)3 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)3