OSDN Git Service

[added] simple LinearLayout. Works so far
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 22 Oct 2010 00:52:31 +0000 (00:52 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Fri, 22 Oct 2010 00:52:31 +0000 (00:52 +0000)
[todo] fix Group.toChildCoordinates(). Rotation code of origin is borked. wtf was i thinking...

tests/gdx-tests/src/com/badlogic/gdx/tests/StageTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/UITest.java

index bee7922..752bd6e 100644 (file)
@@ -75,8 +75,8 @@ public class StageTest implements RenderListener, InputListener
                                Group group = new Group( "group" + i );\r
                                group.x = (float)Math.random() * (stage.width() - NUM_SPRITES * (32 + SPACING));\r
                                group.y = (float)Math.random() * (stage.height() - NUM_SPRITES * (32 + SPACING));\r
-                               group.refX = loc;\r
-                               group.refY = loc;\r
+                               group.originX = loc;\r
+                               group.originY = loc;\r
                                \r
                                fillGroup( group, texture );\r
                                stage.addActor( group );\r
@@ -195,7 +195,7 @@ public class StageTest implements RenderListener, InputListener
                {\r
                        renderer.color( 1, 0, 0, 1 );\r
                        Group group = stage.getRoot().getGroups().get(i);\r
-                       renderer.vertex( group.x + group.refX, group.y + group.refY, 0 );\r
+                       renderer.vertex( group.x + group.originX, group.y + group.originY, 0 );\r
                }\r
                renderer.end();\r
                Gdx.graphics.getGL10().glPointSize( 4 );\r
index 43ae0ac..82f5aa5 100644 (file)
@@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.Texture.TextureFilter;
 import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
 import com.badlogic.gdx.math.Vector2;\r
 import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.Group;\r
 import com.badlogic.gdx.scenes.scene2d.Stage;\r
 import com.badlogic.gdx.scenes.scene2d.actions.Delay;\r
 import com.badlogic.gdx.scenes.scene2d.actions.FadeIn;\r
@@ -22,6 +23,8 @@ import com.badlogic.gdx.scenes.scene2d.actions.ScaleTo;
 import com.badlogic.gdx.scenes.scene2d.actions.Sequence;\r
 import com.badlogic.gdx.scenes.scene2d.actors.Button;\r
 import com.badlogic.gdx.scenes.scene2d.actors.Image;\r
+import com.badlogic.gdx.scenes.scene2d.actors.LinearGroup;\r
+import com.badlogic.gdx.scenes.scene2d.actors.LinearGroup.LinearGroupLayout;\r
 \r
 public class UITest implements RenderListener, InputListener\r
 {\r
@@ -64,12 +67,30 @@ public class UITest implements RenderListener, InputListener
                                                                                                , 1 )\r
                                                                        )\r
                                                );\r
-                       ui.addActor( img1 );\r
+//                     ui.addActor( img1 );\r
                        \r
-                       Button button = new Button( "button", atlas.getRegion( "button" ), atlas.getRegion( "buttonDown" ) );\r
-                       button.x = 100;\r
-                       ui.addActor( button );\r
+                       Group group = new Group( "group" );\r
+                       group.rotation = 700;                   \r
+                       group.width = 64; group.height = 32 * 3;\r
+                       group.originX = group.width / 2; group.originY = group.height / 2;\r
+                       group.x = 100;\r
+                       group.y = 150;\r
+                       Button button = new Button( "button", atlas.getRegion( "button" ), atlas.getRegion( "buttonDown" ) );                   \r
+                       group.addActor( button );\r
+                       ui.addActor( group );\r
                        \r
+                       LinearGroup linear = new LinearGroup( "linear", 64, 32 * 3, LinearGroupLayout.Vertical );\r
+                       linear.x = 200; linear.y = 150; linear.scaleX = linear.scaleY = 1;\r
+                       linear.addActor( new Button( "blend", atlas.getRegion( "blend" ) ) );\r
+                       linear.addActor( new Button( "scale", atlas.getRegion( "scale" ) ) );\r
+                       linear.addActor( new Button( "rotate", atlas.getRegion( "rotate" ) ) );\r
+//                     linear.rotation = 720;\r
+                       linear.action( Parallel.$( RotateTo.$( 720, 2 ) ) );                    \r
+                       \r
+                       ui.addActor( linear );\r
+//                     ui.getRoot().rotation = 720;\r
+                       \r
+                       Group.enableDebugging( "data/debug.png" );\r
                }\r
        }\r
 \r
@@ -124,14 +145,17 @@ public class UITest implements RenderListener, InputListener
                if( !ui.touchUp( x, y, pointer ) )\r
                {\r
                        Actor actor = ui.findActor( "image1" );\r
-                       ui.toStageCoordinates( x, y, point );\r
-                       actor.clearActions();\r
-                       actor.action( MoveTo.$( point.x, point.y, 2 ) );\r
-                       actor.action( RotateTo.$( actor.rotation + 90, 2 ) );\r
-                       if( actor.scaleX == 1.0f )\r
-                               actor.action( ScaleTo.$( 0.5f, 0.5f, 2 ) );\r
-                       else\r
-                               actor.action( ScaleTo.$( 1f, 1f, 2 ) );\r
+                       if( actor != null )\r
+                       {\r
+                               ui.toStageCoordinates( x, y, point );\r
+                               actor.clearActions();\r
+                               actor.action( MoveTo.$( point.x, point.y, 2 ) );\r
+                               actor.action( RotateTo.$( actor.rotation + 90, 2 ) );\r
+                               if( actor.scaleX == 1.0f )\r
+                                       actor.action( ScaleTo.$( 0.5f, 0.5f, 2 ) );\r
+                               else\r
+                                       actor.action( ScaleTo.$( 1f, 1f, 2 ) );\r
+                       }\r
                }\r
                return false;\r
        }\r