Giter Site home page Giter Site logo

nifty-gui / nifty-gui Goto Github PK

View Code? Open in Web Editor NEW
244.0 244.0 78.0 65.52 MB

Your Open Source Java OpenGL GUI. Interactive user interfaces for games or similar applications. LWJGL, JOGL, JME or Java2d rendering.

Home Page: http://nifty-gui.github.io/nifty-gui/

License: Other

Java 98.34% HTML 0.73% GLSL 0.02% Processing 0.91%

nifty-gui's Introduction

Nifty GUI

Please see this comment #474 (comment) for the current state of this project.

Nifty is available in the Maven central:

<groupId>com.github.nifty-gui</groupId>
<artifactId>nifty</artifactId>
<version>1.4.3</version>

To use SNAPSHOT builds of Nifty you'll still need to add the Sonatype snapshots repositories to your pom.xml.

  <repositories>
    <!-- only needed for snapshot builds starting with 1.4.4-SNAPSHOT -->
    <repository>
      <id>ossrh</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
    </repository>
  </repositories>

Stories in Ready

Throughput Graph

nifty-gui's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nifty-gui's Issues

Events being sent twice

I have a custom control which publishes an event when clicked on. The same event is being caught in a different control.
The event publishing and catching works fine. When I put my control inside a window it initially works fine as well.
However, once I drag the window and after that I click on my custom control again, the same event is suddenly being caught twice. The control catching the event is inside the window as well.

If the problem cannot be reproduced, I can provide the full code.

de.lessvoid.nifty.batch.spi not in 1.4

Which means I had to revert to using 1.3 because a library I'm using started calling that interface, forcing me to backport the various fixes I submitted for 1.4 to keep my application running :-(
And guess what, 1.3 initializes things in a different order and now I'm getting NPEs because the element member isn't initialized in time. And I don't know what change influenced that.
This all just threw me back by a week. Can't say I'm happy about that.

Optimize sending of events when changing constraints

When you change constraints using methods like element.setConstraintWidth() this will directly publish an event on the eventbus.

This has two problems:

  1. The change will be applied when you call the layoutElements() method of the parent. It is not immediately active and therefore publishing the event directly is slightly wrong.
  2. When we change multiple constraints every call will publish an event on the eventbus!

A better way would be to not directly publish an event but instead remember that the constraints have changed and publish the event later when the element is being layed out.

Scrollbars never reach their worldMax

Hi! Just got into nifty and so far I like it alot!
I've noticed today that the stand-alone scrollbars are somewhat broken.

I did a trace on their values during various user input tests, and i've noticed that
the maximum value they can reach is clipped to worldMax - worldPageSize
Eg.

<control id="surfaceScrollX" worldPageSize="10.0" name="horizontalScrollbar" valign="bottom" align="left" width="95%" height="24px">

This scrollbar can never reach a value of 100.0 (default maxWorld)
It gets clamped to 90.0;
If I were to change worldPageSize to 1.0 then it progresses to 99.0

I first encountered this behaviour when i was using scrollbars configured to run from 0-1.0 ,
had the exact behaviour, the value never went above 0.9 until i tweaked worldPageSize to 0.01 and now it goes to
0.99

I haven't had time yet to address this issue in my own software, will check it out later.

renderStrategy is not in 1.3 xsd?

When using imageMode="resize" with the nine-part border thingy, I see messages in the log that the property was converted to renderStrategy="nine-part". So I went and made that change manually in the XML, and while it works fine, my validation fails because renderStrategy isn't part of the 1.3 XSD, even though it's supported. So when will it become a part of the schema?

RFE: Support for Double-Click/Pointing at

Currently the Nifty-GUI only supports single mouse clicks, but it lacks the support for double clicks. So in case the user clicks twice on a location the single click function should not be executed, but the one for double clicks should be executed.

Furthermore it would be handy to have a pointing at functionality that is triggered one the user stops the mouse cursor on top of a element. This does only trigger in case the mouse cursor stops on the element, unlike the hover function that triggers already in case the mouse cursor moves over the new element.

NiftyEvent does not need to be generic

Things that point in that direction:

  • NiftyEvent itself does not use T
  • 90% of subclasses fill in a dummy type or have @SuppressWarnings("rawtypes")
  • The few classes that actually use their parameter can just introduce a T

E.g. DropDownSelectionChangedEvent could be generic even if NiftyEvent is non-generic.

Making NiftyEvent non-generic would solve these problems.

Downside: You can't do "implements NiftyEvent" anymore, this needs to be replaced with "implements NiftyEvent".
This is not a problem inside Nifty itself, and the change is trivial anyway.
It would require adaptation in any client code that creates subclasses of NiftyEvent. The changes would still be trivial but would need to be done.
I'm not sure whether that's acceptable or not. It's certainly an incompatible change, i.e. it should not be applied to 1.3.

making a layer visible form the popup menu doesn't work right

I have a setup where I want to make a layer visible when clicking an item in a popup menu. While the layer becomes visible, no mouse events are being processed. It seems like the popup layer is somehow still blocking the mouse events. Even though the popup layer has been closed.

No Textures Displaying

I'm using Eclipse IDE with nifty 1.3.2, with nifty integrated into my own render engine (uses LWJGL).

Everything seems to be working fine, except textures. Backgrounds, icons, etc are just blank white boxes. No warnings or errors have been reported by the logger.

Examples in the nifty example library have worked fine, displaying texture.

Any suggestions on where to look to solve this issue?

Here are the OpenGL states I use for 3D rendering and 2D nifty rendering respectively:

public void set3DRenderStates(){

shaderModule.enableShader();   //Enable Vert, Geo, and Frag shaders

    GL11.glViewport(0, 0, 1024, 768);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    Project.gluPerspective(45.0f,1024.0f/768.0f,0.1f,-500.0f);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    GL11.glShadeModel(GL11.GL_SMOOTH); //GL_SMOOTH GL_FLAT
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glCullFace(GL11.GL_BACK);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glFrontFace(GL11.GL_CCW);  //default is GL_CCW
GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_LIGHTING);

    //Lighting Values
    FloatBuffer globalAmbient = BufferUtils.createFloatBuffer(4).put(new float [] {0.3f, 0.3f, 0.3f, 1.0f});

    //Flip buffer
    globalAmbient.flip();

    //Global Ambient Light Level
    GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, globalAmbient);
    GL11.glLightModeli(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, GL11.GL_TRUE);

    GL11.glEnable(GL11.GL_TEXTURE_2D);   
GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_MIN_FILTER,GL11.GL_LINEAR);     // Linear Texture Filtering
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_MAG_FILTER,GL11.GL_LINEAR);     // Linear Texture Filtering

    GL11.glDisable(GL11.GL_TEXTURE_2D); 
}

public void set2DRenderStates(){

shaderModule.disableShader();   //Disable Vert, Geo, and Frag shaders

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 1024,768, 0, -1, 1);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_NOTEQUAL, 0);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
}

Why would loading a screen break existing textures?

Loading an XML file seems to break the rendering of my scene.

The scene renders fine w/no screens loaded:

Screenshot_2_12_13_3_03_PM

But by adding:

nifty.fromXml("guis/HUD.xml", "hud");

I get mangled textures:

Screenshot_2_12_13_3_04_PM

The only thing that is changed is the line above is commented in or out. Note that the HUD screen does load and loads its fonts correctly. I'm using LWJGL for rendering.

Any ideas?

Nifty 1.3.0 suppressess exceptions

The NIfty GUI doesn't pass the exceptions thrown in client code. It seem the library is "eating" all errors and exceptions and there is no way to terminate an application by throwing an exception.
I can't see stack trace of my errors, and simply things that are supposed to be responded by user interaction are caught by NGUI and nothing happens.
Is there any solution to this?

remove recursive call in Element.setVisible() method (#27 on sourceforge)

Moved from sf.net bugtracker to github issues. Base is -> http://sourceforge.net/p/nifty-gui/bugs/27/


https://sourceforge.net/projects/nifty-gui/forums/forum/807892/topic/4478259

Recursive call in setVisible()/setFocusable() may incur unexpected results to element hierarchy.
Let's say, element A has B1, B2, B3, B4, C as children.
user want to show B1, B2, B3, B4 but not C.
C is shown only for a specific situation.
In such situation, user have to call setVisible(true) for each B*.
It's not only inconvenient but also weird.

I think setting some value to parent element should not change child element properties.

I changed the setVisible()/isVisble() code and confirms it works well on AllExamplesMain.
But setFocusable() doesn't work. I don't know why.
So I attach the setVisible() fix only.


why do you think that this is a bug?

if you hide element x then all child elements of element x (as well as all child elements of all child elements and so on) will be hidden too. this is intended behaviour.

and this is not a trivial issue to solve for all cases. your patch breaks some unit tests too.

it "might" be possible to change this but this will be more involving. first of all nifty does currently not check the visibility related to the parent elements (your patch does this but not for all checks - just check how many code lines access the plain visible flag at the element level without checking the parents visibility state).

being very close to 1.3 and being not convinced that this is a bug I don't think I'd like to change this - al least not now.


I agree it is not appropriate to fix this because it is about to release 1.3.
It is not important when this patch is applied. But I think it should be applied even later.
This feature will make it very difficult to handle nifty ui.
When someone has a complex UI hierarchy and the visibility is changed often,
it makes the nifty ui management catastropic.
I experienced this situation from my current project so I'm convinced. :(

Change the NiftyInputEvent enum into an Interface

A NiftyInputMapping converts a physical KeyboardInputEvent into a device independent NiftyInputEvent.

public interface NiftyInputMapping {
/**
* Convert the given KeyboardInputEvent into a NiftyInputEvent.
* @param inputEvent KeyboardInputEvent to convert
* @return converted NiftInputEvent
*/
NiftyInputEvent convert(KeyboardInputEvent inputEvent);
}

That's pretty cool but unfortunately the NiftyInputEvent is an enum. This means that the set of NiftyInputEvents that can be generated is limited by the NiftyInputEvent enumeration. You can't have your own own NiftyInputEvent!

A better approach would be to change the NiftyInputEvent into an enumeration (a possible solution would be "Item 34: Emulate extensible enums with interface" in josh blochs book "effective java, second edition")

Clean up logging and especially use INFO much less often

I've counted about 80 positions in Nifty where LogLevel INFO is used and I guess most of them don't actually qualify for this LogLevel.

According to the jdk14 specification for INFO:

So the INFO level should only be used for reasonably significant messages that will make sense to end users and system administrators.

most of Niftys INFO messages don't qualify for this and should better use FINE.

Actually it would be best to check all logging for Nifty 1.4!

Crash-To-Desktop from Nifty Text Control

If you copy text containing newlines (for example \n123\n) into a text field control and then try to select text (for example shift then left arrow) nifty crashes with the following stack trace:

ErrMsg: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 14
at java.lang.String.substring(Unknown Source)
at
de.lessvoid.nifty.render.NiftyRenderEngineImpl.renderSelectionText(NiftyRenderEngineImpl.java:323)
at de.lessvoid.nifty.render.NiftyRenderEngineImpl.renderText(NiftyRenderEngineImpl.java:266)
at de.lessvoid.nifty.elements.render.TextRenderer.renderLine(TextRenderer.java:302)
at de.lessvoid.nifty.elements.render.TextRenderer.renderLines(TextRenderer.java:201)
at de.lessvoid.nifty.elements.render.TextRenderer.render(TextRenderer.java:182)
at de.lessvoid.nifty.elements.Element.renderElement(Element.java:734)
at de.lessvoid.nifty.elements.Element.render(Element.java:719)
at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:741)
at de.lessvoid.nifty.elements.Element.render(Element.java:722)
at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
at de.lessvoid.nifty.elements.Element.render(Element.java:722)
at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
at de.lessvoid.nifty.elements.Element.render(Element.java:713)
at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
at de.lessvoid.nifty.elements.Element.render(Element.java:713)
at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
at de.lessvoid.nifty.elements.Element.render(Element.java:722)
at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
at de.lessvoid.nifty.elements.Element.render(Element.java:713)
at de.lessvoid.nifty.screen.Screen.renderLayers(Screen.java:314)
at de.lessvoid.nifty.Nifty.render(Nifty.java:321)
at com.jme3.niftygui.NiftyJmeDisplay.postQueue(NiftyJmeDisplay.java:178)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:979)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1035)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Unknown Source)

For now as a work-around I’ve attached a filter to all the controls where it’s likely to happen, I had a look in the text field control code itself and wasn’t sure where the best place to fix it was, although the most likely place I saw was in

