Search in sources :

Example 1 with Type

use of com.badlogic.gdx.scenes.scene2d.InputEvent.Type in project gaiasky by langurmonkey.

the class OwnButton method initialize.

private void initialize() {
    cursor = SystemCursor.Hand;
    this.addListener(event -> {
        if (event instanceof InputEvent) {
            Type type = ((InputEvent) event).getType();
            if (changeCursor && type == Type.enter) {
                if (!me.isDisabled())
                    Gdx.graphics.setSystemCursor(cursor);
                return true;
            } else if (changeCursor && type == Type.exit) {
                Gdx.graphics.setSystemCursor(SystemCursor.Arrow);
                return true;
            } else if (type == Type.touchDown) {
                // Focus
                this.getStage().setKeyboardFocus(this);
            }
        }
        return false;
    });
}
Also used : Type(com.badlogic.gdx.scenes.scene2d.InputEvent.Type) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 2 with Type

use of com.badlogic.gdx.scenes.scene2d.InputEvent.Type in project gaiasky by langurmonkey.

the class ColormapPicker method initialize.

protected void initialize() {
    this.addListener(new ClickListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return super.touchDown(event, x, y, pointer, button);
        }

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (event.getButton() == Buttons.LEFT) {
                // Launch color picker window
                ColorPickerColormapDialog cpd = new ColorPickerColormapDialog(name, color, stage, skin);
                cpd.setAcceptRunnable(() -> {
                    if (cpd.plainColor.isChecked()) {
                        setPickedColor(cpd.color);
                        if (newColorRunnable != null) {
                            newColorRunnable.run();
                        }
                    } else if (cpd.colormap.isChecked()) {
                        setPickedColormap(cpd.cmapImage);
                        if (newColormapRunnable != null) {
                            newColormapRunnable.run();
                        }
                    }
                });
                cpd.show(stage);
            }
            // Bubble up
            super.touchUp(event, x, y, pointer, button);
        }
    });
    this.addListener(event -> {
        if (event instanceof InputEvent) {
            Type type = ((InputEvent) event).getType();
            // Click
            if (type == Type.enter) {
                Gdx.graphics.setSystemCursor(SystemCursor.Hand);
            } else if (type == Type.exit) {
                Gdx.graphics.setSystemCursor(SystemCursor.Arrow);
            }
            return true;
        }
        return false;
    });
}
Also used : Type(com.badlogic.gdx.scenes.scene2d.InputEvent.Type) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 3 with Type

use of com.badlogic.gdx.scenes.scene2d.InputEvent.Type in project gaiasky by langurmonkey.

the class CollapsibleEntry method createActor.

private void createActor(Actor title, Skin skin) {
    // Unchecked = expand
    // Checked   = collapse
    pad(5f);
    collapse = new OwnImageButton(skin, "expand-collapse");
    // start collapsed (show expand icon)
    collapse.setCheckedNoFire(false);
    add(collapse).top().left().padBottom(10f).padRight(15f);
    actorCell = add(title).top().left().padBottom(10f);
    actorCell.row();
    contentCell = add().top().left().colspan(2).expandX();
    collapse.addListener(event -> {
        if (event instanceof ChangeEvent) {
            boolean checked = collapse.isChecked();
            if (!checked) {
                collapse();
            } else {
                expand();
            }
            return true;
        }
        return false;
    });
    title.addListener(new ClickListener() {

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (event.getButton() == Buttons.LEFT) {
                boolean checked = collapse.isChecked();
                if (checked) {
                    collapse();
                } else {
                    expand();
                }
                collapse.setCheckedNoFire(!checked);
            }
            // Bubble up
            super.touchUp(event, x, y, pointer, button);
        }
    });
    title.addListener(event -> {
        if (event instanceof InputEvent) {
            Type type = ((InputEvent) event).getType();
            if (type == Type.enter) {
                Gdx.graphics.setSystemCursor(SystemCursor.Hand);
            } else if (type == Type.exit) {
                Gdx.graphics.setSystemCursor(SystemCursor.Arrow);
            }
            return true;
        }
        return false;
    });
}
Also used : Type(com.badlogic.gdx.scenes.scene2d.InputEvent.Type) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 4 with Type

