Search in sources :

Example 1 with VisImage

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

the class ValueColorBoxProducer method createValuePart.

private GraphBoxPartImpl createValuePart(String value) {
    Color color = Color.valueOf(value);
    final TextureRegionDrawable drawable = new TextureRegionDrawable(WhitePixel.sharedInstance.texture);
    BaseDrawable baseDrawable = new BaseDrawable(drawable) {

        @Override
        public void draw(Batch batch, float x, float y, float width, float height) {
            drawable.draw(batch, x, y, width, height);
        }
    };
    baseDrawable.setMinSize(20, 20);
    final VisImage image = new VisImage(baseDrawable);
    image.setColor(color);
    final ColorPicker picker = new ColorPicker(new ColorPickerAdapter() {

        @Override
        public void finished(Color newColor) {
            image.setColor(newColor);
            image.fire(new GraphChangedEvent(false, true));
        }
    });
    picker.setColor(color);
    image.addListener(new ClickListener(Input.Buttons.LEFT) {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            // displaying picker with fade in animation
            image.getStage().addActor(picker.fadeIn());
        }
    });
    VisTable table = new VisTable();
    table.add(new VisLabel("Color")).growX();
    table.add(image);
    table.row();
    GraphBoxPartImpl colorPart = new GraphBoxPartImpl(table, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            object.addChild("color", new JsonValue(image.getColor().toString()));
        }
    }) {

        @Override
        public void dispose() {
            picker.dispose();
        }
    };
    colorPart.setOutputConnector(GraphBoxOutputConnector.Side.Right, configuration.getNodeOutputs().get("value"));
    return colorPart;
}
Also used : ColorPicker(com.kotcrab.vis.ui.widget.color.ColorPicker) Color(com.badlogic.gdx.graphics.Color) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) JsonValue(com.badlogic.gdx.utils.JsonValue) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) VisImage(com.kotcrab.vis.ui.widget.VisImage) VisTable(com.kotcrab.vis.ui.widget.VisTable) Batch(com.badlogic.gdx.graphics.g2d.Batch) VisLabel(com.kotcrab.vis.ui.widget.VisLabel) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Color (com.badlogic.gdx.graphics.Color)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 BaseDrawable (com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 VisImage (com.kotcrab.vis.ui.widget.VisImage)1 VisLabel (com.kotcrab.vis.ui.widget.VisLabel)1 VisTable (com.kotcrab.vis.ui.widget.VisTable)1 ColorPicker (com.kotcrab.vis.ui.widget.color.ColorPicker)1 ColorPickerAdapter (com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)1