private boolean filterAndInsert(final CharSequence chars) {

My work-around filter is as simple as this:

private final TextFieldInputCharFilter textFieldFilter = new TextFieldInputCharFilter() {

    public boolean acceptInput(int i, char c) {
        return c != ‘\n’ && c != ‘\r’;
    }
};

Although I have to manually apply that to every text field.

It seems to me two separate fixes are needed here, one to prevent the crash on selection if newline is present and then another to prevent newlines being pasted into a text field control in the first place...

DSLification

I'm currently preparing a pull request that has modified *Builder classes that allow stuff like
new ButtonBuilder().widthPx(102).text("Cancel").build(nifty, screenId, parent)
Existing classes still have an identical API, with the following exceptions:

  • All builders have a parameterless constructor now, so people can do new ButtonBuilder().id("someId"). This allows using builder-creating functions to generate a control template that can have its id filled in by the caller, i.e. it decouples builder construction from id assignment. (It also plays better with frameworks that use reflection, though I don't have a use case for that.)
  • The build() functions return the control created. I.e. ButtonBuilder#build() returns a Button, etc. The obvious exceptions being LayerBuilder, PanelBuilder etc, which return just the Element.
  • Possibly remaining silly mistakes.

I'd be happy to hear what you think about that.

I also have some further plans and would appreciate feedback:

  1. I'd like to make a build(parent) function that picks up the Nifty and the screenId from parent. For that purpose, would it be okay to add a getScreen() to Element, and a getNifty() to screen?
  2. I'd like to make onShow(), onClick(), ..., etc. functions in ElementBuilder and subclasses. The parameter should be something executable (i.e. a Runnable or an EventTopicSubscriber). This would allow writing DSL code like this (not tested):
Panel parent = ... .build();
TextField characterName = new TextFieldBuilder(). ... .build(parent);
Button button =
  new ButtonBuilder().widthPx(150).text("OK").onClick(
    new Runnable(){public void run() {
      gameCharacter.setName(characterName.getRealText());
    }}
  ).build(parent);

What's the best API that the onXxx routines should use? Set up an EventTopicSubscriber (that would have to be postponed until build() time I guess), or is that already available somewhere? I have seen the interactOnXxx functions, but Strings can contain typos and aren't properly updated during refactoring, so I don't want to use these.

MouseMoved/Hover broken in JoglInputSystem

I was playing around with some effects late night and noticed that the hover effect didn't act on mouse-hover but on mouse-click.
I ended up tracing the mouse hover and mouse moved events and realized that they're not sent as they should be.

As of writing no mouse events are delegated to nifty unless mousebutton 1 is down in the JoglInputSystem.
Having had a quick peek at the source I figured it's line 53 that prevents plain mouse movement events
to reach Nifty unless mouse button 1 is down.

I've noticed that there is a commit that explicitly adds that behaviour to the MouseMoved handler:
Commit 894a8195

Could it be a bug in that commit or will MouseDragged gestures break if the If-case were to be omitted?
I'll check it out later this evening.

Nested control styles

When nested controls come in combination with substyles, they either do not work as expected or I am misunderstanding it.
The matter is that I have this controlDefinition (for clarity I'll focus on the important parts):

<controlDefinition name="intField" defaultFocusElement="textField" controller="controls.IntField">
    <panel childLayout="horizontal">
      <control id="textField" name="textfield" style="#textField" />
    </panel>
</controlDefinition>

So I use that controlDefinition in my main .xml like

<control name="intField" id="someId" style="my-intfield" />

The corresponding style xml is:

<style id="my-intfield#textField" base="my-textfield" />

And for completeness, the my-textfield:

<nifty-styles xmlns="http://nifty-gui.sourceforge.net/nifty-styles-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-styles-1.3.xsd http://nifty-gui.sourceforge.net/nifty-styles-1.3.xsd">
  <registerMouseCursor id="textFieldCursor" filename="main/data/interface/nifty/my-style/textfield/mouse-cursor-textfield.png" hotspotX="3" hotspotY="12"/>

  <!-- the background of the textfield -->
  <style id="my-textfield#panel">
    <attributes childLayout="overlay" height="23px" />
    <effect>
      <onHover name="changeMouseCursor" id="textFieldCursor" />
      <onHover name="border" color="#822f" post="true" />
    </effect>
  </style>

  <!-- the actual input field -->
  <style id="my-textfield#field">
    <attributes childLayout="center" childClip="true" backgroundColor="#666f" padding="0px,2px"/>
    <effect>
      <onActive name="border" color="#222f" post="true" inset="1px" />
      <onFocus name="colorBar" color="#080f" post="true" inset="1px" />
      <onEnabled name="renderQuad" startColor="#2228" endColor="#2220" post="true" length="150" />
      <onDisabled name="renderQuad" startColor="#2220" endColor="#2228" post="true" length="150" />
    </effect>
  </style>

  <!-- the text in the input field -->
  <style id="my-textfield#text" base="base-font">
    <attributes color="#000f" selectionColor="#f00f" visibleToMouse="false" align="left" valign="center" textHAlign="left" />
    <effect>
      <onFocus name="textColor" post="false" color="#cccf" />
    </effect>
  </style>

  <!-- the cursor is rendered in a separate layer on top of the input field and this is the parent panel of this -->
  <style id="my-textfield#cursor-panel">
    <attributes childLayout="absolute" padding="0px,2px" />
  </style>

  <!-- the actual cursor -->
  <style id="my-textfield#cursor">
    <attributes filename="main/data/interface/nifty/my-style/textfield/cursor-empty.png" />
    <effect>
      <onCustom name="imageOverlayPulsate" period="250" timeType="infinite" pulsateType="rectangle" filename="main/data/interface/nifty/my-style/textfield/cursor.png" post="true"/>
    </effect>
  </style>

</nifty-styles>

my-textfield is a valid style, at least I think so as I can use it without nesting and it works nicely. But in this context, an exception is thrown by nifty.
The problem is:
I would expect Nifty to look up the style my-intfield#textField. Then it would request the parts of it that the textfield control needs, so it would go deeper and look up for my-intfield#textField#field etc, which would be given (I think) as my-intfield#textField uses my-textfield as base. But actually Nifty doesn't! It only keeps one style and one substyle in mind, so instead of looking for my-intfield#textField#field, it looks for my-intfield#field, which of course it doesn't find and voila, exception and byebye cruel world.
My workaround for now is to point the control directly to its style in the control definition, so it is

<controlDefinition name="intField" defaultFocusElement="textField" controller="controls.IntField">
    <panel childLayout="horizontal">
      <control id="textField" name="textfield" style="my-textfield" />
    </panel>
</controlDefinition>

instead of

<controlDefinition name="intField" defaultFocusElement="textField" controller="controls.IntField">
    <panel childLayout="horizontal">
      <control id="textField" name="textfield" style="#textField" />
    </panel>
</controlDefinition>

, but this doesn't seem as nice to me as the nested styles would. If this is a desired behaviour of Nifty, I would like to know the reason behind that. Else, I hope I could point in the right direction for a fix ;)

#64 Incorrect calculation of "*" width elements

(original from https://sourceforge.net/p/nifty-gui/bugs/64/)

If you create a panel with width * then it calculates its width without allowing for any margins set for other panels, this causes those other panels to then be pushed too far to the right.

For example:

panel(new PanelBuilder("ourTint") {
    {
        childLayoutHorizontal();
        width("100%");
        height("100%");

        panel(new PanelBuilder() {{
            width("*");
        }});                                            

        text() {{
            font("Interface/Fonts/Georgia_20_bold.fnt");
            textHAlignCenter();
            textVAlignCenter();
            color("#fddf");
            margin("6px");
            height("32px");
            width("150px");
        }});

        panel(new PanelBuilder() {{
            width("12px");
        }});
}});

The final 12 pixel wide panel is needed to correct for the problem as the 6 pixel margin on the left and right of the text is not included when the first panel calculates its width so the text gets pushed right too far right.

Feature: Generic eventbus provider

Hello, I see that nifty has pretty sweet eventbus capabilities and my application requires exactly this type of eventbus service.
The nifty eventbus implementation is very free, I can simply extend my own events with NiftyEvent and piggy back onto nifty's eventbus.

But the only thing that stops me is that I Need access to nifty's event bus before I create a Niftyinstance (Way before I create an OpenGL window).
So I begun implementing my own eventbus that I can initialize independently of the nifty main object, but right now i'm pretty much just reinventing the wheel.

So my question is, would it be a be feasible to move all Nifty eventbus logic out of the Nifty class into a statically accessed singleton.

That way nifty could be used as an generic Eventbus provider without depending on an complete Nifty Implementation.

What's your thoughts on that?

Textfield: german keyboard and @ character input in windows

See http://jmonkeyengine.org/forum/topic/nifty-gui-textfield-on-windows/ for details!

According to Dirk the problem is:

"On a German keyboard you must press AltGr+Q to input an @’. Additionally on Windows AltGr it is equivalent to leftCtrl+leftAlt. But in the code the character was set to zero if Ctrl is pressed. That was the issue.

Greets, Dirk."

His patch only takes care of the @ character but I think that is not everything that needs to be fixed. Test with windows is required for this.

Assigning an id from a custom attribute to a control inside a custom control.

Using version 1.3.0. The code:

    <controlDefinition name="text_input">
            <panel childLayout="vertical" height="50" width="100%" align="center">
                <panel childLayout="horizontal" width= "300" align="center" height="190">
                    <control name="label" text="$label" height="40" width="100"></control>
                    <control id="$id" name="textfield" width="200px" height="40" backgroundColor="#aaaf"></control>
                </panel>
            </panel>
        </controlDefinition>

This control is used this way:

    <control name="text_input" id="map_width"  label="Map width: "></control>

In manual it's said that the contents will be replaced with the actual contents of what is inside of controlDefinition, instead when running the example and trying to type some text into the custom control's definition - a null pointer exception occurs.

It seems that the id attributes are somehow in conflict.

More flexible solution in using control definition paramters

Currently control definition parameters work this way:

<controlDefinition name="myInventoryControl">
    <image filename="$myFilenameParameter" />
</controlDefinition>

<control name="myInventoryControl" myFilenameParameter="inventory_items/redherring.png" />

A more flexible way would be like in Java Expression Language (EL):

<controlDefinition name="myInventoryControl">
    <image filename="inventory_items/${inventoryItemName}.png" />
</controlDefinition>

<control name="myInventoryControl" inventoryItemName="redherring" />

Through the curcly braces ${parameterName} it should be possible to differentiate the two parameter using styles. Passing the parameter would be exactly the same. But it could be used in two different ways...

Add more polished mouse selection of text in textfields

Selection of textfield text with the mouse isn't yet standard.

For example:

Selecting text in a textfield with the mouse should select all of the text in the direction of the mouse left-click-drag regardless of how fast the mouse is dragged in said direction, but unless the mouse is left-click-dragged very slowly, much of the text will remain unselected, even though the mouse (theoretically) passed over it. In fact, the amount of text selected is directly proportional to the speed of the mouse movement during text selection.

Also, left-click-dragging the mouse vertically from inside the textfield to outside the textfield should select all of the text in the textfield starting from the current x-position of the mouse, either to the left or the right, as long as the left mouse button is continually held down. Moving the mouse to the other side of the original x-position click (still holding down the button and still outside the textfield) will switch the text selection to that same side, and vice versa.

Another one is when the text in the textfield is longer than can be displayed. Left-click-dragging the mouse over the text all the way to the left or right border of the textfield should scroll the text as appropriate.

I'm pretty sure these behaviors are the standard just about everywhere. I tested it out on in the address bar on Google Chrome in OS X Snow Leopard.

Not sure if this is a bug, or it's the intended behavior and these are just advanced features that haven't been implemented yet due to either difficulty, low prioritization, or both :P

Double closing of a popup

In case Nifty is ordered to close the same popup twice during the same processing run, the removal of the element will fail with a error in the FocusManager at its second run (popState is called once to often).

The error that is raised basically can't be assigned to the actual error that was done. The error should be caught sooner and a proper message should be created to identify this problem.

Can not load fonts in sub folders

In version 1.3.2 it's not possible to load fonts referenced like "./font/myfont.fnt". The source of this error is slick2d.render.font.loader.AngelCodeSlickRenderFontLoader.class (and possibly other loaders as well).

The slick renderer tries to extract the image filename from the font file, in the example that would be something along "myfont.png". This filename is used to load the Angel Code Font in Slick. However, it's wrong because it's relative to the font file, not the working directory. The right filename would be "./font/myfont.png".

Need JOGL Renderer 1.3.2 Example

I've been trying to get the JOGL renderer for 1.3.2 to work by using various JOGL Getting Started Tutorials, but I can't seem to figure out what I'm doing wrong.

Note: using the 11/1/12 version of JogAmp JOGL.

(Image of the odd output produced by the following code below)
JOGL_Test

import com.jogamp.opengl.util.FPSAnimator;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.builder.TextBuilder;
import de.lessvoid.nifty.renderer.jogl.input.JoglInputSystem;
import de.lessvoid.nifty.renderer.jogl.render.JoglRenderDevice;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.tools.TimeProvider;
import digitalsign.sound.SoundDeviceNullImplementation;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.awt.GLCanvas;

public class SimpleNifty implements GLEventListener
{
    private static final int FPS = 60; // animator's target frames per second
    private static final int CANVAS_WIDTH = 640;  // width of the drawable
    private static final int CANVAS_HEIGHT = 480; // height of the drawable
    long time = System.currentTimeMillis();
    long frames = 0;
    private static JoglInputSystem inputSystem;
    private static JoglRenderDevice renderDevice;
    private static Nifty nifty;

    public static void main(String[] args)
    {
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        final GLCanvas canvas = new GLCanvas(caps);

        canvas.setAutoSwapBufferMode(true);
        canvas.setSize(CANVAS_WIDTH, CANVAS_HEIGHT);
        canvas.addGLEventListener(new SimpleNifty());

        // Create a animator that drives canvas' display() at the specified FPS.
        final FPSAnimator animator = new FPSAnimator(canvas, FPS, true);

        final Frame frame = new Frame("AWT Window Test - Nifty");
        frame.setSize(CANVAS_WIDTH, CANVAS_HEIGHT);
        frame.add(canvas);
        frame.setVisible(true);

        // by default, an AWT Frame doesn't do anything when you click
        // the close button; this bit of code will terminate the program when
        // the window is asked to close
        frame.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                animator.stop();
                frame.remove(canvas);
                System.exit(0);
            }
        });

        //start the animator
        animator.start();
    }

    public void display(GLAutoDrawable drawable)
    {
        update(drawable);
        render(drawable);
    }

    public void init(GLAutoDrawable drawable)
    {
        // put your OpenGL initialization code here
        renderDevice = new JoglRenderDevice();
        inputSystem = new JoglInputSystem();

        nifty = new Nifty(renderDevice, new SoundDeviceNullImplementation(), inputSystem,
                new TimeProvider());

        nifty.setDebugOptionPanelColors(true);

        nifty.loadStyleFile("nifty-default-styles.xml");
        // load standard controls
        nifty.loadControlFile("nifty-default-controls.xml");
        Screen screen = new ScreenBuilder("start")
        {
            {
                layer(new LayerBuilder("baseLayer")
                {
                    {
                        height("400px");
                        width("640px");
                        childLayoutCenter();
                        text(new TextBuilder("test")
                        {
                            {
                                font("console.fnt");
                                backgroundColor("#33af");
                                text("l33t");

                                height("20px");
                                width("100px");
                                textHAlignLeft();
                                valignCenter();
                            }
                        });
                        //end: lines that break the rendering
                    }
                });
            }
        }.build(nifty);
        nifty.gotoScreen("start");
    }

    public void dispose(GLAutoDrawable drawable)
    {
        // put your cleanup code here
    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
    {
        GL gl = drawable.getGL();  // get the OpenGL 2 graphics context

        if (height == 0)
        {
            height = 1;   // prevent divide by zero
        }
        float aspect = (float) width / height;

        // Set the view port (display area) to cover the entire window
        gl.glViewport(0, 0, width, height);
    }

    private void update(GLAutoDrawable drawable)
    {
        // update nifty
        boolean di = nifty.update();

        // render Nifty (this will change OpenGL state)
        nifty.render(true);
    }

    private void render(GLAutoDrawable drawable)
    {   
        frames++;

        long diff = System.currentTimeMillis() - time;
        if (diff >= 1000)
        {
            time += diff;
            System.out.println("fps : " + frames);
            frames = 0;
        }
    }
}

Listbox Focus Problem

There is another problem with the list box. While the last patch fixed the focus of the initial item properly it does not set the scrollbar to the proper location. The scrollbar in its initial state still set to the first entry of the list.

Pasting text into a textfield ignores maxLength setting

Expected Behavior:

Pasting text into a textfield with the maxLength setting set will truncate pasted text to ensure that maxLength is not violated, or will at least prevent pasting altogether if the paste operation would result in the total length of the textfield text to be greater than maxLength.

Actual Behavior:

Pasting text into a textfield with the maxLength setting set will ignore the maxLength setting and paste all of the text, regardless of length.

Steps to Reproduce:

  1. Run either the default controls or standard examples web start for nifty gui 1.3.2.
  2. Go to the textfield demonstration.
  3. Ensure maxLength is set and enabled.
  4. Ensure the textfield is not already full to maxLength (it can have maxLength - 1 characters or less). It doesn't occur if the textfield text is already at maxLength.
  5. Paste text longer than maxLength into the textfield, or paste text such that the total length of the text in the textfield will be greater than maxLength.

System:

Nifty Gui 1.3.2
Java 1.6.0_43
2006 Intel Core 2 Duo MacBook
2 GB RAM
Intel GMA 950 Integrated Graphics Chipset
OS X 10.6.8 Snow Leopard

Mouse events also occur for covered elements.

Obtaining mouse events via @NiftyEventSubscriber annotation has the issue, that events occur even for elements, which lie "behind" other elements.

This behaviour seems to be different to obtaining events via the "<interact...." way, but should be work exactly the same so that using either @NiftyEventSubscriber or "<interact...." is interchangeable.

Nifty causing crash in Slick due to mouse wheel moving

So again I stumbled upon an issue of which I don't know if it's just me or the Nifty library itself.
In my NiftyOverlayBasicGameState, I initialize Nifty as follows:
public class WrapperState extends NiftyOverlayBasicGameState
{
....
@OverRide
protected void initGameAndGUI(GameContainer gc, StateBasedGame sbg) throws SlickException
{
initNifty(gc, sbg, new SlickRenderDevice(gc), new SlickSoundDevice(), new SlickSlickInputSystem(new PlainSlickInputSystem()), new LWJGLTimeProvider());
...
}

@Override
protected void prepareNifty(Nifty nifty, StateBasedGame sbg)
{
    nifty.setLocale(LangData.getLocale());
    java.util.logging.Logger.getAnonymousLogger().getParent().setLevel(java.util.logging.Level.SEVERE);
    java.util.logging.Logger.getLogger("de.lessvoid.nifty.*").setLevel(java.util.logging.Level.SEVERE);
    nifty.getResourceLoader().addResourceLocation(new SchnullerResourceLocation());
    nifty.fromXml(GameData.NIFTY_XML, "null");
}
....

}
As far as I know, this is the usual way to get Nifty started and xml parsing, screen switching and rendering etc. works fine, key and mouse input function too - except of the mousewheel, whose movements let Nifty cause a crash:

java.lang.IllegalStateException: Can't generate mouse wheel events without a reference to the Input
at de.lessvoid.nifty.slick2d.input.AbstractSlickInputSystem.mouseWheelMoved(AbstractSlickInputSystem.java:171)
at de.lessvoid.nifty.slick2d.input.events.MouseEventWheelMoved.sendToSlick(MouseEventWheelMoved.java:42)
at de.lessvoid.nifty.slick2d.input.SlickSlickInputSystem.handleInputEvent(SlickSlickInputSystem.java:36)
at de.lessvoid.nifty.slick2d.input.AbstractSlickInputSystem.forwardEvents(AbstractSlickInputSystem.java:85)
at de.lessvoid.nifty.Nifty.update(Nifty.java:287)
at de.lessvoid.nifty.slick2d.NiftyOverlayBasicGameState.update(NiftyOverlayBasicGameState.java:213)
at org.newdawn.slick.state.StateBasedGame.update(StateBasedGame.java:268)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:657)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at main.StartFrame.actionPerformed(StartFrame.java:289)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

