OSDN Git Service

[changed] Button to use Layout.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Thu, 14 Apr 2011 08:30:41 +0000 (08:30 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Thu, 14 Apr 2011 08:30:41 +0000 (08:30 +0000)
gdx/src/com/badlogic/gdx/scenes/scene2d/actors/Button.java

index 7231529..60b1e08 100644 (file)
@@ -19,6 +19,7 @@ import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
 import com.badlogic.gdx.graphics.g2d.TextureRegion;\r
 import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.Layout;\r
 \r
 /**\r
  * A simple Button {@link Actor}, useful for simple UIs\r
@@ -26,13 +27,13 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
  * @author mzechner\r
  * \r
  */\r
-public class Button extends Actor {\r
+public class Button extends Actor implements Layout {\r
        public interface ClickListener {\r
                public void clicked (Button button);\r
        }\r
 \r
-       public final TextureRegion pressedRegion;\r
-       public final TextureRegion unpressedRegion;\r
+       public TextureRegion pressedRegion;\r
+       public TextureRegion unpressedRegion;\r
        public ClickListener clickListener;\r
        protected boolean pressed = false;\r
        protected int pointer = -1;\r
@@ -117,4 +118,14 @@ public class Button extends Actor {
                return x > 0 && y > 0 && x < width && y < height ? this : null;\r
        }\r
 \r
+       public void layout () {\r
+       }\r
+\r
+       public float getPrefWidth () {\r
+               return unpressedRegion.getRegionWidth();\r
+       }\r
+\r
+       public float getPrefHeight () {\r
+               return unpressedRegion.getRegionHeight();\r
+       }\r
 }\r