import com.badlogic.gdx.math.Rectangle;\r
import com.badlogic.gdx.math.Vector2;\r
import com.badlogic.gdx.scenes.scene2d.InputEvent.Type;\r
-import com.badlogic.gdx.scenes.scene2d.actions.Actions;\r
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener;\r
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;\r
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack;\r
import com.badlogic.gdx.utils.Array;\r
import com.badlogic.gdx.utils.DelayedRemovalArray;\r
-import com.badlogic.gdx.utils.GdxRuntimeException;\r
import com.badlogic.gdx.utils.Pools;\r
\r
/** 2D scene graph node. An actor has a position, rectangular size, origin, scale, rotation, Z index, and color. The position\r
}\r
\r
public void setWidth (float width) {\r
+ float oldWidth = this.width;\r
this.width = width;\r
+ if (width != oldWidth) sizeChanged();\r
}\r
\r
public float getHeight () {\r
}\r
\r
public void setHeight (float height) {\r
+ float oldHeight = this.height;\r
this.height = height;\r
+ if (height != oldHeight) sizeChanged();\r
}\r
\r
/** Returns y plus height. */\r
return x + width;\r
}\r
\r
+ /** Called when the actor's size has been changed. */\r
+ protected void sizeChanged () {\r
+ }\r
+\r
/** Sets the width and height. */\r
public void setSize (float width, float height) {\r
+ float oldWidth = this.width;\r
+ float oldHeight = this.height;\r
this.width = width;\r
this.height = height;\r
+ if (width != oldWidth || height != oldHeight) sizeChanged();\r
}\r
\r
/** Adds the specified size to the current size. */\r
public void size (float size) {\r
width += size;\r
height += size;\r
+ sizeChanged();\r
}\r
\r
/** Adds the specified size to the current size. */\r
public void size (float width, float height) {\r
this.width += width;\r
this.height += height;\r
+ sizeChanged();\r
}\r
\r
/** Set bounds the x, y, width, and height. */\r
public void setBounds (float x, float y, float width, float height) {\r
+ float oldWidth = this.width;\r
+ float oldHeight = this.height;\r
this.x = x;\r
this.y = y;\r
this.width = width;\r
this.height = height;\r
+ if (width != oldWidth || height != oldHeight) sizeChanged();\r
}\r
\r
public float getOriginX () {\r
}\r
}\r
\r
- if (widget.getWidth() != widgetWidth || widget.getHeight() != widgetHeight) {\r
- widget.setWidth(widgetWidth);\r
- widget.setHeight(widgetHeight);\r
- if (widget instanceof Layout) {\r
- Layout layout = (Layout)widget;\r
- layout.invalidate();\r
- layout.validate();\r
- }\r
- } else {\r
- if (widget instanceof Layout) ((Layout)widget).validate();\r
- }\r
+ widget.setSize(widgetWidth, widgetHeight);\r
+ if (widget instanceof Layout) ((Layout)widget).validate();\r
}\r
\r
@Override\r
calculateVertBoundsAndPositions();\r
\r
Actor firstWidget = this.firstWidget;\r
- Rectangle firstWidgetBounds = this.firstWidgetBounds;\r
if (firstWidget != null) {\r
- firstWidget.setX(firstWidgetBounds.x);\r
- firstWidget.setY(firstWidgetBounds.y);\r
- if (firstWidget.getWidth() != firstWidgetBounds.width || firstWidget.getHeight() != firstWidgetBounds.height) {\r
- firstWidget.setWidth(firstWidgetBounds.width);\r
- firstWidget.setHeight(firstWidgetBounds.height);\r
- if (firstWidget instanceof Layout) {\r
- Layout layout = (Layout)firstWidget;\r
- layout.invalidate();\r
- layout.validate();\r
- }\r
- } else {\r
- if (firstWidget instanceof Layout) ((Layout)firstWidget).validate();\r
- }\r
+ Rectangle firstWidgetBounds = this.firstWidgetBounds;\r
+ firstWidget.setBounds(firstWidgetBounds.x, firstWidgetBounds.y, firstWidgetBounds.width, firstWidgetBounds.height);\r
+ if (firstWidget instanceof Layout) ((Layout)firstWidget).validate();\r
}\r
Actor secondWidget = this.secondWidget;\r
- Rectangle secondWidgetBounds = this.secondWidgetBounds;\r
if (secondWidget != null) {\r
- secondWidget.setX(secondWidgetBounds.x);\r
- secondWidget.setY(secondWidgetBounds.y);\r
- if (secondWidget.getWidth() != secondWidgetBounds.width || secondWidget.getHeight() != secondWidgetBounds.height) {\r
- secondWidget.setWidth(secondWidgetBounds.width);\r
- secondWidget.setHeight(secondWidgetBounds.height);\r
- if (secondWidget instanceof Layout) {\r
- Layout layout = (Layout)secondWidget;\r
- layout.invalidate();\r
- layout.validate();\r
- }\r
- } else {\r
- if (secondWidget instanceof Layout) ((Layout)secondWidget).validate();\r
- }\r
+ Rectangle secondWidgetBounds = this.secondWidgetBounds;\r
+ secondWidget.setBounds(secondWidgetBounds.x, secondWidgetBounds.y, secondWidgetBounds.width, secondWidgetBounds.height);\r
+ if (secondWidget instanceof Layout) ((Layout)secondWidget).validate();\r
}\r
}\r
\r
Array<Actor> children = getChildren();\r
for (int i = 0, n = children.size; i < n; i++) {\r
Actor child = children.get(i);\r
- child.setX(0);\r
- child.setY(0);\r
- if (child.getWidth() != width || child.getHeight() != height) {\r
- child.setWidth(width);\r
- child.setHeight(height);\r
- if (child instanceof Layout) {\r
- Layout layout = (Layout)child;\r
- layout.invalidate();\r
- layout.validate();\r
- }\r
- } else {\r
- if (child instanceof Layout) ((Layout)child).validate();\r
- }\r
+ child.setBounds(0, 0, width, height);\r
+ if (child instanceof Layout) ((Layout)child).validate();\r
}\r
}\r
\r
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer;\r
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10;\r
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20;\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.ui.TableToolkit.DebugRect;\r
float widgetHeight = Math.round(c.getWidgetHeight());\r
float widgetX = Math.round(c.getWidgetX());\r
float widgetY = height - Math.round(c.getWidgetY()) - widgetHeight;\r
- c.setWidgetX(widgetX);\r
- c.setWidgetY(widgetY);\r
- c.setWidgetWidth(widgetWidth);\r
- c.setWidgetHeight(widgetHeight);\r
+ c.setWidgetBounds(widgetX, widgetY, widgetWidth, widgetHeight);\r
Actor actor = (Actor)c.getWidget();\r
- if (actor != null) {\r
- actor.setX(widgetX);\r
- actor.setY(widgetY);\r
- if (actor.getWidth() != widgetWidth || actor.getHeight() != widgetHeight) {\r
- actor.setWidth(widgetWidth);\r
- actor.setHeight(widgetHeight);\r
- if (actor instanceof Layout) ((Layout)actor).invalidate();\r
- }\r
- }\r
+ if (actor != null) actor.setBounds(widgetX, widgetY, widgetWidth, widgetHeight);\r
}\r
} else {\r
for (int i = 0, n = cells.size(); i < n; i++) {\r
Cell c = cells.get(i);\r
if (c.getIgnore()) continue;\r
- float widgetWidth = c.getWidgetWidth();\r
float widgetHeight = c.getWidgetHeight();\r
- float widgetX = c.getWidgetX();\r
float widgetY = height - c.getWidgetY() - widgetHeight;\r
- c.setWidgetX(widgetX);\r
c.setWidgetY(widgetY);\r
- c.setWidgetWidth(widgetWidth);\r
- c.setWidgetHeight(widgetHeight);\r
Actor actor = (Actor)c.getWidget();\r
- if (actor != null) {\r
- actor.setX(widgetX);\r
- actor.setY(widgetY);\r
- if (actor.getWidth() != widgetWidth || actor.getHeight() != widgetHeight) {\r
- actor.setWidth(widgetWidth);\r
- actor.setHeight(widgetHeight);\r
- if (actor instanceof Layout) ((Layout)actor).invalidate();\r
- }\r
- }\r
+ if (actor != null) actor.setBounds(c.getWidgetX(), widgetY, c.getWidgetWidth(), widgetHeight);\r
}\r
}\r
// Validate children separately from sizing actors to ensure actors without a cell are validated.\r
parentWidth = parent.getWidth();\r
parentHeight = parent.getHeight();\r
}\r
- if (getWidth() != parentWidth || getHeight() != parentHeight) {\r
- setWidth(parentWidth);\r
- setHeight(parentHeight);\r
- invalidate();\r
- }\r
+ setSize(parentWidth, parentHeight);\r
}\r
\r
if (!needsLayout) return;\r
if (parent instanceof Layout) ((Layout)parent).invalidateHierarchy();\r
}\r
\r
+ protected void sizeChanged () {\r
+ invalidate();\r
+ }\r
+\r
public void pack () {\r
- float newWidth = getPrefWidth();\r
- float newHeight = getPrefHeight();\r
- if (newWidth != getWidth() || newHeight != getHeight()) {\r
- setWidth(newWidth);\r
- setHeight(newHeight);\r
- invalidate();\r
- }\r
+ setSize(getPrefWidth(), getPrefHeight());\r
validate();\r
}\r
\r
invalidateHierarchy();\r
}\r
\r
+ protected void sizeChanged () {\r
+ invalidate();\r
+ }\r
+\r
public void pack () {\r
float newWidth = getPrefWidth();\r
float newHeight = getPrefHeight();\r
return this;\r
}\r
\r
+ public void setWidgetBounds (float x, float y, float width, float height) {\r
+ widgetX = x;\r
+ widgetY = y;\r
+ widgetWidth = width;\r
+ widgetHeight = height;\r
+ }\r
+\r
public float getWidgetX () {\r
return widgetX;\r
}\r