As the reason for this exception is out of my knowledge, I would be happy to be told what I did wrong here (or, otherwise, when the fix is coming :P )

lwjgl rendering issues: not everything is properly moving with the viewport

It appears that when using NiftyGui 1.3.2 with LWJGL, as the viewport moves, text and controls within a panel are translated to the correct coordinates, but not the panel itself. Both the debug coloring as well as simply setting a backgroundColor on the panel are relative to the origin and don't respect viewport translations.

For example, the below:

<layer childLayout="vertical">
  <panel childLayout="horizontal" width="100%">
    <panel id="x" width="300px" height="100%" backgroundColor="#F00F" childLayout="vertical" visible="false">
      <text text="test" style="my-font" />
    </panel>
  </panel>
</layer>

Shows the correct red background panel at (0,0) but the text "test" moves with the viewport.

Is there anything I can do to get the panels themselves to translate? I can provide more info as needed.

Screen's rootElement doesn have its screen member set

so myScreen.getRootElement().getScreen() will always return null. This means I can't write code that has just an Element as a parameter.
Can't fix this easily by myself because I wouldn't know where to look for code that might be affected by a fix. (Are there unit tests for all code that might be affected by a change here? If yes, I can try my hand at this... it's just that my impressions is that Nifty wasn't build with robustness in this direction in mind.)

