Merge pull request #140 from mkaring/1.4

1.4 - TabGroup bugfix
#139 fix display of initial CheckBox state

The CheckBox didn't display its correct state when it was shown after
being hidden.

Example: CheckBox on a hidden Tab and change it's state by code. When
you then display the tab the Checkbox won't show it's correct state.

I've modified the TabsControlDialog in the standard controls demo to
test this.
Update text in standard controls demo to 1.4
Create LibGDX renderer and examples.

The main changes are the addition of two new Maven modules to Nifty:
nifty-renderer-libgdx and nifty-examples-libgdx. Changes to existing
modules are listed at the very bottom. All Nifty tests are passing, and
the two new modules are working perfectly after extensive integration
testing.

Important Note: Android / Nifty integration is a work in progress. The
LibGDX renderer seems to work on Android, but it has not been
extensively tested, especially because of the fact that the size of the
resources used in the Nifty Examples module are designed for desktops,
not mobile devices. The Android submodule of the nifty-examples-libgdx
module is broken at this time.

Important Note: iOS is completely unsupported at this time.

Detailed changes:

New Module 1: nifty-renderer-libgdx:

The new Nifty LibGDX renderer handles mouse & keyboard input, sound, music,
custom mouse cursors, graphics, pretty much anything Nifty can throw at
it ;-). It runs the main Nifty demo, the default controls demo, and the
Nifty 1.2 tutorial demo.

It uses the new BatchRenderBackend interface for rendering, but not yet
core profile. The renderer only uses OpenGL 1.0 functionality for
maximum compatibility. I have a very old computer, so even if I write a
core profile renderer, I would not be able to test it or run it :'(.

The LwjglBatchRenderBackend served as a reference; in fact, the renderer
doesn't really make use of any high-level features of LibGDX; the
original RenderDevice implementation of the LibGDX renderer written by
Martin Karing <nitram@illarion.org> tried to take that route, but there
were too many issues, and I eventually removed it completely and focused
on porting the LwjglBatchRenderBackend instead. LibGDX does use LWJGL
for it's desktop implementation after all.

The real "magic" that was required to port LwjglBatchRenderBackend to
LibGDX involved using GL_TRIANGLES in the call to glDrawArrays. The
reason for this is that LibGDX only provides OpenGL ES functionality,
since it must work on Android and iOS, and GL_QUADS is not available in
OpenGL ES. Using GL_TRIANGLES (triangle list) requires the duplication
of two vertices per quad, since two joined triangles must be formed to
create a quad, and they share two vertices. This results in a total of 6
vertices per quad, but the performance should be made up for by the fact
that OpenGL LOVES triangles, and gobbles them up at a faster rate than
large, unwieldy quads, which it has to chew into triangles eventually
anyway, lol.

New Module 2: nifty-examples-libgdx:

This is a complete LibGDX project, set up Maven-style. It has a parent
module with pom packaging, and three sub-modules, core, desktop, and
android. The core submodule contains a LibGDX example application. The
desktop and android submodules merely instantiate a NiftyExample and
pass it to the LibGDX example application in the core submodule.

Three main NiftyExample demos are provided, and work just fine:
Nifty Main Examples Demo
Nifty Default Controls Demo
Nifty 1.2 Tutorial Demo

The example application was set up in IntelliJ with Maven using the
LibGDX Maven archetype project, located at:
https://github.com/libgdx/libgdx-maven-archetype

Changes to existing modules / files in Nifty:

pom.xml:
  Add nifty-renderer-libgdx and nifty-examples-libgdx as modules.

nifty-examples/src/main/java/de/lessvoid/nifty/examples/controls/ControlsDemoStartScreen.java:
  Add "LibGDX" as a dropdown choice in the controls demo.

nifty-examples/src/main/resources/all/intro.xml:
nifty-examples/src/main/resources/all/libgdx.png:
  Add LibGDX mention & logo in main example credits.

nifty-core/src/main/java/de/lessvoid/nifty/input/keyboard/KeyboardInputEvent.java:
  Create an empty default constructor because GdxKeyboardInputEvent, which
  subclasses KeyboardInputEvent, makes use of a default constructor, and needs
  to call super(). Also add a public setData method, to initialize the data for
  the object, so it doesn't have to be done in the constructor. This is
  necessary because GdxKeyboardInputEvent relies on a pool to obtain new
  instances, and the data required by Nifty to initialize the KeyboardInputEvent
  with the parameterized constructor is not yet available. These changes are
  made by Martin Karing <nitram@illarion.org>, who wrote most of the original
  input system for the LibGDX renderer.
Merge pull request #146 from 3xp0n3nt/gdx-renderer-dev

Create LibGDX renderer and examples.
.gitignore added for libgdx and eclipse specific ignores
Various minor fixes.

