浏览代码

add some tests.

/main
kg 6 年前
当前提交
8ba3378e
共有 3 个文件被更改,包括 232 次插入12 次删除
  1. 195
      Assets/UIWidgets/Tests/CanvasAndLayers.cs
  2. 33
      Assets/UIWidgets/ui/painting/editor_canvas.cs
  3. 16
      Assets/UIWidgets/ui/painting/picture.cs

195
Assets/UIWidgets/Tests/CanvasAndLayers.cs


this.drawRect,
this.drawRectShadow,
this.drawPicture,
this.clipRect,
this.clipRRect,
this.saveLayer,
};
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray();
this._selected = 0;

}
void drawPicture() {
var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint = new Paint {
color = new Color(0xFFFF0000),
};
canvas.drawPloygon4(
new[] {new Offset(10, 10), new Offset(10, 110), new Offset(90, 110), new Offset(110, 10)},
paint);
paint = new Paint {
color = new Color(0xFFFFFF00),
};
canvas.drawRect(
Rect.fromLTWH(10, 150, 100, 100),
BorderWidth.only(2, 4, 6, 8),
BorderRadius.only(0, 4, 8, 16),
paint);
canvas.concat(Matrix4x4.Translate(new Vector2(-150, -150)));
canvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -45)));
canvas.concat(Matrix4x4.Translate(new Vector2(150, 150)));
paint = new Paint {
color = new Color(0xFF00FFFF),
blurSigma = 3,
};
canvas.drawRectShadow(
Rect.fromLTWH(150, 150, 110, 120),
paint);
var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
editorCanvas.drawPicture(picture);
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -15)));
editorCanvas.concat(Matrix4x4.Translate(new Vector2(100, 100)));
editorCanvas.drawPicture(picture);
}
void clipRect() {
var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint = new Paint {
color = new Color(0xFFFF0000),
};
canvas.drawPloygon4(
new[] {new Offset(10, 10), new Offset(10, 110), new Offset(90, 110), new Offset(110, 10)},
paint);
paint = new Paint {
color = new Color(0xFFFFFF00),
};
canvas.drawRect(
Rect.fromLTWH(10, 150, 100, 100),
BorderWidth.only(2, 4, 6, 8),
BorderRadius.only(0, 4, 8, 16),
paint);
canvas.concat(Matrix4x4.Translate(new Vector2(-150, -150)));
canvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -45)));
canvas.concat(Matrix4x4.Translate(new Vector2(150, 150)));
paint = new Paint {
color = new Color(0xFF00FFFF),
blurSigma = 3,
};
canvas.drawRectShadow(
Rect.fromLTWH(150, 150, 110, 120),
paint);
var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -5)));
editorCanvas.clipRect(Rect.fromLTWH(25, 15, 250, 250));
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, 5)));
editorCanvas.drawPicture(picture);
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -15)));
editorCanvas.concat(Matrix4x4.Translate(new Vector2(100, 100)));
editorCanvas.drawPicture(picture);
}
void clipRRect() {
var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint = new Paint {
color = new Color(0xFFFF0000),
};
canvas.drawPloygon4(
new[] {new Offset(10, 10), new Offset(10, 110), new Offset(90, 110), new Offset(110, 10)},
paint);
paint = new Paint {
color = new Color(0xFFFFFF00),
};
canvas.drawRect(
Rect.fromLTWH(10, 150, 100, 100),
BorderWidth.only(2, 4, 6, 8),
BorderRadius.only(0, 4, 8, 16),
paint);
canvas.concat(Matrix4x4.Translate(new Vector2(-150, -150)));
canvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -45)));
canvas.concat(Matrix4x4.Translate(new Vector2(150, 150)));
paint = new Paint {
color = new Color(0xFF00FFFF),
blurSigma = 3,
};
canvas.drawRectShadow(
Rect.fromLTWH(150, 150, 110, 120),
paint);
var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -5)));
editorCanvas.clipRRect(RRect.fromRectAndRadius(Rect.fromLTWH(25, 15, 250, 250), 50));
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, 5)));
editorCanvas.drawPicture(picture);
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -15)));
editorCanvas.concat(Matrix4x4.Translate(new Vector2(100, 100)));
editorCanvas.drawPicture(picture);
}
void saveLayer() {
var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint = new Paint {
color = new Color(0xFFFF0000),
};
canvas.drawPloygon4(
new[] {new Offset(10, 10), new Offset(10, 110), new Offset(90, 110), new Offset(110, 10)},
paint);
paint = new Paint {
color = new Color(0xFFFFFF00),
};
canvas.drawRect(
Rect.fromLTWH(10, 150, 100, 100),
BorderWidth.only(2, 4, 6, 8),
BorderRadius.only(0, 4, 8, 16),
paint);
canvas.concat(Matrix4x4.Translate(new Vector2(-150, -150)));
canvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -45)));
canvas.concat(Matrix4x4.Translate(new Vector2(150, 150)));
canvas.clipRRect(RRect.fromRectAndRadius(Rect.fromLTWH(180, 150, 60, 120), 40));
paint = new Paint {
color = new Color(0xFF00FFFF),
blurSigma = 3,
};
canvas.drawRectShadow(
Rect.fromLTWH(150, 150, 110, 120),
paint);
var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -5)));
editorCanvas.clipRRect(RRect.fromRectAndRadius(Rect.fromLTWH(25, 15, 250, 250), 50));
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, 5)));
editorCanvas.saveLayer(picture.paintBounds, new Paint {color = new Color(0x7FFFFFFF)});
editorCanvas.drawPicture(picture);
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -15)));
editorCanvas.concat(Matrix4x4.Translate(new Vector2(100, 100)));
editorCanvas.drawPicture(picture);
editorCanvas.restore();
}
}
}