Anyway, I'll have to re-architect my entire screenbuilding approach now - I was assuming I can start the screen running and add stuff without having to thread a Screen parameter to everything.
Some of my code needs getters to decide what to do when creating a subelement, and the Builder classes don't have getters. Would it be a worthy addition to add getters to the Builders? (Not that I'm very happy to have to do that, mind you... but it will give me something useful to do while I'm held up on the rootElement screen issue.)

Textfield cursor corruption with LWJGL 2.9.0

I know. Another textfield issue ;). I'm not sure if this one is nifty or lwjgl or some combination of both. But I'm betting this one only happens on OS X, as lwjgl got a complete OS X rewrite, including mouse cursors. I tried to take a screenshot, but the mouse cursor isn't included in the resulting image for some reason.

I also tried to test this with the nifty standard controls / standard examples demos, but I couldn't figure out how. I cloned into 1.4 and updated lwjgl to 2.9.0 in the nifty-renderer-lwjgl pom. Then I did mvn clean install but got some errors:

[ERROR] Failed to execute goal on project nifty-slick-renderer: Could not resolve dependencies for project lessvoid:nifty-slick-renderer:jar:1.4.0-SNAPSHOT: Failed to collect dependencies for [lessvoid:nifty:jar:1.4.0-SNAPSHOT (compile), slick:slick:jar:274 (compile), junit:junit:jar:4.3.1 (test), org.easymock:easymock:jar:2.4 (test), org.easymock:easymockclassextension:jar:2.4 (test)]: Failed to read artifact descriptor for slick:slick:jar:274: Could not transfer artifact slick:slick:pom:274 from/to slick-maven-repo (http://slick.cokeandcode.com/mavenrepo): Failed to transfer file: http://slick.cokeandcode.com/mavenrepo/slick/slick/274/slick-274.pom. Return code is: 504, ReasonPhrase:Gateway Time-out. -> [Help 1]

Do I need to manually install those artifacts? Do you not get these errors because you're using Nexus or something?

Is there a better way to go about this? I'd like to work with 1.3.3 or 1.4 if practical...

Expected Behavior:

When the mouse cursor hovers over a textfield, the text cursor image looks normal.

Actual Behavior:

When the mouse cursor hovers over a textfield, the text cursor image is corrupted / garbled.

Steps to Reproduce:

  1. Upgrade to LWJGL 2.9.0
  2. Hover the mouse cursor over a nifty textfield.

System:

Nifty Gui 1.3.2
LWJGL 2.9.0
Java 1.6.0_43
2006 Intel Core 2 Duo MacBook
2 GB RAM
Intel GMA 950 Integrated Graphics Chipset
OS X 10.6.8 Snow Leopard

Make Element.findElementByName() deprecated

The method Element.findElementByName() should better be named Element.findElementById(), because that's what it is.

Element.findElementByName() could be made deprecated and not deleted for compatibility reasons.

The function of the new method shall be exactly the same.

Nifty crashes when selecting text after pasting newline character into a textfield

Expected behavior:

Pasting newlines (i.e., multiple lines of text) into a textfield should replace the newlines with spaces and display the resulting text in one long line. Selection of said text should work normally.

Actual behavior:

Pasting newlines (i.e., multiple lines of text) into a textfield preserves the newlines, causing the text to be rendered outside of the textfield (if enough lines are pasted), and causes selection of said text to crash nifty gui.

Steps to reproduce:

  1. Run either the default controls or standard examples web start for nifty gui 1.3.2.
  2. Go to the textfield demonstration.
  3. Paste a newline character into the textfield, or any text including a newline.
  4. Notice that if many lines of text are pasted, they will be rendered outside of the textfield.
  5. Try and select / highlight any of the text using either shift + arrow or mouse (click + drag).

System:

Nifty Gui 1.3.2
Java 1.6.0_43
2006 Intel Core 2 Duo MacBook
2 GB RAM
Intel GMA 950 Integrated Graphics Chipset
OS X 10.6.8 Snow Leopard

Stack Trace:

java.lang.StringIndexOutOfBoundsException: String index out of range: 1
    at java.lang.String.substring(String.java:1934)
    at de.lessvoid.nifty.render.NiftyRenderEngineImpl.renderSelectionText(NiftyRenderEngineImpl.java:310)
    at de.lessvoid.nifty.render.NiftyRenderEngineImpl.renderText(NiftyRenderEngineImpl.java:266)
    at de.lessvoid.nifty.elements.render.TextRenderer.renderLine(TextRenderer.java:302)
    at de.lessvoid.nifty.elements.render.TextRenderer.renderLines(TextRenderer.java:201)
    at de.lessvoid.nifty.elements.render.TextRenderer.render(TextRenderer.java:182)
    at de.lessvoid.nifty.elements.Element.renderElement(Element.java:734)
    at de.lessvoid.nifty.elements.Element.render(Element.java:719)
    at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
    at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:741)
    at de.lessvoid.nifty.elements.Element.render(Element.java:722)
    at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
    at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
    at de.lessvoid.nifty.elements.Element.render(Element.java:722)
    at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
    at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
    at de.lessvoid.nifty.elements.Element.render(Element.java:713)
    at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
    at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
    at de.lessvoid.nifty.elements.Element.render(Element.java:722)
    at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
    at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
    at de.lessvoid.nifty.elements.Element.render(Element.java:713)
    at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
    at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
    at de.lessvoid.nifty.elements.Element.render(Element.java:713)
    at de.lessvoid.nifty.elements.Element.renderInternalChildElements(Element.java:751)
    at de.lessvoid.nifty.elements.Element.renderChildren(Element.java:744)
    at de.lessvoid.nifty.elements.Element.render(Element.java:713)
    at de.lessvoid.nifty.screen.Screen.renderLayers(Screen.java:314)
    at de.lessvoid.nifty.Nifty.render(Nifty.java:321)
    at de.lessvoid.nifty.examples.defaultcontrols.LwjglInitHelper.renderLoop(LwjglInitHelper.java:251)
    at de.lessvoid.nifty.examples.defaultcontrols.ControlsDemo.main(ControlsDemo.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.javaws.Launcher.executeApplication(Launcher.java:1927)
    at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1860)
    at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1622)
    at com.sun.javaws.Launcher.run(Launcher.java:139)
    at java.lang.Thread.run(Thread.java:680)

