Beispiel #1
0
  public void paint(Graphics g) {
    if (!gameComplete) {
      if (!initialPaintComplete) {
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, MaxX, MaxY);
        initialPaintComplete = true;
      }

      Graphics blockGraphics = blockBuffer.getGraphics();
      Graphics padGraphics = padBuffer.getGraphics();
      Graphics ballGraphics = ballBuffer.getGraphics();
      Graphics ballPreviousGraphics = ballBufferPrevious.getGraphics();

      ballPreviousGraphics.setColor(Color.WHITE);
      ballPreviousGraphics.fillRect(0, 0, ballDiameter, ballDiameter);
      g.drawImage(ballBufferPrevious, ballPreviousX, ballPreviousY, null);

      ballGraphics.setColor(Color.BLUE);
      ballGraphics.fillOval(0, 0, ballDiameter, ballDiameter); // whole line white
      g.drawImage(ballBuffer, ballX, ballY, null);

      ballGraphics.setColor(Color.RED);
      ballGraphics.fillOval(4, 4, ballDiameter - 8, ballDiameter - 8); // whole line white
      g.drawImage(ballBuffer, ballX, ballY, null);

      padGraphics.setColor(Color.WHITE);
      padGraphics.fillRect(0, 0, MaxX, blockHeight); // whole line white
      padGraphics.setColor(Color.BLACK);
      padLeft = padx - padLength / 2;

      if (padLeft >= 0 && padx + padLength / 2 < MaxX) {
        padGraphics.fillRoundRect(padLeft, 0, padLength, padHeight, padHeight, padHeight);
      }
      if (padLeft < 0) {
        padGraphics.fillRoundRect(0, 0, padLength, padHeight, padHeight, padHeight);
      } else if (padx + padLength / 2 >= MaxX) {
        padGraphics.fillRoundRect(MaxX - padLength, 0, padLength, padHeight, padHeight, padHeight);
      }
      g.drawImage(padBuffer, 0, padTop, null);
      // g.drawString(msg, 50, 50);
      // Drawing Blocks

      Iterator<Entry<String, Color>> it = blockMap.entrySet().iterator();
      blockGraphics.setColor(Color.WHITE);
      blockGraphics.fillRect(0, 0, blockSetWidth, blockSetHeight); // whole line white
      while (it.hasNext()) {
        Map.Entry<String, Color> pairs = (Map.Entry<String, Color>) it.next();
        String coordinate = pairs.getKey();
        blockGraphics.setColor(pairs.getValue());
        blockGraphics.fillRect(
            new Pair(coordinate).first, new Pair(coordinate).second, blockLength, blockHeight);
      }
      if (repaintBlocks) {
        g.drawImage(blockBuffer, blockStartX, blockStartY, null);
        if (--count < 0) repaintBlocks = false;
      }
    }
  }
Beispiel #2
0
  /** Affichage du logo */
  protected void drawLogo(Graphics g) {

    int x = 5;
    int y = 2;

    g.setColor(getBackground());
    g.fillRect(0, 0, W, H);

    // Remplissage
    fillBG(g, x, y, Color.white);

    // Dessin
    drawGrid(
        g,
        x,
        y,
        !isAvailable()
            ? Aladin.MYGRAY
            : isActive() ? Aladin.GREEN : isMouseIn() ? Color.blue : Color.black);

    // Label
    g.setColor(isAvailable() ? Color.black : Aladin.MYGRAY);
    g.setFont(Aladin.SPLAIN);
    g.drawString(LABEL, W / 2 - g.getFontMetrics().stringWidth(LABEL) / 2, H - 2);
  }
Beispiel #3
0
    public void draw(Graphics g, ImageObserver ob) {
      if (!todraw) {
        g.setColor(bgcolor);
        g.drawRect(x, y, w + 2 * border, h + 2 * border);
        g.fillRect(x, y, w + 2 * border, h + 2 * border);
        return;
      }

      if (selected) g.setColor(selected_color);
      else g.setColor(unselected_color);

      g.drawRect(x, y, w + 2 * border, h + 2 * border);
      g.fillRect(x, y, w + 2 * border, h + 2 * border);
      g.drawImage(image[im], x + border, y + border, ob);

      // g.setColor(Color.black);
      // g.drawString("" + im,x+5,y+5);
    }
