/** * Configures the origin of this layer based on a logical location which is recomputed whenever * the layer changes size. * * @return a reference to this layer for call chaining. */ public Layer setOrigin (Origin origin) { this.origin = origin; setFlag(Flag.ODIRTY, true); return this; }
/** * Configures this layer's visibility: if true, it will be rendered as normal, if false it and * its children will not be rendered. * * @return a reference to this layer for call chaining. */ public Layer setVisible(boolean visible) { setFlag(Flag.VISIBLE, visible); return this; }
/** Creates an unclipped layer. The {@link #paint} method must be overridden by the creator. */ public Layer() { setFlag(Flag.VISIBLE, true); }
protected void checkOrigin () { if (origin != Origin.FIXED) setFlag(Flag.ODIRTY, true); // trigger an origin recompute }
/** * Sets the origin of the layer to a fixed position. This automatically sets the layer's logical * origin to {@link Origin#FIXED}. * * @param x origin on x axis in display units. * @param y origin on y axis in display units. * * @return a reference to this layer for call chaining. */ public Layer setOrigin (float x, float y) { this.originX = x; this.originY = y; this.origin = Origin.FIXED; setFlag(Flag.ODIRTY, false); return this; }
/** * Sets the current x scale of this layer. Note that a scale of {@code 1} is equivalent to no * scale. * * <p><em>Note:</em> all transform changes are deferred until {@link #transform} is called * (which happens during rendering, if not before) at which point the current scale, rotation and * translation are composed into an affine transform matrix. This means that, for example, * setting rotation and then setting scale will not flip the rotation like it would were these * applied to the transform matrix one operation at a time. </p> * * @param sx non-zero scale value. * @return a reference to this layer for call chaining. */ public Layer setScaleX(float sx) { if (scaleX != sx) { scaleX = sx; setFlag(Flag.XFDIRTY, true); } return this; }
/** * Sets the current rotation of this layer, in radians. The rotation is done around the currently * set origin, See {@link Layer#setOrigin}. * * <p><em>Note:</em> all transform changes are deferred until {@link #transform} is called * (which happens during rendering, if not before) at which point the current scale, rotation and * translation are composed into an affine transform matrix. This means that, for example, * setting rotation and then setting scale will not flip the rotation like it would were these * applied to the transform matrix one operation at a time. </p> * * @param angle angle to rotate, in radians. * * @return a reference to this layer for call chaining. */ public Layer setRotation(float angle) { if (rotation != angle) { rotation = angle; setFlag(Flag.XFDIRTY, true); } return this; }
/** * Sets the current y scale of this layer. Note that a scale of {@code 1} is equivalent to no * scale. * * <p><em>Note:</em> all transform changes are deferred until {@link #transform} is called * (which happens during rendering, if not before) at which point the current scale, rotation and * translation are composed into an affine transform matrix. This means that, for example, * setting rotation and then setting scale will not flip the rotation like it would were these * applied to the transform matrix one operation at a time. </p> * * @param sy non-zero scale value. * @return a reference to this layer for call chaining. */ public Layer setScaleY(float sy) { if (scaleY != sy) { scaleY = sy; setFlag(Flag.XFDIRTY, true); } return this; }
/** * Sets the current x and y scale of this layer. Note that a scale of {@code 1} is equivalent to * no scale. * * <p><em>Note:</em> all transform changes are deferred until {@link #transform} is called * (which happens during rendering, if not before) at which point the current scale, rotation and * translation are composed into an affine transform matrix. This means that, for example, * setting rotation and then setting scale will not flip the rotation like it would were these * applied to the transform matrix one operation at a time. </p> * * @param sx non-zero scale value for the x axis. * @param sy non-zero scale value for the y axis. * * @return a reference to this layer for call chaining. */ public Layer setScale(float sx, float sy) { if (sx != scaleX || sy != scaleY) { scaleX = sx; scaleY = sy; setFlag(Flag.XFDIRTY, true); } return this; }
/** * Configures this layer as reactive to clicks and touches, or not. You usually don't have to do * this automatically because a layer is automatically marked as interactive (along with all of * its parents) when a listener is added to its {@link #events} signal. * * <p>A {@link GroupLayer} will be made non-interactive automatically if an event is dispatched * to it and it discovers that it no longer has any interactive children. Manual management of * interactivity is thus generally only useful for "leaf" nodes in the scene graph. * * @return a reference to this layer for call chaining. */ public Layer setInteractive(boolean interactive) { if (interactive() != interactive) { // if we're being made interactive, active our parent as well, if we have one if (interactive && parent != null) parent.setInteractive(interactive); setFlag(Flag.INTERACTIVE, interactive); } return this; }
/** Returns the x-component of the layer's origin. */ public float originX () { if (isSet(Flag.ODIRTY)) { float width = width(); if (width > 0) { this.originX = origin.ox(width); this.originY = origin.oy(height()); setFlag(Flag.ODIRTY, false); } } return originX; } /** Returns the y-component of the layer's origin. */
/** Returns the y-component of the layer's origin. */ public float originY () { if (isSet(Flag.ODIRTY)) { float height = height(); if (height > 0) { this.originX = origin.ox(width()); this.originY = origin.oy(height); setFlag(Flag.ODIRTY, false); } } return originY; } /** Writes this layer's origin into {@code into}.
/** * Returns the layer's current transformation matrix. If any changes have been made to the * layer's scale, rotation or translation, they will be applied to the transform matrix before it * is returned. * * <p><em>Note:</em> any direct modifications to this matrix <em>except</em> modifications to its * translation, will be overwritten if a call is subsequently made to {@link #setScale(float)}, * {@link #setScale(float,float)}, {@link #setScaleX}, {@link #setScaleY} or {@link #setRotation}. * If you intend to manipulate a layer's transform matrix directly, <em>do not</em> call those * other methods. Also do not expect {@link #scaleX}, {@link #scaleY}, or {@link #rotation} to * reflect the direct changes you've made to the transform matrix. They will not. </p> */ public AffineTransform transform() { if (isSet(Flag.XFDIRTY)) { float sina = FloatMath.sin(rotation), cosa = FloatMath.cos(rotation); float m00 = cosa * scaleX, m01 = sina * scaleX; float m10 = -sina * scaleY, m11 = cosa * scaleY; float tx = transform.tx(), ty = transform.ty(); transform.setTransform(m00, m01, m10, m11, tx, ty); setFlag(Flag.XFDIRTY, false); } return transform; }