use of com.badlogic.gdx.scenes.scene2d.InputEvent.Type in project gaiasky by langurmonkey.

the class CollapsibleWindow method initWindow.

private void initWindow(final Skin skin, final float collapseSpeed) {
    this.me = this;
    this.skin = skin;
    this.collapseSpeed = collapseSpeed;
    this.collapseHeight = 32f;
    vec2 = new Vector2();
    addListener(new ClickListener() {

        private float startx, starty;

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            startx = x + getX();
            starty = y + getY();
            return super.touchDown(event, x, y, pointer, button);
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            float endx = x + getX();
            float endy = y + getY();
            vec2.set(endx - startx, endy - starty);
            // pixels of margin
            if (vec2.len() < 3f) {
                if (getHeight() - y <= getPadTop() && y < getHeight() && x > 0f && x < getWidth())
                    if (button == Input.Buttons.LEFT) {
                        // Left mouse button on title toggles collapse
                        toggleCollapsed();
                    }
            }
            super.touchUp(event, x, y, pointer, button);
        }
    });
    // Pad title cell
    getTitleTable().getCells().get(0).padLeft(8f);
    // Mouse pointer on title
    getTitleTable().addListener(event -> {
        if (event instanceof InputEvent) {
            Type type = ((InputEvent) event).getType();
            // Click
            if (type == Type.mouseMoved) {
                Gdx.graphics.setSystemCursor(SystemCursor.Hand);
            } else if (type == Type.exit) {
                Gdx.graphics.setSystemCursor(SystemCursor.Arrow);
            }
            return true;
        }
        return false;
    });
    addListener(event -> {
        if (isResizable()) {
            if (event instanceof InputEvent) {
                Type type = ((InputEvent) event).getType();
                if (type == Type.mouseMoved) {
                    if ((edge & Align.bottom) != 0 && maxHeight == -1f) {
                        Gdx.graphics.setSystemCursor(SystemCursor.VerticalResize);
                    } else if ((edge & Align.right) != 0 && maxWidth == -1f) {
                        Gdx.graphics.setSystemCursor(SystemCursor.HorizontalResize);
                    }
                } else if (type == Type.exit) {
                    Gdx.graphics.setSystemCursor(SystemCursor.Arrow);
                }
            }
        }
        return false;
    });
    getTitleTable().addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.expandcollapse"), skin));
}
Also used : Type(com.badlogic.gdx.scenes.scene2d.InputEvent.Type) Vector2(com.badlogic.gdx.math.Vector2) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 5 with Type

use of com.badlogic.gdx.scenes.scene2d.InputEvent.Type in project gaiasky by langurmonkey.

the class Link method initialize.

private void initialize() {
    // Fix touchUp issue
    this.addListener(new ClickListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return super.touchDown(event, x, y, pointer, button);
        }

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (event.getButton() == Buttons.LEFT && linkURL != null && !linkURL.isEmpty())
                Gdx.net.openURI(linkURL);
            // Bubble up
            super.touchUp(event, x, y, pointer, button);
        }
    });
    this.addListener(event -> {
        if (event instanceof InputEvent) {
            Type type = ((InputEvent) event).getType();
            if (type == Type.enter) {
                Gdx.graphics.setSystemCursor(SystemCursor.Hand);
            } else if (type == Type.exit) {
                Gdx.graphics.setSystemCursor(SystemCursor.Arrow);
            }
            return true;
        }
        return false;
    });
}
Also used : Type(com.badlogic.gdx.scenes.scene2d.InputEvent.Type) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Type (com.badlogic.gdx.scenes.scene2d.InputEvent.Type)7 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)5 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 Vector2 (com.badlogic.gdx.math.Vector2)1 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)1