Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
update
  • Loading branch information
cping committed Nov 17, 2024
1 parent 71548de commit dc7b36d
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,34 @@ public T getParentBefore(final QueryEvent<T> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -732,5 +732,4 @@ public String toString() {
return builder.toString();
}


}
99 changes: 99 additions & 0 deletions Java/Loon-Lite(PureJava)/LoonLiteCore/src/loon/geom/Affine2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
}

/**
* 让矩阵后置一组新矩阵数据
*
Expand Down Expand Up @@ -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;
}

/**
* 以线性插值方式构建一个新的矩阵
*
Expand Down
28 changes: 28 additions & 0 deletions Java/Loon-Neo/src/loon/action/sprite/SpriteBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,34 @@ public T getParentBefore(final QueryEvent<T> 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;
Expand Down
2 changes: 1 addition & 1 deletion Java/Loon-Neo/src/loon/component/LComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ public LComponent moveInScreen() {
}
return this;
}

@Override
public LComponent setFlipX(boolean x) {
this._flipX = x;
Expand Down
15 changes: 15 additions & 0 deletions Java/Loon-Neo/src/loon/component/LContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Java/Loon-Neo/src/loon/font/BMFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Loading

0 comments on commit dc7b36d

Please sign in to comment.