<commit_before>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.scenes.scene2d.utils;

import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;

/** This debugging utility takes a {@link Stage} and renders all {@link Actor}s bounding boxes via a {@link ShapeRenderer}. The
 * bounding boxes are not axis-aligned but rotated and scaled just like the actor. All you need to do is calling the
 * {@link #render()} method each frame.
 * 
 * @author <NAME> */
public class Scene2DDebugRenderer {

	/** Set to {@code true} if you want to render the actors that are not visible ({@code visible=false} of the actor or any parent)
	 * as well. */
	public boolean renderInvisibleActors = false;

	/** Set to {@code true} to also render group actors. They usually act only as invisible in the scene graph. */
	public boolean renderGroups = true;

	private Stage stage;

	private ShapeRenderer shapeRenderer;

	public Scene2DDebugRenderer (Stage stage) {
		this.stage = stage;
		this.shapeRenderer = new ShapeRenderer();
	}

	/** Renders the bounding boxes of all actors of the stage. */
	public void render () {
		shapeRenderer.setProjectionMatrix(stage.getCamera().projection);
		shapeRenderer.setTransformMatrix(stage.getCamera().view);
		shapeRenderer.begin(ShapeType.Line);
		for (Actor actor : stage.getActors()) {
			render(actor);
		}
		shapeRenderer.end();
	}

	private Vector2 topLeft = new Vector2();
	private Vector2 topRight = new Vector2();
	private Vector2 bottomRight = new Vector2();
	private Vector2 bottomLeft = new Vector2();

	private void render (Actor actor) {
		if (renderInvisibleActors || isActorVisible(actor)) {
			if (renderGroups || !(actor instanceof Group)) {
				// local coordinates
				topLeft.set(0, actor.getHeight());
				topRight.set(actor.getWidth(), actor.getHeight());
				bottomRight.set(actor.getWidth(), 0);
				bottomLeft.set(0, 0);

				// transform to stage coordinates using offsets, scales,
				// rotations etc of the whole ancestor hierarchy until the root
				actor.localToStageCoordinates(topLeft);
				actor.localToStageCoordinates(topRight);
				actor.localToStageCoordinates(bottomRight);
				actor.localToStageCoordinates(bottomLeft);

				shapeRenderer.line(topLeft, topRight);
				shapeRenderer.line(topRight, bottomRight);
				shapeRenderer.line(bottomRight, bottomLeft);
				shapeRenderer.line(bottomLeft, topLeft);
			}
		}

		if (actor instanceof Group) {
			for (Actor child : ((Group)actor).getChildren()) {
				render(child);
			}
		}
	}

	/** Returns {@code true} in case the given actor and all of its ancestors are visible. {@code False} otherwise. */
	private boolean isActorVisible (Actor actor) {
		Actor currentActor = actor;
		while (currentActor != null) {
			if (currentActor.isVisible() == false) {
				return false;
			} else {
				currentActor = currentActor.getParent();
			}
		}

		return true;
	}
}
<commit_msg>Made colours configurable.<commit_after>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.scenes.scene2d.utils;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;

/** This debugging utility takes a {@link Stage} and renders all {@link Actor}s bounding boxes via a {@link ShapeRenderer}. The
 * bounding boxes are not axis-aligned but rotated and scaled just like the actor. All you need to do is calling the
 * {@link #render()} method each frame.
 * 
 * @author <NAME> */
public class Scene2DDebugRenderer {

	/** Set to {@code true} if you want to render the actors that are not visible ({@code visible=false} of the actor or any parent)
	 * as well. */
	public boolean renderInvisibleActors = false;

	/** Set to {@code false} to not render group actors. They usually act only as invisible in the scene graph. */
	public boolean renderGroups = true;

	public Color actorColor = new Color(1, 0, 0, 1);

	public Color groupColor = new Color(0, 1, 0, 1);

	private Stage stage;

	private ShapeRenderer shapeRenderer;

	public Scene2DDebugRenderer (Stage stage) {
		this.stage = stage;
		this.shapeRenderer = new ShapeRenderer();
	}

	public void render () {
		shapeRenderer.setProjectionMatrix(stage.getCamera().projection);
		shapeRenderer.setTransformMatrix(stage.getCamera().view);
		shapeRenderer.begin(ShapeType.Line);
		for (Actor actor : stage.getActors()) {
			render(actor);
		}
		shapeRenderer.end();
	}

	private Vector2 topLeft = new Vector2();
	private Vector2 topRight = new Vector2();
	private Vector2 bottomRight = new Vector2();
	private Vector2 bottomLeft = new Vector2();

	private void render (Actor actor) {
		if (renderInvisibleActors || isActorVisible(actor)) {
			if (renderGroups || !(actor instanceof Group)) {
				// local coordinates
				topLeft.set(0, actor.getHeight());
				topRight.set(actor.getWidth(), actor.getHeight());
				bottomRight.set(actor.getWidth(), 0);
				bottomLeft.set(0, 0);

				// transform to stage coordinates using offsets, scales,
				// rotations etc of the whole ancestor hierarchy until the root
				actor.localToStageCoordinates(topLeft);
				actor.localToStageCoordinates(topRight);
				actor.localToStageCoordinates(bottomRight);
				actor.localToStageCoordinates(bottomLeft);

				if (actor instanceof Group) {
					shapeRenderer.setColor(groupColor);
				} else {
					shapeRenderer.setColor(actorColor);
				}

				shapeRenderer.line(topLeft, topRight);
				shapeRenderer.line(topRight, bottomRight);
				shapeRenderer.line(bottomRight, bottomLeft);
				shapeRenderer.line(bottomLeft, topLeft);
			}
		}

		if (actor instanceof Group) {
			for (Actor child : ((Group)actor).getChildren()) {
				render(child);
			}
		}
	}

	/** Returns {@code true} in case the given actor and all of its ancestors are visible. {@code False} otherwise. */
	private boolean isActorVisible (Actor actor) {
		Actor currentActor = actor;
		while (currentActor != null) {
			if (currentActor.isVisible() == false) {
				return false;
			} else {
				currentActor = currentActor.getParent();
			}
		}

		return true;
	}
}

{'fraction_non_alphanumeric': 0.13951145807101487, 'fraction_numerical': 0.007806597834298665, 'mean_word_length': 4.260264900662252, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '830789', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2172, 'n_words': 731}