Search in sources :

Example 6 with ColorPicker

use of com.kotcrab.vis.ui.widget.color.ColorPicker in project talos by rockbite.

the class GradientColorModuleWrapper method configureSlots.

@Override
protected void configureSlots() {
    addInputSlot("alpha (0 to 1)", InterpolationModule.ALPHA);
    addOutputSlot("output", 0);
    gradientWidget = new GradientWidget(getSkin());
    contentWrapper.add(gradientWidget).expandX().fillX().growX().height(60).padTop(25).padRight(3).padBottom(3);
    leftWrapper.add(new Table()).expandY();
    rightWrapper.add(new Table()).expandY();
    picker = new ColorPicker();
    gradientWidget.setListener(new GradientWidget.GradientWidgetListener() {

        @Override
        public void colorPickerShow(final ColorPoint point) {
            picker.setListener(null);
            picker.setColor(point.color);
            TalosMain.Instance().UIStage().getStage().addActor(picker.fadeIn());
            picker.setListener(new ColorPickerAdapter() {

                @Override
                public void changed(Color newColor) {
                    super.changed(newColor);
                    point.color.set(newColor);
                    gradientWidget.updateGradientData();
                }
            });
        }
    });
    picker.padTop(32);
    picker.padLeft(16);
    picker.setHeight(330);
    picker.setWidth(430);
    picker.padRight(26);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) GradientWidget(com.talosvfx.talos.editor.widgets.GradientWidget) ColorPicker(com.kotcrab.vis.ui.widget.color.ColorPicker) ColorPoint(com.talosvfx.talos.runtime.values.ColorPoint) Color(com.badlogic.gdx.graphics.Color) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)

Example 7 with ColorPicker

use of com.kotcrab.vis.ui.widget.color.ColorPicker in project talos by rockbite.

the class ColorModuleWrapper method configureSlots.

@Override
protected void configureSlots() {
    rField = addInputSlotWithTextField("R: ", 0, 40);
    gField = addInputSlotWithTextField("G: ", 1, 40);
    bField = addInputSlotWithTextField("B: ", 2, 40);
    rField.setText("255");
    gField.setText("0");
    bField.setText("0");
    rField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            float r = floatFromText(rField);
            module.setR(r / 255f);
            update();
        }
    });
    gField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            float g = floatFromText(gField);
            module.setG(g / 255f);
            update();
        }
    });
    bField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            float b = floatFromText(bField);
            module.setB(b / 255f);
            update();
        }
    });
    addOutputSlot("position", 0);
    picker = new ColorPicker(new ColorPickerAdapter() {

        @Override
        public void changed(Color newColor) {
            if (colorBtn != null) {
                colorBtn.setColor(newColor);
                rField.setText("" + (int) (newColor.r * 255f));
                gField.setText("" + (int) (newColor.g * 255f));
                bField.setText("" + (int) (newColor.b * 255f));
                module.setR(newColor.r);
                module.setG(newColor.g);
                module.setB(newColor.b);
            }
        }
    });
    // create color picker Btn
    colorBtn = new Image(getSkin().getDrawable("white"));
    contentWrapper.add(colorBtn).width(50).height(50).right().padLeft(26);
    colorBtn.setColor(1f, 0, 0, 1f);
    colorBtn.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            TalosMain.Instance().UIStage().getStage().addActor(picker.fadeIn());
        }
    });
    picker.padTop(32);
    picker.padLeft(16);
    picker.setHeight(330);
    picker.setWidth(430);
    picker.padRight(26);
}
Also used : ColorPicker(com.kotcrab.vis.ui.widget.color.ColorPicker) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Color(com.badlogic.gdx.graphics.Color) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 8 with ColorPicker

use of com.kotcrab.vis.ui.widget.color.ColorPicker in project HyperLap2D by rednblackgames.

the class UIBasicItemPropertiesMediator method handleNotification.

@Override
public void handleNotification(INotification notification) {
    super.handleNotification(notification);
    switch(notification.getName()) {
        case UIBasicItemProperties.TINT_COLOR_BUTTON_CLICKED:
            Color prevColor = viewComponent.getTintColor().cpy();
            ColorPicker picker = new HyperLapColorPicker(new ColorPickerAdapter() {

                @Override
                public void finished(Color newColor) {
                    TintComponent tintComponent = SandboxComponentRetriever.get(observableReference, TintComponent.class);
                    tintComponent.color.set(prevColor);
                    viewComponent.setTintColor(newColor);
                    facade.sendNotification(viewComponent.getUpdateEventName());
                }

                @Override
                public void changed(Color newColor) {
                    TintComponent tintComponent = SandboxComponentRetriever.get(observableReference, TintComponent.class);
                    tintComponent.color.set(newColor);
                }
            });
            if (notification.getBody() != null) {
                viewComponent.setTintColor(notification.getBody());
            }
            picker.setColor(viewComponent.getTintColor());
            Sandbox.getInstance().getUIStage().addActor(picker.fadeIn());
            break;
        case UIBasicItemProperties.LINKING_CHANGED:
            boolean isLinked = notification.getBody();
            if (!isLinked) {
                facade.sendNotification(MsgAPI.ACTION_ADD_TO_LIBRARY, AddToLibraryCommand.payloadUnLink(observableReference));
            } else {
                facade.sendNotification(MsgAPI.SHOW_ADD_LIBRARY_DIALOG, observableReference);
            }
            break;
        case UIBasicItemProperties.ADD_COMPONENT_BUTTON_CLICKED:
            Class<? extends Component> componentClass = componentClassMap.get(viewComponent.getSelectedComponent());
            if (componentClass == null)
                break;
            facade.sendNotification(MsgAPI.ACTION_ADD_COMPONENT, AddComponentToItemCommand.payload(observableReference, componentClass));
            break;
        default:
            break;
    }
}
Also used : HyperLapColorPicker(games.rednblack.h2d.common.view.ui.widget.HyperLapColorPicker) ColorPicker(com.kotcrab.vis.ui.widget.color.ColorPicker) Color(com.badlogic.gdx.graphics.Color) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter) HyperLapColorPicker(games.rednblack.h2d.common.view.ui.widget.HyperLapColorPicker)

