scaling TWL UI in libgdx

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

scaling TWL UI in libgdx

Postby manifold » Tue Sep 20, 2011 9:17 pm

If you want to scale and transform entire TWL GUI using SpriteBatch's transformation matrix, you may notice that GdxRenderer doesn't take into account its scaling and translation, so:
Change method setClipRect in GdxRenderer.java, compile and put it back in gdx-twl.jar.
Code: Select all
public void setClipRect (Rect rect) {
      if (rendering) batch.flush();
      if (rect == null) {
         Gdx.gl.glDisable(GL10.GL_SCISSOR_TEST);
         hasScissor = false;
      } else {
         Matrix4 transform = batch.getTransformMatrix();

         Vector3 tl = new Vector3(rect.getX(), rect.getY(), 0).mul(transform);
         Vector3 br = new Vector3(rect.getRight(), rect.getBottom(), 0).mul(transform);
         
         tl.y=Gdx.graphics.getHeight()-tl.y;
         br.y=Gdx.graphics.getHeight()-br.y;
         //Gdx.gl.glScissor(rect.getX(), Gdx.graphics.getHeight() - rect.getBottom(), rect.getWidth(), rect.getHeight());
         Gdx.gl.glScissor((int)tl.x, (int)br.y, (int)(br.x-tl.x), (int)(tl.y-br.y));
         if (!hasScissor) {
            Gdx.gl.glEnable(GL10.GL_SCISSOR_TEST);
            hasScissor = true;
         }
      }
   }

Now your TWL TextArea and ScrolPane should be ok. No more incorrect clipping!
manifold
 
Posts: 1
Joined: Tue Sep 20, 2011 9:08 pm

Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest