Пример #1
0
  @Override
  public void setBounds(int x, int y, int width, int height) {
    super.setBounds(x, y, width, height);
    int w = getWidth() - (SHADOW_SIZE - 2) * 2;
    int h = getHeight() - (SHADOW_SIZE - 2) * 2;
    int arc = 15;
    int shadowSize = SHADOW_SIZE;
    shadow = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
    Graphics2D g2 = shadow.createGraphics();

    if (active) {
      g2.setColor(new Color(243, 238, 39, 150));
    } else {
      g2.setColor(Color.WHITE);
    }

    g2.setColor(Color.WHITE);
    g2.fillOval(0, 0, w, h);
    g2.dispose();
    ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f, Color.BLACK);
    shadow = renderer.createShadow(shadow);
    g2 = shadow.createGraphics();
    g2.setColor(Color.GRAY);
    g2.setComposite(AlphaComposite.Clear);
    g2.fillOval(shadowSize, shadowSize, w, h);
    g2.dispose();
  }
Пример #2
0
  private static Icon getThemeIcon(ColorScheme colorScheme, boolean square) {
    int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iSize, iSize);
    Graphics2D graphics = (Graphics2D) result.getGraphics().create();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Color color1 = (colorScheme == null) ? Color.red : colorScheme.getUltraDarkColor();
    Color color2 = (colorScheme == null) ? Color.green : colorScheme.getMidColor();
    Color color3 = (colorScheme == null) ? Color.blue : colorScheme.getExtraLightColor();

    graphics.setColor(color1);
    if (square) graphics.fillRect(5, 2, 6, 6);
    else graphics.fillOval(5, 2, 6, 6);
    graphics.setColor(color1.darker());
    if (square) graphics.drawRect(5, 2, 6, 6);
    else graphics.drawOval(5, 2, 6, 6);

    graphics.setColor(color2);
    if (square) graphics.fillRect(1, 9, 6, 6);
    else graphics.fillOval(1, 9, 6, 6);
    graphics.setColor(color2.darker());
    if (square) graphics.drawRect(1, 9, 6, 6);
    else graphics.drawOval(1, 9, 6, 6);

    graphics.setColor(color3);
    if (square) graphics.fillRect(9, 9, 6, 6);
    else graphics.fillOval(9, 9, 6, 6);
    graphics.setColor(color3.darker());
    if (square) graphics.drawRect(9, 9, 6, 6);
    else graphics.drawOval(9, 9, 6, 6);

    graphics.dispose();
    return new ImageIcon(result);
  }
  @Override
  protected void paintIcon(JComponent c, Graphics2D g, Rectangle viewRect, Rectangle iconRect) {
    int rad = JBUI.scale(4);

    // Paint the radio button
    final int x = iconRect.x + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int y = iconRect.y + (rad - (rad % 2 == 1 ? 1 : 0)) / 2;
    final int w = iconRect.width - rad;
    final int h = iconRect.height - rad;
    final boolean enabled = c.isEnabled();
    Color color = enabled ? Gray.x50 : Gray.xD3;
    g.translate(x, y);
    // setup AA for lines
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    final boolean selected = ((AbstractButton) c).isSelected();
    g.setPaint(color);
    g.drawOval(0, 0, w, h);

    if (selected) {
      g.setColor(color);
      g.fillOval(JBUI.scale(3), JBUI.scale(3), w - 2 * JBUI.scale(3), h - 2 * JBUI.scale(3));
    }
    config.restore();
    g.translate(-x, -y);
  }
Пример #4
0
  @Override
  protected void paintWidget() {
    Graphics2D g = getGraphics();
    g.setStroke(Util.STROKE_2);
    g.setFont(getFont());
    Rectangle bounds = getBounds();

    String text = Util.node(this).toString();
    if (text.length() == 0) {
      g.setColor((Color) getBackground());
      g.fillOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
      g.setColor(getForeground());
      g.drawOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
    } else {
      g.setColor((Color) getBackground());
      int arc = (bounds.height - 1);
      g.fillRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
      g.setColor(getForeground());
      g.drawString(
          text,
          bounds.x + (bounds.height - 1) / 2,
          bounds.y + bounds.height - vborder - 1 - g.getFontMetrics().getMaxDescent());
      g.drawRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
    }
  }
