Skip to content

readme patch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: branch_1.3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/dictionaries/ronn.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions .idea/libraries/rlib.xml

This file was deleted.

12 changes: 1 addition & 11 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,71 @@ JFX Gui bridge for JME with usefull utilities for common usecases

License is the New BSD License (same as JME3)
http://opensource.org/licenses/BSD-3-Clause

How to use:
* 1. You need to create FXContainer inside the method simpleInitApp() of SimpleApplication.

````
final ProtonCursorProvider cursorProvider = new ProtonCursorProvider(this, assetManager, inputManager);

for (final CursorType type : CursorType.values()) {
cursorProvider.setup(type);
}

fxContainer = JmeFxContainer.install(this, guiNode, cursorProvider);
````

if you want to use simple default arrow cursor you should use this:
````
fxContainer = JmeFxContainer.install(this, guiNode, null);
````

* 2. Then you must create javaFX scene and set it on the fx container to build your UI.
You can use FXML if you prefer it like this:
````
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/hud.fxml"));
BorderPane root = fxmlLoader.load();
int width = app.getContext().getSettings().getWidth();
int height = app.getContext().getSettings().getHeight();
root.setPrefSize(width, height);
Hud hud = fxmlLoader.getController();
Group group = new Group(root);
Scene scene = new Scene(group, Color.TRANSPARENT);
fxContainer.setScene(scene, group);
````

where Hud is controller class for example

