text scrolling now works
This commit is contained in:
		@@ -134,16 +134,17 @@ public class Polyjet extends Game {
 | 
			
		||||
		
 | 
			
		||||
		defaultSkin.add("sub-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
 | 
			
		||||
			{
 | 
			
		||||
				size = fontScale(0.04f);
 | 
			
		||||
				size = fontScale(0.05f);
 | 
			
		||||
			}
 | 
			
		||||
		}));
 | 
			
		||||
		
 | 
			
		||||
		defaultSkin.add("default-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
 | 
			
		||||
			{
 | 
			
		||||
				size = fontScale(0.06f);
 | 
			
		||||
				size = fontScale(0.07f);
 | 
			
		||||
			}
 | 
			
		||||
		}));
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
		defaultSkin.add("large-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
 | 
			
		||||
			{
 | 
			
		||||
				size = fontScale(0.08f);
 | 
			
		||||
 
 | 
			
		||||
@@ -73,11 +73,9 @@ public class MusicSelectable extends Button implements Disposable {
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	public void addInfoToPanel() {
 | 
			
		||||
		debug();
 | 
			
		||||
		displayName = new ScrollText(songName, skin, true);
 | 
			
		||||
		
 | 
			
		||||
		displayName = new ScrollText(songName, skin);
 | 
			
		||||
		add(displayName).fillX().spaceBottom(20f);
 | 
			
		||||
 | 
			
		||||
		row();
 | 
			
		||||
 | 
			
		||||
		String formattedTime = "Run time: "+ String.valueOf(durationInSeconds/60) + ":";
 | 
			
		||||
 
 | 
			
		||||
@@ -2,41 +2,108 @@ package zero1hd.polyjet.ui.builders;
 | 
			
		||||
 | 
			
		||||
import com.badlogic.gdx.graphics.g2d.Batch;
 | 
			
		||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
 | 
			
		||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
 | 
			
		||||
import com.badlogic.gdx.math.Rectangle;
 | 
			
		||||
import com.badlogic.gdx.scenes.scene2d.Actor;
 | 
			
		||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
 | 
			
		||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
 | 
			
		||||
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
 | 
			
		||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
 | 
			
		||||
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;
 | 
			
		||||
 | 
			
		||||
public class ScrollText extends Widget {
 | 
			
		||||
	Rectangle scissors = new Rectangle();
 | 
			
		||||
	Rectangle clipBounds = new Rectangle();
 | 
			
		||||
	
 | 
			
		||||
	GlyphLayout gLayout;
 | 
			
		||||
	String text;
 | 
			
		||||
	BitmapFont font;
 | 
			
		||||
	private float fontHeight;
 | 
			
		||||
	private float fontWidth;
 | 
			
		||||
	
 | 
			
		||||
	public ScrollText(String text, Skin skin) {
 | 
			
		||||
	private boolean scrollOnHover;
 | 
			
		||||
	private boolean currentlyHovering;
 | 
			
		||||
	
 | 
			
		||||
	private float textOffset;
 | 
			
		||||
	public ScrollText(String text, Skin skin, boolean scrollOnHover) {
 | 
			
		||||
		super();
 | 
			
		||||
		setName(text);
 | 
			
		||||
		
 | 
			
		||||
		this.scrollOnHover = scrollOnHover;
 | 
			
		||||
		
 | 
			
		||||
		this.text = text;
 | 
			
		||||
		font = skin.getFont("default-font");
 | 
			
		||||
		setWidth(20f);
 | 
			
		||||
		setHeight(40f);
 | 
			
		||||
		font.setColor(skin.getColor("default"));
 | 
			
		||||
		gLayout = new GlyphLayout(font, text);
 | 
			
		||||
		
 | 
			
		||||
		fontHeight = gLayout.height;
 | 
			
		||||
		fontWidth = gLayout.width;
 | 
			
		||||
		
 | 
			
		||||
		addListener(new ClickListener() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
 | 
			
		||||
				currentlyHovering = true;
 | 
			
		||||
				super.enter(event, x, y, pointer, fromActor);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			@Override
 | 
			
		||||
			public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
 | 
			
		||||
				currentlyHovering = false;
 | 
			
		||||
				super.exit(event, x, y, pointer, toActor);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public float getFontHeight() {
 | 
			
		||||
		return fontHeight;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public float getFontWidth() {
 | 
			
		||||
		return fontWidth;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void layout() {
 | 
			
		||||
		clipBounds.setPosition(getX(), getY());
 | 
			
		||||
		clipBounds.setSize(getWidth(), getHeight());
 | 
			
		||||
		clipBounds.set(getParent().getX()+getX(), getParent().getY()+getY(), getWidth(), getHeight());
 | 
			
		||||
		super.layout();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void act(float delta) {
 | 
			
		||||
		if (scrollOnHover) {
 | 
			
		||||
			if (currentlyHovering) {
 | 
			
		||||
				if (textOffset < -fontWidth) {
 | 
			
		||||
					textOffset = clipBounds.getWidth();
 | 
			
		||||
				}
 | 
			
		||||
				textOffset -= 60*delta;
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			if (textOffset < -fontWidth) {
 | 
			
		||||
				textOffset = clipBounds.getWidth();
 | 
			
		||||
			}
 | 
			
		||||
			textOffset -= 60*delta;
 | 
			
		||||
		}
 | 
			
		||||
		super.act(delta);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void draw(Batch batch, float parentAlpha) {
 | 
			
		||||
		ScissorStack.calculateScissors(getStage().getCamera(), batch.getTransformMatrix(), clipBounds, scissors);
 | 
			
		||||
		validate();
 | 
			
		||||
		
 | 
			
		||||
		getStage().calculateScissors(clipBounds, scissors);
 | 
			
		||||
 | 
			
		||||
		batch.flush();
 | 
			
		||||
		if (ScissorStack.pushScissors(scissors)) {
 | 
			
		||||
			font.draw(batch, text, getX(), getY());
 | 
			
		||||
			font.draw(batch, text, clipBounds.getX() + textOffset, clipBounds.getY() + (fontHeight));
 | 
			
		||||
			batch.flush();
 | 
			
		||||
			ScissorStack.popScissors();
 | 
			
		||||
		};
 | 
			
		||||
		
 | 
			
		||||
		super.draw(batch, parentAlpha);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public float getMinHeight() {
 | 
			
		||||
		return fontHeight;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,7 @@ public class MusicSelectionPage extends Page {
 | 
			
		||||
					Gdx.app.postRunnable(new Runnable() {
 | 
			
		||||
						@Override
 | 
			
		||||
						public void run() {
 | 
			
		||||
							musicChoices.add(selectable).size(0.2f*getWidth(), 0.8f*getHeight());
 | 
			
		||||
							musicChoices.add(selectable).size(256f, 0.8f*getHeight());
 | 
			
		||||
							selectable.addInfoToPanel();
 | 
			
		||||
						}
 | 
			
		||||
					});
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user