Пример #5
0
  public void paintComponent(Graphics g) {

    GradientPaint gradient = new GradientPaint(70, 70, Color.blue, 150, 150, Color.orange);
    Image image = new ImageIcon("a.jpg").getImage();
    Random generator = new Random();

    int x1 = generator.nextInt(200) + 1;
    int y1 = generator.nextInt(200) + 1;
    int x2 = x1 + generator.nextInt(100) + 1;
    int y2 = x1 + generator.nextInt(100) + 1;

    g.setColor(Color.blue);
    g.fillRect(70, 70, 200, 100);

    g.setColor(Color.black);
    g.fillOval(80, 80, 170, 70);

    Graphics2D g2d = (Graphics2D) g;

    g.setColor(Color.yellow);
    g2d.fill3DRect(10, 10, 100, 100, true);

    g.drawImage(image, 300, 300, this);

    g2d.setPaint(gradient);
    g2d.fillOval(x1, y1, x2, y2);
  }
Пример #6
0
 private void placerPostes(Graphics2D g) {
   g.setStroke(new BasicStroke());
   for (PlanSalle.Poste poste : modele.listerPostes()) {
     g.setColor(Color.gray);
     int xPoste = Parametres.posteX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPoste = Parametres.posteY(poste.getPosition().getRangee(), poste.getOrientation());
     int xPersonne =
         Parametres.personneX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPersonne =
         Parametres.personneY(poste.getPosition().getRangee(), poste.getOrientation());
     if (poste.getOrientation() == Orientation.NORD
         || poste.getOrientation() == Orientation.SUD) {
       g.fill3DRect(xPoste, yPoste, Parametres.LONGUEUR_POSTE, Parametres.LARGEUR_POSTE, true);
     } else {
       g.fill3DRect(xPoste, yPoste, Parametres.LARGEUR_POSTE, Parametres.LONGUEUR_POSTE, true);
     }
     g.drawOval(xPersonne, yPersonne, Parametres.LARGEUR_PERSONNE, Parametres.LARGEUR_PERSONNE);
     if (poste.peutVoir()) {
       g.setColor(Color.red);
     } else {
       g.setColor(Color.blue);
     }
     g.fillOval(xPersonne, yPersonne, 20, 20);
   }
 }
Пример #7
0
 private void drawPoint(PointDP point, Graphics2D g) {
   g.fillOval(
       frameWidth / 2 + (int) (point.x * unityX) - 3,
       frameHeight / 2 - (int) (point.y * unityY) - 3,
       6,
       6);
 }
Пример #8
0
 public void draw(Graphics2D g2, boolean shouldFlip) {
   Font font = new Font("Sans_Serif", Font.PLAIN, 30);
   g2.setColor(Color.orange);
   g2.fillOval((int) x - 10, (int) (FieldConstants.FIELD_HEIGHT - y - 10), 20, 20);
   font = new Font("Sans_Serif", Font.PLAIN, 18);
   g2.setFont(font);
   g2.drawString(Double.toString(confidence), x, FieldConstants.FIELD_HEIGHT - y + 60);
 }
