OC: fix slow of LCanvas

This commit is contained in:
way-zer
2024-08-06 01:30:38 +08:00
committed by code-explorer786
parent a5de131711
commit 116798e328

View File

@@ -120,10 +120,12 @@ public class LCanvas extends Table{
t.add(statements).pad(2f).center().width(targetWidth);
t.addChild(statements.jumps);
jumps.touchable = Touchable.disabled;
jumps.update(()->jumps.setCullingArea(t.getCullingArea()));
statements.jumps.cullable = false;
}).grow().get();
pane.setFlickScroll(false);
pane.setScrollYForce(s);
pane.setScrollY(s);
if(toLoad != null){
load(toLoad);
@@ -161,13 +163,11 @@ public class LCanvas extends Table{
}
this.statements.updateJumpHeights = true;
this.statements.layout();
}
public void clearStatements(){
statements.jumps.clear();
statements.clearChildren();
statements.layout();
}
StatementElem checkHovered(){
@@ -254,10 +254,12 @@ public class LCanvas extends Table{
float cy = 0;
seq.clear();
float totalHeight = getChildren().sumf(e -> e.getHeight() + space);
height = prefHeight = totalHeight;
width = prefWidth = Scl.scl(targetWidth);
float totalHeight = getChildren().sumf(e -> e.getPrefHeight() + space);
if(height != totalHeight || width != Scl.scl(targetWidth)){
height = prefHeight = totalHeight;
width = prefWidth = Scl.scl(targetWidth);
invalidateHierarchy();
}
//layout everything normally
for(int i = 0; i < getChildren().size; i++){
@@ -267,7 +269,7 @@ public class LCanvas extends Table{
if(dragging == e) continue;
e.setSize(width, e.getPrefHeight());
e.setPosition(0, height - cy, Align.topLeft);
e.setPosition(0, totalHeight - cy, Align.topLeft);
((StatementElem)e).updateAddress(i);
cy += e.getPrefHeight() + space;
@@ -312,8 +314,6 @@ public class LCanvas extends Table{
});
}
if(parent != null) parent.invalidateHierarchy();//don't invalid self
if(parent != null && parent instanceof Table){
setCullingArea(parent.getCullingArea());
}
@@ -472,10 +472,10 @@ public class LCanvas extends Table{
}
dragging = null;
invalidateHierarchy();
}
updateJumpHeights = true;
layout();
}
}
@@ -512,7 +512,6 @@ public class LCanvas extends Table{
remove();
dragging = null;
statements.updateJumpHeights = true;
statements.layout();
}).size(24f);
t.addListener(new InputListener(){
@@ -532,7 +531,7 @@ public class LCanvas extends Table{
dragging = StatementElem.this;
toFront();
statements.updateJumpHeights = true;
statements.layout();
statements.invalidate();
return true;
}
@@ -544,7 +543,7 @@ public class LCanvas extends Table{
lastx = v.x;
lasty = v.y;
statements.layout();
statements.invalidate();
}
@Override
@@ -586,7 +585,6 @@ public class LCanvas extends Table{
StatementElem s = new StatementElem(copy);
statements.addChildAfter(StatementElem.this, s);
statements.layout();
copy.elem = s;
copy.setupUI();
statements.updateJumpHeights = true;
@@ -684,6 +682,7 @@ public class LCanvas extends Table{
public static class JumpCurve extends Element{
public JumpButton button;
private boolean invertedHeight;
// for jump prediction; see DragLayout
public int predHeight = 0;
@@ -697,10 +696,37 @@ public class LCanvas extends Table{
this.button = button;
}
@Override
public void setSize(float width, float height){
if(height < 0){
y += height;
height = -height;
invertedHeight = true;
}
super.setSize(width, height);
}
@Override
public void act(float delta){
super.act(delta);
//MDTX(WayZer, 2024/8/6) Support Cull
invertedHeight = false;
Group desc = canvas.jumps.parent;
Vec2 t = Tmp.v1.set(button.getWidth() / 2f, button.getHeight() / 2f);
button.localToAscendantCoordinates(desc, t);
setPosition(t.x, t.y);
Element hover = button.to.get() == null && button.selecting ? canvas.hovered : button.to.get();
if(hover != null){
t.set(hover.getWidth(), hover.getHeight() / 2f);
hover.localToAscendantCoordinates(desc, t);
setSize(t.x - x, t.y - y);
}else if(button.selecting){
setSize(button.mx, button.my);
}else{
setSize(0, 0);
}
if(button.listener.isOver()){
toFront();
}
@@ -708,36 +734,19 @@ public class LCanvas extends Table{
@Override
public void draw(){
Element hover = button.to.get() == null && button.selecting ? canvas.hovered : button.to.get();
boolean draw = false;
Vec2 t = Tmp.v1, r = Tmp.v2;
if(height == 0) return;
Vec2 t = Tmp.v1.set(width, !invertedHeight ? height : 0), r = Tmp.v2.set(0, !invertedHeight ? 0 : height);
Group desc = canvas.pane;
localToAscendantCoordinates(desc, r);
localToAscendantCoordinates(desc, t);
button.localToAscendantCoordinates(desc, r.set(0, 0));
drawCurve(r.x, r.y, t.x, t.y);
if(hover != null){
hover.localToAscendantCoordinates(desc, t.set(hover.getWidth(), hover.getHeight()/2f));
draw = true;
}else if(button.selecting){
t.set(r).add(button.mx, button.my);
draw = true;
}
float offset = canvas.pane.getVisualScrollY() - canvas.pane.getMaxY();
t.y += offset;
r.y += offset;
if(draw){
drawCurve(r.x + button.getWidth()/2f, r.y + button.getHeight()/2f, t.x, t.y);
float s = button.getWidth();
Draw.color(button.color);
Tex.logicNode.draw(t.x + s*0.75f, t.y - s/2f, -s, s);
Draw.reset();
}
float s = button.getWidth();
Draw.color(button.color);
Tex.logicNode.draw(t.x + s * 0.75f, t.y - s / 2f, -s, s);
Draw.reset();
}
public void drawCurve(float x, float y, float x2, float y2){