package com.badlogic.gdx.ingenuity.utils;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.ingenuity.GdxData;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Align;

public enum GdxUtil {
	;

	@SuppressWarnings("unchecked")
	public static <T extends ApplicationListener> T getAppGame() {
		return (T) Gdx.app.getApplicationListener();
	}

	public static Rectangle getTextBounds(String text, BitmapFont bitmapFont) {
		GlyphLayout glyphLayout = new GlyphLayout();
		glyphLayout.setText(bitmapFont, text);
		return new Rectangle().setSize(glyphLayout.width, glyphLayout.height);
	}

	public static Rectangle getWarppedTextBounds(String text, float wrapWidth, BitmapFont bitmapFont) {
		GlyphLayout glyphLayout = new GlyphLayout();
		glyphLayout.setText(bitmapFont, text, bitmapFont.getColor(), wrapWidth, Align.left, true);
		return new Rectangle().setSize(glyphLayout.width, glyphLayout.height);
	}

	public static void center(Actor actor, boolean horizontal) {
		if (horizontal) {
			float wd = GdxData.WIDTH - actor.getWidth();
			actor.setX(wd / 2);
		} else {
			float ht = GdxData.HEIGHT - actor.getHeight();
			actor.setY(ht / 2);
		}
	}

	public static void center(Actor actor) {
		float wd = GdxData.WIDTH - actor.getWidth();
		float ht = GdxData.HEIGHT - actor.getHeight();
		actor.setPosition(wd / 2, ht / 2);
	}

	public static void center(Actor staticActhor, Actor actor) {
		actor.setPosition(staticActhor.getX() + (staticActhor.getWidth() - actor.getWidth()) / 2, staticActhor.getY() + (staticActhor.getHeight() - actor.getHeight()) / 2);
	}

	public static void replace(Actor oldActor, Actor newActor) {
		if (oldActor != null && oldActor.getParent() != null) {
			newActor.setBounds(oldActor.getX(), oldActor.getY(), oldActor.getWidth(), oldActor.getHeight());
			oldActor.getParent().addActorBefore(oldActor, newActor);
			oldActor.remove();
		}
	}

}

@@ -1120,36 +1120,51 @@
 blic static 
-void
+%3CT extends Actor%3E T
  center(
 Actor actor,
@@ -1147,29 +1147,25 @@
 r%3E T center(
-Actor
+T
  actor, bool
@@ -1357,24 +1357,40 @@
 t / 2);%0A%09%09%7D%0A
+%09%09return actor;%0A
 %09%7D%0A%0A%09public 
@@ -1392,36 +1392,51 @@
 blic static 
-void
+%3CT extends Actor%3E T
  center(
 Actor actor)
@@ -1423,21 +1423,17 @@
  center(
-Actor
+T
  actor) 
@@ -1563,24 +1563,40 @@
 2, ht / 2);%0A
+%09%09return actor;%0A
 %09%7D%0A%0A%09public 

update GdxUtils.javav