コード例 #1
0
 /**
  * Performs the native flip operation for the given target Component.
  *
  * <p>REMIND: we should really not get here because that would mean that a FLIP BufferStrategy has
  * been created, and one could only be created if accelerated pipeline is present but in some rare
  * (and transitional) cases it may happen that the accelerated graphics device may have a default
  * graphics configuraiton, so this is just a precaution.
  */
 public void flip(
     WComponentPeer peer,
     Component target,
     VolatileImage backBuffer,
     int x1,
     int y1,
     int x2,
     int y2,
     BufferCapabilities.FlipContents flipAction) {
   if (flipAction == BufferCapabilities.FlipContents.COPIED
       || flipAction == BufferCapabilities.FlipContents.UNDEFINED) {
     Graphics g = peer.getGraphics();
     try {
       g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
     } finally {
       g.dispose();
     }
   } else if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
     Graphics g = backBuffer.getGraphics();
     try {
       g.setColor(target.getBackground());
       g.fillRect(0, 0, backBuffer.getWidth(), backBuffer.getHeight());
     } finally {
       g.dispose();
     }
   }
   // the rest of the flip actions are not supported
 }
コード例 #2
0
 public void run() {
   // Run the animated solution over and over until the status
   // variable is set to TERMINATED.  When this happens, the
   // delay() method will throw an IllegalArgumentException
   // and the run() method will be terminated.
   try {
     while (true) {
       tower = null;
       if (OSC != null) {
         Graphics g = OSC.getGraphics();
         drawCurrentFrame(g);
         g.dispose();
       }
       repaint();
       delay(2000);
       synchronized (this) {
         tower = new int[3][10];
         for (int i = 0; i < 10; i++) tower[0][i] = 10 - i;
         towerHeight = new int[3];
         towerHeight[0] = 10;
         if (OSC != null) {
           Graphics g = OSC.getGraphics();
           drawCurrentFrame(g);
           g.dispose();
         }
         repaint();
         delay(2000);
       }
       solve(10, 0, 1, 2);
       delay(4000);
     }
   } catch (IllegalArgumentException e) {
   }
 }
コード例 #3
0
  /**
   * Repaints the whole component - either calls repaint() or performs an accelerated repaint
   * directly accessing component's Graphics.
   */
  public final void repaintDirtyAccel() {
    if (!isDirty()) return;
    //        if (bufferType != BUFFER_NONE && offscreenImage == null) return;

    if (!ACCEL_DISABLED && canDirectlyAccessGraphics()) {
      Graphics g = getGraphics();
      try {
        if (bufferType != BUFFER_NONE) { // Painting to an offscreen image
          Graphics offscreenGraphics = offscreenImage.getGraphics();
          try {
            paintComponent(offscreenGraphics, invalidOffscreenArea);
          } finally {
            offscreenGraphics.dispose();
          }
          g.drawImage(offscreenImage, 0, 0, null);
        } else { // Painting directly to the provided Graphics
          paintComponent(g, invalidOffscreenArea);
        }
        invalidOffscreenArea.setBounds(0, 0, 0, 0);
      } finally {
        g.dispose();
      }
    } else {
      repaintImpl(0, 0, getWidth(), getHeight());
    }
  }
コード例 #4
0
  /*
   * Updates the canvas
   */
  @Override
  public void update(Graphics g) {
    Graphics offgc;
    Image offscreen;

    offscreen = createImage(this.getWidth(), this.getHeight());
    offgc = offscreen.getGraphics();
    paint(offgc);
    g.drawImage(offscreen, 0, 0, this);
    g.dispose();
    offgc.dispose();
  };
コード例 #5
0
ファイル: Canvas.java プロジェクト: r0the/logisim
 protected void paintForeground(Graphics g) {
   CanvasModel cModel = this.model;
   CanvasTool tool = listener.getTool();
   if (cModel != null) {
     Graphics dup = g.create();
     cModel.paint(g, selection);
     dup.dispose();
   }
   if (tool != null) {
     Graphics dup = g.create();
     tool.draw(this, dup);
     dup.dispose();
   }
 }
