List of usage examples for com.badlogic.gdx.scenes.scene2d.utils DragAndDrop DragAndDrop
DragAndDrop
From source file:com.mangogames.imagealphabets.ui.layer.AlphabetsLayer.java
License:Open Source License
/** * Perform DragAndDrop functionality /*from w w w. ja v a 2s. c o m*/ * @param actor */ public void handleTouchEvents(final Actor actor) { final AlphabetSprite alphabetSprite = (AlphabetSprite) actor; DragAndDrop dragAndDrop = new DragAndDrop(); char ch = alphabetSprite.getAlphabetName().charAt(0); String s = ch + "2"; if (alphabetSprite.getAlphabetName().equals(s)) { dragAndDrop.addSource(new Source(alphabetSprite) { @Override public Payload dragStart(InputEvent event, float x, float y, int pointer) { alphabetSprite.setDropSuccessful(false); setAlphabetSprite(0, alphabetSprite.getColpos(), true); Payload payload = new Payload(); payload.setDragActor(alphabetSprite); return payload; } @Override public void dragStop(InputEvent event, float x, float y, int pointer, Target target) { super.dragStop(event, x, y, pointer, target); if (alphabetSprite.isDropSuccessful() == false) { setAlphabetSprite(0, alphabetSprite.getColpos(), false); } } }); dragAndDrop.addTarget(new Target(boardScene.getBackgroundLayer().image) { public boolean drag(Source source, Payload payload, float x, float y, int pointer) { return true; } @Override public void drop(Source source, Payload payload, float x, float y, int pointer) { setAlphabetSprite(0, ((AlphabetSprite) payload.getDragActor()).getColpos(), false); if (alphabetSprite.isDropSuccessful() == false) alphabetSprite.setDropSuccessful(true); } }); int length = boardScene.getImagesLayer().imageTable.getCells().size(); for (int i = 0; i < length; i++) { final int col = i; final ImageSprite imageSprite = boardScene.getImageSprite(0, col); dragAndDrop.addTarget(new Target(imageSprite) { public boolean drag(Source source, Payload payload, float x, float y, int pointer) { getActor().setColor(Color.GREEN); return true; } @Override public void drop(Source source, Payload payload, float x, float y, int pointer) { if (alphabetSprite.isDropSuccessful() == false) alphabetSprite.setDropSuccessful(true); if (imageSprite.getImageName().charAt(0) == alphabetSprite.getAlphabetName().charAt(0)) { boardScene.setImageSprite(0, col); String alphasound = imageSprite.getImageName().charAt(0) + ".mp3"; sound = loadMusic(alphasound); sound.play(); // sound.dispose(); count++; if (count == 3) { addAction(Actions.sequence(Actions.delay(2f), Actions.run(onCountThreeFinishedRunnable))); } } else { setAlphabetSprite(0, ((AlphabetSprite) payload.getDragActor()).getColpos(), false); } } }); } } }
From source file:com.mbrlabs.mundus.ui.modules.Outline.java
License:Apache License
private void setupDragAndDrop() { dragAndDrop = new DragAndDrop(); // source/* ww w.j a va 2 s . c o m*/ dragAndDrop.addSource(new DragAndDrop.Source(tree) { @Override public DragAndDrop.Payload dragStart(InputEvent event, float x, float y, int pointer) { DragAndDrop.Payload payload = new DragAndDrop.Payload(); Tree.Node node = tree.getNodeAt(y); if (node != null) { payload.setObject(node); return payload; } return null; } }); // target dragAndDrop.addTarget(new DragAndDrop.Target(tree) { @Override public boolean drag(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer) { // Select node under mouse if not over the selection. Tree.Node overNode = tree.getNodeAt(y); if (overNode == null && tree.getSelection().isEmpty()) { return true; } if (overNode != null && !tree.getSelection().contains(overNode)) { tree.getSelection().set(overNode); } return true; } @Override public void drop(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer) { Tree.Node node = (Tree.Node) payload.getObject(); if (node != null) { GameObject draggedGo = (GameObject) node.getObject(); Tree.Node newParent = tree.getNodeAt(y); // check if a go is dragged in one of its' children or // itself if (newParent != null) { GameObject parentGo = (GameObject) newParent.getObject(); if (parentGo.isChildOf(draggedGo)) { return; } } GameObject oldParent = draggedGo.getParent(); // remove child from old parent draggedGo.remove(); // add to new parent if (newParent == null) { // recalculate position for root layer Vector3 newPos; Vector3 draggedPos = new Vector3(); draggedGo.getPosition(draggedPos); // if moved from old parent if (oldParent != null) { // new position = oldParentPos + draggedPos Vector3 parentPos = new Vector3(); oldParent.getPosition(parentPos); newPos = parentPos.add(draggedPos); } else { // new local position = World position newPos = draggedPos; } projectContext.currScene.sceneGraph.addGameObject(draggedGo); draggedGo.setLocalPosition(newPos.x, newPos.y, newPos.z); } else { GameObject parentGo = (GameObject) newParent.getObject(); // recalculate position Vector3 parentPos = new Vector3(); Vector3 draggedPos = new Vector3(); // World coorinates draggedGo.getPosition(draggedPos); parentGo.getPosition(parentPos); // if gameObject came from old parent if (oldParent != null) { // calculate oldParentPos + draggedPos Vector3 oldParentPos = new Vector3(); oldParent.getPosition(oldParentPos); draggedPos = oldParentPos.add(draggedPos); } // Local in releation to new parent Vector3 newPos = draggedPos.sub(parentPos); // add parentGo.addChild(draggedGo); draggedGo.setLocalPosition(newPos.x, newPos.y, newPos.z); } // update tree buildTree(sceneGraph); } } }); }
From source file:com.o2d.pkayjava.editor.view.ui.box.UILayerBox.java
License:Apache License
public UILayerBox() { super("Layers", 222); facade = Overlap2DFacade.getInstance(); setMovable(false);//from w w w.j ava2 s . c om contentTable = new VisTable(); layersTable = new VisTable(); scrollPane = new VisScrollPane(layersTable); scrollPane.setFadeScrollBars(false); contentTable.add(scrollPane).padTop(2).width(221).height(150); layersTable.top(); scrollPane.layout(); bottomPane = new VisTable(); contentTable.row(); contentTable.add(bottomPane).expandX().fillX(); VisImageButton newBtn = new VisImageButton("new-layer-button"); VisImageButton deleteBtn = new VisImageButton("trash-button"); bottomPane.add().expandX(); bottomPane.add(newBtn).right().pad(3); bottomPane.add(deleteBtn).right().pad(3); newBtn.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { facade.sendNotification(CREATE_NEW_LAYER); } }); deleteBtn.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { facade.sendNotification(DELETE_LAYER); } }); dragAndDrop = new DragAndDrop(); createCollapsibleWidget(contentTable); }
From source file:com.pixelscientists.gdx.inventory.InventoryScreen.java
License:Open Source License
@Override public void show() { stage = new Stage(); Gdx.input.setInputProcessor(stage);/* ww w. j ava 2 s . co m*/ Skin skin = LibgdxUtils.assets.get("skins/uiskin.json", Skin.class); DragAndDrop dragAndDrop = new DragAndDrop(); inventoryActor = new InventoryActor(new Inventory(), dragAndDrop, skin); stage.addActor(inventoryActor); }
From source file:com.uwsoft.editor.gdx.ui.layer.UILayerBox.java
License:Apache License
public UILayerBox(UIStage s) { super(s, 250, 250); addActor(contentGroup);//from w ww .java 2s . com addActor(uiGroup); initBottomBar(); dragAndDrop = new DragAndDrop(); dragAndDrop.setDragActorPosition(0, 0); isLayerDragging = false; }
From source file:com.uwsoft.editor.gdx.ui.UILightBox.java
License:Apache License
public void initContent() { SceneLoader sceneLoader = stage.sceneLoader; CompositeItem ui = sceneLoader.getCompositeElementById("lightBox"); ui.setX(7);//from www . j a va 2s . c o m ui.setY(getHeight() - ui.getHeight() - 14); mainLayer.addActor(ui); cPicker = new ColorPickerButton(); cPicker.setX(100); cPicker.setY(getHeight() - 92); mainLayer.addActor(cPicker); float[] ambientColor = stage.getSandbox().sceneControl.getCurrentSceneVO().ambientColor; cPicker.setColorValue(new Color(ambientColor[0], ambientColor[1], ambientColor[2], ambientColor[3])); //System.out.println("ambient " +cPicker.getColorValue().toString()); ImageItem bulb = ui.getImageById("bulbBtn"); ImageItem cone = ui.getImageById("coneBtn"); cPickerElems = new ColorPickerButton(); cPickerElems.setX(85); cPickerElems.setY(getHeight() - 196); mainLayer.addActor(cPickerElems); // // Image coneThumb = new Image(TextureManager.getInstance().getEditorAsset("cone")); cPicker.addListener(new ClickListener() { public void touchUp(InputEvent event, float x, float y, int pointer, int button) { super.touchUp(event, x, y, pointer, button); ColorPicker picker = new ColorPicker(new ColorPickerAdapter() { @Override public void finished(Color newColor) { cPicker.setColorValue(newColor); // change scene ambient light stage.getSandbox().setSceneAmbientColor(newColor); } }); stage.addActor(picker.fadeIn()); } }); cPickerElems.addListener(new ClickListener() { public void touchUp(InputEvent event, float x, float y, int pointer, int button) { super.touchUp(event, x, y, pointer, button); ColorPicker picker = new ColorPicker(new ColorPickerAdapter() { @Override public void finished(Color newColor) { cPickerElems.setColorValue(newColor); } }); stage.addActor(picker.fadeIn()); } }); final DragAndDrop dragAndDropBulb = new DragAndDrop(); dragAndDropBulb.addSource(new DragAndDrop.Source(bulb) { public DragAndDrop.Payload dragStart(InputEvent event, float x, float y, int pointer) { DragAndDrop.Payload payload = new DragAndDrop.Payload(); Image bulbThumb = new Image(DataManager.getInstance().textureManager.getEditorAsset("bulb")); payload.setDragActor(bulbThumb); dragAndDropBulb.setDragActorPosition(-bulbThumb.getWidth() / 2, bulbThumb.getHeight() / 2); return payload; } }); dragAndDropBulb.addTarget(new DragAndDrop.Target(stage.dummyTarget) { @Override public void drop(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer) { if (disableLights.isChecked()) return; LightVO vo = new LightVO(); Color tint = cPickerElems.getColorValue(); float[] clr = new float[4]; clr[0] = tint.r; clr[1] = tint.g; clr[2] = tint.b; clr[3] = tint.a; vo.tint = clr; vo.type = LightType.POINT; stage.getSandbox().getUac().createLight(vo, x, y); } @Override public boolean drag(DragAndDrop.Source arg0, DragAndDrop.Payload arg1, float arg2, float arg3, int arg4) { return true; } }); final DragAndDrop dragAndDropCone = new DragAndDrop(); dragAndDropCone.addSource(new DragAndDrop.Source(cone) { public DragAndDrop.Payload dragStart(InputEvent event, float x, float y, int pointer) { DragAndDrop.Payload payload = new DragAndDrop.Payload(); Image coneThumb = new Image(DataManager.getInstance().textureManager.getEditorAsset("cone")); payload.setDragActor(coneThumb); dragAndDropCone.setDragActorPosition(-coneThumb.getWidth() / 2, coneThumb.getHeight() / 2); return payload; } }); dragAndDropCone.addTarget(new DragAndDrop.Target(stage.dummyTarget) { @Override public void drop(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer) { if (disableLights.isChecked()) return; LightVO vo = new LightVO(); vo.type = LightType.CONE; Color tint = cPickerElems.getColorValue(); float[] clr = new float[4]; clr[0] = tint.r; clr[1] = tint.g; clr[2] = tint.b; clr[3] = tint.a; vo.tint = clr; stage.getSandbox().getUac().createLight(vo, x, y); } @Override public boolean drag(DragAndDrop.Source arg0, DragAndDrop.Payload arg1, float arg2, float arg3, int arg4) { return true; } }); disableLights = ui.getCheckBoxById("disableLights"); disableLights.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { super.touchUp(event, x, y, pointer, button); stage.getSandbox().sceneControl.disableLights(disableLights.isChecked()); } }); disableAmbiance = ui.getCheckBoxById("disableAmbiance"); disableAmbiance.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { super.touchUp(event, x, y, pointer, button); stage.getSandbox().getSceneControl().disableAmbience(disableAmbiance.isChecked()); } }); }
From source file:com.uwsoft.editor.view.ui.box.UILayerBox.java
License:Apache License
public UILayerBox() { super("Layers", 222); facade = Overlap2DFacade.getInstance(); setMovable(false);/* w w w. j a v a2s . c o m*/ contentTable = new VisTable(); layersTable = new VisTable(); scrollPane = new VisScrollPane(layersTable); scrollPane.setFadeScrollBars(false); contentTable.add(scrollPane).padTop(2).width(221).height(150); layersTable.top(); scrollPane.layout(); bottomPane = new VisTable(); contentTable.row(); contentTable.add(bottomPane).expandX().fillX(); VisImageButton newBtn = new VisImageButton("new-layer-button"); VisImageButton deleteBtn = new VisImageButton("trash-button"); bottomPane.add().expandX(); bottomPane.add(newBtn).right().pad(3); bottomPane.add(deleteBtn).right().pad(3); newBtn.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { facade.sendNotification(CREATE_NEW_LAYER); } }); deleteBtn.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { facade.sendNotification(DELETE_NEW_LAYER); } }); dragAndDrop = new DragAndDrop(); createCollapsibleWidget(contentTable); }
From source file:es.eucm.ead.editor.ui.scenes.ribbon.animation.AnimationEdition.java
License:Open Source License
public AnimationEdition(Controller controller) { super();//from w w w .j a v a 2s .c o m skin = controller.getApplicationAssets().getSkin(); align(Align.top); DragAndDrop dragAndDrop = new DragAndDrop(); buttonReg = new HashMap<IconTextButton, Class<Effect>>(); drawableReg = new HashMap<Class<Effect>, Drawable>(); backgroundTweens = skin.getDrawable("bg-dark"); add(new TweensTypeTab(dragAndDrop, controller)).left(); row(); AnimationTimeline timeline = new AnimationTimeline(dragAndDrop, controller); add(timeline).expandX().fill(); row(); add(new Separator(true, skin)); row(); add(timeline.getAddButton()).fill().expandX(); row(); add(new Separator(true, skin)); }
From source file:es.eucm.ead.editor.view.widgets.dragndrop.DraggableScrollPane.java
License:Open Source License
public DraggableScrollPane(Actor widget, float zone, float speed) { this(widget, new DragAndDrop(), DEFAULT_ACTION_ZONE, DEAFULT_SPEED); }
From source file:es.eucm.ead.editor.view.widgets.layouts.TrackLayout.java
License:Open Source License
/** * Creates a new {@link TrackLayout} with a new {@link DragAndDrop} and * without background. * */ public TrackLayout() { this(null, new DragAndDrop()); }