OSDN Git Service

Shortcut hit detection in WidgetGroup, since groups UI are normally sized to encompas...
authorNathanSweet <nathan.sweet@gmail.com>
Fri, 4 Oct 2013 16:48:05 +0000 (18:48 +0200)
committerNathanSweet <nathan.sweet@gmail.com>
Fri, 4 Oct 2013 16:48:05 +0000 (18:48 +0200)
http://www.java-gaming.org/topics/ui-mouse-detection/30896/msg/285894/view.html#msg285894

gdx/src/com/badlogic/gdx/scenes/scene2d/ui/WidgetGroup.java

index bb2fac6..79e02b9 100644 (file)
@@ -20,6 +20,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 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.Touchable;\r
 import com.badlogic.gdx.scenes.scene2d.utils.Layout;\r
 import com.badlogic.gdx.utils.SnapshotArray;\r
 \r
@@ -148,4 +149,10 @@ public class WidgetGroup extends Group implements Layout {
                validate();\r
                super.draw(batch, parentAlpha);\r
        }\r
+\r
+       public Actor hit (float x, float y, boolean touchable) {\r
+               if (touchable && getTouchable() == Touchable.disabled) return null;\r
+               if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight()) return null;\r
+               return super.hit(x, y, touchable);\r
+       }\r
 }\r