Example usage for com.badlogic.gdx.scenes.scene2d.utils DragAndDrop setDragActorPosition

List of usage examples for com.badlogic.gdx.scenes.scene2d.utils DragAndDrop setDragActorPosition

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.utils DragAndDrop setDragActorPosition.

Prototype

public void setDragActorPosition(float dragActorX, float dragActorY) 

Source Link

Usage

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  . jav a  2  s .co 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());
        }

    });
}