Пример #9
0
  public void drawStar(int xpos, int ypos, double rot, double xscale, double yscale) {
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.fillOval(-10, -10, 20, 20);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
Пример #10
0
  public void drawCircle(int xpos, int ypos, double rot, double xscale, double yscale, int width) {
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.fillOval(-width / 2, -width / 2, width, width);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
Пример #11
0
 /**
  * Draw the icon at the specified location. Icon implementations may use the Component argument to
  * get properties useful for painting, e.g. the foreground or background color.
  *
  * @param c Component
  * @param g Graphics
  * @param x X
  * @param y Y
  * @see javax.swing.Icon#paintIcon(Component, Graphics, int, int)
  */
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2D = (Graphics2D) g;
   Icon icon = CTreeNode.getIcon(m_type);
   if (icon != null) {
     int xI = x + ((WIDTH - icon.getIconWidth()) / 2);
     int yI = y + ((HEIGHT - icon.getIconHeight()) / 2);
     icon.paintIcon(c, g, xI, yI);
   } else //	draw dot
   {
     int size = 10;
     int xI = x + ((WIDTH - size) / 2);
     int yI = y + ((HEIGHT - size) / 2);
     g2D.setColor(Color.magenta);
     g2D.fillOval(xI, yI, size, size);
   }
 } //	PaintIcon
Пример #12
0
  public void paintComponent(Graphics g) {

    int red = (int) (Math.random() * 255);
    int green = (int) (Math.random() * 255);
    int blue = (int) (Math.random() * 255);
    Color startrandomColor = new Color(red, green, blue);

    red = (int) (Math.random() * 255);
    green = (int) (Math.random() * 255);
    blue = (int) (Math.random() * 255);
    Color endrandomColor = new Color(red, green, blue);

    Graphics2D g2d = (Graphics2D) g;
    this.addMouseListener(this);
    GradientPaint gradient = new GradientPaint(70, 70, startrandomColor, 150, 150, endrandomColor);

    g2d.setPaint(gradient);
    g2d.fillOval(70, 70, 100, 100);
  }
Пример #13
0
  private void paintMap(Graphics2D g2) {
    for (int y = 0; y < this.m_map.length; y++) {
      for (int x = 0; x < this.m_map[y].length; x++) {
        if (this.m_map[y][x] == GameBody.SNAKE || this.m_map[y][x] == GameBody.SNAKE_HEAD) {
          g2.drawRect(
              x * UserInterface.SCALE,
              y * UserInterface.SCALE,
              UserInterface.SCALE,
              UserInterface.SCALE);

        } else if (this.m_map[y][x] == GameBody.FRUIT) {
          g2.fillOval(
              x * UserInterface.SCALE,
              y * UserInterface.SCALE,
              UserInterface.SCALE,
              UserInterface.SCALE);
        }
      }
    }
  }
Пример #14
0
  public void update(Graphics g) {
    if (offimage == null) {
      offimage = createImage(getWidth(), getHeight());
      offg = offimage.getGraphics();
    }
    Graphics2D g2d = (Graphics2D) offg;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    circleList.add(new Circle(getWidth(), getHeight()));
    for (Circle circle : circleList) {
      circle.grow();
      g2d.setColor(circle.color);
      g2d.fillOval(
          circle.x - circle.radius, circle.y - circle.radius, circle.radius * 2, circle.radius * 2);
      if (circle.radius > 100) {
        circleList.remove(circle);
      }
    }

    g.drawImage(offimage, 0, 0, this);
  }
Пример #15
0
 private void render(Graphics2D g2, int x, int y, int w, int h) {
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (shadow != null) {
     int xOffset = (shadow.getWidth() - w) / 2;
     int yOffset = (shadow.getHeight() - h) / 2;
     g2.drawImage(shadow, x - xOffset, y - yOffset, null);
   }
   GradientPaint grad =
       new GradientPaint(
           new Point(0, 0),
           actualFillColor,
           new Point(0, getHeight()),
           new Color(255, 127, 36, 220));
   g2.setPaint(grad);
   g2.fillOval(x, y, w, h);
   g2.setStroke(new BasicStroke(2f));
   g2.setColor(borderColor);
   if (selected) {
     g2.setColor(new Color(243, 238, 39, 150));
   } else {
     g2.setColor(Color.WHITE);
   }
   g2.drawOval(x, y, w, h); // , arc, arc);
   g2.setColor(Color.WHITE);
   g2.setFont(new Font("Monospaced", Font.BOLD, 9));
   // g2.drawChars(title.toCharArray(), 0, title.length(), 0, 5);
   String[] titles = title.split(":");
   for (int i = 0; i < titles.length; i++) {
     g2.drawString(
         titles[i].trim(),
         (int) ((getWidth() / 2) - (title.trim().length() / 2) * 2.6),
         40 + i * 25);
     if (i != 0) {
       g2.drawString(":", (int) ((getWidth() / 2) - 1), 30 + (i * 25));
     }
   }
   // g2.drawString(title, (int)(getWidth()/2-title.length()*3),(getHeight()/2)+5);
   g2.dispose();
 }
Пример #16
0
    public void paint(Graphics g) { // 注意这里的参数,只能有层序来调用
      // 要渐变效果的话,需要将Graphics转化为 Graphics2D
      Graphics2D g2d = (Graphics2D) g;

      int red = (int) (Math.random() * 255);
      int blue = (int) (Math.random() * 255);
      int green = (int) (Math.random() * 255);
      // 颜色的决定使用color对象
      Color scolor = new Color(red, green, blue);

      red = (int) (Math.random() * 255);
      blue = (int) (Math.random() * 255);
      green = (int) (Math.random() * 255);
      Color ecolor = new Color(red, green, blue);

      // int  posi1= (int)(Math.random()*300);
      // int  posi2= (int)(Math.random()*300);
      // int  posi3= (int)(Math.random()*300);
      // int  posi4= (int)(Math.random()*300);
      // 创建颜料画对象
      GradientPaint dp = new GradientPaint(70, 70, scolor, 150, 150, ecolor);
      g2d.setPaint(dp);
      g2d.fillOval(70, 70, 100, 100);
    }
Пример #17
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      if (!JTattooUtilities.isLeftToRight(c)) {
        x += GAP;
      }
      int w = getIconWidth() - GAP;
      int h = getIconHeight();

      Graphics2D g2D = (Graphics2D) g;
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      Color colors[];
      if (button.isEnabled()) {
        if ((button.isRolloverEnabled() && model.isRollover())
            || (model.isPressed() && model.isArmed())) {
          colors = AbstractLookAndFeel.getTheme().getRolloverColors();
        } else {
          if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) {
            colors = AbstractLookAndFeel.getTheme().getFocusColors();
          } else {
            colors = AbstractLookAndFeel.getTheme().getCheckBoxColors();
          }
        }
      } else {
        colors = AbstractLookAndFeel.getTheme().getDisabledColors();
      }

      Color frameColor =
          ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6);
      Shape savedClip = g.getClip();
      Area clipArea = new Area(new Ellipse2D.Double(x, y, w + 1, h + 1));
      if (savedClip != null) {
        clipArea.intersect(new Area(savedClip));
      }
      g2D.setClip(clipArea);
      JTattooUtilities.fillHorGradient(g, colors, x, y, w, h);
      g2D.setClip(savedClip);

      Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(frameColor);
      g.drawOval(x, y, w, h);

      if (model.isSelected()) {
        if (model.isEnabled()) {
          Color fc = AbstractLookAndFeel.getForegroundColor();
          if (ColorHelper.getGrayValue(colors[0]) < 128) {
            if (ColorHelper.getGrayValue(fc) < 128) {
              g2D.setColor(Color.white);
            } else {
              g2D.setColor(fc);
            }
          } else {
            if (ColorHelper.getGrayValue(fc) > 128) {
              g2D.setColor(Color.black);
            } else {
              g2D.setColor(fc);
            }
          }
        } else {
          g.setColor(AbstractLookAndFeel.getDisabledForegroundColor());
        }
        if (AbstractLookAndFeel.getTheme().isSmallFontSize()) {
          g2D.fillOval(x + 4, y + 4, w - 7, h - 7);
        } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) {
          g2D.fillOval(x + 4, y + 4, w - 7, h - 7);
        } else {
          g2D.fillOval(x + 5, y + 5, w - 9, h - 9);
        }
      }
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
    }