33
Assets/UIWidgets/ui/painting/editor_canvas.cs


}
public void drawPicture(Picture picture) {
this.save();
int saveCount = 0;
var drawCmds = picture.drawCmds;
foreach (var drawCmd in drawCmds) {
if (drawCmd is DrawPloygon4) {

} else if (drawCmd is DrawConcat) {
this.concat(((DrawConcat) drawCmd).transform);
} else if (drawCmd is DrawSave) {
saveCount++;
saveCount++;
saveCount--;
if (saveCount < 0) {
throw new Exception("unmatched save/restore in picture");
}
this.restore();
} else if (drawCmd is DrawClipRect) {
var drawClipRect = (DrawClipRect) drawCmd;

throw new Exception("unknown drawCmd: " + drawCmd);
}
}
if (saveCount != 0) {
throw new Exception("unmatched save/restore in picture");
}
this.restore();
}
public void concat(Matrix4x4 transform) {

}
public void restore() {
var layerRect = this._layerRec;
var layerRec = this._layerRec;
var state = this._stack.Pop();
this._transform = state.transform;

RenderTexture.active = this._layerRec != null ? this._layerRec.texture : null;
GL.PopMatrix();
if (layerRec != this._layerRec) {
RenderTexture.active = this._layerRec != null ? this._layerRec.texture : null;
GL.PopMatrix();
if (layerRect != null) {
Graphics.DrawTexture(layerRect.bounds.toRect(), layerRect.texture,
Graphics.DrawTexture(layerRec.bounds.toRect(), layerRec.texture,
layerRect.paint.color.toColor(), EditorCanvas.guiTextureClipMat);
layerRec.paint.color.toColor(), EditorCanvas.guiTextureClipMat);
RenderTexture.ReleaseTemporary(layerRect.texture);
layerRect.texture = null;
RenderTexture.ReleaseTemporary(layerRec.texture);
layerRec.texture = null;
}
}

16
Assets/UIWidgets/ui/painting/picture.cs


this._transform = Matrix4x4.identity;
this._clipRect = null;
this._isInLayer = false;
this._paintBounds = Rect.zero;
this._paintBounds = null;
}
private Stack<CanvasRec> stack {

this._transform = Matrix4x4.identity;
this._clipRect = drawSaveLayer.rect;
this._isInLayer = true;
this._paintBounds = Rect.zero;
this._paintBounds = null;
} else if (drawCmd is DrawRestore) {
var isLayer = this._isInLayer;

}
private void addPaintBounds(Rect paintBounds) {
if (paintBounds == null) {
return;
}
this._paintBounds = this._paintBounds.expandToInclude(paintBounds);
this._paintBounds = this._paintBounds == null
? paintBounds
: this._paintBounds.expandToInclude(paintBounds);
}
private void addPaintBounds(Offset[] points) {

}
this._paintBounds = this._paintBounds.expandToInclude(paintBounds);
this._paintBounds = this._paintBounds == null
? paintBounds
: this._paintBounds.expandToInclude(paintBounds);
}
private class CanvasRec {

正在加载...
取消
保存