/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.preui.gdx.gui;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import transientlibs.preui.objects.gui.interfaces.IMarker;
import transientlibs.processors.misc.Detonator;
/**
* Partial integration of IMarker objects into LibGDX's scene2d framework.
*
* @author Cameron Seebach
*/
public class WidgetLink {
public IMarker marker;
public Actor actor = null;
public WidgetLink(final IMarker marker) {
this.marker = marker;
//construct the actual marker
if (marker.getText() != null && marker.getImage() != null) {
ImageTextButton.ImageTextButtonStyle style =
new ImageTextButton.ImageTextButtonStyle();
style.imageUp = new TextureRegionDrawable(
marker.getImage().getTextureRegion());
style.font = marker.getFont();
actor = new ImageTextButton(marker.getText(), style);
} else if (marker.getText() != null) {
Label.LabelStyle style = new Label.LabelStyle();
style.font = marker.getFont();
actor = new Label(marker.getText(), style);
} else if (marker.getImage() != null) {
actor = new ImageButton(
new TextureRegionDrawable(
marker.getImage().getTextureRegion()));
}
if (actor != null) {
actor.setX(marker.getScreenCoords().x);
actor.setY(Detonator.INSTANCE.ScreenSizeY - marker.getScreenCoords().y);
actor.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
marker.processClick();
}
});
}
}
}