Пример #18
0
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
Пример #19
0
 public void drawImage(Graphics2D graphics2D, int w, int h) {
   graphics2D.setColor(Color.RED);
   graphics2D.fillOval(h / 2 - 60, w / 2 - 60, 30, 30);
 }
Пример #20
0
 @Override
 protected void paintComponent(Graphics graphics) {
   BufferedImage backImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D backGraphics = backImage.createGraphics();
   BufferedImage frontImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D frontGraphics = frontImage.createGraphics();
   BufferedImage particleImage =
       new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D particleGraphics = particleImage.createGraphics();
   Graphics2D graphics2D = (Graphics2D) graphics;
   graphics.setColor(Color.BLACK);
   graphics.fillRect(0, 0, getWidth(), getHeight());
   graphics2D.translate(-cameraX, -cameraY);
   backGraphics.translate(-cameraX, -cameraY);
   frontGraphics.translate(-cameraX, -cameraY);
   particleGraphics.translate(-cameraX, -cameraY);
   for (int y = cameraY / 64; y < (cameraY / 64) + (getHeight() / 64) + 2; y++) {
     for (int x = cameraX / 64; x < (cameraX / 64) + (getWidth() / 64) + 2; x++) {
       Tile tile = world.getTileAt(x, y);
       if (tile != null) {
         backGraphics.drawImage(
             client.getTextureManager().getTexture("grass"), x * 64, y * 64, null);
         Unit unit = tile.getUnit();
         if (unit != null) {
           if (unit instanceof Dragon) {
             BufferedImage texture;
             if (unit.getDX() > 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_right_1")
                       : client.getTextureManager().getTexture("dragon_right_2");
             } else if (unit.getDX() < 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_left_1")
                       : client.getTextureManager().getTexture("dragon_left_2");
             } else if (unit.getDY() > 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_down_1")
                       : client.getTextureManager().getTexture("dragon_down_2");
             } else if (unit.getDY() < 0) {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_up_1")
                       : client.getTextureManager().getTexture("dragon_up_2");
             } else {
               texture =
                   currentDragonFrame == 0
                       ? client.getTextureManager().getTexture("dragon_down_1")
                       : client.getTextureManager().getTexture("dragon_down_2");
             }
             frontGraphics.drawImage(
                 texture, (x * 64) + unit.getXOffset(), (y * 64) + unit.getYOffset(), null);
             particleGraphics.setColor(Color.BLACK);
             if (unit.getAttackTarget() != null
                 && ((abs(unit.getAttackTarget().getTile().getX() - unit.getTile().getX()) == 1
                         && unit.getAttackTarget().getTile().getY() == unit.getTile().getY())
                     || (abs(unit.getAttackTarget().getTile().getY() - unit.getTile().getY()) == 1
                         && unit.getAttackTarget().getTile().getX() == unit.getTile().getX()))) {
               int xStart = min(unit.getTile().getX(), unit.getAttackTarget().getTile().getX());
               int xEnd = max(unit.getTile().getX(), unit.getAttackTarget().getTile().getX());
               int yStart = min(unit.getTile().getY(), unit.getAttackTarget().getTile().getY());
               int yEnd = max(unit.getTile().getY(), unit.getAttackTarget().getTile().getY());
               Random random = new Random();
               for (int pX = (xStart * 64) + 28; pX < (xEnd * 64) + 34; pX++) {
                 for (int pY = (yStart * 64) + 28; pY < (yEnd * 64) + 34; pY++) {
                   switch (random.nextInt(3)) {
                     case 0:
                       particleGraphics.setColor(Color.RED);
                       break;
                     case 1:
                       particleGraphics.setColor(Color.ORANGE);
                       break;
                     case 2:
                       particleGraphics.setColor(Color.YELLOW);
                       break;
                   }
                   particleGraphics.fillOval(
                       pX - 3 + random.nextInt(3), pY - 3 + random.nextInt(3), 4, 4);
                 }
               }
             }
           } else if (unit instanceof Wall) {
             TextureManager textureManager = client.getTextureManager();
             BufferedImage texture = textureManager.getTexture("tower");
             int offset = 128;
             Tile upTile = unit.getTile().getAdjacent(0, -1);
             boolean up =
                 upTile != null
                     && upTile.getUnit() != null
                     && upTile.getUnit() instanceof Wall
                     && upTile.getUnit().isComplete();
             Tile downTile = unit.getTile().getAdjacent(0, 1);
             boolean down =
                 downTile != null
                     && downTile.getUnit() != null
                     && downTile.getUnit() instanceof Wall
                     && downTile.getUnit().isComplete();
             Tile leftTile = unit.getTile().getAdjacent(-1, 0);
             boolean left =
                 leftTile != null
                     && leftTile.getUnit() != null
                     && leftTile.getUnit() instanceof Wall
                     && leftTile.getUnit().isComplete();
             Tile rightTile = unit.getTile().getAdjacent(1, 0);
             boolean right =
                 rightTile != null
                     && rightTile.getUnit() != null
                     && rightTile.getUnit() instanceof Wall
                     && rightTile.getUnit().isComplete();
             if (unit.isComplete()) {
               if (up) {
                 if (down) {
                   if (left) {
                     if (right) {
                       texture = textureManager.getTexture("tower_wall_up_down_left_right");
                     } else {
                       texture = textureManager.getTexture("tower_wall_up_down_left");
                     }
                   } else if (right) {
                     texture = textureManager.getTexture("tower_wall_up_down_right");
                   } else {
                     texture = textureManager.getTexture("wall_ver");
                     offset = 64;
                   }
                 } else if (left) {
                   if (right) {
                     texture = textureManager.getTexture("tower_wall_up_left_right");
                   } else {
                     texture = textureManager.getTexture("tower_wall_up_left");
                   }
                 } else if (right) {
                   texture = textureManager.getTexture("tower_wall_up_right");
                 } else {
                   texture = textureManager.getTexture("tower_wall_up");
                 }
               } else if (down) {
                 if (left) {
                   if (right) {
                     texture = textureManager.getTexture("tower_wall_down_left_right");
                   } else {
                     texture = textureManager.getTexture("tower_wall_down_left");
                   }
                 } else if (right) {
                   texture = textureManager.getTexture("tower_wall_down_right");
                 } else {
                   texture = textureManager.getTexture("tower_wall_down");
                 }
               } else if (left) {
                 if (right) {
                   texture = textureManager.getTexture("wall_hor");
                   offset = 64;
                 } else {
                   texture = textureManager.getTexture("tower_wall_left");
                 }
               } else if (right) {
                 texture = textureManager.getTexture("tower_wall_right");
               }
             } else {
               texture = textureManager.getTexture("wall_in_progress");
               offset = 64;
             }
             frontGraphics.drawImage(
                 texture,
                 (x * 64) + unit.getXOffset(),
                 (y * 64) + unit.getYOffset() - offset,
                 null);
           } else if (unit instanceof Flag) {
             BufferedImage texture = null;
             if (currentFlagFrame == 0) texture = client.getTextureManager().getTexture("flag_1");
             else if (currentFlagFrame == 1)
               texture = client.getTextureManager().getTexture("flag_2");
             else if (currentFlagFrame == 2)
               texture = client.getTextureManager().getTexture("flag_3");
             else if (currentFlagFrame == 3)
               texture = client.getTextureManager().getTexture("flag_4");
             if (texture != null) frontGraphics.drawImage(texture, (x * 64), (y * 64) - 64, null);
           }
         }
       }
     }
   }
   int mouseTileX =
       ((cameraX
               - (int) getLocationOnScreen().getX()
               + (int) MouseInfo.getPointerInfo().getLocation().getX())
           / 64);
   int mouseTileY =
       ((cameraY
               - (int) getLocationOnScreen().getY()
               + (int) MouseInfo.getPointerInfo().getLocation().getY())
           / 64);
   Tile mouseTile = getWorld().getTileAt(mouseTileX, mouseTileY);
   if (mouseTile != null) {
     if (mouseTile.getUnit() == null) {
       if (client.getShopPanel().getSelectedItem() == null) {
         backGraphics.setColor(new Color(0F, 1F, 0F, 0.5F));
       } else {
         backGraphics.setColor(new Color(0F, 0F, 1F, 0.5F));
       }
     } else {
       backGraphics.setColor(new Color(1F, 0F, 0F, 0.5F));
     }
     backGraphics.fillRect(mouseTileX * 64, mouseTileY * 64, 64, 64);
     if (mouseTile.getUnit() == null) {
       if (client.getShopPanel().getSelectedItem() == null) {
         backGraphics.setColor(Color.GREEN);
       } else {
         backGraphics.setColor(Color.BLUE);
       }
     } else {
       backGraphics.setColor(Color.RED);
     }
     backGraphics.drawRect(
         ((cameraX
                     - (int) getLocationOnScreen().getX()
                     + (int) MouseInfo.getPointerInfo().getLocation().getX())
                 / 64)
             * 64,
         ((cameraY
                     - (int) getLocationOnScreen().getY()
                     + (int) MouseInfo.getPointerInfo().getLocation().getY())
                 / 64)
             * 64,
         64,
         64);
   }
   graphics2D.translate(cameraX, cameraY);
   backGraphics.translate(cameraX, cameraY);
   frontGraphics.translate(cameraX, cameraY);
   particleGraphics.translate(cameraX, cameraY);
   graphics.drawImage(backImage, 0, 0, null);
   graphics.drawImage(frontImage, 0, 0, null);
   graphics.drawImage(particleImage, 0, 0, null);
   backGraphics.dispose();
   frontGraphics.dispose();
   particleGraphics.dispose();
   backImage.flush();
   frontImage.flush();
   particleImage.flush();
 }
