Skip to content

Commit

Permalink
try to rework DragAndDropDemo to a SimpleApplication
Browse files Browse the repository at this point in the history
known bug: sphere disappears when dragging and only reappears on dropping
  • Loading branch information
tomreineke committed Nov 26, 2018
1 parent 2f1d18c commit 676ca7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 39 deletions.
4 changes: 2 additions & 2 deletions examples/demos/src/main/java/demo/DemoLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public static void main( String... args ) throws Exception {
}*/

main.setSettings(settings);

main.start();
DragAndDropDemoState drag = new DragAndDropDemoState();
drag.start();
}

public DemoLauncher() {
Expand Down
60 changes: 23 additions & 37 deletions examples/demos/src/main/java/demo/DragAndDropDemoState.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@
import java.util.*;

import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.input.event.*;
import com.jme3.light.*;
import com.jme3.material.*;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.material.RenderState.FaceCullMode;
import com.jme3.math.*;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.*;
import com.jme3.scene.Spatial.CullHint;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.debug.WireBox;
import com.jme3.scene.shape.*;
Expand All @@ -61,16 +56,15 @@
import com.simsilica.lemur.dnd.*;
import com.simsilica.lemur.core.GuiMaterial;
import com.simsilica.lemur.event.*;
import com.simsilica.lemur.style.BaseStyles;
import javafx.util.Pair;

/**
* Demo and test of the drag-and-drop support in Lemur.
*
* @author Paul Speed
*/
public class DragAndDropDemoState extends BaseAppState {

private Node dndRoot;
public class DragAndDropDemoState extends SimpleApplication {

private ColorRGBA containerColor = new ColorRGBA(1, 1, 0, 0.5f);
private ColorRGBA containerHighlight = new ColorRGBA(0, 1, 0, 0.5f);
Expand All @@ -81,32 +75,43 @@ public class DragAndDropDemoState extends BaseAppState {
private AssetManager assetManager;

private static final int GRID_SIZE = 5;
private static final float LOCAL_SCALE = 0.3f;
private static final float LOCAL_SCALE = 13.5f;

public DragAndDropDemoState() {
}

@Override
public void simpleInitApp() {
setPauseOnLostFocus(false);
setDisplayFps(false);
setDisplayStatView(false);

GuiGlobals.initialize(this);

GuiGlobals globals = GuiGlobals.getInstance();
BaseStyles.loadGlassStyle();
globals.getStyles().setDefaultStyle("glass");
initialize(this);
}

protected Node getRoot() {
return dndRoot;
return guiNode;
}

@Override
protected void initialize( Application app ) {
dndRoot = new Node("dndRoot");

this.assetManager = app.getAssetManager();

container1 = new ContainerNode("container2", containerColor);
container1.setSize(GRID_SIZE, GRID_SIZE, 0);
container1.setLocalTranslation(0f, 0f, 0.5f);
container1.setLocalTranslation(200f, 100f, 0.5f);
container1.setLocalScale(LOCAL_SCALE);
MouseEventControl.addListenersToSpatial(container1,
new HighlightListener(container1.material,
containerHighlight,
containerColor));
container1.addControl(new GridControl(GRID_SIZE));
container1.addControl(new DragAndDropControl(new GridContainerListener(container1)));
dndRoot.attachChild(container1);
getRoot().attachChild(container1);

// Add some random items to our MVC grid 'model' control
container1.getControl(GridControl.class).setCell(0, 0, createItem());
Expand All @@ -115,15 +120,15 @@ protected void initialize( Application app ) {
// Setup a grid based container
container2 = new ContainerNode("container2", containerColor);
container2.setSize(GRID_SIZE, GRID_SIZE, 0);
container2.setLocalTranslation(4f, 0f, 0.5f);
container2.setLocalTranslation(400f, 100f, 0.5f);
container2.setLocalScale(LOCAL_SCALE);
MouseEventControl.addListenersToSpatial(container2,
new HighlightListener(container2.material,
containerHighlight,
containerColor));
container2.addControl(new GridControl(GRID_SIZE));
container2.addControl(new DragAndDropControl(new GridContainerListener(container2)));
dndRoot.attachChild(container2);
getRoot().attachChild(container2);

// Add some random items to our MVC grid 'model' control
container2.getControl(GridControl.class).setCell(0, 0, createItem());
Expand All @@ -144,25 +149,6 @@ private Spatial createItem() {
return geom;
}

@Override
protected void cleanup( Application app ) {
}

@Override
protected void onEnable() {
((DemoLauncher)getApplication()).getRootNode().attachChild(dndRoot);
}

@Override
protected void onDisable() {
dndRoot.removeFromParent();
}

@Override
public void update( float tpf ) {
//System.out.println("-------- update -----");
}

/**
* Just to encapsulate the visuals needed to have both a wireframe
* view but an actual box for picking.
Expand Down

0 comments on commit 676ca7a

Please sign in to comment.