Example 9 with ColorPicker

use of com.kotcrab.vis.ui.widget.color.ColorPicker in project gdx-graph by MarcinSc.

the class GradientShaderBoxProducer method createPipelineGraphBox.

@Override
public GraphBox createPipelineGraphBox(Skin skin, String id, JsonValue data) {
    final GraphBoxImpl result = createGraphBox(id);
    addConfigurationInputsAndOutputs(result);
    final GradientWidget gradientWidget = new GradientWidget();
    gradientWidget.setSize(300, 40);
    if (data != null) {
        JsonValue points = data.get("points");
        for (String point : points.asStringArray()) {
            String[] split = point.split(",");
            gradientWidget.createPoint(Color.valueOf(split[0]), Float.parseFloat(split[1]));
        }
    } else {
        gradientWidget.createPoint(Color.WHITE, 0);
    }
    gradientWidget.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            gradientWidget.fire(new GraphChangedEvent(false, true));
        }
    });
    gradientWidget.setListener(new GradientWidget.GradientWidgetListener() {

        @Override
        public void colorPickerShow(final ColorPoint point, final Runnable onSuccess) {
            final ColorPicker picker = new ColorPicker();
            picker.setColor(point.color);
            picker.setListener(new ColorPickerAdapter() {

                @Override
                public void finished(Color newColor) {
                    point.color.set(newColor);
                    picker.dispose();
                    onSuccess.run();
                    result.getActor().fire(new GraphChangedEvent(false, true));
                }

                @Override
                public void canceled(Color oldColor) {
                    picker.dispose();
                }
            });
            gradientWidget.getStage().addActor(picker.fadeIn());
        }
    });
    result.addGraphBoxPart(new GraphBoxPartImpl(gradientWidget, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            Array<ColorPoint> points = gradientWidget.getPoints();
            JsonValue pointsValue = new JsonValue(JsonValue.ValueType.array);
            for (ColorPoint point : points) {
                pointsValue.addChild(new JsonValue(point.color.toString() + "," + SimpleNumberFormatter.format(point.pos)));
            }
            object.addChild("points", pointsValue);
        }
    }));
    final VisSelectBox<ClampMethod> clampMethodSelectBox = new VisSelectBox<ClampMethod>();
    clampMethodSelectBox.setItems(ClampMethod.values());
    if (data != null)
        clampMethodSelectBox.setSelected(ClampMethod.valueOf(data.getString("clamp", "Normal")));
    clampMethodSelectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            result.getActor().fire(new GraphChangedEvent(false, true));
        }
    });
    VisTable clampActor = new VisTable();
    clampActor.add("Clamp method:").row();
    clampActor.add(clampMethodSelectBox).growX();
    result.addGraphBoxPart(new GraphBoxPartImpl(clampActor, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            object.addChild("clamp", new JsonValue(clampMethodSelectBox.getSelected().name()));
        }
    }));
    return result;
}
Also used : GraphBoxImpl(com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl) GraphChangedEvent(com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent) ColorPicker(com.kotcrab.vis.ui.widget.color.ColorPicker) Color(com.badlogic.gdx.graphics.Color) JsonValue(com.badlogic.gdx.utils.JsonValue) GraphBoxPartImpl(com.gempukku.libgdx.graph.ui.graph.GraphBoxPartImpl) VisSelectBox(com.kotcrab.vis.ui.widget.VisSelectBox) VisTable(com.kotcrab.vis.ui.widget.VisTable) GradientWidget(com.talosvfx.talos.editor.widgets.GradientWidget) ClampMethod(com.gempukku.libgdx.graph.shader.ClampMethod) ColorPoint(com.talosvfx.talos.runtime.values.ColorPoint) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)

Aggregations

ColorPicker (com.kotcrab.vis.ui.widget.color.ColorPicker)9 Color (com.badlogic.gdx.graphics.Color)8 ColorPickerAdapter (com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)8 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)4 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 HyperLapColorPicker (games.rednblack.h2d.common.view.ui.widget.HyperLapColorPicker)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 JsonValue (com.badlogic.gdx.utils.JsonValue)2 VisTable (com.kotcrab.vis.ui.widget.VisTable)2 GradientWidget (com.talosvfx.talos.editor.widgets.GradientWidget)2 ColorPoint (com.talosvfx.talos.runtime.values.ColorPoint)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 BaseDrawable (com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable)1 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)1 XmlReader (com.badlogic.gdx.utils.XmlReader)1