Beispiel #4
0
 /**
  * Turn a (possibly) translucent or indexed image into a display-compatible bitmask image using
  * the given alpha threshold and render-to-background colour, or display-compatible translucent
  * image. The alpha values in the image are set to either 0 (below threshold) or 255 (above
  * threshold). The render-to-background colour bg_col is used to determine how the pixels
  * overlapping transparent pixels should be rendered. The fast algorithm just sets the colour
  * behind the transparent pixels in the image (for bitmask source images); the slow algorithm
  * actually renders the image to a background of bg_col (for translucent sources).
  *
  * @param thresh alpha threshold between 0 and 255
  * @param fast use fast algorithm (only set bg_col behind transp. pixels)
  * @param bitmask true=use bitmask, false=use translucent
  */
 public JGImage toDisplayCompatible(int thresh, JGColor bg_col, boolean fast, boolean bitmask) {
   Color bgcol = new Color(bg_col.r, bg_col.g, bg_col.b);
   int bgcol_rgb = (bgcol.getRed() << 16) | (bgcol.getGreen() << 8) | bgcol.getBlue();
   JGPoint size = getSize();
   int[] buffer = getPixels();
   // render image to bg depending on bgcol
   BufferedImage img_bg;
   if (bitmask) {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.BITMASK);
   } else {
     img_bg = createCompatibleImage(size.x, size.y, Transparency.TRANSLUCENT);
   }
   int[] bg_buf;
   if (!fast) {
     Graphics g = img_bg.getGraphics();
     g.setColor(bgcol);
     // the docs say I could use bgcol in the drawImage as an
     // equivalent to the following two lines, but this
     // doesn't handle translucency properly and is _slower_
     g.fillRect(0, 0, size.x, size.y);
     g.drawImage(img, 0, 0, null);
     bg_buf = new JREImage(img_bg).getPixels();
   } else {
     bg_buf = buffer;
   }
   // g.dispose();
   // ColorModel rgb_bitmask = ColorModel.getRGBdefault();
   // rgb_bitmask = new PackedColorModel(
   //		rgb_bitmask.getColorSpace(),25,0xff0000,0x00ff00,0x0000ff,
   //		0x1000000, false, Transparency.BITMASK, DataBuffer.TYPE_INT);
   //		ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean
   // isAlphaPremultiplied, int trans, int transferType)
   int[] thrsbuf = new int[size.x * size.y];
   for (int y = 0; y < size.y; y++) {
     for (int x = 0; x < size.x; x++) {
       if (((buffer[y * size.x + x] >> 24) & 0xff) >= thresh) {
         thrsbuf[y * size.x + x] = bg_buf[y * size.x + x] | (0xff << 24);
       } else {
         // explicitly set the colour of the transparent pixel.
         // This makes a difference when scaling!
         // thrsbuf[y*size.x+x]=bg_buf[y*size.x+x]&~(0xff<<24);
         thrsbuf[y * size.x + x] = bgcol_rgb;
       }
     }
   }
   return new JREImage(
       output_comp.createImage(
           new MemoryImageSource(
               size.x,
               size.y,
               // rgb_bitmask,
               img_bg.getColorModel(), // display compatible bitmask
               bitmask ? thrsbuf : bg_buf,
               0,
               size.x)));
 }
