OSDN Git Service

Fixed issue 912, optional background for label.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 11 Jul 2012 04:50:28 +0000 (04:50 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 11 Jul 2012 04:50:28 +0000 (04:50 +0000)
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Label.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Table.java

index b9f4dd1..79f0d4e 100644 (file)
@@ -23,6 +23,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
 import com.badlogic.gdx.graphics.g2d.BitmapFontCache;\r
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
 import com.badlogic.gdx.scenes.scene2d.utils.Align;\r
+import com.badlogic.gdx.scenes.scene2d.utils.Drawable;\r
 \r
 /** A text label, with optional word wrapping.\r
  * <p>\r
@@ -196,6 +197,11 @@ public class Label extends Widget {
        public void draw (SpriteBatch batch, float parentAlpha) {\r
                layout();\r
                validate();\r
+               if (style.background != null) {\r
+                       Color color = getColor();\r
+                       batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);\r
+                       style.background.draw(batch, getX(), getY(), getWidth(), getHeight());\r
+               }\r
                cache.setPosition(getX(), getY());\r
                cache.draw(batch, getColor().a * parentAlpha);\r
        }\r
@@ -215,6 +221,8 @@ public class Label extends Widget {
                public BitmapFont font;\r
                /** Optional. */\r
                public Color fontColor;\r
+               /** Optional. */\r
+               public Drawable background;\r
 \r
                public LabelStyle () {\r
                }\r
index e25fc9f..1871b84 100644 (file)
@@ -56,7 +56,7 @@ public class Table extends WidgetGroup {
        }\r
 \r
        private final TableLayout layout;\r
-       private Drawable backgroundDrawable;\r
+       private Drawable background;\r
        private boolean clip;\r
        private Skin skin;\r
 \r
@@ -95,10 +95,10 @@ public class Table extends WidgetGroup {
        /** Called to draw the background, before clipping is applied (if enabled). Default implementation draws the background\r
         * drawable. */\r
        protected void drawBackground (SpriteBatch batch, float parentAlpha) {\r
-               if (backgroundDrawable != null) {\r
+               if (background != null) {\r
                        Color color = getColor();\r
                        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);\r
-                       backgroundDrawable.draw(batch, getX(), getY(), getWidth(), getHeight());\r
+                       background.draw(batch, getX(), getY(), getWidth(), getHeight());\r
                }\r
        }\r
 \r
@@ -106,7 +106,7 @@ public class Table extends WidgetGroup {
                Rectangle tableBounds = Rectangle.tmp;\r
                tableBounds.width = getWidth();\r
                tableBounds.height = getHeight();\r
-               if (backgroundDrawable == null) {\r
+               if (background == null) {\r
                        tableBounds.x = 0;\r
                        tableBounds.y = 0;\r
                } else {\r
@@ -125,12 +125,12 @@ public class Table extends WidgetGroup {
        }\r
 \r
        public float getPrefWidth () {\r
-               if (backgroundDrawable != null) return Math.max(layout.getPrefWidth(), backgroundDrawable.getMinWidth());\r
+               if (background != null) return Math.max(layout.getPrefWidth(), background.getMinWidth());\r
                return layout.getPrefWidth();\r
        }\r
 \r
        public float getPrefHeight () {\r
-               if (backgroundDrawable != null) return Math.max(layout.getPrefHeight(), backgroundDrawable.getMinHeight());\r
+               if (background != null) return Math.max(layout.getPrefHeight(), background.getMinHeight());\r
                return layout.getPrefHeight();\r
        }\r
 \r
@@ -146,8 +146,8 @@ public class Table extends WidgetGroup {
         * {@link Drawable#getTopHeight()}, {@link Drawable#getLeftWidth()}, and {@link Drawable#getRightWidth()}.\r
         * @param background If null, the background will be cleared and all padding is removed. */\r
        public void setBackground (Drawable background) {\r
-               if (this.backgroundDrawable == background) return;\r
-               this.backgroundDrawable = background;\r
+               if (this.background == background) return;\r
+               this.background = background;\r
                if (background == null)\r
                        pad(null);\r
                else {\r
@@ -160,7 +160,7 @@ public class Table extends WidgetGroup {
        }\r
 \r
        public Drawable getBackground () {\r
-               return backgroundDrawable;\r
+               return background;\r
        }\r
 \r
        /** Causes the contents to be clipped if they exceed the table widget bounds. Enabling clipping will set\r