OSDN Git Service

[updated] Table constructors, simpler.
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Mon, 24 Oct 2011 02:44:18 +0000 (02:44 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Mon, 24 Oct 2011 02:44:18 +0000 (02:44 +0000)
[fixed] Mp3 decoder.
[fixed] OpenALAudioDevice initial buffer fill.
[updated] Added color constants.
[updated] LibgdxToolkit, added support to call setWidget instead of addActor.

12 files changed:
backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java
backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudioDevice.java
gdx/src/com/badlogic/gdx/graphics/Color.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Button.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/FlickScrollPane.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/LibgdxToolkit.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/Table.java
tests/gdx-tests/src/com/badlogic/gdx/tests/MipMapTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/ProjectiveTextureTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/ShadowMappingTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/SoundTest.java

index 72a50ad..ad40330 100644 (file)
@@ -61,8 +61,8 @@ public class Mp3 {
                                }\r
 \r
                                int totalLength = 0;\r
-                               int minRequiredLength = buffer.length - OutputBuffer.BUFFERSIZE * 2 - 1;\r
-                               while (totalLength < minRequiredLength) {\r
+                               int minRequiredLength = buffer.length - OutputBuffer.BUFFERSIZE * 2;\r
+                               while (totalLength <= minRequiredLength) {\r
                                        Header header = bitstream.readFrame();\r
                                        if (header == null) break;\r
                                        if (setup) {\r
index 8358b6f..6a7c974 100644 (file)
@@ -73,16 +73,28 @@ public class OpenALAudioDevice implements AudioDevice {
                        }\r
                        alSourcei(sourceID, AL_LOOPING, AL_FALSE);\r
                        alSourcef(sourceID, AL_GAIN, volume);\r
-                       // Queue empty buffers.\r
-                       tempBuffer.clear().flip();\r
+                       // Fill initial buffers.\r
+                       int queuedBuffers = 0;\r
                        for (int i = 0; i < bufferCount; i++) {\r
                                int bufferID = buffers.get(i);\r
+                               int written = Math.min(bufferSize, length);\r
+                               tempBuffer.clear();\r
+                               tempBuffer.put(data, offset, written).flip();\r
+                               alBufferData(bufferID, format, tempBuffer, sampleRate);\r
+                               alSourceQueueBuffers(sourceID, bufferID);\r
+                               length -= written;\r
+                               offset += written;\r
+                               queuedBuffers++;\r
+                       }\r
+                       // Queue rest of buffers, empty.\r
+                       tempBuffer.clear().flip();\r
+                       for (int i = queuedBuffers; i < bufferCount; i++) {\r
+                               int bufferID = buffers.get(i);\r
                                alBufferData(bufferID, format, tempBuffer, sampleRate);\r
                                alSourceQueueBuffers(sourceID, bufferID);\r
                        }\r
                        alSourcePlay(sourceID);\r
                        isPlaying = true;\r
-                       return;\r
                }\r
 \r
                while (length > 0) {\r
index f7baa28..a2c0066 100644 (file)
@@ -28,6 +28,14 @@ public class Color {
        public static final Color RED = new Color(1, 0, 0, 1);\r
        public static final Color GREEN = new Color(0, 1, 0, 1);\r
        public static final Color BLUE = new Color(0, 0, 1, 1);\r
+       public static final Color LIGHT_GRAY = new Color(0.75f, 0.75f, 0.75f, 1);\r
+       public static final Color GRAY = new Color(0.5f, 0.5f, 0.5f, 1);\r
+       public static final Color DARK_GRAY = new Color(0.25f, 0.25f, 0.25f, 1);\r
+       public static final Color PINK = new Color(1, 0.68f, 0.68f, 1);\r
+       public static final Color ORANGE = new Color(1, 0.78f, 0, 1);\r
+       public static final Color YELLOW = new Color(1, 1, 0, 1);\r
+       public static final Color MAGENTA = new Color(1, 0, 1, 1);\r
+       public static final Color CYAN = new Color(0, 1, 1, 1);\r
 \r
        /** the red, green, blue and alpha components **/\r
        public float r, g, b, a;\r
index 2e498dc..3859536 100644 (file)
@@ -53,7 +53,7 @@ public class Button extends Table {
        }
 
        public Button (ButtonStyle style, String name) {
-               super(name);
+               super(null, null, null, name);
                setStyle(style);
                initialize();
        }
index 7edc67c..677b6d0 100644 (file)
@@ -59,6 +59,10 @@ public class FlickScrollPane extends WidgetGroup {
        /** Prevents scrolling out of the widget's bounds. */\r
        public boolean clamp = true;\r
 \r
+       public FlickScrollPane (Stage stage) {\r
+               this(null, stage, null);\r
+       }\r
+\r
        public FlickScrollPane (Actor widget, Stage stage) {\r
                this(widget, stage, null);\r
        }\r
index 01e638c..3181ba4 100644 (file)
@@ -100,7 +100,7 @@ public class Window extends Table {
         * @param prefHeight the (preferred) height\r
         * @param style the {@link WindowStyle} */\r
        public Window (String name, String title, Stage stage, WindowStyle style, int prefWidth, int prefHeight) {\r
-               super(name);\r
+               super(null, null, null, name);\r
                this.stage = stage;\r
                this.title = title;\r
                width = prefWidth;\r
index d5322ba..21ae07e 100644 (file)
@@ -177,6 +177,10 @@ public class LibgdxToolkit extends Toolkit<Actor, Table, TableLayout> {
 \r
        public void addChild (Actor parent, Actor child, String layoutString) {\r
                if (child.parent != null) child.remove();\r
+               try {\r
+                       parent.getClass().getMethod("setWidget", Actor.class).invoke(parent, child);\r
+               } catch (Exception ignored) {\r
+               }\r
                ((Group)parent).addActor(child);\r
        }\r
 \r
index ddb7ca7..e91d4eb 100644 (file)
@@ -60,32 +60,21 @@ public class Table extends WidgetGroup {
        public boolean isPressed;\r
 \r
        public Table () {\r
-               this(new TableLayout(), null);\r
+               this(null, null, null, null);\r
        }\r
 \r
-       public Table (TableLayout layout) {\r
-               this(layout, null);\r
+       public Table (Stage stage, Skin skin) {\r
+               this(stage, skin, null, null);\r
        }\r
 \r
-       public Table (String name) {\r
-               this(new TableLayout(), name);\r
-       }\r
-\r
-       public Table (Skin skin) {\r
-               this(new TableLayout(), null);\r
-               layout.skin = skin;\r
-       }\r
-\r
-       public Table (Skin skin, String name) {\r
-               this(new TableLayout(), name);\r
-               layout.skin = skin;\r
-       }\r
-\r
-       public Table (TableLayout layout, String name) {\r
+       public Table (Stage stage, Skin skin, TableLayout layout, String name) {\r
                super(name);\r
                transform = false;\r
+               if (layout == null) layout = new TableLayout();\r
                this.layout = layout;\r
                layout.setTable(this);\r
+               layout.stage = stage;\r
+               layout.skin = skin;\r
        }\r
 \r
        public void draw (SpriteBatch batch, float parentAlpha) {\r
index b807025..8790870 100644 (file)
@@ -103,7 +103,7 @@ public class MipMapTest extends GdxTest {
                minFilter = new ComboBox(filters, ui, skin.getStyle(ComboBoxStyle.class), "minfilter");\r
                magFilter = new ComboBox(new String[] {"Nearest", "Linear"}, ui, skin.getStyle(ComboBoxStyle.class), "magfilter");\r
 \r
-               Table table = new Table("container");\r
+               Table table = new Table();\r
                table.width = ui.width();\r
                table.height = 30;\r
                table.y = ui.height() - 30;\r
index e5e47db..a897e3e 100644 (file)
@@ -112,7 +112,7 @@ public class ProjectiveTextureTest extends GdxTest {
                ComboBox camera = new ComboBox(new String[] {"Camera", "Light"}, ui, skin.getStyle(ComboBoxStyle.class), "camera");\r
                Label fps = new Label("fps: ", skin.getStyle(LabelStyle.class), "fps");\r
 \r
-               Table table = new Table("container");\r
+               Table table = new Table();\r
                table.width = ui.width();\r
                table.height = ui.height();\r
                table.top().padTop(15);\r
index 8b080b4..eb20dc2 100644 (file)
@@ -123,7 +123,7 @@ public class ShadowMappingTest extends GdxTest {
                        skin.getStyle(ComboBoxStyle.class), "shaderCombo");\r
                Label fpsLabel = new Label("fps:", skin.getStyle(LabelStyle.class), "fps");\r
 \r
-               Table table = new Table("toolbar");\r
+               Table table = new Table();\r
                table.width = Gdx.graphics.getWidth();\r
                table.height = 100;\r
                table.top().padTop(12);\r
index 93d43c2..ec13266 100644 (file)
@@ -57,7 +57,7 @@ public class SoundTest extends GdxTest {
                final Slider volume = new Slider(0.1f, 1, 0.1f, skin);\r
                volume.setValue(1);\r
                final Label volumeValue = new Label("1.0", skin);\r
-               Table table = new Table("ui");\r
+               Table table = new Table();\r
                final Slider pan = new Slider(-1f, 1f, 0.1f, skin);\r
                pan.setValue(0);\r
                final Label panValue = new Label("0.0", skin);\r