Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Direction


      instance.fireInvalidated();
    }
  }

  private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    Port[] ps = new Port[outputs + (enable ? 2 : 1)];
View Full Code Here


    }
  }

  @Override
  public void paintGhost(InstancePainter painter) {
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    Plexers.drawTrapezoid(painter.getGraphics(), painter.getBounds(),
        facing.reverse(), select.getWidth() == 1 ? 10 : 20);
  }
View Full Code Here

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int selMult = selectLoc == Plexers.SELECT_TOP_RIGHT ? -1 : 1;
    int outputs = 1 << select.getWidth();

    // draw stubs for select and enable ports
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) { // draw select wire
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs).getColor());
      }
      Location pt = painter.getInstance().getPortLocation(outputs);
      g.drawLine(pt.getX(), pt.getY(), pt.getX() + 2 * dx, pt.getY() + 2 * dy);
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(outputs + 1);
      int len = outputs == 2 ? 6 : 4;
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs + 1).getColor());
      }
      g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
    }
    GraphicsUtil.switchToWidth(g, 1);
   
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
   
    // draw "0"
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
      x0 = 3;
      y0 = 15;
      halign = GraphicsUtil.H_LEFT;
    } else if (facing == Direction.NORTH) {
      x0 = 10;
      y0 = 15;
      halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
      x0 = 10;
      y0 = bds.getHeight() - 3;
      halign = GraphicsUtil.H_CENTER;
    } else {
      x0 = bds.getWidth() - 3;
      y0 = 15;
      halign = GraphicsUtil.H_RIGHT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0,
        halign, GraphicsUtil.V_BASELINE);
   
    // draw trapezoid, "Decd", and ports
    g.setColor(Color.BLACK);
    Plexers.drawTrapezoid(g, bds, facing.reverse(), outputs == 2 ? 10 : 20);
    GraphicsUtil.drawCenteredText(g, "Decd",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
  }
View Full Code Here

    setInstanceLogger(Logger.class);
  }

  @Override
  public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    return Bounds.create(-20, -10, 20, 20).rotate(Direction.EAST, facing, 0, 0);
  }
View Full Code Here

      computeTextField(instance);
    }
  }

  private void computeTextField(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);

    Bounds bds = instance.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y = bds.getY() + bds.getHeight() / 2;
View Full Code Here

  }

  @Override
  public Bounds getOffsetBounds(AttributeSet attrsBase) {
    GateAttributes attrs = (GateAttributes) attrsBase;
    Direction facing = attrs.facing;
    int size = ((Integer) attrs.size.getValue()).intValue();
    int inputs = attrs.inputs;
    if (inputs % 2 == 0) {
      inputs++;
    }
View Full Code Here

    GateAttributes attrs = (GateAttributes) attrsBase;
    if (super.contains(loc, attrs)) {
      if (attrs.negated == 0) {
        return true;
      } else {
        Direction facing = attrs.facing;
        Bounds bds = getOffsetBounds(attrsBase);
        int delt;
        if (facing == Direction.NORTH) {
          delt = loc.getY() - (bds.getY() + bds.getHeight());
        } else if (facing == Direction.SOUTH) {
View Full Code Here

    }
  }
 
  private void paintBase(InstancePainter painter) {
    GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
    Direction facing = attrs.facing;
    int inputs = attrs.inputs;
    int negated = attrs.negated;

    Object shape = painter.getGateShape();
    Location loc = painter.getLocation();
    Bounds bds = painter.getOffsetBounds();
    int width = bds.getWidth();
    int height = bds.getHeight();
    if (facing == Direction.NORTH || facing == Direction.SOUTH) {
      int t = width; width = height; height = t;
    }
    if (negated != 0) {
      width -= 10;
    }

    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) {
      PainterShaped.paintInputLines(painter, this);
    } else if (negated != 0) {
      for (int i = 0; i < inputs; i++) {
        int negatedBit = (negated >> i) & 1;
        if (negatedBit == 1) {
          Location in = getInputOffset(attrs, i);
          Location cen = in.translate(facing, 5);
          painter.drawDongle(loc.getX() + cen.getX(),
              loc.getY() + cen.getY());
        }
      }
    }
   
    g.setColor(baseColor);
    g.translate(loc.getX(), loc.getY());
    double rotate = 0.0;
    if (facing != Direction.EAST && g instanceof Graphics2D) {
      rotate = -facing.toRadians();
      Graphics2D g2 = (Graphics2D) g;
      g2.rotate(rotate);
    }
   
    if (shape == AppPreferences.SHAPE_RECTANGULAR) {
View Full Code Here

    }
  }
 
  private void computeLabel(Instance instance) {
    GateAttributes attrs = (GateAttributes) instance.getAttributeSet();
    Direction facing = attrs.facing;
    int baseWidth = ((Integer) attrs.size.getValue()).intValue();
   
    int axis = baseWidth / 2 + (negateOutput ? 10 : 0);
    int perp = 0;
    if (AppPreferences.GATE_SHAPE.get().equals(AppPreferences.SHAPE_RECTANGULAR)) {
View Full Code Here

    return super.getInstanceFeature(instance, key);
  }
 
  Location getInputOffset(GateAttributes attrs, int index) {
    int inputs = attrs.inputs;
    Direction facing = attrs.facing;
    int size = ((Integer) attrs.size.getValue()).intValue();
    int axisLength = size + bonusWidth + (negateOutput ? 10 : 0);
    int negated = attrs.negated;

    int skipStart;
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Direction

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.