Author Topic: Window icon?  (Read 2577 times)

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Window icon?
« on: November 30, 2012, 11:14:55 pm »
Ok, this seems ridiculous. xD

There has to be a better way to get one tiny little picture, into the top left of the window.

I mean, that one with the 4 keys, and the blue circle got up there somehow.

Surely there's some quick trick I'm missing where I just put icon.ico or something next to the .jar and it goes "Aha! - I'll just use that!"

Or a method somewhere in a class for "setIcon". xD

I've searched high and low for icons, lwjgl, bytebuffers etc. - and none of it seems to help a great deal.

I got to the point where I had:
org.lwjgl.opengl.Display.setIcon(bufs);

And thought, "Ah! All I have to do, is load an image in as a bytebuffer!"

But that seems a monster of a task as well. xD

What can I do?

Surely there's a way to get an icon on the jPCT window, I mean, it's already gotten one from somewhere. :(

Either that, or some kind of handler for the window, that can then be manipulated?

D: <Stuck>

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Window icon?
« Reply #1 on: November 30, 2012, 11:24:34 pm »
jPCT doesn't offer a way to set this icon. However, converting an Image into a ByteBuffer isn't that hard. Basically, you grab the pixels and put them into the buffer. I did a quick copy-and-paste job with some old code for setting the mouse pointer. It should help to get you started.

Code: [Select]
private IntBuffer createBuffer(Image img) {
      int len=img.getHeight(null)*img.getWidth(null);
      ByteBuffer temp=ByteBuffer.allocateDirect(len<<2);;
      temp.order(ByteOrder.LITTLE_ENDIAN);

      int[] pixels=new int[len];

      PixelGrabber pg=new PixelGrabber(img, 0, 0, img.getWidth(null), img.getHeight(null), pixels, 0, img.getWidth(null));

      try {
         pg.grabPixels();
      } catch (InterruptedException e) {
         Logger.log("Could not grab pixels from image!", Logger.ERROR);
      }

      for (int i=0; i<len; i++) {
         int pos=i<<2;
         int texel=pixels[i];
         if (texel!=0) {
            texel|=0xff000000;
         }
         temp.putInt(pos, texel);
      }

      return temp.asIntBuffer();
   }

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Window icon?
« Reply #2 on: December 01, 2012, 12:07:52 am »
I found that snippet already and can't do anything with it. (I don't have a pixelgrabber, or some of the other things it's after.)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Window icon?
« Reply #3 on: December 01, 2012, 08:18:20 am »
It's all standard Java...PixelGrabber is part of awt. I don't see a reason why you shouldn't have it available.

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Window icon?
« Reply #4 on: December 01, 2012, 02:17:12 pm »
Oh! xD

I didn't realise it was in AWT. :D

I just didn't have AWT imported where I tried it.

I shall give it another shot in a bit. :)