コード例 #6
0
  /** Performs the native GLX flip operation for the given target Component. */
  @Override
  public void flip(
      X11ComponentPeer peer,
      Component target,
      VolatileImage xBackBuffer,
      int x1,
      int y1,
      int x2,
      int y2,
      BufferCapabilities.FlipContents flipAction) {
    if (flipAction == BufferCapabilities.FlipContents.COPIED) {
      SurfaceManager vsm = SurfaceManager.getManager(xBackBuffer);
      SurfaceData sd = vsm.getPrimarySurfaceData();

      if (sd instanceof GLXVSyncOffScreenSurfaceData) {
        GLXVSyncOffScreenSurfaceData vsd = (GLXVSyncOffScreenSurfaceData) sd;
        SurfaceData bbsd = vsd.getFlipSurface();
        Graphics2D bbg = new SunGraphics2D(bbsd, Color.black, Color.white, null);
        try {
          bbg.drawImage(xBackBuffer, 0, 0, null);
        } finally {
          bbg.dispose();
        }
      } else {
        Graphics g = peer.getGraphics();
        try {
          g.drawImage(xBackBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
        } finally {
          g.dispose();
        }
        return;
      }
    } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
      // not supported by GLX...
      return;
    }

    OGLSurfaceData.swapBuffers(peer.getContentWindow());

    if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
      Graphics g = xBackBuffer.getGraphics();
      try {
        g.setColor(target.getBackground());
        g.fillRect(0, 0, xBackBuffer.getWidth(), xBackBuffer.getHeight());
      } finally {
        g.dispose();
      }
    }
  }
コード例 #7
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.drawLine</code>. */
  public void drawLine(int x1, int y1, int x2, int y2) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Drawing line: from "
                  + pointToString(x1, y1)
                  + " to "
                  + pointToString(x2, y2));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawLine(x1, y1, x2, y2);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawLine(x1, y1, x2, y2);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawLine(x1, y1, x2, y2);
  }
コード例 #8
0
  public Icon getIcon(File f) {
    if (isDirLink(f)) {
      /* all of this nonsense is to get to the
      default file view */
      System.out.println("get icon for: " + f);
      JFileChooser chooser = new JFileChooser();
      ComponentUI ui = UIManager.getUI(chooser);
      System.out.println("got : " + ui);
      FileChooserUI fcui = (FileChooserUI) ui;
      fcui.installUI(chooser);
      FileView def = fcui.getFileView(chooser);

      // get the standard icon for a folder
      File tmp = new File("C:\\windows");
      Icon folder = def.getIcon(tmp);
      int w = folder.getIconWidth();
      int h = folder.getIconHeight();

      // create a buffered image the same size as the icon
      Image img = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics g = img.getGraphics();

      // draw the normal icon
      folder.paintIcon(chooser, g, 0, 0);
      Image shortcut = new ImageIcon("shortcut.png").getImage();
      g.drawImage(shortcut, 0, 0, null);
      g.dispose();
      return new ImageIcon(img);
    }
    return super.getIcon(f);
  }
コード例 #9
0
  private void initialise() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    backBuffer = worldMap.getGraphics();

    // Make the image buffer as large as could possibly be used (screensize)
    if (backBufferImage == null) {
      logger.debug(
          "Creating backBufferImage of dimensions "
              + toolkit.getScreenSize().width
              + ","
              + toolkit.getScreenSize().height
              + ".");
      backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height);
      backBuffer = backBufferImage.getGraphics();
    } else {
      backBufferImage.flush();
      backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height);
      backBuffer.dispose();
      backBuffer = backBufferImage.getGraphics();
    }

    setupWindow(worldMap.getWidth(), worldMap.getHeight());

    initialise = false;

    logger.debug(
        "initialised backBufferImage with size "
            + worldMap.getWidth()
            + ","
            + worldMap.getHeight()
            + ".");
  }