Beispiel #5
0
 public void paint(Graphics g) {
   if (comp != null) {
     width = comp.getWidth() / 6;
     height = comp.getHeight() * 2 / 3;
   }
   g.setColor(bgColor);
   g.fillRect(x, y, width, height);
   g.setColor(fgColor);
   g.setFont(font);
   g.drawString(strTray, x / 2 + width / 2, y + height + 10);
   super.paint(g);
 }
 private final void showpercent(String s, int i, int j) {
   Graphics g = getGraphics();
   Font font = new Font("Helvetica", 1, 13);
   FontMetrics fontmetrics = getFontMetrics(font);
   Font font1 = new Font("Helvetica", 0, 13);
   FontMetrics fontmetrics1 = getFontMetrics(font1);
   if (all || !img && mt.checkAll(true)) {
     all = false;
     if (img || mt.checkAll(true)) {
       g.drawImage(loading, 0, 0, this);
       img = true;
     } else {
       g.setColor(Color.black);
       g.fillRect(0, 0, 512, 344);
     }
     g.setColor(Color.white);
     g.setFont(font);
     String s1 = "RuneScape has been updated!";
     g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 125);
     s1 = "Please wait - Fetching new files...";
     g.drawString(s1, 256 - fontmetrics.stringWidth(s1) / 2, 140);
     g.setFont(font1);
     s1 = "This may take a few minutes, but only";
     g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 165);
     s1 = "needs to be done when the game is updated.";
     g.drawString(s1, 256 - fontmetrics1.stringWidth(s1) / 2, 180);
   }
   Color color = new Color(140, 17, 17);
   g.setColor(color);
   g.drawRect(104, 190, 304, 34);
   g.fillRect(106, 192, j * 3, 30);
   g.setColor(Color.black);
   g.fillRect(106 + j * 3, 192, 300 - j * 3, 30);
   String s2 = "Loading " + s + " - " + i + "%";
   g.setFont(font);
   g.setColor(Color.white);
   g.drawString(s2, 256 - fontmetrics.stringWidth(s2) / 2, 212);
 }
    public void paint(Graphics g) {
      g.setColor(getBackground());
      g.fillRect(0, 0, getWidth(), getHeight());

      for (int i = 0; i < numImages; i++) {
        if (x[i] > 3 * i) {
          nudge(i);
          squish(g, icon[i], xh[i], yh[i], scale[i]);
        } else {
          x[i] += .05;
          y[i] += .05;
        }
      }
    }
Beispiel #8
0
  public void paint(Graphics g) {
    Message("Copyright Feb, 2000 Weicon Conan Yuan.", "All Rights Reserved", 7);
    for (int i = 0; i < NUM_LOCATIONS; i++) {
      locs[i].draw(g, this);
      g.setColor(txtcolor);
      if (locs[i].ToDraw()) {
        g.drawString("" + i, locs[i].GetX(), locs[i].GetY() + 10);
      }
    }

    g.setColor(Color.red);
    g.drawRect(400, 200, 30, 30);
    g.fillRect(400, 200, 30, 30);
    Message("Cheat", 4);
  }
Beispiel #9
0
 public void paint(Graphics g) {
   g.setColor(this.getBackground());
   g.fillRect(0, 0, this.width, this.height);
   g.setColor(this.getForeground());
   g.drawImage(this.imLogo, 10, 40, this);
   g.setFont(this.fontTitle);
   g.drawString(this.appName, 70, 65);
   g.setFont(this.fontText);
   int startY = 130;
   int l = 6;
   for (int i = 0; i < textLines.length; ++i) {
     g.drawString(this.textLines[i], 10, startY);
     startY += 20;
   }
   if (str != null) g.drawString(str, 10, startY);
   g.drawImage(this.imHelp, 50, startY + 30, this);
 }
 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
