Exemple #1
0
  /**
   * Sets one or more icons for the Display.
   *
   * <ul>
   *   <li>On Windows you should supply at least one 16x16 icon and one 32x32.
   *   <li>Linux (and similar platforms) expect one 32x32 icon.
   *   <li>Mac OS X should be supplied one 128x128 icon
   * </ul>
   *
   * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any
   * conversions nescesarry for the specific platform.
   *
   * @param icons Array of icons in RGBA mode
   * @return number of icons used.
   */
  public int setIcon(ByteBuffer[] icons) {
    boolean done_small = false;
    boolean done_large = false;
    int used = 0;

    int small_icon_size = 16;
    int large_icon_size = 32;
    for (ByteBuffer icon : icons) {
      int size = icon.limit() / 4;

      if ((((int) Math.sqrt(size)) == small_icon_size) && (!done_small)) {
        long small_new_icon = createIcon(small_icon_size, small_icon_size, icon.asIntBuffer());
        sendMessage(hwnd, WM_SETICON, ICON_SMALL, small_new_icon);
        freeSmallIcon();
        small_icon = small_new_icon;
        used++;
        done_small = true;
      }
      if ((((int) Math.sqrt(size)) == large_icon_size) && (!done_large)) {
        long large_new_icon = createIcon(large_icon_size, large_icon_size, icon.asIntBuffer());
        sendMessage(hwnd, WM_SETICON, ICON_BIG, large_new_icon);
        freeLargeIcon();
        large_icon = large_new_icon;
        used++;
        done_large = true;

        // Problem: The taskbar icon won't update until Windows sends a WM_GETICON to our window
        // proc and we reply. But this method is usually called
        // on init and it might take a while before the next call to nUpdate (because of resources
        // being loaded, etc). So we wait for the next
        // WM_GETICON message (usually received about 100ms after WM_SETICON) to make sure the
        // taskbar icon has updated before we return to the user.
        // (We wouldn't need to do this if the event loop was running continuously on its own
        // thread.)
        iconsLoaded = false;

        // Track how long the wait takes and give up at 500ms, just in case.
        long time = System.nanoTime();
        long MAX_WAIT = 500L * 1000L * 1000L;
        while (true) {
          nUpdate();
          if (iconsLoaded || MAX_WAIT < System.nanoTime() - time) break;

          Thread.yield();
        }
      }
    }

    return used;
  }
Exemple #2
0
 /**
  * Copy ARGB pixels to a ByteBuffer without changing the ARGB byte order. If used to make a
  * texture, the pixel format is GL12.GL_BGRA. With this format we can leave pixels in ARGB order
  * (faster), but unfortunately I had problems building mipmaps in BGRA format
  * (GLU.gluBuild2DMipmaps() did not recognize GL_UNSIGNED_INT_8_8_8_8 and
  * GL_UNSIGNED_INT_8_8_8_8_REV types so screwed up the BGRA/ARGB byte order on Mac).
  *
  * @return ByteBuffer
  */
 public static ByteBuffer convertImagePixelsARGB(
     int[] jpixels, int imgw, int imgh, boolean flipVertically) {
   // flip Y axis
   if (flipVertically) {
     jpixels = flipPixels(jpixels, imgw, imgh); // flip Y axis
   }
   // put int pixels into Byte Buffer
   ByteBuffer bb = GLApp.allocBytes(jpixels.length * 4); // 4 bytes per pixel
   bb.asIntBuffer().put(jpixels);
   return bb;
 }
  private void readPalette() {
    RandomAccessFile rIn = null;
    ByteBuffer buf = null;
    int i;
    try {
      if (paletteFile != null) {
        // see if the file exists, if not, set it to the default palette.
        File file = new File(paletteFile);

        numPaletteEntries = (int) (file.length() / 4);

        buf = ByteBuffer.allocate(numPaletteEntries * 4);

        rIn = new RandomAccessFile(paletteFile, "r");

        FileChannel inChannel = rIn.getChannel();

        inChannel.position(0);
        inChannel.read(buf);

        // Check the byte order.
        buf.order(ByteOrder.LITTLE_ENDIAN);

        buf.rewind();
        IntBuffer ib = buf.asIntBuffer();
        paletteData = new int[numPaletteEntries];
        ib.get(paletteData);
        ib = null;
      }

    } catch (Exception e) {
      System.err.println("Caught exception: " + e.toString());
      System.err.println(e.getStackTrace());
    } finally {
      if (rIn != null) {
        try {
          rIn.close();
        } catch (Exception e) {
        }
      }
    }
  }