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