import com.badlogic.gdx.graphics.Color;\r
import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
import com.badlogic.gdx.math.MathUtils;\r
+import com.badlogic.gdx.math.Rectangle;\r
import com.badlogic.gdx.math.Vector2;\r
import com.badlogic.gdx.scenes.scene2d.InputEvent.Type;\r
+import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;\r
import com.badlogic.gdx.utils.Array;\r
import com.badlogic.gdx.utils.DelayedRemovalArray;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
return parent.getChildren().indexOf(this, true);\r
}\r
\r
+ /** Calls {@link #clipBegin(float, float, float, float)} to clip this actor's bounds. */\r
+ public boolean clipBegin () {\r
+ return clipBegin(getX(), getY(), getWidth(), getHeight());\r
+ }\r
+\r
+ /** Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's SpriteBatch. The\r
+ * transform matrix and the stage's camera must not have rotational components. Calling this method must be followed by a call\r
+ * to {@link #clipEnd()} if true is returned.\r
+ * @return false if the clipping area is zero and no drawing should occur.\r
+ * @see ScissorStack */\r
+ public boolean clipBegin (float x, float y, float width, float height) {\r
+ Rectangle tableBounds = Rectangle.tmp;\r
+ tableBounds.x = x;\r
+ tableBounds.y = y;\r
+ tableBounds.width = width;\r
+ tableBounds.height = height;\r
+ Stage stage = getStage();\r
+ Rectangle scissorBounds = Pools.obtain(Rectangle.class);\r
+ ScissorStack.calculateScissors(stage.getCamera(), stage.getSpriteBatch().getTransformMatrix(), tableBounds, scissorBounds);\r
+ return ScissorStack.pushScissors(scissorBounds);\r
+ }\r
+\r
+ /** Ends clipping begun by {@link #clipBegin(float, float, float, float)}. */\r
+ public void clipEnd () {\r
+ Pools.free(ScissorStack.popScissors());\r
+ }\r
+\r
/** Transforms the specified point in screen coordinates to the actor's local coordinate system. */\r
public Vector2 screenToLocalCoordinates (Vector2 screenCoords) {\r
Stage stage = getStage();\r
import com.esotericsoftware.tablelayout.Toolkit;\r
import com.esotericsoftware.tablelayout.Value;\r
\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.GL10;\r
import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
-import com.badlogic.gdx.math.Matrix4;\r
-import com.badlogic.gdx.math.Rectangle;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
import com.badlogic.gdx.scenes.scene2d.Group;\r
import com.badlogic.gdx.scenes.scene2d.Stage;\r
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;\r
import com.badlogic.gdx.scenes.scene2d.utils.Align;\r
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;\r
-import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;\r
import com.badlogic.gdx.utils.Array;\r
\r
import java.util.List;\r
private final TableLayout layout;\r
private Drawable background;\r
private boolean clip;\r
- private Rectangle scissorBounds;\r
private Skin skin;\r
\r
public Table () {\r
if (isTransform()) {\r
applyTransform(batch, computeTransform());\r
if (clip) {\r
- if (ScissorStack.pushScissors(calculateScissors(batch.getTransformMatrix()))) {\r
+ boolean draw = background == null ? clipBegin(0, 0, getWidth(), getHeight()) : clipBegin(layout.getPadLeft(),\r
+ layout.getPadBottom(), getWidth() - layout.getPadLeft() - layout.getPadRight(),\r
+ getHeight() - layout.getPadBottom() - layout.getPadTop());\r
+ if (draw) {\r
drawChildren(batch, parentAlpha);\r
- ScissorStack.popScissors();\r
+ clipEnd();\r
}\r
} else\r
drawChildren(batch, parentAlpha);\r
}\r
}\r
\r
- private Rectangle calculateScissors (Matrix4 transform) {\r
- Rectangle tableBounds = Rectangle.tmp;\r
- tableBounds.width = getWidth();\r
- tableBounds.height = getHeight();\r
- if (background == null) {\r
- tableBounds.x = 0;\r
- tableBounds.y = 0;\r
- } else {\r
- tableBounds.x = layout.getPadLeft();\r
- tableBounds.y = layout.getPadBottom();\r
- tableBounds.width -= tableBounds.x + layout.getPadRight();\r
- tableBounds.height -= tableBounds.y + layout.getPadTop();\r
- }\r
- if (scissorBounds == null) scissorBounds = new Rectangle();\r
- ScissorStack.calculateScissors(getStage().getCamera(), transform, tableBounds, scissorBounds);\r
- return scissorBounds;\r
- }\r
-\r
public void invalidate () {\r
layout.invalidate();\r
super.invalidate();\r
\r
/** Pops the current scissor rectangle from the stack and sets the new scissor area to the new top of stack rectangle. In case\r
* no more rectangles are on the stack, {@link GL10#GL_SCISSOR_TEST} is disabled. */\r
- public static void popScissors () {\r
- scissors.pop();\r
+ public static Rectangle popScissors () {\r
+ Rectangle old = scissors.pop();\r
if (scissors.size == 0)\r
Gdx.gl.glDisable(GL10.GL_SCISSOR_TEST);\r
else {\r
Rectangle scissor = scissors.peek();\r
Gdx.gl.glScissor((int)scissor.x, (int)scissor.y, (int)scissor.width, (int)scissor.height);\r
}\r
+ return old;\r
}\r
\r
private static void fix (Rectangle rect) {\r