Beispiel #11
0
  public void Message(String s, int i) {
    Graphics g = getGraphics();

    if (s == null) {
      g.setColor(bgcolor);
      g.drawRect(400, 50 * i - 10, 200, 10);
      g.fillRect(400, 50 * i - 10, 200, 10);
      return;
    }
    /*
      g.setColor(Color.blue);
      g.drawRect(400,50 * i - 10,200,10);
      g.fillRect(400,50 * i - 10,200,10);
    */
    g.setColor(txtcolor);
    g.drawString(s, 400, 50 * i);
  }
  private synchronized void render(Graphics g) {
    if (level != null) {
      int xScroll = (int) (player.pos.x - screen.w / 2);
      int yScroll = (int) (player.pos.y - (screen.h - 24) / 2);
      soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y);
      level.render(screen, xScroll, yScroll);
    }
    if (!menuStack.isEmpty()) {
      menuStack.peek().render(screen);
    }

    Font.draw(screen, "FPS: " + fps, 10, 10);
    // for (int p = 0; p < players.length; p++) {
    // if (players[p] != null) {
    // String msg = "P" + (p + 1) + ": " + players[p].getScore();
    // Font.draw(screen, msg, 320, screen.h - 24 + p * 8);
    // }
    // }
    if (player != null && menuStack.size() == 0) {
      Font.draw(screen, player.health + " / 10", 340, screen.h - 19);
      Font.draw(screen, "" + player.score, 340, screen.h - 33);
    }

    g.setColor(Color.BLACK);

    g.fillRect(0, 0, getWidth(), getHeight());
    g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
    g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);

    if (!menuStack.isEmpty() || level != null) {

      // render mouse
      renderMouse(screen, mouseButtons);

      g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null);
    }

    // String msg = "FPS: " + fps;
    // g.setColor(Color.LIGHT_GRAY);
    // g.drawString(msg, 11, 11);
    // g.setColor(Color.WHITE);
    // g.drawString(msg, 10, 10);

  }
Beispiel #13
0
 protected static void fillBG(Graphics g, int x, int y, Color c) {
   g.setColor(c);
   for (int i = 0; i < 2; i++) g.fillRect(FD[i][0] + x, FD[i][1] + y, FD[i][2], FD[i][3]);
 }
  /**
   * Paints the image.
   *
   * @param g the rendering surface to use
   * @param a the allocated region to render into
   * @see View#paint
   */
  public void paint(Graphics g, Shape a) {
    Color oldColor = g.getColor();
    fBounds = a.getBounds();
    int border = getBorder();
    int x = fBounds.x + border + getSpace(X_AXIS);
    int y = fBounds.y + border + getSpace(Y_AXIS);
    int width = fWidth;
    int height = fHeight;
    int sel = getSelectionState();

    // Make sure my Component is in the right place:
    /*
    if( fComponent == null ) {
    fComponent = new Component() { };
    fComponent.addMouseListener(this);
    fComponent.addMouseMotionListener(this);
    fComponent.setCursor(Cursor.getDefaultCursor());	// use arrow cursor
    fContainer.add(fComponent);
    }
    fComponent.setBounds(x,y,width,height);
    */
    // If no pixels yet, draw gray outline and icon:
    if (!hasPixels(this)) {
      g.setColor(Color.lightGray);
      g.drawRect(x, y, width - 1, height - 1);
      g.setColor(oldColor);
      loadIcons();
      Icon icon = fImage == null ? sMissingImageIcon : sPendingImageIcon;
      if (icon != null) icon.paintIcon(getContainer(), g, x, y);
    }

    // Draw image:
    if (fImage != null) {
      g.drawImage(fImage, x, y, width, height, this);
      // Use the following instead of g.drawImage when
      // BufferedImageGraphics2D.setXORMode is fixed (4158822).

      //  Use Xor mode when selected/highlighted.
      // ! Could darken image instead, but it would be more expensive.
      /*
      if( sel > 0 )
      g.setXORMode(Color.white);
      g.drawImage(fImage,x, y,
      width,height,this);
      if( sel > 0 )
      g.setPaintMode();
      */
    }

    // If selected exactly, we need a black border & grow-box:
    Color bc = getBorderColor();
    if (sel == 2) {
      // Make sure there's room for a border:
      int delta = 2 - border;
      if (delta > 0) {
        x += delta;
        y += delta;
        width -= delta << 1;
        height -= delta << 1;
        border = 2;
      }
      bc = null;
      g.setColor(Color.black);
      // Draw grow box:
      g.fillRect(x + width - 5, y + height - 5, 5, 5);
    }

    // Draw border:
    if (border > 0) {
      if (bc != null) g.setColor(bc);
      // Draw a thick rectangle:
      for (int i = 1; i <= border; i++)
        g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i);
      g.setColor(oldColor);
    }
  }