Details:

- Add compile scope to xpp3 dependency in core pom. The scope was
missing, and the default is 'compile', anyway. It's best not to rely
on the defaults.

- Fix spelling errors in NiftyInputConsumer and ControlsDemo.

- Remove javadoc for nonexistent parameter in BatchRenderBackend.

- Add @Override to toString method in ResolutionControlJOGL.

- Fix getScreen method in ControlsDemo.  The getScreen method returns
"demo" when it should return "start". The "demo" screen is the second
screen in the ControlsDemo example. If someone were to use this method,
they would miss the intro on the "start" screen.  Plus, all the
getScreen method in every other NiftyExample implementation return
"start".

- Move comment to the correct location. Move the "internal
implementations" divider comment above the first private method in
LwjglBatchRenderBackend, where it should be. There is one private method
that is above the comment.

- Fix parsing of the "fillRemovedTexture" property. In the LWJGL and JOGL
batch render backends (both core and non-core), fix the parsing of the
boolean system property called "fillRemovedTexture". The current
implementation doesn't respect the default setting; it will always be
false, even if the default setting is set to true. The problem is that
it should use the parseBoolean method instead of the getBoolean method
because getBoolean tries to call System.getProperty, when
System.getProperty is already being called, so it would result in a
redundant call to System.getProperty, whereas the parseBoolean method
just simply converts the result of System.getProperty from a String to a
Boolean, if the value is "true" or "false", which is exactly what we
want.

- Fix crashing bug in LwjglBatchRenderBackend. Don't attempt to render an
empty batch, i.e., if its vertex buffer is empty, because the render
method will attempt to access non-accessible elements, throwing some
nasty exception and crashing the program. This happens when the batch
pool reaches maximum capacity, causing it to double in size, i.e., from
2 to 4, and the problem is that in some cases it will only have enough
data for the 3rd batch, and the 4th batch will be completely empty.

- Fix example with dynamic drop down list. The problem is that there is
not enough room for the dynamic drop down list to be inserted above the
static drop down list in the drop down example, so increase the size of
the spacer panel between them from 8px to 70px to make room. Otherwise
they overlap, which looks bad. This may be a bug in Nifty, as it seems
like it should make space on the fly instead of having to manually do
it.
Merge pull request #147 from 3xp0n3nt/minor_fixes

Various minor fixes.
manual added (both pdf and .pages source document)
Fix hover effects after screen transitions.

Process a fake mouse event with current coordinates so that Nifty will
activate hover effects for any element currently under the mouse, and
will also deactivate any hover effects for any element NOT currently
under the mouse. This prevents the undesirable behavior of having an
element under the mouse that should be in a hovered-effect state, but is
not due to the screen change, and of having an element that is NOT under
the mouse that should NOT be in a hovered-effect state, but IS due to
the screen change.
Merge pull request #150 from 3xp0n3nt/mouse-hover-bug-fix

Fix hover effects after screen transitions.
Fix bugs in nifty-renderer-libgdx.

Fix several bugs in nifty-renderer-libgdx module:

1) Attempting to type a capital C (with either SHIFT + C or c with
CAPSLOCK on) in a TextField control is not typing a capital C but
instead is activating backspace. It turns out that the GdxInputSystem
needs to set the nifty key code to 0 for character keys, but in fact, it
is setting the key code to a completely incorrect value for every single
character key. The problem just happened to manifest with 'C' because it
is sending the key code of backspace with it. Now, for all printable
character keys, the key code sent to nifty will be 0, since it should be
ignored for all printable character keys - you only need the character
itself. Key codes for non-printable control keys are already correct,
and are not affected by this fix.

2) Forward delete is not working at all in a TextField control. It turns
out that GdxKeyboardInputEvent.getNiftyKeyCode, which maps libGDX key
codes to Nifty key codes, did not have a mapping set up for forward
delete. Add a mapping for forward delete so that it works in TextField
controls.

3) Set forward delete to repeat in nifty-examples-libgdx using the
GdxKeyRepeatSystem.
Merge pull request #151 from 3xp0n3nt/gdx-bug-fixes

Fix bugs in nifty-renderer-libgdx.
Fix off-by-one pixel bugs.

This is really two separate but related bugs, related because they both
cause off-by-one pixel errors. The first affects nifty-core, but the
second only affects nifty-renderer-libgdx.

Bug #1) Many classes in the effects and layout packages in nifty-core
are using a method in the SizeValue class called getValue that returns a
floating point value. The issue is not with this method itself per se,
but with callers of the method, who really need an integer value, and
cast the returned floating point value to an integer, effectively
discarding everything to the right of the decimal. It can easily be
verified that calling getValue and then casting to an integer returns
incorrect values much of the time. This bug is now verified with a
simple test in SizeValueTest. The bug rears its ugly head the worst when
converting a simple pixel value of say "212px" from a SizeValue whose
percent is set to 100, to a floating point pixel value, and then casting
it to an integer: the result will always be 211 and NOT 212. There are
countless other values that return a similar result when the SizeValue
percent is set to 100.

