OSDN Git Service

[fixed] SkinLoader failed when no fonts.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 19 Oct 2011 05:27:48 +0000 (05:27 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 19 Oct 2011 05:27:48 +0000 (05:27 +0000)
[updated] TextureLoader, added filter.
[fixed] Json bug with ignore unknown fields.

12 files changed:
extensions/gdx-tools/src/com/badlogic/gdx/tools/imagepacker/TexturePacker.java
gdx/src/com/badlogic/gdx/assets/loaders/SkinLoader.java
gdx/src/com/badlogic/gdx/assets/loaders/TextureLoader.java
gdx/src/com/badlogic/gdx/graphics/g2d/TextureRegion.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/ComboBox.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/List.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Slider.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/SplitPane.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextField.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java
gdx/src/com/badlogic/gdx/utils/Json.java

index 8108397..03c50e8 100644 (file)
@@ -339,6 +339,15 @@ public class TexturePacker {
                                        int amount = settings.padding / 2;\r
                                        int imageWidth = image.getWidth();\r
                                        int imageHeight = image.getHeight();\r
+                                       // Copy corner pixels to fill corners of the padding.\r
+                                       g.drawImage(image, node.left - amount, node.top - amount, node.left, node.top, 0, 0, 1, 1, null);\r
+                                       g.drawImage(image, node.left + imageWidth, node.top - amount, node.left + imageWidth + amount, node.top, 0, 0, 1,\r
+                                               1, null);\r
+                                       g.drawImage(image, node.left - amount, node.top + imageHeight, node.left, node.top + imageHeight + amount, 0, 0,\r
+                                               1, 1, null);\r
+                                       g.drawImage(image, node.left + imageWidth, node.top + imageHeight, node.left + imageWidth + amount, node.top\r
+                                               + imageHeight + amount, 0, 0, 1, 1, null);\r
+                                       // Copy edge picels into padding.\r
                                        g.drawImage(image, node.left, node.top - amount, node.left + imageWidth, node.top, 0, 0, imageWidth, 1, null);\r
                                        g.drawImage(image, node.left, node.top + imageHeight, node.left + imageWidth, node.top + imageHeight + amount, 0,\r
                                                imageHeight - 1, imageWidth, imageHeight, null);\r
index 2b55966..b512f85 100644 (file)
@@ -51,9 +51,10 @@ public class SkinLoader extends AsynchronousAssetLoader<Skin, SkinLoader.SkinPar
                ObjectMap<String, String> bitmapFontMap = null;\r
                if (resources != null) bitmapFontMap = resources.get(BitmapFont.class.getName());\r
 \r
+               skinFile = resolve(fileName);\r
+               \r
                fontPaths = new ObjectMap();\r
                if (bitmapFontMap != null) {\r
-                       skinFile = resolve(fileName);\r
                        for (Entry<String, String> entry : bitmapFontMap.entries()) {\r
                                FileHandle fontFile = skinFile.parent().child(entry.value);\r
                                if (!fontFile.exists()) fontFile = Gdx.files.internal(entry.value);\r
index 5c68c20..8aa78c9 100644 (file)
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- ******************************************************************************/
+ ******************************************************************************/\r
+\r
 package com.badlogic.gdx.assets.loaders;\r
 \r
-import com.badlogic.gdx.Gdx;\r
 import com.badlogic.gdx.assets.AssetDescriptor;\r
 import com.badlogic.gdx.assets.AssetLoaderParameters;\r
 import com.badlogic.gdx.assets.AssetManager;\r
@@ -23,6 +23,7 @@ import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.Pixmap;\r
 import com.badlogic.gdx.graphics.Pixmap.Format;\r
 import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
 import com.badlogic.gdx.graphics.TextureData;\r
 import com.badlogic.gdx.graphics.glutils.ETC1TextureData;\r
 import com.badlogic.gdx.graphics.glutils.FileTextureData;\r
@@ -38,7 +39,7 @@ public class TextureLoader extends AsynchronousAssetLoader<Texture, TextureLoade
 \r
        @Override\r
        public void loadAsync (AssetManager manager, String fileName, TextureParameter parameter) {\r
-               if(parameter == null || (parameter != null && parameter.textureData == null)) {\r
+               if (parameter == null || (parameter != null && parameter.textureData == null)) {\r
                        Pixmap pixmap = null;\r
                        Format format = null;\r
                        boolean genMipMaps = false;\r
@@ -49,9 +50,9 @@ public class TextureLoader extends AsynchronousAssetLoader<Texture, TextureLoade
                                genMipMaps = parameter.genMipMaps;\r
                                texture = parameter.texture;\r
                        }\r
-                       \r
+\r
                        FileHandle handle = resolve(fileName);\r
-                       if(!fileName.contains(".etc1")) {\r
+                       if (!fileName.contains(".etc1")) {\r
                                pixmap = new Pixmap(handle);\r
                                data = new FileTextureData(handle, pixmap, format, genMipMaps);\r
                        } else {\r
@@ -65,12 +66,14 @@ public class TextureLoader extends AsynchronousAssetLoader<Texture, TextureLoade
 \r
        @Override\r
        public Texture loadSync (AssetManager manager, String fileName, TextureParameter parameter) {\r
+               Texture texture = this.texture;\r
                if (texture != null) {\r
                        texture.load(data);\r
-                       return texture;\r
                } else {\r
-                       return new Texture(data);\r
+                       texture = new Texture(data);\r
                }\r
+               if (parameter != null) texture.setFilter(parameter.minFilter, parameter.magFilter);\r
+               return texture;\r
        }\r
 \r
        @Override\r
@@ -87,5 +90,7 @@ public class TextureLoader extends AsynchronousAssetLoader<Texture, TextureLoade
                public Texture texture = null;\r
                /** TextureData for textures created on the fly, optional. When set, all format and genMipMaps are ignored */\r
                public TextureData textureData = null;\r
+               public TextureFilter minFilter = TextureFilter.Nearest;\r
+               public TextureFilter magFilter = TextureFilter.Nearest;\r
        }\r
-}
\ No newline at end of file
+}\r
index 7f58fe9..a25e5c0 100644 (file)
@@ -152,7 +152,7 @@ public class TextureRegion {
 \r
        /** Returns the region's width. May be negative if the texture region is flipped horizontally. */\r
        public int getRegionWidth () {\r
-               return (int)(u2 * texture.getWidth()) - (int)(u * texture.getWidth());\r
+               return Math.round((u2 - u) * texture.getWidth());\r
        }\r
 \r
        public void setRegionWidth (int width) {\r
@@ -161,7 +161,7 @@ public class TextureRegion {
 \r
        /** Returns the region's height. May be negative if the texture region is flipped horizontally. */\r
        public int getRegionHeight () {\r
-               return (int)(v2 * texture.getHeight()) - (int)(v * texture.getHeight());\r
+               return Math.round((v2 - v) * texture.getHeight());\r
        }\r
 \r
        public void setRegionHeight (int height) {\r
index 2b5c8af..b54fb14 100644 (file)
@@ -40,7 +40,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.utils.ScissorStack;
  * \r
  * <h2>Layout</h2> A ComboBox's (preferred) width and height are determined by the border patches in the background\r
  * {@link NinePatch} as well as the bounding box of the widest item in the list of strings. Use\r
- * {@link ComboBox#setPrefSize(int, int)} to change this size programmatically. In case the set size is to small to contain the\r
+ *  to change this size programmatically. In case the set size is to small to contain the\r
  * widest item, artifacts may appear.</p>\r
  * \r
  * The additional popup list will be positioned at the bottom edge of the ComboBox, displaying all items. The width and size is\r
@@ -69,7 +69,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.utils.ScissorStack;
  * \r
  * <ul>\r
  * <li>The <code>name</code> attribute defines the name of the style which you can later use with\r
- * {@link Skin#newComboBox(String, String[], Stage, String)}.</li>\r
+ * .</li>\r
  * <li>The <code>background</code> attribute references a {@link NinePatch} by name, to be used as the ComboBox's background</li>\r
  * <li>The <code>listBackground</code> attribute references a {@link NinePatch} by name, to be used as the background for the\r
  * popup list</li>\r
index d80f316..199bdda 100644 (file)
@@ -30,7 +30,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * registered with the list to listen to selection changes. Items have an index in the list, the top item having the index 0.\r
  * \r
  * <h2>Layout</h2> The (preferred) width and height of a List are derrived from the bounding box around all list items. Use\r
- * {@link #setPrefSize(int, int)} to programmatically change the size to your liking. In case the width and height you set are to\r
+ *  to programmatically change the size to your liking. In case the width and height you set are to\r
  * small for the contained text you will see artifacts. The patch highlighting the current selection will have the width of the\r
  * List, either determined as explained above or set programmatically.\r
  * \r
@@ -53,7 +53,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * \r
  * <ul>\r
  * <li>The <code>name</code> attribute defines the name of the style which you can later use with\r
- * {@link Skin#newList(String, String[], String)}.</li>\r
+ * .</li>\r
  * <li>The <code>fontName</code> attribute references a {@link BitmapFont} by name, to be used for render the items</li>\r
  * <li>The <code>fontColorUnselected</code> attribute references a {@link Color} by name, to be used for render unselected items</li>\r
  * <li>The <code>fontColorSelected</code> attribute references a {@link Color} by name, to be used to render the selected item</li>\r
index b53b438..02288cb 100644 (file)
@@ -71,7 +71,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.utils.ScissorStack;
  * \r
  * <ul>\r
  * <li>The <code>name</code> attribute defines the name of the style which you can later use with\r
- * {@link Skin#newScrollPane(String, Stage, Actor, int, int, String)}.</li>\r
+ * .</li>\r
  * <li>The <code>background</code> attribute references a {@link NinePatch} by name, to be used as the scroll pane's background</li>\r
  * <li>The <code>hScroll</code> attribute references a {@link NinePatch} by name, to be used as the scroll pane's horizontal\r
  * scroll bar.</li>\r
index d79a2cb..6239540 100644 (file)
@@ -27,7 +27,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
  * \r
  * <h2>Layout</h2> A slider's (preferred) width and height are determined by the parameter past to its constructor as well as the\r
  * maximum height of the {@link NinePatch} and {@link TextureRegion} involved in the display of the slider. Use\r
- * {@link #setPrefSize(int, int)} to programmatically change the size to your liking. In case the width and height you set are to\r
+ *  to programmatically change the size to your liking. In case the width and height you set are to\r
  * small you will see artifacts.</p>\r
  * \r
  * The slider background will only be stretched in the x-axis. The slider handle will be centered on the background vertically.\r
@@ -48,7 +48,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
  * \r
  * <ul>\r
  * <li>The <code>name</code> attribute defines the name of the style which you can later use with\r
- * {@link Skin#newSlider(String, float, float, float, float, String)}.</li>\r
+ * .</li>\r
  * <li>The <code>slider</code> attribute references a {@link NinePatch} by name, to be used as the slider's background</li>\r
  * <li>The <code>knob</code> attribute references a {@link TextureRegion} by name, to be used as the slider's handle</li> *\r
  * </ul>\r
index 211e800..0c402eb 100644 (file)
@@ -70,7 +70,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * \r
  * <ul>\r
  * <li>The <code>name</code> attribute defines the name of the style which you can later use with\r
- * {@link Skin#newSplitPane(String, Stage, Actor, Actor, boolean, int, int, String)}.</li>\r
+ * .</li>\r
  * <li>The <code>handle</code> attribute references a {@link NinePatch} by name, to be used as the split pane's handle</li>\r
  * </ul>\r
  * @author mzechner */\r
index 0a8b43b..0673374 100644 (file)
@@ -55,7 +55,7 @@ import com.badlogic.gdx.utils.FloatArray;
  * \r
  * <h2>Layout</h2>\r
  * The (preferred) width and height of a TextField are derrived from the width given at construction time as well as the\r
- * combination of the used font's height and the top and bottom border patches. Use {@link Button#setPrefSize(int, int)} to\r
+ * combination of the used font's height and the top and bottom border patches. Use to\r
  * programmatically change the size to your liking. In case the width and height you set are to small for the contained text, the\r
  * TextField will clip the characters based on the current cursor position.\r
  * \r
@@ -80,7 +80,7 @@ import com.badlogic.gdx.utils.FloatArray;
  * \r
  * <ul>\r
  * <li>The <code>name</code> attribute defines the name of the style which you can later use with\r
- * {@link Skin#newTextField(String, float, String)}.</li>\r
+ * .</li>\r
  * <li>The <code>font</code> attribute references a {@link BitmapFont} by name, to be used to render the text in the text field</li>\r
  * <li>The <code>fontColor</code> attribute references a {@link Color} by name, to be used to render the text on the text field</li>\r
  * <li>The <code>cursorPatch</code> attribute references a {@link NinePatch} by name, to be used to render the text field's cursor\r
index 2d5d45c..6425362 100644 (file)
@@ -64,7 +64,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.utils.ScissorStack;
  * \r
  * <ul>\r
  * <li>The <code>name</code> attribute defines the name of the style which you can later use with\r
- * {@link Skin#newWindow(String, Stage, String, int, int, String)}.</li>\r
+ * .</li>\r
  * <li>The <code>titleFont</code> attribute references a {@link BitmapFont} by name, to be used to render the title string.</li>\r
  * *\r
  * <li>The <code>titleFontColor</code> attribute references a {@link Color} by name, to be used to render the title string.</li>\r
index ae4b5b0..8ebe51d 100644 (file)
@@ -585,10 +585,13 @@ public class Json {
                if (fields == null) fields = cacheFields(type);\r
                for (Entry<String, Object> entry : jsonMap.entries()) {\r
                        FieldMetadata metadata = fields.get(entry.key);\r
-                       if (ignoreUnknownFields) {\r
-                               if (debug) System.out.println("Ignoring unknown field: " + entry.key + " (" + type.getName() + ")");\r
-                       } else if (metadata == null)\r
-                               throw new SerializationException("Field not found: " + entry.key + " (" + type.getName() + ")");\r
+                       if (metadata == null) {\r
+                               if (ignoreUnknownFields) {\r
+                                       if (debug) System.out.println("Ignoring unknown field: " + entry.key + " (" + type.getName() + ")");\r
+                                       continue;\r
+                               } else\r
+                                       throw new SerializationException("Field not found: " + entry.key + " (" + type.getName() + ")");\r
+                       }\r
                        Field field = metadata.field;\r
                        if (entry.value == null) continue;\r
                        try {\r