Improve dropdown

The dropdown control has currently some limits. For 1.3.2 I suggest to improve this element.

The keyboard focus should be placed on the selected element once the popup opens. Also the listbox should be scrolled to the selected element. These are the most important things.

Issue with running slick2d example

Hello

I tried to run AllDemoMain in the slick example package, but I'm struck with the following stack trace:

Exception in thread "main" java.lang.NoSuchMethodError: org.newdawn.slick.Font.getWidth(Ljava/lang/String;)I
    at de.lessvoid.nifty.slick2d.render.font.AbstractSlickRenderFont.getWidth(AbstractSlickRenderFont.java:80)
    at de.lessvoid.nifty.elements.render.TextRenderer.initText(TextRenderer.java:166)
    at de.lessvoid.nifty.elements.render.TextRenderer.setText(TextRenderer.java:136)
    [...]

I found a forum post (http://slick.javaunlimited.net/viewtopic.php?p=31527) reporting this issue. The current workaround there is using an older version of slick. But this link there does not work.

My question is now, how I could continue? Does someone maybe have a compatible build of slick with nifty 1.3.2?

java.lang.RuntimeException: No OpenGL context found in the current thread.

When I try and give a nifty panel (named "myPanel") keyboard focus, I'm getting a strange exception that doesn't make any sense because I'm not doing any multithreading, and the OpenGL context is active in my (only) thread. The panel "myPanel" exists in myScreen.xml. I only try and set the keyboard focus when myScreen is active.

What I'm trying to achieve is to take the keyboard focus away from a nifty-textfield (i.e., blinking cursor) when myPanel is left clicked on, and give it to myPanel. Just setting myPanel to focusable="true" in myPanel.xml isn't good enough (although I do have this set) because I want the keyboard focus to happen when the mouse left clicks on myPanel.

Ok, so what I'm REALLY trying to achieve is taking the keyboard focus away from nifty components such as textfield and giving it to the game. I am just using lwjgl and nifty, not slick or jme. It doesn't work automatically because nifty only releases textfield keyboard focus when clicking on ANOTHER nifty component. So I have the 100% transparent panel named "myPanel" overlay the game to take keyboard focus. Otherwise if you type in a nifty textfield and then click inside the game with the mouse, you cannot use the keyboard inside the game; it will still type in the textfield.

Setting visibleToMouse="true" is also not an option because I have openGL rendered graphics underneath myPanel that need to be interacted with the mouse. I know you changed the behavior of visibleToMouse to fix some bugs, but this change is really hurting me because if it worked like before, then I could set visibleToMouse="true" on myPanel and get the behavior I want for free, and still get mouse clicks underneath the panel. Is there a way to force the mouse clicks to not be consumed only for that one panel?

Anyway, everything else is working correctly (nifty, lwjgl, openGL). If I remove this line from MyScreenController.java:

this.myScreen.findElementByName("myPanel").setFocus();

The problem goes away. Here is the stack trace that the above line causes:

java.lang.RuntimeException: No OpenGL context found in the current thread.
java.lang.RuntimeException: No OpenGL context found in the current thread.
    at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
    at org.lwjgl.opengl.GL11.glDeleteTextures(GL11.java:731)
    at de.lessvoid.nifty.renderer.lwjgl.render.LwjglRenderImage.dispose(LwjglRenderImage.java:65)
    at de.lessvoid.nifty.render.NiftyImageManager$ReferencedCountedImage.removeReference(NiftyImageManager.java:107)
    at de.lessvoid.nifty.render.NiftyImageManager.dispose(NiftyImageManager.java:52)
    at de.lessvoid.nifty.render.NiftyRenderEngineImpl.disposeImage(NiftyRenderEngineImpl.java:559)
    at de.lessvoid.nifty.render.NiftyImage.dispose(NiftyImage.java:84)
    at de.lessvoid.nifty.effects.impl.ImageOverlayPulsate.deactivate(ImageOverlayPulsate.java:50)
    at de.lessvoid.nifty.effects.Effect.setActiveInternal(Effect.java:139)
    at de.lessvoid.nifty.effects.Effect.deactivate(Effect.java:132)
    at de.lessvoid.nifty.effects.EffectProcessorImpl.reset(EffectProcessorImpl.java:107)
    at de.lessvoid.nifty.effects.EffectProcessorImpl.setActive(EffectProcessorImpl.java:179)
    at de.lessvoid.nifty.effects.EffectManager.stopEffect(EffectManager.java:125)
    at de.lessvoid.nifty.elements.Element.stopEffectInternal(Element.java:1259)
    at de.lessvoid.nifty.elements.Element.stopEffect(Element.java:1244)
    at de.lessvoid.nifty.controls.textfield.TextFieldControl.onFocus(TextFieldControl.java:308)
    at de.lessvoid.nifty.controls.NiftyInputControl.onFocus(NiftyInputControl.java:88)
    at de.lessvoid.nifty.elements.Element.stopEffectInternal(Element.java:1271)
    at de.lessvoid.nifty.elements.Element.stopEffect(Element.java:1244)
    at de.lessvoid.nifty.controls.FocusHandler.setKeyFocus(FocusHandler.java:215)
    at de.lessvoid.nifty.elements.Element.setFocus(Element.java:1883)

BitBlt??

I have an Image (with alpha) and want to copy … lets say … image-coordinates x, y, w, h into current panel at position a,b. How can i do this…??

To be more specific: Im inside EffectImpl.execute of an effect, set upon a panel, and i have an Image (BufferedImage or com.jme3.texture.Image, having it as com.jme3.Texture would be OK) already as pointer ready to use.

So i now need to copy coordinates 10,10,10,10 at 20,20 and coordinates 10,20,10,10 at 30,40 and coordinates … you got it.

In grafic2D, there is that reasonable simple function BitBlt. What is the alpha-aware(!) equivalent in Nifty? And … yes… i read about "subImageDirect" but i cant figure out how that would be useful in here.

I need something like r.renderQuadFromImage(x,y,w,h, image, ix, iy)…

Make findNiftyControl more typesafe

findNiftyControl cannot currently handle container controls like Menu and DropDown in a typesafe way.
I could write an overloaded variant to deal with that:

findNiftyControl (String elementName, Class containerClazz, Class elementClazz)

Code using the existing, two-parameter findNiftyControl should continue to work, it would simply continue to generate generics warnings.

Useful?

Nested controls

Recently I'm figuring out how to make a custom control, which is ok to dive in with the Missing Manual and continous looks on the default xmls. One thing is bugging me though, which is the use of nested controls.
I have one as follows in my controls xml: (Had to switch the "<>"s to "[]"s because some dark interpreter magic made them invisible otherwise)
[controlDefinition name="intField" focusable="true" visibleToMouse="true" controller="controls.IntFieldControl"]
[control id="textField" name="textfield" /]
[/controlDefinition]
That is embedded in the main .xml file:
[control id="testControl" name="intField" focusable="true" /]
The central Controller code looks this way (though I think that code is slightly irrelevant to the core problem):
public class IntFieldControl implements Controller {
...
@OverRide
public void bind(Nifty nifty, Screen screen, Element element, Properties parameter, Attributes controlDefinitionAttributes) {
...
}

@Override
public void init(Properties parameter, Attributes controlDefinitionAttributes) {

}

@Override
public void onStartScreen() {

}

@Override
public void onFocus(boolean getFocus) {

}

@Override
public boolean inputEvent(NiftyInputEvent inputEvent) { 
    System.out.println("InputEvent: " + inputEvent);
    return false;
}

@NiftyEventSubscriber(pattern="textField.*") //so I'm sure to be listening
public void onTextFieldChange(String id, TextFieldChangedEvent event) { 
    System.out.println("OnTextFieldChange: " + event.getText());
}

}

The first issue I noticed is that the mouse cursor looks really weird when he's hovering the textfield control, he has some black lines attached on the top and a black filled rectangle attached on its bottom (that also goes for non-nested textfield controls).

So hovering and clicking on the textfield is possible. But it does not become actually usable!
I can rage-click as much as I want, but there is no text cursor daring to appear on the textfield. Key input is also just being ignored. The IntFieldControl prints me the corresponding events. but the desired TextFieldChangedEvents are not being delivered at all. Non-nested textfields work regarding that matter, though.

My question is, if nested controls are even possible or if there are some rules I am not aware of atm? After all, I would hate to switch my planed custom controls to some unholy panel pattern that is copied wildly around my xmls just to have some working controls inside of them...

color tag for image object

Would it be possible to take a color="#asdf" tag into account when drawing an image ? The incentive is being able to set a color to an otherwise white image programmatically. Coloring icons for a hud come to mind.

Getter methods in Element for margin and padding

I've got the need for knowing the padding values for some elements at runtime.
Just like the methods

getConstraintX();
getConstraintY();
getConstraintWidth();
getConstraintHeight();

and so on...

buttonStepSize / pageStepSize for scrollPanel and listBox

Are the buttonStepSize / pageStepSize (or similar) attributes available for scrollPanels and listBoxes? They would be pretty helpful when browsing through larger data sets (i.e. large grid of tiles, library listings, spreadsheets).

Didn't find anything in the documentation.

-cf01

Allow option to set minimum scrollbar thumb size.

I need the ability to set a hard limit pixel-wise on how small the scrollbar thumb will get, no matter how many items are added to a listbox.

Currently it seems to have some kind of default limit, but I can't find any way to change it without rewriting part of niftyGui.

Double subscription of annotation-based events

Its possible to subscribe the same events more then once by calling the subscripeAnnoations function of Nifty twice. That shouldn't be possible and throw a error or at least a warning.

The effect of the double subscription is that all events are published twice to the listeners.

Using nifty.setLocale(Locale locale) "at runtime" (after it was loaded from an xml file) does not have an effect

As the title already says it all, setting nifty's locale before loading the .xml file works well, but after letting nifty load, setting the locale with nifty.setLocale(...) will change nifty's locale variable, but seemingly not update anything, as the texts remain the same ones. So the user is forced to use work-arounds like letting nifty load all over again or by updating it all manually like here: http://jmonkeyengine.org/forum/topic/nifty-resourcebundle/
Either way this seems somewhat ugly to me, so I would recommend looking on this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.