````
public class Hud implements Initializable {
@FXML
public BorderPane root;

@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
````
Ofc hud.fxml should be accessible in resources, valid and points to Hud class.
If you do not want to use FXML your code can be even simpler:

````
BorderPane root = new BorderPane();
int width = app.getContext().getSettings().getWidth();
int height = app.getContext().getSettings().getHeight();
root.setPrefSize(width, height);
Group group = new Group(root);
Scene scene = new Scene(group, Color.TRANSPARENT);
fxContainer.setScene(scene, group);
````

* 3. From now you are able to get transparent JavaFX scene and use it as in classic JavaFX application.
````
fxContainer.getScene();
````

* 3. Also you need to add calling a draw method in the main loop(the method update() of your application)

````
if (fxContainer.isNeedWriteToJME()) fxContainer.writeToJME();
````
Binary file removed build/jfx-1.2.jar
Binary file not shown.
Binary file removed build/jfx-1.3.1.jar
Binary file not shown.
Binary file removed build/jfx-1.3.2.jar
Binary file not shown.
Binary file removed build/jfx-1.3.jar
Binary file not shown.
Binary file added build/jfx-1.4.0.jar
Binary file not shown.
Binary file added lib/rlib-4.0.0.jar
Binary file not shown.
Binary file added lib/rlib-sources-4.0.0.jar
Binary file not shown.
20 changes: 20 additions & 0 deletions src/com/jme3x/jfx/cursor/CursorDisplayProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jme3x.jfx.cursor;


import java.awt.Cursor;

/**
* The interface for implementing the provider of cursors.
*/
public interface CursorDisplayProvider {

/**
* Setups the type of cursor.
*/
void setupCursor(Cursor normal);

/**
* Shows ths cursor.
*/
void showCursor(Cursor cursorFrame);
}
83 changes: 83 additions & 0 deletions src/com/jme3x/jfx/cursor/proton/ProtonCursorProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.jme3x.jfx.cursor.proton;

import com.jme3.app.Application;
import com.jme3.asset.AssetManager;
import com.jme3.asset.plugins.ClasspathLocator;
import com.jme3.cursors.plugins.JmeCursor;
import com.jme3.input.InputManager;
import com.jme3x.jfx.cursor.CursorDisplayProvider;

import java.awt.Cursor;
import java.util.concurrent.ConcurrentHashMap;

/**
* http://www.rw-designer.com/cursor-set/proton by juanello <br> A cursorProvider that simulates the
* native JFX one and tries to behave similar,<br> using native cursors and 2D surface logic.
*
* @author empire
*/
public class ProtonCursorProvider implements CursorDisplayProvider {

private ConcurrentHashMap<Cursor, JmeCursor> cache = new ConcurrentHashMap<>();

private AssetManager assetManager;
private InputManager inputManager;
private Application app;

public ProtonCursorProvider(final Application app, final AssetManager assetManager, final InputManager inputManager) {
this.assetManager = assetManager;
this.inputManager = inputManager;
this.app = app;
assetManager.registerLocator("", ClasspathLocator.class);
}

@Override
public synchronized void showCursor(final Cursor cursor) {

if (cache.get(cursor) == null) {
setupCursor(cursor);
}

final JmeCursor toDisplay = cache.get(cursor);
if (toDisplay == null) return;

app.enqueue(() -> {
inputManager.setMouseCursor(toDisplay);
return null;
});
}

@Override
public void setupCursor(final Cursor cursor) {

JmeCursor loaded = null;

switch (cursor.getType()) {
case Cursor.CROSSHAIR_CURSOR:
loaded = (JmeCursor) assetManager.loadAsset("com/jme3x/jfx/cursor/proton/aero_cross.cur");
break;
case Cursor.DEFAULT_CURSOR:
loaded = (JmeCursor) assetManager.loadAsset("com/jme3x/jfx/cursor/proton/aero_arrow.cur");
break;
case Cursor.MOVE_CURSOR:
loaded = (JmeCursor) assetManager.loadAsset("com/jme3x/jfx/cursor/proton/aero_move.cur");
break;
case Cursor.HAND_CURSOR:
break;
case Cursor.TEXT_CURSOR:
loaded = (JmeCursor) assetManager.loadAsset("com/jme3x/jfx/cursor/proton/aero_text.cur");
break;
case Cursor.WAIT_CURSOR:
loaded = (JmeCursor) assetManager.loadAsset("com/jme3x/jfx/cursor/proton/aero_busy.ani");
break;
case Cursor.W_RESIZE_CURSOR:
loaded = (JmeCursor) assetManager.loadAsset("com/jme3x/jfx/cursor/proton/aero_ew.cur");
break;
default: {
loaded = (JmeCursor) assetManager.loadAsset("com/jme3x/jfx/cursor/proton/aero_arrow.cur");
}
}

if (loaded != null) cache.put(cursor, loaded);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 16 additions & 16 deletions ...va/com/jme3x/jfx/cursor/proton/readme.txt → src/com/jme3x/jfx/cursor/proton/readme.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
=== Proton Cursor Set ===
By: juanello
Download: http://www.rw-designer.com/cursor-set/proton
Author's decription:
==========
License: Released to Public Domain
You are free:
=== Proton Cursor Set ===

By: juanello

Download: http://www.rw-designer.com/cursor-set/proton

Author's decription:



==========

License: Released to Public Domain

You are free:

* To use this work for any legal purpose.
62 changes: 62 additions & 0 deletions src/com/jme3x/jfx/injfx/ApplicationThreadExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.jme3x.jfx.injfx;

import com.sun.istack.internal.NotNull;

import rlib.util.ArrayUtils;
import rlib.util.array.Array;
import rlib.util.array.ArrayFactory;
import rlib.util.array.ConcurrentArray;

/**
* The executor for executing tasks in application thread.
*
* @author JavaSaBr
*/
public class ApplicationThreadExecutor {

private static final ApplicationThreadExecutor INSTANCE = new ApplicationThreadExecutor();

@NotNull
public static ApplicationThreadExecutor getInstance() {
return INSTANCE;
}

/**
* The list of waiting tasks.
*/
@NotNull
private final ConcurrentArray<Runnable> waitTasks;

/**
* THe list of tasks to execute.
*/
@NotNull
private final Array<Runnable> execute;

public ApplicationThreadExecutor() {
this.waitTasks = ArrayFactory.newConcurrentAtomicARSWLockArray(Runnable.class);
this.execute = ArrayFactory.newArray(Runnable.class);
}

/**
* Add the task to execute.
*
* @param task the new task.
*/
public void addToExecute(@NotNull final Runnable task) {
ArrayUtils.runInWriteLock(waitTasks, task, Array::add);
}

/**
* Execute the waiting tasks.
*/
public void execute() {
if (waitTasks.isEmpty()) return;
ArrayUtils.runInWriteLock(waitTasks, execute, ArrayUtils::move);
try {
execute.forEach(Runnable::run);
} finally {
execute.clear();
}
}
}
Loading