Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 5a989ac

Browse files
committed
Merge branch 'master' of github.com:UnityTech/UIWidgets into dev
# Conflicts: # Runtime/ui/painting/picture.cs
2 parents 0e37838 + 345d6cc commit 5a989ac

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

Runtime/ui/painting/canvas.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ public void saveLayer(Rect rect, Paint paint) {
9999
}
100100

101101
public void restore() {
102-
this._saveCount--;
103-
this._recorder.addDrawCmd(new DrawRestore {
104-
});
102+
if (this._saveCount > 1) {
103+
this._saveCount--;
104+
this._recorder.addDrawCmd(new DrawRestore {
105+
});
106+
}
105107
}
106108

107109
public int getSaveCount() {

Runtime/ui/painting/picture.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,32 @@ public void reset() {
6868
this._stateUpdateIndices.Clear();
6969
}
7070

71+
void restoreToCount(int count) {
72+
count = this._states.Count - count;
73+
while (count > 0) {
74+
this.addDrawCmd(new DrawRestore());
75+
count--;
76+
}
77+
}
78+
79+
void restore() {
80+
var stateToRestore = this._getState();
81+
this._states.RemoveAt(this._states.Count - 1);
82+
var state = this._getState();
83+
84+
if (!stateToRestore.saveLayer) {
85+
state.paintBounds = stateToRestore.paintBounds;
86+
}
87+
else {
88+
var paintBounds = stateToRestore.paintBounds.shift(stateToRestore.layerOffset);
89+
paintBounds = state.xform.mapRect(paintBounds);
90+
this._addPaintBounds(paintBounds);
91+
}
92+
}
93+
7194
public Picture endRecording() {
95+
this.restoreToCount(1);
96+
7297
if (this._states.Count > 1) {
7398
throw new Exception("unmatched save/restore commands");
7499
}
@@ -103,20 +128,11 @@ public void addDrawCmd(DrawCmd drawCmd) {
103128
}
104129

105130
case DrawRestore _: {
106-
var stateToRestore = this._getState();
107-
this._states.RemoveAt(this._states.Count - 1);
108-
var state = this._getState();
109-
110-
if (!stateToRestore.saveLayer) {
111-
state.paintBounds = stateToRestore.paintBounds;
131+
//check for underflow
132+
if (this._states.Count > 1) {
133+
this.restore();
134+
this._stateUpdateIndices.Add(this._drawCmds.Count - 1);
112135
}
113-
else {
114-
var paintBounds = stateToRestore.paintBounds.shift(stateToRestore.layerOffset);
115-
paintBounds = state.xform.mapRect(paintBounds);
116-
this._addPaintBounds(paintBounds);
117-
}
118-
this._stateUpdateIndices.Add(this._drawCmds.Count - 1);
119-
120136
break;
121137
}
122138

0 commit comments

Comments
 (0)