コード例 #10
0
  public void paint(Graphics g) {
    Graphics2D graficos = (Graphics2D) g;
    graficos.drawImage(fundo, 0, 0, null);

    if (emJogo) {
      graficos.drawImage(nave.getImagem(), nave.getX(), nave.getY(), this);

      List<Missel> misseis = nave.getMisseis();

      for (int i = 0; i < misseis.size(); i++) {
        Missel m = (Missel) misseis.get(i);
        graficos.drawImage(m.getImagem(), m.getX(), m.getY(), this);
      }

      for (int i = 0; i < inimigos.size(); i++) {
        Inimigo in = inimigos.get(i);
        graficos.drawImage(in.getImagem(), in.getX(), in.getY(), this);
      }

      graficos.setColor(Color.white);
      graficos.drawString("Inimigos: " + inimigos.size(), 5, 15);

    } else {
      ImageIcon fimJogo = new ImageIcon(Main.class.getResource("/res/game_over.jpg"));

      graficos.drawImage(fimJogo.getImage(), 0, 0, null);
    }
    g.dispose();
  }
コード例 #11
0
  @Test
  public void testTranslatedImage() {
    BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY);
    Graphics g = image.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(236, 236, 20, 20);
    g.setColor(new Color(80, 80, 80)); // A dark gray
    g.fillRect(216, 216, 20, 20);
    g.setColor(new Color(200, 200, 200)); // A light gray
    g.fillRect(216, 236, 20, 20);
    g.dispose();
    image = image.getSubimage(128, 128, 128, 128);
    CustomPaletteBuilder builder = new CustomPaletteBuilder(image, 256, 1, 1, 1);
    RenderedImage indexed = builder.buildPalette().getIndexedImage();
    assertTrue(indexed.getColorModel() instanceof IndexColorModel);
    IndexColorModel icm = (IndexColorModel) indexed.getColorModel();
    assertEquals(
        4,
        icm
            .getMapSize()); // Black background, white fill, light gray fill, dark gray fill = 4
                            // colors

    // check image not black
    ImageWorker iw = new ImageWorker(indexed).forceComponentColorModel().intensity();
    double[] mins = iw.getMinimums();
    double[] maxs = iw.getMaximums();
    boolean result = true;
    for (int i = 0; i < mins.length; i++) {
      result = mins[i] == maxs[i] ? false : result;
    }
    assertTrue(result);
  }
コード例 #12
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.fillArc</code>. */
  public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling arc: "
                  + new Rectangle(x, y, width, height)
                  + " startAngle: "
                  + startAngle
                  + " arcAngle: "
                  + arcAngle);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.fillArc(x, y, width, height, startAngle, arcAngle);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  }