The solution to this error, which rectifies issues such as creating
quads at off-by-one pixel sizes, is to change all callers of getValue
that actually need an integer value to use the preexisting getValueAsInt
method, BUT since it ALSO simply casts the floating point value of the
getValue method to an integer, persisting the bug, we modify the
getValueAsInt method to use Math.round, and round the result returned by
getValue to the nearest integer instead of casting it. This returns much
more correct values, and fixes the bug. This solution has been
integration-tested without noticing the introduction of any other
regressions.

There is an additional test in SizeValueTest that verifies that this
off-by-one SizeValue bug is fixed. The javadoc for SizeValueTest has
also been improved, especially noteworthy is the warning to NOT cast the
result of getValue to an integer, but rather to use getValueAsInt.

Classes that call SizeValue.getValue method, and do NOT cast to an
integer, but store the result in a floating point variable have not been
modified as this is a legitimate use of the getValue method.

Bug #2) nifty-renderer-libgdx is not configured to use exact openGL
pixelization. Configure nifty-renderer-libgdx to use exact openGL
pixelization for 2D rendering as officially recommended in a faq on
opengl.org at:

http://www.opengl.org/archives/resources/faq/technical/transformations.htm#tran0030
Clean up input files in nifty-renderer-libgdx.

Update comments and remove mapping of Input.Keys.SYM to
KeyboardInputEvent.KEY_SYSRQ because it's incorrect. The SYM key seems
to be the Apple key on OS X, but it is buggy on the libGDX side, so just
map it to nothing for now.
Merge pull request #152 from 3xp0n3nt/off-by-one-pixel-fix

Fix off-by-one pixel bugs.
Merge pull request #154 from 3xp0n3nt/libgdx-input-minor-cleanup

Clean up input files in nifty-renderer-libgdx.
Cleanup Element class.

The Element class in nifty-core is badly in need of some basic cleanup.

Remove useless, tautological comments/javadoc. Add some useful
comments/javadoc where necessary. Improve comment/javadoc grammar,
sentence structure, and spelling.

Rename getElements to getChildren, add to addChild, and the overloaded
add method that takes an index parameter to insertChild because those
methods names are infinitely clearer. Rename these methods in all
calling classes. Also rename elements field to children.

Recreate the two old add methods, but mark them as deprecated and
delegate to the new methods.

Fix code style violations so that it matches the code style of the rest
of the project.

No actual logic is altered. All tests are passing, and
integration-testing reveals no problems.
Fix NullPointerException in Nifty class.

The Bug: If Nifty.exit() is called more than once in a row, or if the
current Screen is an instance of NullScreen when Nifty.exit() is called,
then a NullPointerException is thrown in the current Screen's
endScreenMethod, specifically when it tries to call
Nifty.resetMouseInputEvents() on a null instance of Nifty within the
resetLayers() method, since the Nifty instance will be null if the
current Screen is an instance of NullScreen.

The scenario above specifically occurs when exiting from the
AllExamplesMain example demo from nifty-examples when running the
example from nifty-examples-libgdx. When the "Exit" menu choice is
clicked in the menu scrollPanel, and the button labeled "yes" is
clicked, Nifty.exit() is called, but the main application window itself
stays open. The NullPointerException described above occurs when closing
the main application window because that in turn calls
LibgdxExampleApplication.dispose(), which in turn calls Nifty.exit(),
like it should because it can't assume that Nifty.exit() has already
been called.

The Fix: Don't call the endScreen method in Nifty.exit() if the current
Screen is null, i.e., an instance of NullScreen. In fact, since
Nifty.exit() is designed to only ever be called once, and since it
should really be idempotent since that increases robustness, simply
return immediately from Nifty.exit() if the current Screen is null.
Since the first invocation of Nifty.exit() will always make the current
screen an instance of NullScreen, this is effectively the same as
returning immediately if Nifty.exit() has already been called.

Add a test to ensure that calling Nifty.exit() multiple times in a row
does not throw a NullPointerException.
Clean up ScreenTest & upgrade EasyMock.

Upgrade EasyMock dependency in main pom.xml to version 3.1.

Change EasyMock imports from package org.easymock.classextension.* to
org.easymock.*, since the classextension package is deprecated; i.e.,
the functionality has been merged into standard EasyMock in version 3.1.

When stubReturn-ing the getMsTime() method on the TimeProvider mock,
specify the return value as 0L to satisfy the compiler, since it needs
to return a long, rather than casting the 0 to a long, since it's more
elegant.