Пример #21
0
  public boolean paint(Graphics graphics) {
    if (!Game.isLoggedIn()) return false;
    try {
      Graphics2D g = (Graphics2D) graphics;
      PComponent clayout = null;
      try {
        clayout =
            new PColumnLayout(
                227,
                404,
                infoColumnValues,
                infoColumnData,
                new Font("Arial", 0, 9),
                PColumnLayout.ColorScheme.WHITE);
      } catch (Exception e) {
        e.printStackTrace();
      }
      getFrame("options").removeComponent(firstLayout);
      getFrame("options").removeComponent(secondLayout);
      int secondColx = -1;
      int bestLength = -1;
      firstColumn.clear();
      secondColumn.clear();
      if (checkBoxes.size() <= 6) firstColumn.putAll(checkBoxes);
      else {
        for (int i = 0; i < checkBoxes.size(); i++) {
          if (i <= 5) {
            String text;
            Iterator it = checkBoxes.keySet().iterator();
            for (int j = 0; j < i; j++) it.next();
            text = (String) it.next();
            int length = SwingUtilities.computeStringWidth(g.getFontMetrics(g.getFont()), text);
            if (length > bestLength) bestLength = length;
            firstColumn.put(text, checkBoxes.get(text));
          } else {
            String text;
            Iterator it = checkBoxes.keySet().iterator();
            for (int j = 0; j < i; j++) it.next();
            text = (String) it.next();
            secondColumn.put(text, checkBoxes.get(text));
          }
        }
      }
      secondColx = 8 + bestLength;
      firstLayout =
          new PCheckBoxLayout(
              8,
              407,
              firstColumn
                  .keySet()
                  .toArray(new String[(firstColumn.size() > 6) ? 6 : firstColumn.size()]),
              firstColumn
                  .values()
                  .toArray(new PCheckBox[(firstColumn.size() > 6) ? 6 : firstColumn.size()]),
              new Font("Arial", 0, 11),
              PCheckBoxLayout.ColorScheme.WHITE);
      secondLayout =
          new PCheckBoxLayout(
              secondColx + 12,
              407,
              secondColumn
                  .keySet()
                  .toArray(new String[(secondColumn.size() > 6) ? 6 : secondColumn.size()]),
              secondColumn
                  .values()
                  .toArray(new PCheckBox[(secondColumn.size() > 6) ? 6 : secondColumn.size()]),
              new Font("Arial", 0, 11),
              PCheckBoxLayout.ColorScheme.WHITE);
      getFrame("options").addComponent(firstLayout);
      getFrame("options").addComponent(secondLayout);
      if (showPaint) {
        Paint p = g.getPaint();
        g.setPaint(
            new GradientPaint(
                0, 1000, new Color(55, 55, 55, 240), 512, 472, new Color(15, 15, 15, 240)));
        g.fillRect(7, 396, 505, 128);
        final Point loc = Mouse.getLocation();
        if (Mouse.isPressed()) {
          g.fillOval(loc.x - 5, loc.y - 5, 10, 10);
          g.drawOval(loc.x - 5, loc.y - 5, 10, 10);
        }
        g.drawLine(0, loc.y + 1, 766, loc.y + 1);
        g.drawLine(0, loc.y - 1, 766, loc.y - 1);
        g.drawLine(loc.x + 1, 0, loc.x + 1, 505);
        g.drawLine(loc.x - 1, 0, loc.x - 1, 505);
        g.setPaint(p);
      }
      if (clayout != null) getFrame("info").addComponent(clayout);
      PaintController.onRepaint(graphics);
      if (clayout != null) getFrame("info").removeComponent(clayout);
      if (!showPaint) return false;
      String infoTxt = name + " - " + "v" + version;
      g.drawString(
          infoTxt,
          510 - SwingUtilities.computeStringWidth(g.getFontMetrics(g.getFont()), infoTxt),
          468);

      int offset = 0;
      for (Skill skill : skills) {
        if (skill.xpGained() > 0) {
          PSkill skillComp =
              new PSkill(8, 397 + offset, skill.getSkill(), PSkill.ColorScheme.GRAPHITE);
          if (!getFrame("info").containsComponent(skillComp)) {
            getFrame("info").addComponent(skillComp);
          }
          offset += 20;
        }
      }

      // == Mouse ==
      if (Mouse.isPressed()) {
        g.setColor(new Color(255, 252, 0, 150));

        g.setColor(new Color(255, 252, 0, 100));
      } else {
        g.setColor(new Color(255, 252, 0, 50));
      }

      g.setColor(new Color(0, 0, 0, 50));

      // == End mouse ==
    } catch (Exception ignored) {
      // if (Utils.isDevMode())
      //    ignored.printStackTrace();
    }
    return true;
  }