コード例 #13
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.drawChars</code>. */
  public void drawChars(char data[], int offset, int length, int x, int y) {
    DebugGraphicsInfo info = info();

    Font font = graphics.getFont();

    if (debugLog()) {
      info().log(toShortString() + " Drawing chars at " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawChars(data, offset, length, x, y);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawChars(data, offset, length, x, y);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawChars(data, offset, length, x, y);
  }
コード例 #14
0
 /**
  * @param font where to get the descent
  * @return the descent of the font
  */
 private int getDescent(Font font) {
   Graphics g = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).createGraphics();
   g.setFont(font);
   int d = (int) (g.getFontMetrics().getDescent() + 0.99f);
   g.dispose();
   return d;
 }
コード例 #15
0
 public Image getScreenshot() {
   BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   Graphics g = image.getGraphics();
   paint(g);
   g.dispose();
   return image;
 }
コード例 #16
0
  private PageImage scale(double scaleFactor, int scaledDpi) {

    //	check size
    if (scaleFactor >= 1.0) return this;

    //	scale image
    BufferedImage scaled =
        new BufferedImage(
            ((int) (this.image.getWidth() * scaleFactor)),
            ((int) (this.image.getHeight() * scaleFactor)),
            BufferedImage.TYPE_INT_ARGB);
    Graphics g = scaled.getGraphics();
    g.drawImage(this.image, 0, 0, scaled.getWidth(), scaled.getHeight(), null);
    g.dispose();

    //	wrap and return scaled image
    return new PageImage(
        scaled,
        this.originalWidth,
        this.originalHeight,
        this.originalDpi,
        scaledDpi,
        ((int) Math.round(this.leftEdge * scaleFactor)),
        ((int) Math.round(this.rightEdge * scaleFactor)),
        ((int) Math.round(this.topEdge * scaleFactor)),
        ((int) Math.round(this.bottomEdge * scaleFactor)),
        this.source);
  }
コード例 #17
0
  private void btImprimirMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_btImprimirMouseClicked
    Dimension size = this.getSize();
    BufferedImage img = new BufferedImage(size.width, size.height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics g = img.getGraphics();
    this.paint(g);
    g.dispose();

    try {
      ImageIO.write(
          img,
          "png",
          new File(
              new JFileChooser().getFileSystemView().getDefaultDirectory().toString()
                  + "/factura"
                  + lbNumeroVenta.getText()
                  + ".png"));

      JOptionPane.showMessageDialog(
          rootPane,
          "La factura ha sido guardada con nombre /factura"
              + lbNumeroVenta.getText()
              + ".png en sus documentos");
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  } // GEN-LAST:event_btImprimirMouseClicked
コード例 #18
0
  /**
   * Calls <code>setBoundsForFrame</code> with the new values.
   *
   * @param f the component to be resized
   * @param newX the new x-coordinate
   * @param newY the new y-coordinate
   * @param newWidth the new width
   * @param newHeight the new height
   */
  public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {

    if (dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE) {
      setBoundsForFrame(f, newX, newY, newWidth, newHeight);
    } else {
      JDesktopPane desktopPane = getDesktopPane(f);
      if (desktopPane != null) {
        Graphics g = JComponent.safelyGetGraphics(desktopPane);

        g.setXORMode(Color.white);
        if (currentBounds != null) {
          g.drawRect(
              currentBounds.x, currentBounds.y, currentBounds.width - 1, currentBounds.height - 1);
        }
        g.drawRect(newX, newY, newWidth - 1, newHeight - 1);

        // Work around for 6635462, see comment in dragFrame()
        sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData();
        if (!sData.isSurfaceLost()) {
          currentBounds = new Rectangle(newX, newY, newWidth, newHeight);
        }

        g.setPaintMode();
        g.dispose();
      }
    }
  }
コード例 #19
0
  /**
   * Moves the visible location of the frame being dragged to the location specified. The means by
   * which this occurs can vary depending on the dragging algorithm being used. The actual logical
   * location of the frame might not change until <code>endDraggingFrame</code> is called.
   */
  public void dragFrame(JComponent f, int newX, int newY) {

    if (dragMode == OUTLINE_DRAG_MODE) {
      JDesktopPane desktopPane = getDesktopPane(f);
      if (desktopPane != null) {
        Graphics g = JComponent.safelyGetGraphics(desktopPane);

        g.setXORMode(Color.white);
        if (currentLoc != null) {
          g.drawRect(currentLoc.x, currentLoc.y, f.getWidth() - 1, f.getHeight() - 1);
        }
        g.drawRect(newX, newY, f.getWidth() - 1, f.getHeight() - 1);
        /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
         * Swing doesn't expect that its XOR drawRect did
         * not complete, so believes that on re-entering at
         * the next update location, that there is an XOR rect
         * to draw out at "currentLoc". But in fact
         * it's now got a new clean surface without that rect,
         * so drawing it "out" in fact draws it on, leaving garbage.
         * So only update/set currentLoc if the draw completed.
         */
        sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData();

        if (!sData.isSurfaceLost()) {
          currentLoc = new Point(newX, newY);
        }
        g.dispose();
      }
    } else if (dragMode == FASTER_DRAG_MODE) {
      dragFrameFaster(f, newX, newY);
    } else {
      setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
    }
  }
コード例 #20
0
  public static Image getScaledInstance(File file) throws Exception {
    srcBImage = javax.imageio.ImageIO.read(file);

    if (srcBImage.getWidth() > srcBImage.getHeight()) {
      width = 100;
      height = (srcBImage.getHeight() * 100) / srcBImage.getWidth();
    } else {
      height = 100;
      width = (srcBImage.getWidth() * 100) / srcBImage.getHeight();
    }

    dest = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    dest2 = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

    g = dest.getGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, 100, 100);
    g.drawImage(srcBImage, 0, 0, width, height, null);

    g.dispose();
    srcBImage = null;
    blurOperator.filter(dest, dest2);

    return dest2;
  }
コード例 #21
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.fill3DRect</code>. */
  public void fill3DRect(int x, int y, int width, int height, boolean raised) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling 3D rect: "
                  + new Rectangle(x, y, width, height)
                  + " Raised bezel: "
                  + raised);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fill3DRect(x, y, width, height, raised);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.fill3DRect(x, y, width, height, raised);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fill3DRect(x, y, width, height, raised);
  }
