OSDN Git Service

Fixed stage clipping when using glViewport. Fixed clicking outside of stage.
authorNathanSweet <nathan.sweet@gmail.com>
Wed, 2 Oct 2013 10:33:13 +0000 (12:33 +0200)
committerNathanSweet <nathan.sweet@gmail.com>
Wed, 2 Oct 2013 10:33:13 +0000 (12:33 +0200)
gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java
gdx/src/com/badlogic/gdx/scenes/scene2d/Stage.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SplitPane.java
gdx/src/com/badlogic/gdx/scenes/scene2d/utils/ScissorStack.java
tests/gdx-tests/src/com/badlogic/gdx/tests/ScrollPaneTest.java

index 12354f9..83d02f4 100644 (file)
@@ -565,7 +565,7 @@ public class Actor {
                tableBounds.height = height;\r
                Stage stage = this.stage;\r
                Rectangle scissorBounds = Pools.obtain(Rectangle.class);\r
-               ScissorStack.calculateScissors(stage.getCamera(), stage.getSpriteBatch().getTransformMatrix(), tableBounds, scissorBounds);\r
+               stage.calculateScissors(tableBounds, scissorBounds);\r
                if (ScissorStack.pushScissors(scissorBounds)) return true;\r
                Pools.free(scissorBounds);\r
                return false;\r
index f5655cc..8d60c4a 100644 (file)
@@ -26,6 +26,7 @@ import com.badlogic.gdx.graphics.Camera;
 import com.badlogic.gdx.graphics.OrthographicCamera;\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.math.Vector2;\r
 import com.badlogic.gdx.math.Vector3;\r
 import com.badlogic.gdx.scenes.scene2d.InputEvent.Type;\r
@@ -243,6 +244,9 @@ public class Stage extends InputAdapter implements Disposable {
 \r
        /** Applies a touch down event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the event. */\r
        public boolean touchDown (int screenX, int screenY, int pointer, int button) {\r
+               if (screenX < viewportX || screenX >= viewportX + viewportWidth) return false;\r
+               if (screenY < viewportY || screenY >= viewportY + viewportHeight) return false;\r
+\r
                pointerTouched[pointer] = true;\r
                pointerScreenX[pointer] = screenX;\r
                pointerScreenY[pointer] = screenY;\r
@@ -339,6 +343,9 @@ public class Stage extends InputAdapter implements Disposable {
        /** Applies a mouse moved event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the event.\r
         * This event only occurs on the desktop. */\r
        public boolean mouseMoved (int screenX, int screenY) {\r
+               if (screenX < viewportX || screenX >= viewportX + viewportWidth) return false;\r
+               if (screenY < viewportY || screenY >= viewportY + viewportHeight) return false;\r
+\r
                mouseScreenX = screenX;\r
                mouseScreenY = screenY;\r
 \r
@@ -688,6 +695,11 @@ public class Stage extends InputAdapter implements Disposable {
                return coords;\r
        }\r
 \r
+       public void calculateScissors (Rectangle area, Rectangle scissor) {\r
+               ScissorStack.calculateScissors(camera, viewportX, viewportY, viewportWidth, viewportHeight, batch.getTransformMatrix(),\r
+                       area, scissor);\r
+       }\r
+\r
        public void dispose () {\r
                clear();\r
                if (ownsBatch) batch.dispose();\r
index d732fc8..55c5248 100644 (file)
@@ -516,7 +516,7 @@ public class ScrollPane extends WidgetGroup {
 \r
                // Caculate the scissor bounds based on the batch transform, the available widget area and the camera transform. We need to\r
                // project those to screen coordinates for OpenGL ES to consume.\r
-               ScissorStack.calculateScissors(getStage().getCamera(), batch.getTransformMatrix(), widgetAreaBounds, scissorBounds);\r
+               getStage().calculateScissors(widgetAreaBounds, scissorBounds);\r
 \r
                // Draw the background ninepatch.\r
                Color color = getColor();\r
index cf6025c..089f1ab 100644 (file)
@@ -253,7 +253,7 @@ public class SplitPane extends WidgetGroup {
                applyTransform(batch, computeTransform());\r
                Matrix4 transform = batch.getTransformMatrix();\r
                if (firstWidget != null) {\r
-                       ScissorStack.calculateScissors(getStage().getCamera(), transform, firstWidgetBounds, firstScissors);\r
+                       getStage().calculateScissors(firstWidgetBounds, firstScissors);\r
                        if (ScissorStack.pushScissors(firstScissors)) {\r
                                if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a);\r
                                batch.flush();\r
@@ -261,7 +261,7 @@ public class SplitPane extends WidgetGroup {
                        }\r
                }\r
                if (secondWidget != null) {\r
-                       ScissorStack.calculateScissors(getStage().getCamera(), transform, secondWidgetBounds, secondScissors);\r
+                       getStage().calculateScissors(secondWidgetBounds, secondScissors);\r
                        if (ScissorStack.pushScissors(secondScissors)) {\r
                                if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a);\r
                                batch.flush();\r
index 578f45c..fd7719b 100644 (file)
@@ -105,16 +105,17 @@ public class ScissorStack {
         * @param batchTransform the transformation {@link Matrix4}\r
         * @param area the {@link Rectangle} to transform to window coordinates\r
         * @param scissor the Rectangle to store the result in */\r
-       public static void calculateScissors (Camera camera, Matrix4 batchTransform, Rectangle area, Rectangle scissor) {\r
+       public static void calculateScissors (Camera camera, float viewportX, float viewportY, float viewportWidth,\r
+               float viewportHeight, Matrix4 batchTransform, Rectangle area, Rectangle scissor) {\r
                tmp.set(area.x, area.y, 0);\r
                tmp.mul(batchTransform);\r
-               camera.project(tmp);\r
+               camera.project(tmp, viewportX, viewportY, viewportWidth, viewportHeight);\r
                scissor.x = tmp.x;\r
                scissor.y = tmp.y;\r
 \r
                tmp.set(area.x + area.width, area.y + area.height, 0);\r
                tmp.mul(batchTransform);\r
-               camera.project(tmp);\r
+               camera.project(tmp, viewportX, viewportY, viewportWidth, viewportHeight);\r
                scissor.width = tmp.x - scissor.x;\r
                scissor.height = tmp.y - scissor.y;\r
        }\r
index 6162133..913f63f 100644 (file)
@@ -128,6 +128,9 @@ public class ScrollPaneTest extends GdxTest {
 \r
        public void resize (int width, int height) {\r
                stage.setViewport(width, height, false);\r
+\r
+               // Gdx.gl.glViewport(100, 100, width - 200, height - 200);\r
+               // stage.setViewport(800, 600, false, 100, 100, width - 200, height - 200);\r
        }\r
 \r
        public void dispose () {\r