Window icon?

Started by Cowbox, November 30, 2012, 11:14:55 PM

Previous topic - Next topic

Cowbox

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>

EgonOlsen

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.


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();
   }

Cowbox

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.)

EgonOlsen

It's all standard Java...PixelGrabber is part of awt. I don't see a reason why you shouldn't have it available.

Cowbox

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. :)