コード例 #22
0
  public static ImageIcon getBigSystemIcon(Image image) throws Exception {
    if ((image.getWidth(null) < 20) || (image.getHeight(null) < 20)) {
      if (image.getWidth(null) > image.getHeight(null)) {
        width = 24;
        height = (image.getHeight(null) * 24) / image.getWidth(null);
      } else {
        height = 24;
        width = (image.getWidth(null) * 24) / image.getHeight(null);
      }
    } else {
      return new ImageIcon(image);
    }

    dest = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    dest2 = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

    g = dest.getGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, 22, 22);
    g.drawImage(image, 0, 0, width, height, null);

    g.dispose();

    sharpenOperator.filter(dest, dest2);

    return new ImageIcon(dest);
  }
コード例 #23
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.drawOval</code>. */
  public void drawOval(int x, int y, int width, int height) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Drawing oval: " + new Rectangle(x, y, width, height));
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawOval(x, y, width, height);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawOval(x, y, width, height);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawOval(x, y, width, height);
  }
コード例 #24
0
ファイル: Game.java プロジェクト: RyanImperiun/AcreageRedux
  public void render() {
    BufferStrategy bs = getBufferStrategy();

    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    Graphics g = bs.getDrawGraphics();

    g.drawImage(image, 0, 0, getWidth(), getHeight(), this);

    level.renderLevel(g);
    getPlayer().render(g);
    getInv().render(g);

    if (showDebug) debug.render(g);

    g.setColor(Color.WHITE);
    g.fillRect(103, 0, 160, 33);
    g.drawImage(getRes().toolMap, 103, 0, this);
    g.setColor(Color.BLACK);
    g.drawRect((Player.toolSelected * 32) + 71, 0, 32, 32);
    // Draw tool selected at mouse location
    g.drawImage(getRes().tools[Player.toolSelected - 1], mouseP.x, mouseP.y, this);

    g.dispose();
    bs.show();
  }
コード例 #25
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.drawString</code>. */
  public void drawString(AttributedCharacterIterator iterator, int x, int y) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Drawing text: \"" + iterator + "\" at: " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawString(iterator, x, y);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawString(iterator, x, y);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawString(iterator, x, y);
  }
コード例 #26
0
ファイル: Game.java プロジェクト: blooregard/Java2DGame
  public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    int xOffset = player.x - (screen.width / 2);
    int yOffset = player.y - (screen.height / 2);

    level.renderTiles(screen, xOffset, yOffset);
    level.renderEntities(screen);
    level.cleanUp();
    screen.renderHud();

    for (int y = 0; y < screen.height; y++) {
      for (int x = 0; x < screen.width; x++) {
        int colorCode = screen.pixels[x + y * screen.width];
        if (colorCode < 255) pixels[x + y * WIDTH] = colors[colorCode];
      }
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);

    g.dispose();
    bs.show();
  }
