From: nathan.sweet Date: Mon, 24 Oct 2011 02:44:18 +0000 (+0000) Subject: [updated] Table constructors, simpler. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=cb553906a6e25ef0073f29ba1bad66a1cca01cb1;p=mikumikustudio%2Flibgdx-mikumikustudio.git [updated] Table constructors, simpler. [fixed] Mp3 decoder. [fixed] OpenALAudioDevice initial buffer fill. [updated] Added color constants. [updated] LibgdxToolkit, added support to call setWidget instead of addActor. --- diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java index 72a50adb2..ad4033001 100644 --- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java +++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java @@ -61,8 +61,8 @@ public class Mp3 { } int totalLength = 0; - int minRequiredLength = buffer.length - OutputBuffer.BUFFERSIZE * 2 - 1; - while (totalLength < minRequiredLength) { + int minRequiredLength = buffer.length - OutputBuffer.BUFFERSIZE * 2; + while (totalLength <= minRequiredLength) { Header header = bitstream.readFrame(); if (header == null) break; if (setup) { diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudioDevice.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudioDevice.java index 8358b6f3d..6a7c9746c 100644 --- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudioDevice.java +++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudioDevice.java @@ -73,16 +73,28 @@ public class OpenALAudioDevice implements AudioDevice { } alSourcei(sourceID, AL_LOOPING, AL_FALSE); alSourcef(sourceID, AL_GAIN, volume); - // Queue empty buffers. - tempBuffer.clear().flip(); + // Fill initial buffers. + int queuedBuffers = 0; for (int i = 0; i < bufferCount; i++) { int bufferID = buffers.get(i); + int written = Math.min(bufferSize, length); + tempBuffer.clear(); + tempBuffer.put(data, offset, written).flip(); + alBufferData(bufferID, format, tempBuffer, sampleRate); + alSourceQueueBuffers(sourceID, bufferID); + length -= written; + offset += written; + queuedBuffers++; + } + // Queue rest of buffers, empty. + tempBuffer.clear().flip(); + for (int i = queuedBuffers; i < bufferCount; i++) { + int bufferID = buffers.get(i); alBufferData(bufferID, format, tempBuffer, sampleRate); alSourceQueueBuffers(sourceID, bufferID); } alSourcePlay(sourceID); isPlaying = true; - return; } while (length > 0) { diff --git a/gdx/src/com/badlogic/gdx/graphics/Color.java b/gdx/src/com/badlogic/gdx/graphics/Color.java index f7baa28cd..a2c006654 100644 --- a/gdx/src/com/badlogic/gdx/graphics/Color.java +++ b/gdx/src/com/badlogic/gdx/graphics/Color.java @@ -28,6 +28,14 @@ public class Color { public static final Color RED = new Color(1, 0, 0, 1); public static final Color GREEN = new Color(0, 1, 0, 1); public static final Color BLUE = new Color(0, 0, 1, 1); + public static final Color LIGHT_GRAY = new Color(0.75f, 0.75f, 0.75f, 1); + public static final Color GRAY = new Color(0.5f, 0.5f, 0.5f, 1); + public static final Color DARK_GRAY = new Color(0.25f, 0.25f, 0.25f, 1); + public static final Color PINK = new Color(1, 0.68f, 0.68f, 1); + public static final Color ORANGE = new Color(1, 0.78f, 0, 1); + public static final Color YELLOW = new Color(1, 1, 0, 1); + public static final Color MAGENTA = new Color(1, 0, 1, 1); + public static final Color CYAN = new Color(0, 1, 1, 1); /** the red, green, blue and alpha components **/ public float r, g, b, a; diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Button.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Button.java index 2e498dc28..3859536e2 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Button.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Button.java @@ -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(); } diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/FlickScrollPane.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/FlickScrollPane.java index 7edc67c67..677b6d0e1 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/FlickScrollPane.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/FlickScrollPane.java @@ -59,6 +59,10 @@ public class FlickScrollPane extends WidgetGroup { /** Prevents scrolling out of the widget's bounds. */ public boolean clamp = true; + public FlickScrollPane (Stage stage) { + this(null, stage, null); + } + public FlickScrollPane (Actor widget, Stage stage) { this(widget, stage, null); } diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java index 01e638c17..3181ba43c 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java @@ -100,7 +100,7 @@ public class Window extends Table { * @param prefHeight the (preferred) height * @param style the {@link WindowStyle} */ public Window (String name, String title, Stage stage, WindowStyle style, int prefWidth, int prefHeight) { - super(name); + super(null, null, null, name); this.stage = stage; this.title = title; width = prefWidth; diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/LibgdxToolkit.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/LibgdxToolkit.java index d5322ba27..21ae07ea4 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/LibgdxToolkit.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/LibgdxToolkit.java @@ -177,6 +177,10 @@ public class LibgdxToolkit extends Toolkit { public void addChild (Actor parent, Actor child, String layoutString) { if (child.parent != null) child.remove(); + try { + parent.getClass().getMethod("setWidget", Actor.class).invoke(parent, child); + } catch (Exception ignored) { + } ((Group)parent).addActor(child); } diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/Table.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/Table.java index ddb7ca761..e91d4eb90 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/Table.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/tablelayout/Table.java @@ -60,32 +60,21 @@ public class Table extends WidgetGroup { public boolean isPressed; public Table () { - this(new TableLayout(), null); + this(null, null, null, null); } - public Table (TableLayout layout) { - this(layout, null); + public Table (Stage stage, Skin skin) { + this(stage, skin, null, null); } - public Table (String name) { - this(new TableLayout(), name); - } - - public Table (Skin skin) { - this(new TableLayout(), null); - layout.skin = skin; - } - - public Table (Skin skin, String name) { - this(new TableLayout(), name); - layout.skin = skin; - } - - public Table (TableLayout layout, String name) { + public Table (Stage stage, Skin skin, TableLayout layout, String name) { super(name); transform = false; + if (layout == null) layout = new TableLayout(); this.layout = layout; layout.setTable(this); + layout.stage = stage; + layout.skin = skin; } public void draw (SpriteBatch batch, float parentAlpha) { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/MipMapTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/MipMapTest.java index b807025dc..87908704f 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/MipMapTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/MipMapTest.java @@ -103,7 +103,7 @@ public class MipMapTest extends GdxTest { minFilter = new ComboBox(filters, ui, skin.getStyle(ComboBoxStyle.class), "minfilter"); magFilter = new ComboBox(new String[] {"Nearest", "Linear"}, ui, skin.getStyle(ComboBoxStyle.class), "magfilter"); - Table table = new Table("container"); + Table table = new Table(); table.width = ui.width(); table.height = 30; table.y = ui.height() - 30; diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/ProjectiveTextureTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/ProjectiveTextureTest.java index e5e47db5d..a897e3e60 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/ProjectiveTextureTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/ProjectiveTextureTest.java @@ -112,7 +112,7 @@ public class ProjectiveTextureTest extends GdxTest { ComboBox camera = new ComboBox(new String[] {"Camera", "Light"}, ui, skin.getStyle(ComboBoxStyle.class), "camera"); Label fps = new Label("fps: ", skin.getStyle(LabelStyle.class), "fps"); - Table table = new Table("container"); + Table table = new Table(); table.width = ui.width(); table.height = ui.height(); table.top().padTop(15); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/ShadowMappingTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/ShadowMappingTest.java index 8b080b4b2..eb20dc276 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/ShadowMappingTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/ShadowMappingTest.java @@ -123,7 +123,7 @@ public class ShadowMappingTest extends GdxTest { skin.getStyle(ComboBoxStyle.class), "shaderCombo"); Label fpsLabel = new Label("fps:", skin.getStyle(LabelStyle.class), "fps"); - Table table = new Table("toolbar"); + Table table = new Table(); table.width = Gdx.graphics.getWidth(); table.height = 100; table.top().padTop(12); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/SoundTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/SoundTest.java index 93d43c200..ec13266c3 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/SoundTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/SoundTest.java @@ -57,7 +57,7 @@ public class SoundTest extends GdxTest { final Slider volume = new Slider(0.1f, 1, 0.1f, skin); volume.setValue(1); final Label volumeValue = new Label("1.0", skin); - Table table = new Table("ui"); + Table table = new Table(); final Slider pan = new Slider(-1f, 1f, 0.1f, skin); pan.setValue(0); final Label panValue = new Label("0.0", skin);