diff --git a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/action/sprite/SpriteBase.java b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/action/sprite/SpriteBase.java index 70c6a7ee..b7a843cb 100644 --- a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/action/sprite/SpriteBase.java +++ b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/action/sprite/SpriteBase.java @@ -1250,6 +1250,34 @@ public T getParentBefore(final QueryEvent test) { return prev; } + public float measureWidth() { + if (_childrens == null) { + return 0f; + } + float max = 0; + for (int i = this._childrens.size - 1; i > -1; i--) { + T spr = _childrens.get(i); + if (spr.isVisible()) { + max = MathUtils.max(spr.getScaleX() + spr.getWidth(), max); + } + } + return max; + } + + public float measureHeight() { + if (_childrens == null) { + return 0f; + } + float max = 0; + for (int i = this._childrens.size - 1; i > -1; i--) { + T spr = _childrens.get(i); + if (spr.isVisible()) { + max = MathUtils.max(spr.getScaleY() + spr.getHeight(), max); + } + } + return max; + } + @Override public boolean isVisible() { return this._visible; diff --git a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/component/LContainer.java b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/component/LContainer.java index 610d3f69..a1913ccf 100644 --- a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/component/LContainer.java +++ b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/component/LContainer.java @@ -1475,6 +1475,13 @@ public LContainer setChildIndex(int index, LComponent comp) { return this; } + public LComponent getChildByIndex(int idx) { + if (this._childs == null || (idx < 0 || idx > this._childCount - 1)) { + return null; + } + return this._childs[idx]; + } + public int getChildIndex(LComponent comp) { if (comp == null) { return -1; @@ -1721,6 +1728,14 @@ public void setChildExpandCount(int e) { this._childExpandCount = e; } + public float measureWidth() { + return getContextWidth(); + } + + public float measureHeight() { + return getContextHeight(); + } + public Margin margin(boolean vertical, float left, float top, float right, float bottom) { float size = vertical ? getHeight() : getWidth(); if (_component_isClose) { diff --git a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/font/BMFont.java b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/font/BMFont.java index be1e032c..7ac12fbe 100644 --- a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/font/BMFont.java +++ b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/font/BMFont.java @@ -195,7 +195,7 @@ private void parse(String text) throws LSysException { char ch = info.charAt(i); if (ch == newSpaceFlag && sbr.length() > 0) { String result = sbr.toString().toLowerCase().trim(); - String[] list = StringUtils.split(result, '='); + String[] list = StringUtils.split(result, LSystem.EQUAL); if (list.length == 2) { if (list[0].equals("size")) { _size = (int) Float.parseFloat(list[1]); @@ -732,5 +732,4 @@ public String toString() { return builder.toString(); } - } diff --git a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/geom/Affine2f.java b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/geom/Affine2f.java index f3e5954d..26b457b3 100644 --- a/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/geom/Affine2f.java +++ b/Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/geom/Affine2f.java @@ -96,6 +96,51 @@ public final static Affine2f ofRect(BoxSize r) { return xform; } + public final static RectBox transformRect(RectBox rect, Affine2f aff) { + if (rect == null) { + return rect; + } + float x = rect.x, y = rect.y, width = rect.width, height = rect.height; + if (x != 0f || y != 0f) { + aff.appendTransform(0, 0, 1, 1, 0, 0, 0, -x, -y); + } + float x_a = width * aff.m00, x_b = width * aff.m01; + float y_c = height * aff.m10, y_d = height * aff.m11; + float tx = aff.tx, ty = aff.ty; + float minX = tx, maxX = tx, minY = ty, maxY = ty; + if ((x = x_a + tx) < minX) { + minX = x; + } else if (x > maxX) { + maxX = x; + } + if ((x = x_a + y_c + tx) < minX) { + minX = x; + } else if (x > maxX) { + maxX = x; + } + if ((x = y_c + tx) < minX) { + minX = x; + } else if (x > maxX) { + maxX = x; + } + if ((y = x_b + ty) < minY) { + minY = y; + } else if (y > maxY) { + maxY = y; + } + if ((y = x_b + y_d + ty) < minY) { + minY = y; + } else if (y > maxY) { + maxY = y; + } + if ((y = y_d + ty) < minY) { + minY = y; + } else if (y > maxY) { + maxY = y; + } + return rect.set(minX, minY, maxX - minX, maxY - minY); + } + public final static Affine2f transform(Affine2f tx, float x, float y, int transform) { switch (transform) { case TRANS_ROT90: { @@ -1328,6 +1373,33 @@ public Affine2f prepend(Affine2f other) { return prepend(other.m00, other.m10, other.m01, other.m11, other.tx, other.ty); } + public Affine2f prependTransform(float x, float y, float scaleX, float scaleY, float rotation, float skewX, + float skewY, float regX, float regY) { + float cos; + float sin; + if (rotation % 360 != 0f) { + float r = rotation * MathUtils.DEG_TO_RAD; + cos = MathUtils.cos(r); + sin = MathUtils.sin(r); + } else { + cos = 1f; + sin = 0f; + } + if (skewX != 0f || skewY != 0f) { + skewX *= MathUtils.DEG_TO_RAD; + skewY *= MathUtils.DEG_TO_RAD; + this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0); + this.prepend(MathUtils.cos(skewY), MathUtils.sin(skewY), -MathUtils.sin(skewX), MathUtils.cos(skewX), x, y); + } else { + this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y); + } + if (regX != 0f || regY != 0f) { + this.tx -= regX * this.m00 + regY * this.m10; + this.ty -= regX * this.m01 + regY * this.m11; + } + return this; + } + /** * 让矩阵后置一组新矩阵数据 * @@ -1365,6 +1437,33 @@ public Affine2f append(Affine2f other) { return append(other.m00, other.m10, other.m01, other.m11, other.tx, other.ty); } + public Affine2f appendTransform(float x, float y, float scaleX, float scaleY, float rotation, float skewX, + float skewY, float regX, float regY) { + float cos; + float sin; + if (rotation % 360 != 0f) { + float r = rotation * MathUtils.DEG_TO_RAD; + cos = MathUtils.cos(r); + sin = MathUtils.sin(r); + } else { + cos = 1f; + sin = 0f; + } + if (skewX != 0f || skewY != 0f) { + skewX *= MathUtils.DEG_TO_RAD; + skewY *= MathUtils.DEG_TO_RAD; + this.append(MathUtils.cos(skewY), MathUtils.sin(skewY), -MathUtils.sin(skewX), MathUtils.cos(skewX), x, y); + this.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0); + } else { + this.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y); + } + if (regX != 0f || regY != 0f) { + this.tx -= regX * this.m00 + regY * this.m10; + this.ty -= regX * this.m01 + regY * this.m11; + } + return this; + } + /** * 以线性插值方式构建一个新的矩阵 * diff --git a/Java/Loon-Neo/src/loon/action/sprite/SpriteBase.java b/Java/Loon-Neo/src/loon/action/sprite/SpriteBase.java index 70c6a7ee..b7a843cb 100644 --- a/Java/Loon-Neo/src/loon/action/sprite/SpriteBase.java +++ b/Java/Loon-Neo/src/loon/action/sprite/SpriteBase.java @@ -1250,6 +1250,34 @@ public T getParentBefore(final QueryEvent test) { return prev; } + public float measureWidth() { + if (_childrens == null) { + return 0f; + } + float max = 0; + for (int i = this._childrens.size - 1; i > -1; i--) { + T spr = _childrens.get(i); + if (spr.isVisible()) { + max = MathUtils.max(spr.getScaleX() + spr.getWidth(), max); + } + } + return max; + } + + public float measureHeight() { + if (_childrens == null) { + return 0f; + } + float max = 0; + for (int i = this._childrens.size - 1; i > -1; i--) { + T spr = _childrens.get(i); + if (spr.isVisible()) { + max = MathUtils.max(spr.getScaleY() + spr.getHeight(), max); + } + } + return max; + } + @Override public boolean isVisible() { return this._visible; diff --git a/Java/Loon-Neo/src/loon/component/LComponent.java b/Java/Loon-Neo/src/loon/component/LComponent.java index 3c30b07d..73fee7af 100644 --- a/Java/Loon-Neo/src/loon/component/LComponent.java +++ b/Java/Loon-Neo/src/loon/component/LComponent.java @@ -1917,7 +1917,7 @@ public LComponent moveInScreen() { } return this; } - + @Override public LComponent setFlipX(boolean x) { this._flipX = x; diff --git a/Java/Loon-Neo/src/loon/component/LContainer.java b/Java/Loon-Neo/src/loon/component/LContainer.java index 610d3f69..a1913ccf 100644 --- a/Java/Loon-Neo/src/loon/component/LContainer.java +++ b/Java/Loon-Neo/src/loon/component/LContainer.java @@ -1475,6 +1475,13 @@ public LContainer setChildIndex(int index, LComponent comp) { return this; } + public LComponent getChildByIndex(int idx) { + if (this._childs == null || (idx < 0 || idx > this._childCount - 1)) { + return null; + } + return this._childs[idx]; + } + public int getChildIndex(LComponent comp) { if (comp == null) { return -1; @@ -1721,6 +1728,14 @@ public void setChildExpandCount(int e) { this._childExpandCount = e; } + public float measureWidth() { + return getContextWidth(); + } + + public float measureHeight() { + return getContextHeight(); + } + public Margin margin(boolean vertical, float left, float top, float right, float bottom) { float size = vertical ? getHeight() : getWidth(); if (_component_isClose) { diff --git a/Java/Loon-Neo/src/loon/font/BMFont.java b/Java/Loon-Neo/src/loon/font/BMFont.java index 02206fc9..9af7d1fd 100644 --- a/Java/Loon-Neo/src/loon/font/BMFont.java +++ b/Java/Loon-Neo/src/loon/font/BMFont.java @@ -205,7 +205,7 @@ private void parse(String text) throws LSysException { char ch = info.charAt(i); if (ch == newSpaceFlag && sbr.length() > 0) { String result = sbr.toString().toLowerCase().trim(); - String[] list = StringUtils.split(result, '='); + String[] list = StringUtils.split(result, LSystem.EQUAL); if (list.length == 2) { if (list[0].equals("size")) { _size = (int) Float.parseFloat(list[1]); diff --git a/Java/Loon-Neo/src/loon/geom/Affine2f.java b/Java/Loon-Neo/src/loon/geom/Affine2f.java index 2dc31fd2..40617619 100644 --- a/Java/Loon-Neo/src/loon/geom/Affine2f.java +++ b/Java/Loon-Neo/src/loon/geom/Affine2f.java @@ -96,6 +96,51 @@ public final static Affine2f ofRect(BoxSize r) { return xform; } + public final static RectBox transformRect(RectBox rect, Affine2f aff) { + if (rect == null) { + return rect; + } + float x = rect.x, y = rect.y, width = rect.width, height = rect.height; + if (x != 0f || y != 0f) { + aff.appendTransform(0, 0, 1, 1, 0, 0, 0, -x, -y); + } + float x_a = width * aff.m00, x_b = width * aff.m01; + float y_c = height * aff.m10, y_d = height * aff.m11; + float tx = aff.tx, ty = aff.ty; + float minX = tx, maxX = tx, minY = ty, maxY = ty; + if ((x = x_a + tx) < minX) { + minX = x; + } else if (x > maxX) { + maxX = x; + } + if ((x = x_a + y_c + tx) < minX) { + minX = x; + } else if (x > maxX) { + maxX = x; + } + if ((x = y_c + tx) < minX) { + minX = x; + } else if (x > maxX) { + maxX = x; + } + if ((y = x_b + ty) < minY) { + minY = y; + } else if (y > maxY) { + maxY = y; + } + if ((y = x_b + y_d + ty) < minY) { + minY = y; + } else if (y > maxY) { + maxY = y; + } + if ((y = y_d + ty) < minY) { + minY = y; + } else if (y > maxY) { + maxY = y; + } + return rect.set(minX, minY, maxX - minX, maxY - minY); + } + public final static Affine2f transform(Affine2f tx, float x, float y, int transform) { switch (transform) { case TRANS_ROT90: { @@ -1400,6 +1445,33 @@ public Affine2f prepend(Affine2f other) { return prepend(other.m00, other.m10, other.m01, other.m11, other.tx, other.ty); } + public Affine2f prependTransform(float x, float y, float scaleX, float scaleY, float rotation, float skewX, + float skewY, float regX, float regY) { + float cos; + float sin; + if (rotation % 360 != 0f) { + float r = rotation * MathUtils.DEG_TO_RAD; + cos = MathUtils.cos(r); + sin = MathUtils.sin(r); + } else { + cos = 1f; + sin = 0f; + } + if (skewX != 0f || skewY != 0f) { + skewX *= MathUtils.DEG_TO_RAD; + skewY *= MathUtils.DEG_TO_RAD; + this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0); + this.prepend(MathUtils.cos(skewY), MathUtils.sin(skewY), -MathUtils.sin(skewX), MathUtils.cos(skewX), x, y); + } else { + this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y); + } + if (regX != 0f || regY != 0f) { + this.tx -= regX * this.m00 + regY * this.m10; + this.ty -= regX * this.m01 + regY * this.m11; + } + return this; + } + /** * 让矩阵后置一组新矩阵数据 * @@ -1437,6 +1509,33 @@ public Affine2f append(Affine2f other) { return append(other.m00, other.m10, other.m01, other.m11, other.tx, other.ty); } + public Affine2f appendTransform(float x, float y, float scaleX, float scaleY, float rotation, float skewX, + float skewY, float regX, float regY) { + float cos; + float sin; + if (rotation % 360 != 0f) { + float r = rotation * MathUtils.DEG_TO_RAD; + cos = MathUtils.cos(r); + sin = MathUtils.sin(r); + } else { + cos = 1f; + sin = 0f; + } + if (skewX != 0f || skewY != 0f) { + skewX *= MathUtils.DEG_TO_RAD; + skewY *= MathUtils.DEG_TO_RAD; + this.append(MathUtils.cos(skewY), MathUtils.sin(skewY), -MathUtils.sin(skewX), MathUtils.cos(skewX), x, y); + this.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, 0, 0); + } else { + this.append(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y); + } + if (regX != 0f || regY != 0f) { + this.tx -= regX * this.m00 + regY * this.m10; + this.ty -= regX * this.m01 + regY * this.m11; + } + return this; + } + /** * 以线性插值方式构建一个新的矩阵 *