Custom Style and problems with android keyboard

Hey,

I want to change my GUI (based on Nifty) to tonegodGUI. I’ve played a while with it and works really fine!! Good work.
However I’ve found some problems in the way.

My first aproach was to use the default button and change the images used by default. It works perfect on my pc but when I run it on android an error related to the android.Keyboard appears.
After looking in the AndroidGUITestApp I changed my screen initalization from this:
[java]screenToneGodGui = new Screen(this);[/java]

To this:
[java] screen = new Screen(this, “tonegod/gui/style/atlasdef/style_map.xml”);
screen.setUseTextureAtlas(true,“tonegod/gui/style/atlasdef/atlas.png”);
screen.setUseMultiTouch(true);
guiNode.addControl(screen);
screen.setUseKeyboardIcons(true);[/java]

And the android application runs fine but the image assoiated with the constructor doesn’t appear.

I used this constructor:
[/java] Button botonTTTRev = new Button(screenToneGodGui,
“Boton1”,
new Vector2f(screenSizeX/10.0f, screenSizeY/20.0f),
new Vector2f(screenSizeX/2.5f, screenSizeY/10.0f), new Vector4f(2, 2, 2, 2), “Interface/Boton.png”)
{ [java]

And I have noticed that the following exception appears:

The provided texture information does not conform to the expected standard of ?x=(int)&y=(int)&w=(int)&h=(int)
java.text.ParseException: The provided texture information does not conform to the expected standard of ?x=(int)&y=(int)&w=(int)&h=(int)
at tonegod.gui.core.Screen.throwParserException(Screen.java:418)
at tonegod.gui.core.Screen.parseAtlasCoords(Screen.java:411)
at tonegod.gui.core.Element.<init>(Element.java:233)
at tonegod.gui.controls.buttons.Button.<init>(Button.java:141)

What is wrong? I think I’m missing something. What steps should I follow to have a working tonegodGUI GUI on android and be able to change the style of the controls?

Thanks!

Since you are using texture atlases… you’ll want to do the following after adding the button using the default img:

[java]
Texture texThumb = screen.createNewTexture(“Interface/Boton.png”);
// Set the new atlas image for this button and the coords for the texture region for the default button image
someButton.setTextureAtlasImage(texThumb, “x=0|y=0|w=32|h=32”);
[/java]

Then to adjust the hover and pressed images, you simply call the standard setters and passing in the x, y, w, h like so:

[java]
// Uses the atlas image you provided above and sets the texture region for the hover state
someButton.setButtonHoverInfo(“x=0|y=0|w=100|h=50”, someColorRGBA);
// Uses the atlas image you provided above and sets the texture region for the pressed state
someButton.setButtonPressedInfo(“x=0|y=0|w=100|h=50”, someColorRGBA);
[/java]

Or simply clear the alt images if you don’t need them (like there is no hover state on Android)

[java]
someButton.clearAltImages();
[/java]

1 Like

Oh… there are also methods for specifically clearing just the hover or pressed state.

The other option is to specifically remove the effects for hover, etc like so:

[java]
someButton.removeEffect(Effect.EffectEvent.Hover);
someButton.removeEffect(Effect.EffectEvent.Press);
someButton.removeEffect(Effect.EffectEvent.GetFocus);
someButton.removeEffect(Effect.EffectEvent.LoseFocus);
[/java]

1 Like

Heh… I just realized I didn’t explain why you are seeing the error:

The simple (and only) version is:

When using a texture atlasing, all Elements assume you are using the default image provided by the screen and doesn’t recreate the texture each time… just shares it between elements. So, instead of providing image paths, you provide texture region coords in the form of a query string like this:

“x=10|y=30|w=50|h=50”

The library uses the pixel coords to determine the texCoords for sampling out of the atlas image. If you want to use another imahe, you have to set the new image using the method above.

Suggestions for keeping overhead down on Android:

  • Create a class that loads you atlas images into a HashMap or some such keyed List.
  • Always reuse the same image for each button (i.e. the new image should contain all states of the button, all potential icons you would want to use, etc, etc)
  • use myImgPool.getMyImage(someHashKey) to retrieve a pointer to the texture for each new button you add so you are not constantly creating new Textures with the same image.

This allows your app to load the texture once into GPU memory and just reference the loaded texture by the index of the Texture slot it is stored in for multiple objects being rendered.

Anyways, I hope this is helpful and not rehashing something you were already aware of! If so… sorry! And maybe others will find it useful =)

1 Like

Wow t0neg0d!!! That’s a lot of information. Thanks for your answer. It has been very helpful.
The last recomendations to keep overhead down on Android has been very helpful too.
I’m going to follow your advice for my new GUI!!!

1 Like
@galvez6000 said: Wow t0neg0d!!! That's a lot of information. Thanks for your answer. It has been very helpful. The last recomendations to keep overhead down on Android has been very helpful too. I'm going to follow your advice for my new GUI!!!

This is very helpful info for regular game objects as well. Especially for Android.

If your game allows for it, always create object pools to pull from and reuse them. One of the biggest issues on Android (and actually creates lag on desktop as well) is garbage collection. So… the optimal way to fix this problem is stop the GC from ever firing off =)

I’ll more than likely create a utility Pooling class + interface that will allow you to easily set up object pools for your game, be it GUI components or just regular game classes.

Should help people avoid frustration when developing for Android especially.