Search in sources :

Example 1 with ChangeEvent

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent in project libgdx by libgdx.

the class Benchmark3DTest method create.

@Override
public void create() {
    super.create();
    GLProfiler.enable();
    randomizeLights();
    cam.position.set(10, 10, 10);
    cam.lookAt(0, 0, 0);
    cam.update();
    showAxes = true;
    lighting = true;
    vertexCountLabel = new Label("Vertices: 999", skin);
    vertexCountLabel.setPosition(0, fpsLabel.getTop());
    hud.addActor(vertexCountLabel);
    textureBindsLabel = new Label("Texture bindings: 999", skin);
    textureBindsLabel.setPosition(0, vertexCountLabel.getTop());
    hud.addActor(textureBindsLabel);
    shaderSwitchesLabel = new Label("Shader switches: 999", skin);
    shaderSwitchesLabel.setPosition(0, textureBindsLabel.getTop());
    hud.addActor(shaderSwitchesLabel);
    drawCallsLabel = new Label("Draw calls: 999", skin);
    drawCallsLabel.setPosition(0, shaderSwitchesLabel.getTop());
    hud.addActor(drawCallsLabel);
    glCallsLabel = new Label("GL calls: 999", skin);
    glCallsLabel.setPosition(0, drawCallsLabel.getTop());
    hud.addActor(glCallsLabel);
    lightsLabel = new Label("Lights: 999", skin);
    lightsLabel.setPosition(0, glCallsLabel.getTop());
    hud.addActor(lightsLabel);
    lightingCheckBox = new CheckBox("Lighting", skin);
    lightingCheckBox.setChecked(lighting);
    lightingCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            lighting = lightingCheckBox.isChecked();
        }
    });
    lightingCheckBox.setPosition(hudWidth - lightingCheckBox.getWidth(), gridCheckBox.getTop());
    hud.addActor(lightingCheckBox);
    lightsCheckBox = new CheckBox("Randomize lights", skin);
    lightsCheckBox.setChecked(false);
    lightsCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            lightsCheckBox.setChecked(false);
            randomizeLights();
        }
    });
    lightsCheckBox.setPosition(hudWidth - lightsCheckBox.getWidth(), lightingCheckBox.getTop());
    hud.addActor(lightsCheckBox);
    moveCheckBox.remove();
    rotateCheckBox.remove();
}
Also used : ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 2 with ChangeEvent

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent in project libgdx by libgdx.

the class TextField method changeText.

/** @param oldText May be null.
	 * @return True if the text was changed. */
boolean changeText(String oldText, String newText) {
    if (newText.equals(oldText))
        return false;
    text = newText;
    ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
    boolean cancelled = fire(changeEvent);
    text = cancelled ? oldText : newText;
    Pools.free(changeEvent);
    return !cancelled;
}
Also used : ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)

Example 3 with ChangeEvent

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent in project libgdx by libgdx.

the class Touchpad method calculatePositionAndValue.

void calculatePositionAndValue(float x, float y, boolean isTouchUp) {
    float oldPositionX = knobPosition.x;
    float oldPositionY = knobPosition.y;
    float oldPercentX = knobPercent.x;
    float oldPercentY = knobPercent.y;
    float centerX = knobBounds.x;
    float centerY = knobBounds.y;
    knobPosition.set(centerX, centerY);
    knobPercent.set(0f, 0f);
    if (!isTouchUp) {
        if (!deadzoneBounds.contains(x, y)) {
            knobPercent.set((x - centerX) / knobBounds.radius, (y - centerY) / knobBounds.radius);
            float length = knobPercent.len();
            if (length > 1)
                knobPercent.scl(1 / length);
            if (knobBounds.contains(x, y)) {
                knobPosition.set(x, y);
            } else {
                knobPosition.set(knobPercent).nor().scl(knobBounds.radius).add(knobBounds.x, knobBounds.y);
            }
        }
    }
    if (oldPercentX != knobPercent.x || oldPercentY != knobPercent.y) {
        ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
        if (fire(changeEvent)) {
            knobPercent.set(oldPercentX, oldPercentY);
            knobPosition.set(oldPositionX, oldPositionY);
        }
        Pools.free(changeEvent);
    }
}
Also used : ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)

Example 4 with ChangeEvent

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent in project libgdx by libgdx.

the class ProgressBar method setValue.

/** Sets the progress bar position, rounded to the nearest step size and clamped to the minimum and maximum values.
	 * {@link #clamp(float)} can be overridden to allow values outside of the progress bar's min/max range.
	 * @return false if the value was not changed because the progress bar already had the value or it was canceled by a
	 *         listener. */
public boolean setValue(float value) {
    value = clamp(Math.round(value / stepSize) * stepSize);
    float oldValue = this.value;
    if (value == oldValue)
        return false;
    float oldVisualValue = getVisualValue();
    this.value = value;
    ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
    boolean cancelled = fire(changeEvent);
    if (cancelled)
        this.value = oldValue;
    else if (animateDuration > 0) {
        animateFromValue = oldVisualValue;
        animateTime = animateDuration;
    }
    Pools.free(changeEvent);
    return !cancelled;
}
Also used : ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)

Example 5 with ChangeEvent

use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent in project libgdx by libgdx.

the class Button method setChecked.

void setChecked(boolean isChecked, boolean fireEvent) {
    if (this.isChecked == isChecked)
        return;
    if (buttonGroup != null && !buttonGroup.canCheck(this, isChecked))
        return;
    this.isChecked = isChecked;
    if (fireEvent) {
        ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
        if (fire(changeEvent))
            this.isChecked = !isChecked;
        Pools.free(changeEvent);
    }
}
Also used : ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)

Aggregations

ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)7 Actor (com.badlogic.gdx.scenes.scene2d.Actor)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)3 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)2 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Texture (com.badlogic.gdx.graphics.Texture)1 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)1 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)1 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)1 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)1 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)1