コード例 #1
0
  private void drawPedals(Graphics g, int panelWidth, int panelHeight) {
    // drawing the box for gas
    int x = panelWidth / 2 - WheelRadius - ElementPadding - PedalBoxWidth - 2 * PedalBorderSize;
    int y = panelHeight / 2 - PedalBoxHeight / 2 - 2 * PedalBorderSize;
    g.setColor(Color.LIGHT_GRAY);
    g.drawRect(x, y, PedalBoxWidth + PedalBorderSize, PedalBoxHeight + PedalBorderSize);

    // drawing the fill in the gas box
    int valueScaleRatio = (int) (PedalBoxHeight / DriverInput.MaxPedalPushValue);
    double valueDiffFromMax = DriverInput.MaxPedalPushValue - in.getGasPedalPercentage();
    int tempGasPedalBoxX = x;
    int tempGasPedalBoxY = y;
    x += PedalBorderSize;
    y += valueDiffFromMax * valueScaleRatio + PedalBorderSize;
    g.setColor(Color.GREEN);
    g.fillRect(x, y, PedalBoxWidth, (int) (PedalBoxHeight - (valueDiffFromMax * valueScaleRatio)));

    // drawing the box for brake
    x = tempGasPedalBoxX - ElementPadding - PedalBoxWidth - 2 * PedalBorderSize;
    y = tempGasPedalBoxY;
    g.setColor(Color.LIGHT_GRAY);
    g.drawRect(x, y, PedalBoxWidth + PedalBorderSize, PedalBoxHeight + PedalBorderSize);

    // drawing the fill in the brake box
    valueDiffFromMax = DriverInput.MaxPedalPushValue - in.getBrakePedalPercentage();
    x += PedalBorderSize;
    y += valueDiffFromMax * valueScaleRatio + PedalBorderSize;
    g.setColor(Color.RED);
    g.fillRect(x, y, PedalBoxWidth, (int) (PedalBoxHeight - (valueDiffFromMax * valueScaleRatio)));
  }
コード例 #2
0
  private void drawGear(Graphics g, int panelWidth, int panelHeight) {
    int x = panelWidth / 2 + WheelRadius + ElementPadding * 2;
    int y = panelHeight / 2 - WheelRadius + GearBoxOffset;

    ShiftLeverPosition shiftLeverPosition = in.getShiftLeverPosition();
    // parking
    g.setColor(Color.LIGHT_GRAY);
    if (shiftLeverPosition == ShiftLeverPosition.Parking) g.setColor(Color.BLUE);
    g.drawString("P", x, y);
    y += GearLevelPadding;

    // reverse
    g.setColor(Color.LIGHT_GRAY);
    if (shiftLeverPosition == ShiftLeverPosition.Reverse) g.setColor(Color.BLUE);
    g.drawString("R", x, y);
    y += GearLevelPadding;

    // neutral
    g.setColor(Color.LIGHT_GRAY);
    if (shiftLeverPosition == ShiftLeverPosition.Neutral) g.setColor(Color.BLUE);
    g.drawString("N", x, y);
    y += GearLevelPadding;

    // drive
    g.setColor(Color.LIGHT_GRAY);
    if (shiftLeverPosition == ShiftLeverPosition.Drive) g.setColor(Color.BLUE);
    g.drawString("D", x, y);
  }
コード例 #3
0
  private void drawEngineButton(Graphics g, int panelWidth, int panelHeight) {
    int x = panelWidth - EngineButtonRadius - EngineButtonMargin;
    int y = panelHeight - EngineButtonRadius - EngineButtonMargin;

    if (in.getEngineToggleButtonState()) g.setColor(Color.GREEN);
    else g.setColor(Color.RED);
    g.fillOval(x, y, EngineButtonRadius, EngineButtonRadius);
    g.setColor(Color.DARK_GRAY);
    g.drawOval(x, y, EngineButtonRadius, EngineButtonRadius);
  }
コード例 #4
0
  private void drawSteeringWheel(Graphics g, int panelWidth, int panelHeight) {
    // outer circle
    int x = panelWidth / 2 - WheelRadius;
    int y = panelHeight / 2 - WheelRadius;
    Color defaultColor = this.getBackground();
    g.setColor(Color.LIGHT_GRAY);
    g.fillOval(x, y, WheelRadius * 2, WheelRadius * 2);

    // inner circle
    int innerWheelRadius = (int) (WheelRadius * InnerWheelRatio);

    x = panelWidth / 2 - innerWheelRadius;
    y = panelHeight / 2 - innerWheelRadius;
    g.setColor(defaultColor);
    g.fillOval(x, y, innerWheelRadius * 2, innerWheelRadius * 2);

    double steeringWheelRotation = in.getSteeringWheelSignedPercentage();
    // drawing the 'needle'
    {
      double needleRadius = (WheelRadius - innerWheelRadius) / 2;
      double needleRotation = (steeringWheelRotation * WheelMovementScaleRatio - 90);
      double needleLength = innerWheelRadius + needleRadius;

      x =
          (int)
              (panelWidth / 2
                  - needleRadius
                  + Math.cos(Math.toRadians(needleRotation)) * needleLength);
      y =
          (int)
              (panelHeight / 2
                  - needleRadius
                  + Math.sin(Math.toRadians(needleRotation)) * needleLength);
      g.setColor(Color.DARK_GRAY);
      g.fillOval(x, y, (int) needleRadius * 2, (int) needleRadius * 2);
    }

    // drawing the value in text
    x = panelWidth / 2 - g.getFontMetrics().stringWidth(steeringWheelRotation + "%") / 2;
    y = panelHeight / 2;
    g.setColor(Color.BLACK);
    g.drawString(steeringWheelRotation + "%", x, y);
  }