コード例 #27
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.drawImage</code>. */
  public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawImage(img, x, y, observer);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      int i, count = (info.flashCount * 2) - 1;
      ImageProducer oldProducer = img.getSource();
      ImageProducer newProducer =
          new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
      Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
      DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();

      Image imageToDraw;
      for (i = 0; i < count; i++) {
        imageToDraw = (i % 2) == 0 ? newImage : img;
        loadImage(imageToDraw);
        graphics.drawImage(imageToDraw, x, y, imageObserver);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
    }
    return graphics.drawImage(img, x, y, observer);
  }
コード例 #28
0
  public void paint(Graphics g) {
    if (scale == 0.0f) getScaledImages();
    double rollRad = roll * Math.PI / 180;
    // Center of Horizon Image
    Point ptRotation = new Point(125, 360);
    // Center of Instrument
    Point ptCenter = new Point(150, 150);
    // Modified Center of Rotation
    Point ptModRot = new Point(ptCenter.x - 2 * ptRotation.x, ptCenter.y - 2 * ptRotation.y);
    Graphics2D g2d = (Graphics2D) g;

    // Set bounds
    g2d.setClip(
        0,
        0,
        (int) (attitudeBackground.getWidth(null)),
        (int) (attitudeBackground.getHeight(null)));
    RotateAndTranslate(g2d, attitudeSky, rollRad, 0.0, ptModRot, 4 * pitch, ptRotation, scale);
    g2d.drawImage(
        attitudeMarker,
        Math.round(
            (float)
                ((0.5 * attitudeBackground.getWidth(null) - 0.5 * attitudeMarker.getWidth(null)))),
        Math.round(
            (float)
                ((0.5 * attitudeBackground.getHeight(null)
                    - 0.5 * attitudeMarker.getHeight(null)))),
        Math.round(attitudeMarker.getWidth(null)),
        Math.round(attitudeMarker.getHeight(null)),
        null);

    g2d.dispose();
    g.dispose();
  }
コード例 #29
0
ファイル: NongFrame.java プロジェクト: lekro/Nong
  /** Draws the lines and ball. */
  public void drawScreen() {
    BufferStrategy bf = this.getBufferStrategy();
    Graphics g = null;
    try {
      g = bf.getDrawGraphics();

      g.setColor(Color.black);
      g.fillRect(0, 0, getWidth(), getHeight());

      g.setColor(Color.GREEN);

      g.drawOval(ballX, ballY, Ball.RADIUS * 2, Ball.RADIUS * 2);

      for (int i = 0; i < lines.size(); i++) {
        Line x = lines.get(i);
        g.drawLine(x.x1, x.y1, x.x2, x.y2);
      }
    } finally {
      g.dispose();
    }

    bf.show();

    Toolkit.getDefaultToolkit().sync();
  }
コード例 #30
0
ファイル: QRCodeUtil.java プロジェクト: phantom2012/java
 /**
  * 插入LOGO
  *
  * @param source 二维码图片
  * @param imgPath LOGO图片地址
  * @param needCompress 是否压缩
  * @throws Exception
  */
 private static void insertImage(BufferedImage source, String imgPath, boolean needCompress)
     throws Exception {
   File file = new File(imgPath);
   if (!file.exists()) {
     System.err.println("" + imgPath + " 该文件不存在!");
     return;
   }
   Image src = ImageIO.read(new File(imgPath));
   int width = src.getWidth(null);
   int height = src.getHeight(null);
   if (needCompress) { // 压缩LOGO
     if (width > WIDTH) {
       width = WIDTH;
     }
     if (height > HEIGHT) {
       height = HEIGHT;
     }
     Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH);
     BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     Graphics g = tag.getGraphics();
     g.drawImage(image, 0, 0, null); // 绘制缩小后的图
     g.dispose();
     src = image;
   }
   // 插入LOGO
   Graphics2D graph = source.createGraphics();
   int x = (QRCODE_WIDTH - width) / 2;
   int y = (QRCODE_HEIGHT - height) / 2;
   graph.drawImage(src, x, y, width, height, null);
   Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
   graph.setStroke(new BasicStroke(3f));
   graph.draw(shape);
   graph.dispose();
 }