[todo] fix Group.toChildCoordinates(). Rotation code of origin is borked. wtf was i thinking...
public float y;\r
public float width;\r
public float height;\r
- public float refX;\r
- public float refY;\r
+ public float originX;\r
+ public float originY;\r
public float scaleX = 1;\r
public float scaleY = 1;\r
public float rotation;\r
\r
public String toString( )\r
{\r
- return name + ": [x=" + x + ", y=" + y + ", refX=" + refX + ", refY=" + refY + ", width=" + width + ", height=" + height + "]";\r
+ return name + ": [x=" + x + ", y=" + y + ", refX=" + originX + ", refY=" + originY + ", width=" + width + ", height=" + height + "]";\r
}\r
\r
}\r
private void updateTransform( )\r
{\r
transform.idt();\r
- if( refX != 0 || refY != 0 )\r
- transform.setToTranslation( refX, refY );\r
+ if( originX != 0 || originY != 0 )\r
+ transform.setToTranslation( originX, originY );\r
if( scaleX != 1 || scaleY != 1 )\r
transform.mul( scenetransform.setToScaling( scaleX, scaleY ) );\r
if( rotation != 0 )\r
transform.mul( scenetransform.setToRotation( rotation ) );\r
- if( refX != 0 || refY != 0 )\r
- transform.mul( scenetransform.setToTranslation( -refX, -refY ) );\r
+ if( originX != 0 || originY != 0 )\r
+ transform.mul( scenetransform.setToTranslation( -originX, -originY ) );\r
if( x != 0 || y != 0 )\r
{\r
transform.getValues()[6] += x;\r
tmp4.set( scenetransform ); \r
\r
if( debug && debugTexture != null )\r
- batch.draw( debugTexture, x, y, refX, refY, 200, 200, scaleX, scaleY, rotation, 0, 0, debugTexture.getWidth(), debugTexture.getHeight(), Color.WHITE, false, false );\r
+ batch.draw( debugTexture, x, y, originX, originY, width==0?200:width, height==0?200:height, scaleX, scaleY, rotation, 0, 0, debugTexture.getWidth(), debugTexture.getHeight(), Color.WHITE, false, false );\r
\r
batch.end(); \r
oldBatchTransform.set(batch.getTransformMatrix());\r
}\r
else\r
{\r
- if( child.refX == 0 && child.refY == 0 )\r
+ if( child.originX == 0 && child.originY == 0 )\r
{\r
out.x = (x - child.x) / child.scaleX;\r
out.y = (y - child.y) / child.scaleY;\r
}\r
else\r
{\r
- out.x = x / child.scaleX - (child.x - child.refX);\r
- out.x = x / child.scaleX - (child.x - child.refX);\r
+ out.x = x / child.scaleX - (child.x - child.originX);\r
+ out.x = x / child.scaleX - (child.x - child.originX);\r
}\r
}\r
}\r
\r
if( child.scaleX == 1 && child.scaleY == 1 )\r
{\r
- if( child.refX == 0 && child.refY == 0 )\r
+ if( child.originX == 0 && child.originY == 0 )\r
{ \r
float tox = x - child.x;\r
float toy = y - child.y;\r
}\r
else\r
{\r
- float refX = -sin * child.refX + cos * child.refY;\r
- float refY = cos * child.refX + sin * child.refY;\r
+ float refX = -sin * child.originX + cos * child.originY;\r
+ float refY = cos * child.originX + sin * child.originY;\r
\r
- float px = child.x + child.refX - refX;\r
- float py = child.y + child.refY - refY;\r
+ float px = child.x + child.originX - refX;\r
+ float py = child.y + child.originY - refY;\r
\r
float tox = x - px;\r
float toy = y - py;\r
}\r
else\r
{\r
- if( child.refX == 0 && child.refY == 0 )\r
+ if( child.originX == 0 && child.originY == 0 )\r
{ \r
float tox = x - child.x;\r
float toy = y - child.y;\r
}\r
else\r
{\r
- float srefX = child.refX * child.scaleY;\r
- float srefY = child.refY * child.scaleX;\r
+ float srefX = child.originX * child.scaleY;\r
+ float srefY = child.originY * child.scaleX;\r
\r
float refX = -sin * srefX + cos * srefY;\r
float refY = cos * srefX + sin * srefY;\r
\r
- float px = child.x + child.refX - refX;\r
- float py = child.y + child.refY - refY;\r
+ float px = child.x + child.originX - refX;\r
+ float py = child.y + child.originY - refY;\r
\r
float tox = x - px;\r
float toy = y - py;\r
if( !touchable )\r
return false;\r
\r
+ if( debug )\r
+ Gdx.app.log( "Group", name + ": " + x + ", " + y );\r
+ \r
if( focusedActor != null )\r
{\r
point.x = x; point.y = y;\r
--- /dev/null
+package com.badlogic.gdx.scenes.scene2d.actors;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.Group;\r
+\r
+/**\r
+ * This is a group that respects its width and height. Useful for implementing\r
+ * layouts.\r
+ * @author mzechner\r
+ *\r
+ */\r
+public class BoundGroup extends Group \r
+{\r
+ public BoundGroup(String name, float width, float height ) \r
+ {\r
+ super(name); \r
+ this.width = width;\r
+ this.height = height;\r
+ this.originX = width / 2;\r
+ this.originY = height / 2;\r
+ }\r
+ \r
+ protected boolean touchDown( float x, float y, int pointer )\r
+ {\r
+ if( focusedActor != null )\r
+ {\r
+ return super.touchDown(x, y, pointer);\r
+ }\r
+ else\r
+ {\r
+ if( !(x > 0 && y > 0 && x < width && y < height) )\r
+ return false; \r
+ return super.touchDown( x, y, pointer );\r
+ } \r
+ }\r
+ \r
+ protected boolean touchUp( float x, float y, int pointer )\r
+ {\r
+ if( focusedActor != null )\r
+ {\r
+ return super.touchUp(x, y, pointer);\r
+ }\r
+ else\r
+ {\r
+ if( !(x > 0 && y > 0 && x < width && y < height) )\r
+ return false;\r
+ return super.touchUp(x, y, pointer);\r
+ } \r
+ }\r
+ \r
+ protected boolean touchDragged( float x, float y, int pointer )\r
+ {\r
+ if( focusedActor != null )\r
+ {\r
+ return super.touchDragged(x, y, pointer);\r
+ }\r
+ else\r
+ {\r
+ if( !(x > 0 && y > 0 && x < width && y < height) )\r
+ return false;\r
+ return super.touchDragged(x, y, pointer);\r
+ } \r
+ }\r
+ \r
+ public Actor hit( float x, float y )\r
+ {\r
+ return x > 0 && y > 0 && x < width && y < height? this: null;\r
+ }\r
+}\r
public Button( String name, Texture texture )\r
{\r
super( name );\r
- this.refX = texture.getWidth() / 2.0f;\r
- this.refY = texture.getHeight() / 2.0f;\r
+ this.originX = texture.getWidth() / 2.0f;\r
+ this.originY = texture.getHeight() / 2.0f;\r
this.width = texture.getWidth();\r
this.height = texture.getHeight();\r
this.pressedRegion = new TextureRegion( texture, 0, 0, texture.getWidth(), texture.getHeight() );\r
public Button( String name, TextureRegion unpressedRegion, TextureRegion pressedRegion )\r
{\r
super( name );\r
- this.refX = unpressedRegion.width / 2.0f;\r
- this.refY = unpressedRegion.height / 2.0f;\r
+ this.originX = unpressedRegion.width / 2.0f;\r
+ this.originY = unpressedRegion.height / 2.0f;\r
this.width = unpressedRegion.width;\r
this.height = unpressedRegion.height;\r
this.unpressedRegion = new TextureRegion( unpressedRegion.texture, unpressedRegion.x, unpressedRegion.y, unpressedRegion.width, unpressedRegion.height );\r
if( scaleX == 0 && scaleY == 0 && rotation == 0 )\r
batch.draw( region.texture, x, y, width, height, region.x, region.y, region.width, region.height, color, false, false );\r
else\r
- batch.draw( region.texture, x, y, refX, refY, width, height, scaleX, scaleY, rotation, region.x, region.y, region.width, region.height, color, false, false );\r
+ batch.draw( region.texture, x, y, originX, originY, width, height, scaleX, scaleY, rotation, region.x, region.y, region.width, region.height, color, false, false );\r
}\r
}\r
\r
public Image( String name, Texture texture )\r
{\r
super( name );\r
- this.refX = texture.getWidth() / 2.0f;\r
- this.refY = texture.getHeight() / 2.0f;\r
+ this.originX = texture.getWidth() / 2.0f;\r
+ this.originY = texture.getHeight() / 2.0f;\r
this.width = texture.getWidth();\r
this.height = texture.getHeight();\r
this.region = new TextureRegion( texture, 0, 0, texture.getWidth(), texture.getHeight() );\r
public Image( String name, TextureRegion region )\r
{\r
super( name );\r
- this.refX = region.width / 2.0f;\r
- this.refY = region.height / 2.0f;\r
+ this.originX = region.width / 2.0f;\r
+ this.originY = region.height / 2.0f;\r
this.width = region.width;\r
this.height = region.height;\r
this.region = new TextureRegion( region.texture, region.x, region.y, region.width, region.height );\r
if( scaleX == 0 && scaleY == 0 && rotation == 0 )\r
batch.draw( region.texture, x, y, width, height, region.x, region.y, region.width, region.height, color, false, false );\r
else\r
- batch.draw( region.texture, x, y, refX, refY, width, height, scaleX, scaleY, rotation, region.x, region.y, region.width, region.height, color, false, false );\r
+ batch.draw( region.texture, x, y, originX, originY, width, height, scaleX, scaleY, rotation, region.x, region.y, region.width, region.height, color, false, false );\r
}\r
}\r
\r
super(name);\r
this.font = font;\r
this.text = text;\r
+ this.width = font.getStringWidth( text );\r
+ this.height = font.getLineHeight();\r
}\r
\r
@Override\r
--- /dev/null
+package com.badlogic.gdx.scenes.scene2d.actors;\r
+\r
+import com.badlogic.gdx.GdxRuntimeException;\r
+import com.badlogic.gdx.scenes.scene2d.Actor;\r
+import com.badlogic.gdx.scenes.scene2d.Group;\r
+\r
+public class LinearGroup extends BoundGroup\r
+{\r
+ public static enum LinearGroupLayout\r
+ {\r
+ Vertical,\r
+ Horizontal\r
+ }\r
+ \r
+ private final LinearGroupLayout layout;\r
+ \r
+ public LinearGroup(String name, int width, int height, LinearGroupLayout layout ) \r
+ {\r
+ super(name, width, height); \r
+ this.layout = layout;\r
+ }\r
+ \r
+ public void addActor( Actor actor )\r
+ {\r
+ if( actor instanceof Group && !(actor instanceof BoundGroup) )\r
+ throw new GdxRuntimeException( "Can only add Actors and BoundGroup subclasses" );\r
+ \r
+ super.addActor( actor );\r
+ layout( );\r
+ }\r
+ \r
+ public void removeActor( Actor actor )\r
+ {\r
+ super.removeActor( actor );\r
+ layout();\r
+ }\r
+ \r
+ protected void layout( )\r
+ {\r
+ int len = getActors().size();\r
+ float x = 0;\r
+ float y = 0;\r
+ for( int i = 0; i < len; i++ )\r
+ {\r
+ Actor actor = getActors().get(i);\r
+ actor.x = x; actor.y = y;\r
+ if( layout == LinearGroupLayout.Horizontal )\r
+ x += actor.width;\r
+ else\r
+ y += actor.height;\r
+ }\r
+ }\r
+}\r