OSDN Git Service

add buttons to test for fade and scrollbarsOnTop, used eclipse code formatter, exclud...
authorJon Renner <rennerjc@gmail.com>
Sun, 6 Oct 2013 04:19:09 +0000 (12:19 +0800)
committerJon Renner <rennerjc@gmail.com>
Sun, 6 Oct 2013 04:19:09 +0000 (12:19 +0800)
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.java
tests/gdx-tests/src/com/badlogic/gdx/tests/ScrollPaneScrollBarsTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java

index c4c4e24..c030e5f 100644 (file)
@@ -464,7 +464,7 @@ public class ScrollPane extends WidgetGroup {
                                // bar on the top or bottom\r
                                if (hScrollOnBottom) {\r
                                        boundsY = bgBottomHeight;\r
-                               } else {                                        \r
+                               } else {\r
                                        boundsY = height - bgTopHeight - hScrollHeight;\r
                                }\r
                                hScrollBounds.set(boundsX, boundsY, areaWidth, hScrollHeight);\r
@@ -894,18 +894,12 @@ public class ScrollPane extends WidgetGroup {
                this.clamp = clamp;\r
        }\r
 \r
-       /** Put the vertical scroll bar and knob on the left or right side of the ScrollPane\r
-        * @param atRight set to true to draw on the right, false to draw on the left (default : right)\r
-        */\r
-       public void setVScrollBarAtRight(boolean atRight) {\r
-               vScrollOnRight = atRight;\r
-       }\r
-\r
-       /** Put the vertical scroll bar and knob on the top (y coords, not draw order) or bottom of the ScrollPane\r
-        * @param atBottom set to true to draw on the bottom, false to draw on the top (default : bottom)\r
-        */\r
-       public void setHScrollBarAtBottom(boolean atBottom) {\r
-               hScrollOnBottom = atBottom;\r
+       /** Set the position of the vertical and horizontal scroll bars (if they exist).\r
+        * @param bottom sets horizontal scroll bar to be at the bottom or the top\r
+        * @param right sets vertical scroll bar to be at the right or the left */\r
+       public void setScrollBarPositions (boolean bottom, boolean right) {\r
+               hScrollOnBottom = bottom;\r
+               vScrollOnRight = right;\r
        }\r
 \r
        /** When true the scroll bars fade out after some time of not being used. */\r
index 234345c..76020be 100644 (file)
@@ -18,41 +18,78 @@ package com.badlogic.gdx.tests;
 \r
 import com.badlogic.gdx.Gdx;\r
 import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.scenes.scene2d.Actor;\r
 import com.badlogic.gdx.scenes.scene2d.Stage;\r
 import com.badlogic.gdx.scenes.scene2d.ui.Label;\r
 import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;\r
 import com.badlogic.gdx.scenes.scene2d.ui.Skin;\r
 import com.badlogic.gdx.scenes.scene2d.ui.Table;\r
+import com.badlogic.gdx.scenes.scene2d.ui.TextButton;\r
+import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;\r
 import com.badlogic.gdx.tests.utils.GdxTest;\r
+import com.badlogic.gdx.utils.Array;\r
 \r
-/**\r
- * Test switch of scroll bars + knobs from right to left, and bottom to top\r
- */\r
+/** Test switch of scroll bars + knobs from right to left, and bottom to top */\r
 public class ScrollPaneScrollBarsTest extends GdxTest {\r
        private Stage stage;\r
-       private Table bottomLeft, bottomRight, topLeft, topRight,\r
-                       horizOnlyTop, horizOnlyBottom, vertOnlyLeft, vertOnlyRight;\r
+       private Array<ScrollPane> scrollPanes = new Array<ScrollPane>();\r
+       private boolean doFade = true;\r
+       private boolean doOnTop = true;\r
+       private Table bottomLeft, bottomRight, topLeft, topRight, horizOnlyTop, horizOnlyBottom, vertOnlyLeft, vertOnlyRight;\r
 \r
        public void create () {\r
+               float width = Gdx.graphics.getWidth();\r
+               float height = Gdx.graphics.getHeight();\r
+               float btnWidth = 200;\r
+               float btnHeight = 40;\r
                stage = new Stage(0, 0, false);\r
                Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));\r
                Gdx.input.setInputProcessor(stage);\r
 \r
+               final TextButton fadeBtn = new TextButton("Fade: " + doFade, skin);\r
+               fadeBtn.setSize(btnWidth, btnHeight);\r
+               fadeBtn.setPosition(0, height - fadeBtn.getHeight());\r
+               stage.addActor(fadeBtn);\r
+               fadeBtn.addListener(new ChangeListener() {\r
+                       @Override\r
+                       public void changed (ChangeEvent event, Actor actor) {\r
+                               doFade = !doFade;\r
+                               fadeBtn.setText("Fade: " + doFade);\r
+                               for (ScrollPane pane : scrollPanes) {\r
+                                       pane.setFadeScrollBars(doFade);\r
+                               }\r
+                       }\r
+               });\r
+\r
+               final TextButton onTopBtn = new TextButton("ScrollbarsOnTop: " + doOnTop, skin);\r
+               onTopBtn.setSize(btnWidth, btnHeight);\r
+               onTopBtn.setPosition(0 + fadeBtn.getWidth() + 20, height - onTopBtn.getHeight());\r
+               stage.addActor(onTopBtn);\r
+               onTopBtn.addListener(new ChangeListener() {\r
+                       @Override\r
+                       public void changed (ChangeEvent event, Actor actor) {\r
+                               doOnTop = !doOnTop;\r
+                               onTopBtn.setText("ScrollbarOnTop: " + doOnTop);\r
+                               onTopBtn.invalidate();\r
+                               for (ScrollPane pane : scrollPanes) {\r
+                                       pane.setScrollbarsOnTop(doOnTop);\r
+                               }\r
+                       }\r
+               });\r
+\r
                // Gdx.graphics.setVSync(false);\r
 \r
-               float width = Gdx.graphics.getWidth();\r
-               float height = Gdx.graphics.getHeight();\r
                float gap = 8;\r
                float x = gap;\r
                float y = gap;\r
                float contWidth = width / 2 - gap * 1.5f;\r
-               float contHeight = height / 4 - gap * 1.25f;\r
+               float contHeight = height / 4.5f - gap * 1.25f;\r
 \r
                bottomLeft = new Table();\r
                bottomLeft.setPosition(x, y);\r
                bottomLeft.setSize(contWidth, contHeight);\r
                stage.addActor(bottomLeft);\r
-               \r
+\r
                bottomRight = new Table();\r
                bottomRight.setSize(contWidth, contHeight);\r
                x = bottomLeft.getX() + bottomLeft.getWidth() + gap;\r
@@ -72,14 +109,14 @@ public class ScrollPaneScrollBarsTest extends GdxTest {
                y = topLeft.getY();\r
                topRight.setPosition(x, y);\r
                stage.addActor(topRight);\r
-               \r
+\r
                horizOnlyTop = new Table();\r
                horizOnlyTop.setSize(contWidth, contHeight);\r
                x = topRight.getX();\r
                y = topRight.getY() + topRight.getHeight() + gap;\r
                horizOnlyTop.setPosition(x, y);\r
                stage.addActor(horizOnlyTop);\r
-               \r
+\r
                horizOnlyBottom = new Table();\r
                horizOnlyBottom.setSize(contWidth, contHeight);\r
                x = topLeft.getX();\r
@@ -111,72 +148,67 @@ public class ScrollPaneScrollBarsTest extends GdxTest {
                Table vertOnlyRightTable = new Table();\r
 \r
                final ScrollPane bottomLeftScroll = new ScrollPane(bottomLeftTable, skin);\r
-               bottomLeftScroll.setVScrollBarAtRight(false);\r
-               bottomLeftScroll.setHScrollBarAtBottom(true);\r
+               bottomLeftScroll.setScrollBarPositions(true, false);\r
 \r
                final ScrollPane bottomRightScroll = new ScrollPane(bottomRightTable, skin);\r
-               bottomRightScroll.setVScrollBarAtRight(true);\r
-               bottomRightScroll.setHScrollBarAtBottom(true);\r
+               bottomRightScroll.setScrollBarPositions(true, true);\r
 \r
                final ScrollPane topLeftScroll = new ScrollPane(topLeftTable, skin);\r
-               topLeftScroll.setVScrollBarAtRight(false);\r
-               topLeftScroll.setHScrollBarAtBottom(false);\r
+               topLeftScroll.setScrollBarPositions(false, false);\r
 \r
                final ScrollPane topRightScroll = new ScrollPane(topRightTable, skin);\r
-               topRightScroll.setVScrollBarAtRight(true);\r
-               topRightScroll.setHScrollBarAtBottom(false);\r
-               \r
+               topRightScroll.setScrollBarPositions(false, true);\r
+\r
                final ScrollPane horizOnlyTopScroll = new ScrollPane(horizOnlyTopTable, skin);\r
-               horizOnlyTopScroll.setHScrollBarAtBottom(false);\r
-               \r
+               horizOnlyTopScroll.setScrollBarPositions(false, true);\r
+\r
                final ScrollPane horizOnlyBottomScroll = new ScrollPane(horizOnlyBottomTable, skin);\r
-               horizOnlyBottomScroll.setHScrollBarAtBottom(true);\r
+               horizOnlyBottomScroll.setScrollBarPositions(true, true);\r
 \r
                final ScrollPane vertOnlyLeftScroll = new ScrollPane(vertOnlyLeftTable, skin);\r
-               vertOnlyLeftScroll.setVScrollBarAtRight(false);\r
+               vertOnlyLeftScroll.setScrollBarPositions(true, false);\r
 \r
                final ScrollPane vertOnlyRightScroll = new ScrollPane(vertOnlyRightTable, skin);\r
-               vertOnlyRightScroll.setVScrollBarAtRight(true);\r
-               \r
-               ScrollPane[] scrollPanes = new ScrollPane[] {\r
-                       bottomLeftScroll, bottomRightScroll, topLeftScroll, topRightScroll,\r
-                       horizOnlyTopScroll, horizOnlyBottomScroll,\r
-                       vertOnlyLeftScroll, vertOnlyRightScroll\r
-               };\r
-               // want to see all scroll bars all the time\r
-               for (ScrollPane pane : scrollPanes) {\r
-                       pane.setFadeScrollBars(false);\r
+               vertOnlyRightScroll.setScrollBarPositions(true, true);\r
+\r
+               ScrollPane[] panes = new ScrollPane[] {bottomLeftScroll, bottomRightScroll, topLeftScroll, topRightScroll,\r
+                       horizOnlyTopScroll, horizOnlyBottomScroll, vertOnlyLeftScroll, vertOnlyRightScroll};\r
+               for (ScrollPane pane : panes) {\r
+                       scrollPanes.add(pane);\r
                }\r
 \r
-               Table[] tables = new Table[] { \r
-                       bottomLeftTable, bottomRightTable, topLeftTable, topRightTable,\r
-                       horizOnlyTopTable, horizOnlyBottomTable,\r
-                       vertOnlyLeftTable, vertOnlyRightTable\r
-               };\r
+               Table[] tables = new Table[] {bottomLeftTable, bottomRightTable, topLeftTable, topRightTable, horizOnlyTopTable,\r
+                       horizOnlyBottomTable, vertOnlyLeftTable, vertOnlyRightTable};\r
                for (Table t : tables) {\r
                        t.pad(10).defaults().expandX().space(4);\r
                }\r
-               \r
-               horizOnlyTopTable.add(new Label("HORIZONTAL-ONLY-TOP verify HORIZONTAL scroll bar is on the TOP and properly aligned", skin));\r
-               horizOnlyBottomTable.add(new Label("HORIZONTAL-ONLY-BOTTOM verify HORIZONTAL scroll bar is on the BOTTOM and properly aligned", skin));\r
-               \r
+\r
+               horizOnlyTopTable\r
+                       .add(new Label("HORIZONTAL-ONLY-TOP verify HORIZONTAL scroll bar is on the TOP and properly aligned", skin));\r
+               horizOnlyBottomTable.add(new Label(\r
+                       "HORIZONTAL-ONLY-BOTTOM verify HORIZONTAL scroll bar is on the BOTTOM and properly aligned", skin));\r
+\r
                for (int i = 0; i < 12; i++) {\r
                        bottomLeftTable.row();\r
                        bottomRightTable.row();\r
                        topLeftTable.row();\r
-                       topRightTable.row();                    \r
+                       topRightTable.row();\r
 \r
-                       bottomLeftTable.add(new Label(i + " BOTTOM-LEFT verify scroll bars are on the BOTTOM and the LEFT, and are properly aligned", skin));\r
-                       bottomRightTable.add(new Label(i + " BOTTOM-RIGHT verify scroll bars are on the BOTTOM and the RIGHT, and are properly aligned", skin));\r
-                       topLeftTable.add(new Label(i + " TOP-LEFT verify scroll bars are on the TOP and the LEFT, and are properly aligned", skin));\r
-                       topRightTable.add(new Label(i + " TOP-RIGHT verify scroll bars are on the TOP and the RIGHT, and are properly aligned", skin));\r
+                       bottomLeftTable.add(new Label(i\r
+                               + " BOTTOM-LEFT verify scroll bars are on the BOTTOM and the LEFT, and are properly aligned", skin));\r
+                       bottomRightTable.add(new Label(i\r
+                               + " BOTTOM-RIGHT verify scroll bars are on the BOTTOM and the RIGHT, and are properly aligned", skin));\r
+                       topLeftTable.add(new Label(i + " TOP-LEFT verify scroll bars are on the TOP and the LEFT, and are properly aligned",\r
+                               skin));\r
+                       topRightTable.add(new Label(i + " TOP-RIGHT verify scroll bars are on the TOP and the RIGHT, and are properly aligned",\r
+                               skin));\r
 \r
                        vertOnlyLeftTable.row();\r
                        vertOnlyRightTable.row();\r
 \r
                        vertOnlyLeftTable.add(new Label("VERT-ONLY-LEFT", skin));\r
                        vertOnlyRightTable.add(new Label("VERT-ONLY-RIGHT", skin));\r
-               }               \r
+               }\r
 \r
                bottomLeft.add(bottomLeftScroll).expand().fill().colspan(4);\r
                bottomRight.add(bottomRightScroll).expand().fill().colspan(4);\r
index 1fe1e23..e697968 100644 (file)
@@ -55,6 +55,7 @@ import com.badlogic.gdx.tests.superkoalio.SuperKoalio;
  * @author badlogicgames@gmail.com */\r
 public class GdxTests {\r
        public static final List<Class<? extends GdxTest>> tests = new ArrayList<Class<? extends GdxTest>>(Arrays.asList(\r
+               // @off\r
                AccelerometerTest.class,\r
                ActionSequenceTest.class,\r
                ActionTest.class,\r
@@ -224,9 +225,11 @@ public class GdxTests {
                VibratorTest.class,\r
                WaterRipples.class,\r
                YDownTest.class\r
+               // @on\r
+\r
                // SoundTouchTest.class, Mpg123Test.class, WavTest.class, FreeTypeTest.class,\r
                // InternationalFontsTest.class, VorbisTest.class\r
-       ));\r
+               ));\r
 \r
        public static List<String> getNames () {\r
                List<String> names = new ArrayList<String>(tests.size());\r
@@ -236,11 +239,9 @@ public class GdxTests {
                return names;\r
        }\r
 \r
-       private static Class<? extends GdxTest> forName (String name)\r
-       {\r
+       private static Class<? extends GdxTest> forName (String name) {\r
                for (Class clazz : tests)\r
-                       if (clazz.getSimpleName().equals(name))\r
-                               return clazz;\r
+                       if (clazz.getSimpleName().equals(name)) return clazz;\r
                return null;\r
        }\r
 \r