Skip to content

Commit

Permalink
[fixed] TWL clipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan.sweet committed Oct 24, 2011
1 parent cb55390 commit 7a2a162
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public class GdxRenderer implements Renderer, LineRenderer {
final SpriteBatch batch;

private final ClipStack clipStack;
protected final Rect clipRectTemp;

public GdxRenderer (SpriteBatch batch) {
this.batch = batch;
clipStack = new ClipStack();
clipRectTemp = new Rect();
Widget root = new Widget() {
protected void layout () {
layoutChildrenFullInnerArea();
Expand Down Expand Up @@ -119,17 +121,18 @@ public void endRendering () {
}
}

public void setClipRect (Rect rect) {
public void setClipRect () {
if (rendering) batch.flush();
if (rect == null) {
Gdx.gl.glDisable(GL10.GL_SCISSOR_TEST);
hasScissor = false;
} else {
final Rect rect = clipRectTemp;
if (clipStack.getClipRect(rect)) {
Gdx.gl.glScissor(rect.getX(), Gdx.graphics.getHeight() - rect.getBottom(), rect.getWidth(), rect.getHeight());
if (!hasScissor) {
Gdx.gl.glEnable(GL10.GL_SCISSOR_TEST);
hasScissor = true;
}
} else if (hasScissor) {
Gdx.gl.glDisable(GL10.GL_SCISSOR_TEST);
hasScissor = false;
}
}

Expand Down Expand Up @@ -234,20 +237,19 @@ public TintStack push (float r, float g, float b, float a) {
@Override
public void clipEnter (Rect rect) {
clipStack.push(rect);
// using null might not be correct here.
setClipRect(null);
setClipRect();
}

@Override
public void clipEnter (int x, int y, int w, int h) {
clipStack.push(x, y, w, h);
setClipRect(null);
setClipRect();
}

@Override
public void clipLeave () {
clipStack.pop();
setClipRect(null);
setClipRect();
}

@Override
Expand Down

0 comments on commit 7a2a162

Please sign in to comment.