TonegodGUI : How to attach and Image?

Hi there =D s. Im kinda new to JME, so, I’m also new to Tonegod’s library :stuck_out_tongue: Ive read almos everything in it’s wiki, and I couldn’t find the part of “Images”. To clarify, all I want to do is attach an Image (PNG in this case) to a Tonegod’s Window object…
This is probably a really stupid question, but I just don’t know how to work it out!
Thanks and sorry for my English!
And btw, JMonkey RLZ!!

@turco.chaia said: Hi there =D s. Im kinda new to JME, so, I'm also new to Tonegod's library :P Ive read almos everything in it's wiki, and I couldn't find the part of "Images". To clarify, all I want to do is attach an Image (PNG in this case) to a Tonegod's Window object.. This is probably a really stupid question, but I just don't know how to work it out! Thanks and sorry for my English! And btw, JMonkey RLZ!!

Out of curiosity, where in the window do you want the picture?

In the drag bar?
In the actual window area?
Or?
Also, it is important to know whether you plan on using separate images or texture atlases?

Every Element you create from the library has a visual component that you can set to anything you like. There is a constructor for setting in when you create the Element and there are methods for updating it after you create it.

For the time being, until I know where you want it… here is how you set the image of an element when you create it:

[java]
// This assumes that the entire image will scale and not use the nine-patch method of scaling
Element element = new Element(
screen, // Reference to the screen
UIDUtil.getUID(), // A random ID generator or any unique string you like
Vector2f.ZERO, // We’ll center the element after we attach it to a parent
new Vector2f(100,100), // A 100x100 pixel image
Vector4f.ZERO, // A non-nine-patch-ish scaling element
“PATH_TO_YOUR_IMAGE” // Here is where you define the image to use.
);
screen.addElement(element);
element.centerToParent();
[/java]

There are other controls you can use instead of element that have short-hand versions of the common constructor, but Element is usually my first choice for simple objects.

A couple things to keep in mind, to save on complexity, windows don’t have a separate area defined for content, you have to account for the drag bar height (win.getDragBarHeight()) when adding children… unless you define a content area yourself and add the children to the content area you create (of course).

Creating a second post to save formatting here…

To add elements to the windoww’s drag bar, you would:

[java]
win.getDragBar().addChild(someElement);
[/java]

You’ll have to push the title over if it is suppposed to be left justified:

[java]
// This should be done AFTER setting the title, as text elements are only created when needed.
win.getDragBar().getTextElement().setX(110);
[/java]

Nothing better than an answer from (tone)God itself. lol.
I can’t belive I didn’t see that before! Well actually I did read it, when I started with the lib, but didn’t expected the images part to be in the constructor.
I’m gonna be using an Image for now…
So, I’m planning to add this image to a Window, and I want a label with text on the image’s right. I should use an Element for the image?
And, what’s the syntaxt to set the image in XML Layout? and what’s the method to change it from Java?
Thank you really much mate. Great work you’ve done with this lib.

@turco.chaia said: Nothing better than an answer from (tone)God itself. lol. I can't belive I didn't see that before! Well actually I did read it, when I started with the lib, but didn't expected the images part to be in the constructor. I'm gonna be using an Image for now.. So, I'm planning to add this image to a Window, and I want a label with text on the image's right. I should use an Element for the image? And, what's the syntaxt to set the image in XML Layout? and what's the method to change it from Java? Thank you really much mate. Great work you've done with this lib.

The reason you probably didn’t notice it was most controls have simplified constructors and the first thing to go was the image portion as those are pulled from the style info when not defined and most controls use the same image (or image region) over and over again.

@rockfire has a method for dynamically changing the style info that looked really cool, but I’ve lost track of which thread he posted it in (hint, hint). I’d love to get this added to the library… if he could just point me at that thread one more time :wink:

EDIT: I should read better >.<

You can still call win.setWindowTitle(“Some title”);
Then add your image to the drag bar
Lastly, adjust the x coord of the dragbar title to offset it for the icon.

Ooops. forgot to tell you the XML info…

There should be an area defined as:

[java]
<images>
<property name=“defaultImg” type=“String” value=“tonegod/gui/style/def/Window/panel_x.png” />
</images>
[/java]

defaultImg will be the one your wanting to update. When using texture atlasing, the string is defined like this:

“x=0|y=0|w=100|h=100”

x - The x pixel the image region starts at
y - The y pixel the image region starts at
w = how many pixels the actual width of the region is
h = how many pixels the actual height of the region is

Great!! I was just posting to ask you that lol.
So, to change the defaultImg from Java i’d have to use the method from @rockfire ?
Thanks!

Oh! Hey!! Forgot to mention this.

You will likely want the dragbar to function even if they click on the icon. To do this, just set the following flag on your icon Element:

[java]
icon.setIgnoreMouse(true);
[/java]

@turco.chaia said: Great!! I was just posting to ask you that lol. So, to change the defaultImg from Java i'd have to use the method from @rockfire ? Thanks!

Nope… you can change this a few ways. Easiest is to call:

[java]
element.setColorMap(“NEW_PATH_TO_IMAGE”);
[/java]

EDIT: @rockfire added a method to completely update the sttyle information using another defined style (from xml) after the control is created. It was one of those forehead-slap moments… should have always been there, but I would have to be smart to have figured this out :wink:

@t0neg0d said: Oh! Hey!! Forgot to mention this.

You will likely want the dragbar to function even if they click on the icon. To do this, just set the following flag on your icon Element:

[java]
icon.setIgnoreMouse(true);
[/java]

Cool!! really cool!
Awww, I saw the mtehod setColorMap() but I just didnt’ expected it to set an image to an element! Maybe it’s becouse I’m spanish speaker.
Thank you very much for your help!! I really appreciate it!

1 Like