Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Direction


    instance.setPorts(ports);
  }

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


  }
 
  @Override
  public boolean contains(Location loc, AttributeSet attrs) {
    if (super.contains(loc, attrs)) {
      Direction facing = attrs.getValue(StdAttr.FACING);
      Location center = Location.create(0, 0).translate(facing, -20);
      return center.manhattanDistanceTo(loc) < 24;
    } else {
      return false;
    }
View Full Code Here

  }

  private void drawInstance(InstancePainter painter, boolean isGhost) {
    Bounds bds = painter.getBounds();
    Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST)
      == (powerLoc == Wiring.GATE_TOP_LEFT);

    int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
    if (flip) degrees += 180;
    double radians = Math.toRadians((degrees + 360) % 360);

    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
View Full Code Here

    setFacingAttribute(StdAttr.FACING);
  }

  @Override
  public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    if (facing == Direction.EAST) {
      return Bounds.create(-42, -6, 42, 12);
    } else if (facing == Direction.WEST) {
      return Bounds.create(0, -6, 42, 12);
    } else if (facing == Direction.NORTH) {
View Full Code Here

  }
 
  private void paintBase(InstancePainter painter, Value pullValue,
      Color inColor, Color outColor) {
    boolean color = painter.shouldDrawColor();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    GraphicsUtil.switchToWidth(g, 3);
    if (color && inColor != null) g.setColor(inColor);
    if (facing == Direction.EAST) {
      GraphicsUtil.drawText(g, pullValue.toDisplayString(), -32, 0,
          GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.WEST) {
      GraphicsUtil.drawText(g, pullValue.toDisplayString(), 32, 0,
          GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    } else if (facing == Direction.NORTH) {
      GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, 32,
          GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
    } else {
      GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, -32,
          GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    }
   
    double rotate = 0.0;
    if (g instanceof Graphics2D) {
      rotate = Direction.SOUTH.toRadians() - facing.toRadians();
      if (rotate != 0.0) ((Graphics2D) g).rotate(rotate);
    }
    g.drawLine(0, -30, 0, -26);
    g.drawLine(-6, -30, 6, -30);
    if (color && outColor != null) g.setColor(outColor);
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.