浏览代码

some updates.

/main
kg 6 年前
当前提交
1b1a743c
共有 30 个文件被更改,包括 663 次插入589 次删除
  1. 92
      Assets/UIWidgets/Tests/CanvasAndLayers.cs
  2. 7
      Assets/UIWidgets/Tests/Menu.cs
  3. 45
      Assets/UIWidgets/editor/editor_window.cs
  4. 8
      Assets/UIWidgets/flow/clip_rect_layer.cs
  5. 2
      Assets/UIWidgets/flow/layer.cs
  6. 16
      Assets/UIWidgets/flow/layer_builder.cs
  7. 4
      Assets/UIWidgets/flow/opacity_layer.cs
  8. 6
      Assets/UIWidgets/flow/picture_layer.cs
  9. 2
      Assets/UIWidgets/flow/transform_layer.cs
  10. 34
      Assets/UIWidgets/rendering/binding.cs
  11. 66
      Assets/UIWidgets/rendering/layer.cs
  12. 110
      Assets/UIWidgets/rendering/object.cs
  13. 10
      Assets/UIWidgets/rendering/view.cs
  14. 19
      Assets/UIWidgets/scheduler/binding.cs
  15. 9
      Assets/UIWidgets/ui/compositing.cs
  16. 4
      Assets/UIWidgets/ui/geometry.cs
  17. 37
      Assets/UIWidgets/ui/painting/painting.cs
  18. 2
      Assets/UIWidgets/ui/painting/picture.cs
  19. 2
      scripts/cmds/codegen.js
  20. 67
      Assets/UIWidgets/Tests/RenderBoxes.cs
  21. 3
      Assets/UIWidgets/Tests/RenderBoxes.cs.meta
  22. 40
      Assets/UIWidgets/flow/clip_rrect_layer.cs
  23. 3
      Assets/UIWidgets/flow/clip_rrect_layer.cs.meta
  24. 322
      Assets/UIWidgets/ui/painting/canvas_impl.cs
  25. 11
      Assets/UIWidgets/rendering/binding.gen.cs.meta
  26. 3
      Assets/UIWidgets/rendering/binding.njk
  27. 3
      Assets/UIWidgets/rendering/binding.njk.meta
  28. 3
      Assets/UIWidgets/rendering/binding.gen.cs
  29. 322
      Assets/UIWidgets/ui/painting/editor_canvas.cs
  30. 0
      /Assets/UIWidgets/ui/painting/canvas_impl.cs.meta

92
Assets/UIWidgets/Tests/CanvasAndLayers.cs


using Color = UIWidgets.ui.Color;
using Rect = UIWidgets.ui.Rect;
namespace Editor.Tests {
namespace UIWidgets.Tests {
public class CanvasAndLayers : EditorWindow {
private readonly Action[] _options;

void OnGUI() {
this._selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings);
this._options[this._selected]();
if (Event.current.type == EventType.Repaint) {
this._options[this._selected]();
}
var canvas = new EditorCanvas();
var canvas = new CanvasImpl();
var paint = new Paint {
color = new Color(0xFFFF0000),

new[] {new Offset(10, 10), new Offset(10, 110), new Offset(110, 110), new Offset(110, 10)},
paint);
canvas.drawPloygon4(
new[] {new Offset(10, 150), new Offset(10, 160), new Offset(140, 120), new Offset(110, 180)},
paint);

var canvas = new EditorCanvas();
var canvas = new CanvasImpl();
var paint = new Paint {
color = new Color(0xFFFF0000),

BorderWidth.only(2, 4, 6, 8),
BorderRadius.only(0, 4, 8, 16),
paint);
canvas.drawRect(
Rect.fromLTWH(150, 150, 100, 100),
BorderWidth.only(10, 12, 14, 16),

void drawRectShadow() {
var canvas = new EditorCanvas();
var canvas = new CanvasImpl();
canvas.drawRectShadow(
Rect.fromLTWH(10, 150, 100, 100),
paint);

var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint = new Paint {
color = new Color(0xFFFF0000),
};

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)));

var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
var editorCanvas = new CanvasImpl();
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -15)));
editorCanvas.concat(Matrix4x4.Translate(new Vector2(100, 100)));
editorCanvas.drawPicture(picture);

var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint = new Paint {
color = new Color(0xFFFF0000),
};

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)));

var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
var editorCanvas = new CanvasImpl();
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -15)));
editorCanvas.concat(Matrix4x4.Translate(new Vector2(100, 100)));
editorCanvas.drawPicture(picture);

var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);
var paint = new Paint {
color = new Color(0xFFFF0000),
};

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)));

var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
var editorCanvas = new CanvasImpl();
var paint = new Paint {
color = new Color(0xFFFF0000),
};

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)));

var picture = pictureRecorder.endRecording();
Debug.Log("picture.paintBounds: " + picture.paintBounds);
var editorCanvas = new EditorCanvas();
var editorCanvas = new CanvasImpl();
editorCanvas.concat(Matrix4x4.Rotate(Quaternion.Euler(0, 0, -15)));
editorCanvas.concat(Matrix4x4.Translate(new Vector2(100, 100)));
editorCanvas.drawPicture(picture);

7
Assets/UIWidgets/Tests/Menu.cs


using UnityEditor;
namespace Editor.Tests {
namespace UIWidgets.Tests {
}
[MenuItem("UIWidgetsTests/RenderBoxes")]
public static void renderBoxes() {
EditorWindow.GetWindow(typeof(RenderBoxes));
}
}
}

45
Assets/UIWidgets/editor/editor_window.cs


public readonly DateTime _epoch = DateTime.Now;
public void OnGUI() {
if (this.onBeginFrame != null) {
this.onBeginFrame(DateTime.Now - this._epoch);
}
if (Event.current.type == EventType.Repaint) {
if (this.onBeginFrame != null) {
this.onBeginFrame(DateTime.Now - this._epoch);
}
if (this.onDrawFrame != null) {
this.onDrawFrame();
if (this.onDrawFrame != null) {
this.onDrawFrame();
}
}
}

var prerollContext = new PrerollContext();
layer.preroll(prerollContext, Matrix4x4.identity);
var paintContext = new PaintContext();
var paintContext = new PaintContext {canvas = new CanvasImpl()};
}
}
public class EditorWindow : UnityEditor.EditorWindow {
protected virtual void OnGUI() {
if (this.windowAdapter != null) {
this.windowAdapter.OnGUI();
}
}
protected virtual void Update() {
if (this.windowAdapter != null) {
this.windowAdapter.Update();
}
}
protected virtual void Awake() {
this.windowAdapter = new WindowAdapter(this);
}
protected void OnDestroy() {
this.windowAdapter = null;
}
public WindowAdapter windowAdapter;
public void runWidget(Widget root) {
}
public void runRenderBox(RenderBox root) {
new RendererBindingImpl(this.windowAdapter, root);
}
}
}

8
Assets/UIWidgets/flow/clip_rect_layer.cs


using UnityEngine;
using UIWidgets.ui;
using UnityEngine;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.flow {
public class ClipRectLayer : ContainerLayer {

public override void paint(PaintContext context) {
var canvas = context.canvas;
canvas.save();
var paint = new Paint {color = new Color(0xFFFFFFFF)};
canvas.saveLayer(this.paintBounds, paint);
canvas.clipRect(this.paintBounds);
this.paintChildren(context);
}
finally {

2
Assets/UIWidgets/flow/layer.cs


set { this._parent = value; }
}
private Rect _paintBounds;
private Rect _paintBounds = Rect.zero;
public Rect paintBounds {
get { return this._paintBounds; }

16
Assets/UIWidgets/flow/layer_builder.cs


}
public void pushTransform(Matrix4x4 matrix) {
Rect cullRect = Rect.largest;
var det = matrix.determinant;
if (det != 0f) {
cullRect = MatrixUtils.transformRect(matrix.inverse, this._cullRects.Peek());
}
Rect cullRect = MatrixUtils.transformRect(matrix.inverse, this._cullRects.Peek());
var layer = new TransformLayer();
layer.transform = matrix;

var layer = new ClipRectLayer();
layer.clipRect = clipRect;
this.pushLayer(layer, cullRect);
}
public void pushClipRRect(RRect clipRRect) {
Rect cullRect = clipRRect.outerRect.intersect(this._cullRects.Peek());
var layer = new ClipRRectLayer();
layer.clipRRect = clipRRect;
this.pushLayer(layer, cullRect);
}

4
Assets/UIWidgets/flow/opacity_layer.cs


public override void paint(PaintContext context) {
var canvas = context.canvas;
var paint = new Paint();
paint.color = Color.fromARGB(this._alpha, 255, 255, 255);
var paint = new Paint {color = Color.fromARGB(this._alpha, 255, 255, 255)};
canvas.saveLayer(this.paintBounds, paint);
try {
this.paintChildren(context);

6
Assets/UIWidgets/flow/picture_layer.cs


public override void paint(PaintContext context) {
var canvas = context.canvas;
canvas.save();
if (this._offset == Offset.zero) {
canvas.drawPicture(this._picture);
return;
}
canvas.save();
try {
canvas.concat(Matrix4x4.Translate(new Vector2((float) this._offset.dx, (float) this._offset.dy)));
canvas.drawPicture(this._picture);

2
Assets/UIWidgets/flow/transform_layer.cs


}
public override void preroll(PrerollContext context, Matrix4x4 matrix) {
var childMatrix = matrix * this._tranform;
var childMatrix = this._tranform * matrix;
Rect childPaintBounds = Rect.zero;
this.prerollChildren(context, childMatrix, ref childPaintBounds);

34
Assets/UIWidgets/rendering/binding.cs


using UIWidgets.ui;
namespace UIWidgets.rendering {
public abstract class RendererBinding : SchedulerBinding {
public RendererBinding(Window window) : base(window) {
public class RendererBinding {
public RendererBinding(Window window, SchedulerBinding schedulerBinding) {
this._window = window;
this._schedulerBinding = schedulerBinding;
onNeedVisualUpdate: this.ensureVisualUpdate
onNeedVisualUpdate: this._schedulerBinding.ensureVisualUpdate
this.addPersistentFrameCallback(this._handlePersistentFrameCallback);
this._schedulerBinding.addPersistentFrameCallback(this._handlePersistentFrameCallback);
public readonly Window _window;
public readonly SchedulerBinding _schedulerBinding;
public void initRenderView() {
this.renderView = new RenderView(configuration: this.createViewConfiguration());

public void handleMetricsChanged() {
this.renderView.configuration = this.createViewConfiguration();
this.scheduleForcedFrame();
this._schedulerBinding.scheduleForcedFrame();
}
public ViewConfiguration createViewConfiguration() {

}
}
public class RendererBindingImpl : RendererBinding {
public RendererBindingImpl(Window window, RenderBox root) : base(window) {
this.renderView.child = root;
public class RendererBindings {
public RendererBindings(Window window) {
this._window = window;
this._schedulerBinding = new SchedulerBinding(window);
this._rendererBinding = new RendererBinding(window, this._schedulerBinding);
}
public readonly Window _window;
public readonly RendererBinding _rendererBinding;
public readonly SchedulerBinding _schedulerBinding;
public void setRoot(RenderBox root) {
this._rendererBinding.renderView.child = root;
}
}
}

66
Assets/UIWidgets/rendering/layer.cs


using UIWidgets.foundation;
using UIWidgets.rendering;
using UIWidgets.ui;
using UnityEngine;
using Rect = UIWidgets.ui.Rect;

this.parent.dropChild(this);
}
public abstract S find<S>(Offset regionOffset);
public override S find<S>(Offset regionOffset) {
return default(S);
}
public override void addToScene(SceneBuilder builder, Offset layerOffset) {
builder.addPicture(layerOffset, this.picture);

public Layer _lastChild;
public override S find<S>(Offset regionOffset) {
Layer current = this.lastChild;
while (current != null) {
var value = current.find<S>(regionOffset);
if (value != null) {
return value;
}
current = current.previousSibling;
}
return default(S);
}
public override void attach(object owner) {
base.attach(owner);

child = child.nextSibling;
}
}
public virtual void applyTransform(Layer child, UnityEngine.Matrix4x4 transform) {
}
}
public class OffsetLayer : ContainerLayer {

public Offset offset;
public override S find<S>(Offset regionOffset) {
return base.find<S>(regionOffset - this.offset);
}
public override void addToScene(SceneBuilder builder, Offset layerOffset) {
this.addChildrenToScene(builder, this.offset + layerOffset);
}

public Rect clipRect;
public override S find<S>(Offset regionOffset) {
if (!this.clipRect.contains(regionOffset)) {
return default(S);
}
public override void addToScene(SceneBuilder builder, Offset layerOffset) {
builder.pushClipRect(this.clipRect.shift(layerOffset));
this.addChildrenToScene(builder, layerOffset);
builder.pop();
}
}
return base.find<S>(regionOffset);
public class ClipRRectLayer : ContainerLayer {
public ClipRRectLayer(RRect clipRRect) {
this.clipRRect = clipRRect;
public RRect clipRRect;
builder.pushClipRect(this.clipRect.shift(layerOffset));
builder.pushClipRRect(this.clipRRect.shift(layerOffset));
this.addChildrenToScene(builder, layerOffset);
builder.pop();
}

this._transform = transform;
}
public Matrix4x4 transform {
get { return this._transform; }
set { this._transform = value; }
}
public Matrix4x4 _lastEffectiveTransform;
public override void addToScene(SceneBuilder builder, Offset layerOffset) {
this._lastEffectiveTransform = this.transform;
var totalOffset = this.offset + layerOffset;
if (totalOffset != Offset.zero) {
this._lastEffectiveTransform =
Matrix4x4.Translate(totalOffset.toVector()) * this._lastEffectiveTransform;
}
builder.pushTransform(this._lastEffectiveTransform);
this.addChildrenToScene(builder, Offset.zero);
builder.pop();
}
}
public class OpacityLayer : ContainerLayer {

110
Assets/UIWidgets/rendering/object.cs


public delegate void PaintingContextCallback(PaintingContext context, Offset offset);
public delegate void LayoutCallback<T>(T constraints) where T : Constraints;
public class PaintingContext {
private PaintingContext(ContainerLayer containerLayer) {
this._containerLayer = containerLayer;

public void _compositeChild(RenderObject child, Offset offset) {
if (child._needsPaint) {
PaintingContext.repaintCompositedChild(child);
} else {
}
child._layer.offset = offset;

public void pushClipRect(bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter) {
Rect offsetClipRect = clipRect.shift(offset);
if (needsCompositing) {
this.pushLayer(new ClipRectLayer(clipRect: offsetClipRect), painter, offset);
this.pushLayer(new ClipRectLayer(offsetClipRect), painter, offset);
} else {
this.canvas.save();
this.canvas.clipRect(offsetClipRect);
painter(this, offset);
this.canvas.restore();
}
}
public void pushClipRRect(bool needsCompositing, Offset offset, RRect clipRRect,
PaintingContextCallback painter) {
RRect offsetClipRRect = clipRRect.shift(offset);
if (needsCompositing) {
this.pushLayer(new ClipRRectLayer(offsetClipRRect), painter, offset);
// canvas
// ..save()
// ..clipRect(offsetClipRect);
// painter(this, offset);
// canvas
// ..restore();
this.canvas.save();
this.canvas.clipRRect(offsetClipRRect);
painter(this, offset);
this.canvas.restore();
void pushTransform(Offset offset, Matrix4x4 transform, PaintingContextCallback painter) {
void pushTransform(bool needsCompositing, Offset offset, Matrix4x4 transform, PaintingContextCallback painter) {
var effectiveTransform = Matrix4x4.Translate(offset.toVector())
* transform * Matrix4x4.Translate(-offset.toVector());
if (needsCompositing) {
this.pushLayer(new TransformLayer(effectiveTransform), painter, offset);
} else {
this.canvas.save();
this.canvas.concat(effectiveTransform);
painter(this, offset);
this.canvas.restore();
}
this.pushLayer(new OpacityLayer(alpha: alpha), painter, offset);
this.pushLayer(new OpacityLayer(alpha), painter, offset);
public abstract class Constraints {
public abstract bool isTight { get; }
public abstract bool isNormalized { get; }
}
public delegate void RenderObjectVisitor(RenderObject child);
public delegate void LayoutCallback<T>(T constraints) where T : Constraints;
RendererBinding binding = null,
RendererBinding binding = null,
VoidCallback onNeedVisualUpdate = null) {
this.binding = binding;
this.onNeedVisualUpdate = onNeedVisualUpdate;

public readonly VoidCallback onNeedVisualUpdate;
public void requestVisualUpdate() {

}
}
public abstract class Constraints {
public abstract bool isTight { get; }
public abstract bool isNormalized { get; }
}
public delegate void RenderObjectVisitor(RenderObject child);
public abstract class ContainerParentDataMixin<ChildType> : ParentData where ChildType : RenderObject {
public ChildType previousSibling;

public abstract class RenderObject : AbstractNode {
protected RenderObject() {
this._needsCompositing = this.isRepaintBoundary || this.alwaysNeedsCompositing;
}
public ParentData parentData;

var child = (RenderObject) childNode;
this.setupParentData(child);
base.adoptChild(child);
this.markNeedsCompositingBitsUpdate();
}
public override void dropChild(AbstractNode childNode) {

child.parentData = null;
base.dropChild(child);
this.markNeedsCompositingBitsUpdate();
}
public virtual void visitChildren(RenderObjectVisitor visitor) {

this.markNeedsLayout();
}
if (this._needsPaint) {
if (this._needsCompositingBitsUpdate) {
this._needsCompositingBitsUpdate = false;
this.markNeedsCompositingBitsUpdate();
}
if (this._needsPaint && this._layer != null) {
this._needsPaint = false;
this.markNeedsPaint();
}
}

public Constraints _constraints;
public virtual void markNeedsLayout() {
if (this._needsLayout) {
return;

this.markNeedsLayout();
this.markParentNeedsLayout();
} else {
this._needsLayout = true;
if (this.owner != null) {

public void markParentNeedsLayout() {
this._needsLayout = true;
var parent = (RenderObject) this.parent;
parent.markNeedsLayout();
((RenderObject) this.parent).markNeedsLayout();
}
}

public void layout(Constraints constraints, bool parentUsesSize = false) {
RenderObject relayoutBoundary;
if (!parentUsesSize || this.sizedByParent || constraints.isTight || !(parent is RenderObject)) {
if (!parentUsesSize || this.sizedByParent || constraints.isTight || !(this.parent is RenderObject)) {
var parent1 = (RenderObject) this.parent;
relayoutBoundary = parent1._relayoutBoundary;
relayoutBoundary = ((RenderObject) this.parent)._relayoutBoundary;
if (!this._needsLayout && constraints == this._constraints && relayoutBoundary == this._relayoutBoundary) {
if (!this._needsLayout && object.Equals(constraints, this._constraints) &&
relayoutBoundary == this._relayoutBoundary) {
return;
}

public bool _needsCompositingBitsUpdate = false;
public void markNeedsCompositingBitsUpdate() {
if (!this._needsCompositingBitsUpdate) {
if (this._needsCompositingBitsUpdate) {
return;
}

public Matrix4x4 getTransformTo(RenderObject ancestor) {
if (ancestor == null) {
AbstractNode rootNode = this.owner.rootNode;
if (rootNode is RenderObject)
if (rootNode is RenderObject) {
}
}
var renderers = new List<RenderObject>();

return transform;
}
}
public class GUIContext {
public void paintChild(RenderObject child) {
//child.onGUI(this);
}
}
public class RenderLabel {
public RenderLabel() {
}
}
public class TextSpan {
}
}

10
Assets/UIWidgets/rendering/view.cs


public readonly double devicePixelRatio;
public Matrix4x4 toMatrix() {
return Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(
return Matrix4x4.Scale(new Vector3(
(float) this.devicePixelRatio, (float) this.devicePixelRatio, 1));
}

}
public class RenderView : RenderObjectWithChildMixinRenderObject<RenderBox> {
public RenderView(

}
}
public void applyPaintTransform(RenderBox child, Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, Matrix4x4 transform) {
transform *= this._rootTransform;
base.applyPaintTransform(child, transform);
}

this.layer.addToScene(builder, Offset.zero);
using (var scene = builder.build()) {
this.owner.binding.render(scene);
}
var scene = builder.build();
this.owner.binding.render(scene);
}
public override Rect paintBounds {

19
Assets/UIWidgets/scheduler/binding.cs


using UnityEngine;
namespace UIWidgets.scheduler {
public enum SchedulerPhase {
idle,
transientCallbacks,
midFrameMicrotasks,
persistentCallbacks,
postFrameCallbacks,
}
public class _FrameCallbackEntry {
public _FrameCallbackEntry(FrameCallback callback, bool rescheduling = false) {
this.callback = callback;

}
public abstract class SchedulerBinding {
public enum SchedulerPhase {
idle,
transientCallbacks,
midFrameMicrotasks,
persistentCallbacks,
postFrameCallbacks,
}
public class SchedulerBinding {
public SchedulerBinding(Window window) {
this._window = window;

}
public double _timeDilation = 1.0;
public int _nextFrameCallbackId = 0;
public Dictionary<int, _FrameCallbackEntry> _transientCallbacks = new Dictionary<int, _FrameCallbackEntry>();

9
Assets/UIWidgets/ui/compositing.cs


this._layerBuilder.pushClipRect(rect);
}
public void pushClipRRect(RRect rrect) {
this._layerBuilder.pushClipRRect(rrect);
}
public void pushOpacity(int alpha) {
this._layerBuilder.pushOpacity(alpha);
}

}
}
public class Scene : IDisposable {
public class Scene {
public Scene(Layer rootLayer) {
this._rootLayer = rootLayer;
}

public Layer takeLayer() {
return this._rootLayer;
}
public void Dispose() {
}
}
}

4
Assets/UIWidgets/ui/geometry.cs


return new Offset(this.dx + translateX, this.dy + translateY);
}
public static Offset operator -(Offset a) {
return new Offset(-a.dx, -a.dy);
}
public static Offset operator -(Offset a, Offset b) {
return new Offset(a.dx - b.dx, a.dy - b.dy);
}

37
Assets/UIWidgets/ui/painting/painting.cs


};
}
public static Vector4 toVector(this BorderRadius borderRadius) {
return new Vector4((float) borderRadius.topLeft, (float) borderRadius.topRight,
(float) borderRadius.bottomRight, (float) borderRadius.bottomLeft);

};
}
}
// public class GUICanvas : Canvas {
// static GUICanvas() {
// GUICanvas.shadowMat = Resources.Load<Material>("UIWidgets_ShadowMat");
// if (GUICanvas.shadowMat == null) {
// throw new Exception("UIWidgets_ShadowShader not found");
// }
// }
//
// public static readonly Material shadowMat;
//
// public override void drawPloygon4(Paint paint, params Offset[] points) {
// Vector3[] vectors = new Vector3 [points.Length];
// for (int i = 0; i < points.Length; i++) {
// vectors[i] = points[i].toVector();
// }
//
// Handles.DrawSolidRectangleWithOutline(vectors, paint.color.toColor(),
// new UnityEngine.Color(0f, 0f, 0f, 0f));
// }
//
// public override void drawRect(Paint paint, Rect rect, BorderWidth borderWidth, BorderRadius borderRadius) {
// GUI.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, true, 0,
// paint.color.toColor(), borderWidth.toVector(), borderRadius.toVector());
// }
//
// public override void drawRectShadow(Paint paint, Rect rect) {
// GUICanvas.shadowMat.SetFloatArray("_Rect", new float[] {
// (float) rect.left, (float) rect.top, (float) rect.width, (float) rect.height,
// });
// GUICanvas.shadowMat.SetFloat("_sigma", (float) paint.blurSigma);
//
// Graphics.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture,
// new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, paint.color.toColor(), GUICanvas.shadowMat);
// }
// }
}

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


}
public class PictureRecorder {
private List<DrawCmd> _drawCmds = new List<DrawCmd>();
private readonly List<DrawCmd> _drawCmds = new List<DrawCmd>();
private Matrix4x4 _transform;
private Rect _clipRect;

2
scripts/cmds/codegen.js


var chokidar = require('chokidar');
exports.command = 'codegen [dir]';
exports.desc = "codegen";
exports.desc = "generate mixin code";
exports.builder = function (yargs) {
return yargs.positional('dir', {
describe: 'the working directory',

67
Assets/UIWidgets/Tests/RenderBoxes.cs


using System;
using System.Linq;
using UIWidgets.editor;
using UIWidgets.rendering;
using UnityEditor;
using UnityEngine;
namespace UIWidgets.Tests {
public class RenderBoxes : EditorWindow {
private readonly Func<RenderBox>[] _options;
private readonly string[] _optionStrings;
private int _selected;
RenderBoxes() {
this._options = new Func<RenderBox>[] {
this.test1,
};
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray();
this._selected = 0;
this.titleContent = new GUIContent("RenderBoxes");
}
private WindowAdapter windowAdapter;
private RendererBindings rendererBindings;
[NonSerialized] private bool hasInvoked = false;
void OnGUI() {
if (this.windowAdapter != null) {
this.windowAdapter.OnGUI();
}
var selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings);
if (selected != this._selected || !this.hasInvoked) {
this._selected = selected;
this.hasInvoked = true;
var renderBox = this._options[this._selected]();
this.rendererBindings.setRoot(renderBox);
}
}
void Update() {
if (this.windowAdapter != null) {
this.windowAdapter.Update();
}
}
private void OnEnable() {
this.windowAdapter = new WindowAdapter(this);
this.rendererBindings = new RendererBindings(this.windowAdapter);
}
void OnDestroy() {
this.windowAdapter = null;
this.rendererBindings = null;
}
RenderBox test1() {
return null;
}
}
}

3
Assets/UIWidgets/Tests/RenderBoxes.cs.meta


fileFormatVersion: 2
guid: e773b48a6f94416d89e1f690b34c1379
timeCreated: 1534920245

40
Assets/UIWidgets/flow/clip_rrect_layer.cs


using UIWidgets.ui;
using UnityEngine;
using Rect = UIWidgets.ui.Rect;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.flow {
public class ClipRRectLayer : ContainerLayer {
private RRect _clipRRect;
public RRect clipRRect {
set { this._clipRRect = value; }
}
public override void preroll(PrerollContext context, Matrix4x4 matrix) {
var childPaintBounds = Rect.zero;
this.prerollChildren(context, matrix, ref childPaintBounds);
childPaintBounds = childPaintBounds.intersect(this._clipRRect.outerRect);
if (!childPaintBounds.isEmpty) {
this.paintBounds = childPaintBounds;
}
}
public override void paint(PaintContext context) {
var canvas = context.canvas;
canvas.save();
canvas.clipRRect(this._clipRRect);
var paint = new Paint {color = new Color(0xFFFFFFFF)};
canvas.saveLayer(this.paintBounds, paint);
try {
this.paintChildren(context);
}
finally {
canvas.restore();
canvas.restore();
}
}
}
}

3
Assets/UIWidgets/flow/clip_rrect_layer.cs.meta


fileFormatVersion: 2
guid: 8c1ecaedbb1c4868bd17a21e7466284c
timeCreated: 1534912541

322
Assets/UIWidgets/ui/painting/canvas_impl.cs


using System;
using System.Collections.Generic;
using UIWidgets.painting;
using UnityEditor;
using UnityEngine;
namespace UIWidgets.ui {
public class CanvasImpl : Canvas {
static CanvasImpl() {
var shader = Shader.Find("UIWidgets/2D Handles Lines");
if (shader == null) {
throw new Exception("UIWidgets/2D Handles Lines not found");
}
CanvasImpl.linesMat = new Material(shader);
CanvasImpl.linesMat.hideFlags = HideFlags.HideAndDontSave;
shader = Shader.Find("UIWidgets/GUIRoundedRect");
if (shader == null) {
throw new Exception("UIWidgets/GUIRoundedRect not found");
}
CanvasImpl.guiRoundedRectMat = new Material(shader);
CanvasImpl.guiRoundedRectMat.hideFlags = HideFlags.HideAndDontSave;
shader = Shader.Find("UIWidgets/GUITextureClip");
if (shader == null) {
throw new Exception("UIWidgets/GUITextureClip not found");
}
CanvasImpl.guiTextureClipMat = new Material(shader);
CanvasImpl.guiTextureClipMat.hideFlags = HideFlags.HideAndDontSave;
shader = Shader.Find("UIWidgets/ShadowRect");
if (shader == null) {
throw new Exception("UIWidgets/ShadowRect not found");
}
CanvasImpl.shadowRectMat = new Material(shader);
CanvasImpl.shadowRectMat.hideFlags = HideFlags.HideAndDontSave;
}
private static readonly Material linesMat;
private static readonly Material guiRoundedRectMat;
private static readonly Material guiTextureClipMat;
private static readonly Material shadowRectMat;
private Matrix4x4 _transform;
private ClipRec _clipRec;
private LayerRec _layerRec;
private Stack<CanvasRec> _stack;
private Stack<CanvasRec> stack {
get { return this._stack ?? (this._stack = new Stack<CanvasRec>()); }
}
public CanvasImpl() {
this._transform = Matrix4x4.identity;
}
public void drawPloygon4(Offset[] points, Paint paint) {
var color = paint.color;
if (color.alpha > 0) {
Vector3[] verts = new Vector3 [points.Length];
for (int i = 0; i < points.Length; i++) {
verts[i] = points[i].toVector();
}
this.prepareGL(CanvasImpl.linesMat);
CanvasImpl.linesMat.SetPass(0);
GL.Begin(GL.TRIANGLES);
GL.Color(color.toColor());
for (int index = 0; index < 2; ++index) {
GL.Vertex(verts[index * 2]);
GL.Vertex(verts[index * 2 + 1]);
GL.Vertex(verts[(index * 2 + 2) % 4]);
GL.Vertex(verts[index * 2]);
GL.Vertex(verts[(index * 2 + 2) % 4]);
GL.Vertex(verts[index * 2 + 1]);
}
GL.End();
}
}
public void drawRect(Rect rect, BorderWidth borderWidth, BorderRadius borderRadius, Paint paint) {
this.prepareGL(CanvasImpl.guiRoundedRectMat);
CanvasImpl.guiRoundedRectMat.SetFloatArray("UIWidgets_BorderWidth",
borderWidth == null ? new[] {0f, 0f, 0f, 0f} : borderWidth.toFloatArray());
CanvasImpl.guiRoundedRectMat.SetFloatArray("UIWidgets_CornerRadius",
borderRadius == null ? new[] {0f, 0f, 0f, 0f} : borderRadius.toFloatArray());
Graphics.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
paint.color.toColor(), CanvasImpl.guiRoundedRectMat);
}
public void drawRectShadow(Rect rect, Paint paint) {
this.prepareGL(CanvasImpl.shadowRectMat);
CanvasImpl.shadowRectMat.SetFloat("UIWidgets_sigma", (float) paint.blurSigma);
Graphics.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
paint.color.toColor(), CanvasImpl.shadowRectMat);
}
public void drawPicture(Picture picture) {
this.save();
int saveCount = 0;
var drawCmds = picture.drawCmds;
foreach (var drawCmd in drawCmds) {
if (drawCmd is DrawPloygon4) {
var drawPloygon4 = (DrawPloygon4) drawCmd;
this.drawPloygon4(drawPloygon4.points, drawPloygon4.paint);
} else if (drawCmd is DrawRect) {
var drawRect = (DrawRect) drawCmd;
this.drawRect(drawRect.rect, drawRect.borderWidth, drawRect.borderRadius, drawRect.paint);
} else if (drawCmd is DrawRectShadow) {
var drawRectShadow = (DrawRectShadow) drawCmd;
this.drawRectShadow(drawRectShadow.rect, drawRectShadow.paint);
} else if (drawCmd is DrawPicture) {
var drawPicture = (DrawPicture) drawCmd;
this.drawPicture(drawPicture.picture);
} else if (drawCmd is DrawConcat) {
this.concat(((DrawConcat) drawCmd).transform);
} else if (drawCmd is DrawSave) {
saveCount++;
this.save();
} else if (drawCmd is DrawSaveLayer) {
saveCount++;
var drawSaveLayer = (DrawSaveLayer) drawCmd;
this.saveLayer(drawSaveLayer.rect, drawSaveLayer.paint);
} else if (drawCmd is DrawRestore) {
saveCount--;
if (saveCount < 0) {
throw new Exception("unmatched save/restore in picture");
}
this.restore();
} else if (drawCmd is DrawClipRect) {
var drawClipRect = (DrawClipRect) drawCmd;
this.clipRect(drawClipRect.rect);
} else if (drawCmd is DrawClipRRect) {
var drawClipRRect = (DrawClipRRect) drawCmd;
this.clipRRect(drawClipRRect.rrect);
} else {
throw new Exception("unknown drawCmd: " + drawCmd);
}
}
if (saveCount != 0) {
throw new Exception("unmatched save/restore in picture");
}
this.restore();
}
public void concat(Matrix4x4 transform) {
this._transform = transform * this._transform;
}
public void save() {
var state = new CanvasRec {
transform = this._transform,
clipRect = this._clipRec,
layerRec = this._layerRec,
};
this.stack.Push(state);
}
public void saveLayer(Rect bounds, Paint paint) {
this.save();
var textureWidth = (int) Math.Round(bounds.width * EditorGUIUtility.pixelsPerPoint);
var textureHeight = (int) Math.Round(bounds.height * EditorGUIUtility.pixelsPerPoint);
var texture = RenderTexture.GetTemporary(
textureWidth, textureHeight, 32,
RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
RenderTexture.active = texture;
GL.PushMatrix();
GL.LoadPixelMatrix((float) bounds.left, (float) bounds.right, (float) bounds.bottom, (float) bounds.top);
GL.Clear(true, true, new UnityEngine.Color(0, 0, 0, 0));
this._layerRec = new LayerRec {
bounds = bounds,
paint = paint,
texture = texture,
};
this._transform = Matrix4x4.identity;
this._clipRec = null;
}
public void restore() {
var layerRec = this._layerRec;
var state = this._stack.Pop();
this._transform = state.transform;
this._clipRec = state.clipRect;
this._layerRec = state.layerRec;
if (layerRec != this._layerRec) {
RenderTexture.active = this._layerRec != null ? this._layerRec.texture : null;
GL.PopMatrix();
this.prepareGL(CanvasImpl.guiTextureClipMat);
Graphics.DrawTexture(layerRec.bounds.toRect(), layerRec.texture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
layerRec.paint.color.toColor(), CanvasImpl.guiTextureClipMat);
RenderTexture.ReleaseTemporary(layerRec.texture);
layerRec.texture = null;
}
}
public void clipRect(Rect rect) {
if (rect.isInfinite) {
return;
}
this.pushClipRect(rect, this._transform);
}
public void clipRRect(RRect rect) {
if (rect.isInfinite) {
return;
}
this.pushClipRRect(rect, this._transform);
}
private void pushClipRect(Rect clipRect, Matrix4x4 transform) {
if (this._clipRec != null) {
throw new Exception("already a clipRec, considering using saveLayer.");
}
this._clipRec = new ClipRec(transform, rect: clipRect);
}
private void pushClipRRect(RRect clipRRect, Matrix4x4 transform) {
if (this._clipRec != null) {
throw new Exception("already a clipRec, considering using saveLayer.");
}
this._clipRec = new ClipRec(transform, rrect: clipRRect);
}
private void prepareGL(Material mat) {
if (this._clipRec != null) {
mat.SetMatrix("UIWidgets_GUIClipMatrix", this._clipRec.transform.inverse);
if (this._clipRec.rect != null) {
var rect = this._clipRec.rect;
mat.SetVector("UIWidgets_GUIClipRect", new Vector4(
(float) rect.left,
(float) rect.top,
(float) rect.width,
(float) rect.height));
mat.SetVector("UIWidgets_GUIClipRectRadius", new Vector4(0, 0, 0, 0));
} else {
var rrect = this._clipRec.rrect;
var rect = rrect.outerRect;
mat.SetVector("UIWidgets_GUIClipRect", new Vector4(
(float) rect.left,
(float) rect.top,
(float) rect.width,
(float) rect.height));
mat.SetVector("UIWidgets_GUIClipRectRadius",
new Vector4(
(float) rrect.tlRadius,
(float) rrect.trRadius,
(float) rrect.brRadius,
(float) rrect.blRadius));
}
} else {
mat.SetMatrix("UIWidgets_GUIClipMatrix", Matrix4x4.identity);
var rect = Rect.largest;
mat.SetVector("UIWidgets_GUIClipRect", new Vector4(
(float) rect.left,
(float) rect.top,
(float) rect.width,
(float) rect.height));
mat.SetVector("UIWidgets_GUIClipRectRadius", new Vector4(0, 0, 0, 0));
}
GL.MultMatrix(this._transform);
}
private class ClipRec {
public ClipRec(Matrix4x4 transform, Rect rect = null, RRect rrect = null) {
this.transform = transform;
this.rect = rect;
this.rrect = rrect;
}
public readonly Matrix4x4 transform;
public readonly Rect rect;
public readonly RRect rrect;
}
private class LayerRec {
public Rect bounds;
public Paint paint;
public RenderTexture texture;
}
private class CanvasRec {
public Matrix4x4 transform;
public ClipRec clipRect;
public LayerRec layerRec;
}
}
}

11
Assets/UIWidgets/rendering/binding.gen.cs.meta


fileFormatVersion: 2
guid: b8e36c63511f04dbf8d5ed86f144274d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

3
Assets/UIWidgets/rendering/binding.njk


namespace UIWidgets.rendering {
}

3
Assets/UIWidgets/rendering/binding.njk.meta


fileFormatVersion: 2
guid: 3c1a210c4c4b4354bba182d6903742cd
timeCreated: 1534222730

3
Assets/UIWidgets/rendering/binding.gen.cs


namespace UIWidgets.rendering {
}

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


using System;
using System.Collections.Generic;
using UIWidgets.painting;
using UnityEditor;
using UnityEngine;
namespace UIWidgets.ui {
public class EditorCanvas : Canvas {
static EditorCanvas() {
var shader = Shader.Find("UIWidgets/2D Handles Lines");
if (shader == null) {
throw new Exception("UIWidgets/2D Handles Lines not found");
}
EditorCanvas.linesMat = new Material(shader);
EditorCanvas.linesMat.hideFlags = HideFlags.HideAndDontSave;
shader = Shader.Find("UIWidgets/GUIRoundedRect");
if (shader == null) {
throw new Exception("UIWidgets/GUIRoundedRect not found");
}
EditorCanvas.guiRoundedRectMat = new Material(shader);
EditorCanvas.guiRoundedRectMat.hideFlags = HideFlags.HideAndDontSave;
shader = Shader.Find("UIWidgets/GUITextureClip");
if (shader == null) {
throw new Exception("UIWidgets/GUITextureClip not found");
}
EditorCanvas.guiTextureClipMat = new Material(shader);
EditorCanvas.guiTextureClipMat.hideFlags = HideFlags.HideAndDontSave;
shader = Shader.Find("UIWidgets/ShadowRect");
if (shader == null) {
throw new Exception("UIWidgets/ShadowRect not found");
}
EditorCanvas.shadowRectMat = new Material(shader);
EditorCanvas.shadowRectMat.hideFlags = HideFlags.HideAndDontSave;
}
private static readonly Material linesMat;
private static readonly Material guiRoundedRectMat;
private static readonly Material guiTextureClipMat;
private static readonly Material shadowRectMat;
private Matrix4x4 _transform;
private ClipRec _clipRec;
private LayerRec _layerRec;
private Stack<CanvasRec> _stack;
private Stack<CanvasRec> stack {
get { return this._stack ?? (this._stack = new Stack<CanvasRec>()); }
}
public EditorCanvas() {
this._transform = Matrix4x4.identity;
}
public void drawPloygon4(Offset[] points, Paint paint) {
var color = paint.color;
if (color.alpha > 0) {
Vector3[] verts = new Vector3 [points.Length];
for (int i = 0; i < points.Length; i++) {
verts[i] = points[i].toVector();
}
this.prepareGL(EditorCanvas.linesMat);
EditorCanvas.linesMat.SetPass(0);
GL.Begin(GL.TRIANGLES);
GL.Color(color.toColor());
for (int index = 0; index < 2; ++index) {
GL.Vertex(verts[index * 2]);
GL.Vertex(verts[index * 2 + 1]);
GL.Vertex(verts[(index * 2 + 2) % 4]);
GL.Vertex(verts[index * 2]);
GL.Vertex(verts[(index * 2 + 2) % 4]);
GL.Vertex(verts[index * 2 + 1]);
}
GL.End();
}
}
public void drawRect(Rect rect, BorderWidth borderWidth, BorderRadius borderRadius, Paint paint) {
this.prepareGL(EditorCanvas.guiRoundedRectMat);
EditorCanvas.guiRoundedRectMat.SetFloatArray("UIWidgets_BorderWidth",
borderWidth == null ? new[] {0f, 0f, 0f, 0f} : borderWidth.toFloatArray());
EditorCanvas.guiRoundedRectMat.SetFloatArray("UIWidgets_CornerRadius",
borderRadius == null ? new[] {0f, 0f, 0f, 0f} : borderRadius.toFloatArray());
Graphics.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
paint.color.toColor(), EditorCanvas.guiRoundedRectMat);
}
public void drawRectShadow(Rect rect, Paint paint) {
this.prepareGL(EditorCanvas.shadowRectMat);
EditorCanvas.shadowRectMat.SetFloat("UIWidgets_sigma", (float) paint.blurSigma);
Graphics.DrawTexture(rect.toRect(), EditorGUIUtility.whiteTexture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
paint.color.toColor(), EditorCanvas.shadowRectMat);
}
public void drawPicture(Picture picture) {
this.save();
int saveCount = 0;
var drawCmds = picture.drawCmds;
foreach (var drawCmd in drawCmds) {
if (drawCmd is DrawPloygon4) {
var drawPloygon4 = (DrawPloygon4) drawCmd;
this.drawPloygon4(drawPloygon4.points, drawPloygon4.paint);
} else if (drawCmd is DrawRect) {
var drawRect = (DrawRect) drawCmd;
this.drawRect(drawRect.rect, drawRect.borderWidth, drawRect.borderRadius, drawRect.paint);
} else if (drawCmd is DrawRectShadow) {
var drawRectShadow = (DrawRectShadow) drawCmd;
this.drawRectShadow(drawRectShadow.rect, drawRectShadow.paint);
} else if (drawCmd is DrawPicture) {
var drawPicture = (DrawPicture) drawCmd;
this.drawPicture(drawPicture.picture);
} else if (drawCmd is DrawConcat) {
this.concat(((DrawConcat) drawCmd).transform);
} else if (drawCmd is DrawSave) {
saveCount++;
this.save();
} else if (drawCmd is DrawSaveLayer) {
saveCount++;
var drawSaveLayer = (DrawSaveLayer) drawCmd;
this.saveLayer(drawSaveLayer.rect, drawSaveLayer.paint);
} else if (drawCmd is DrawRestore) {
saveCount--;
if (saveCount < 0) {
throw new Exception("unmatched save/restore in picture");
}
this.restore();
} else if (drawCmd is DrawClipRect) {
var drawClipRect = (DrawClipRect) drawCmd;
this.clipRect(drawClipRect.rect);
} else if (drawCmd is DrawClipRRect) {
var drawClipRRect = (DrawClipRRect) drawCmd;
this.clipRRect(drawClipRRect.rrect);
} else {
throw new Exception("unknown drawCmd: " + drawCmd);
}
}
if (saveCount != 0) {
throw new Exception("unmatched save/restore in picture");
}
this.restore();
}
public void concat(Matrix4x4 transform) {
this._transform = transform * this._transform;
}
public void save() {
var state = new CanvasRec {
transform = this._transform,
clipRect = this._clipRec,
layerRec = this._layerRec,
};
this.stack.Push(state);
}
public void saveLayer(Rect bounds, Paint paint) {
this.save();
var textureWidth = (int) Math.Round(bounds.width * EditorGUIUtility.pixelsPerPoint);
var textureHeight = (int) Math.Round(bounds.height * EditorGUIUtility.pixelsPerPoint);
var texture = RenderTexture.GetTemporary(
textureWidth, textureHeight, 32,
RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
RenderTexture.active = texture;
GL.PushMatrix();
GL.LoadPixelMatrix((float) bounds.left, (float) bounds.right, (float) bounds.bottom, (float) bounds.top);
GL.Clear(true, true, new UnityEngine.Color(0, 0, 0, 0));
this._layerRec = new LayerRec {
bounds = bounds,
paint = paint,
texture = texture,
};
this._transform = Matrix4x4.identity;
this._clipRec = null;
}
public void restore() {
var layerRec = this._layerRec;
var state = this._stack.Pop();
this._transform = state.transform;
this._clipRec = state.clipRect;
this._layerRec = state.layerRec;
if (layerRec != this._layerRec) {
RenderTexture.active = this._layerRec != null ? this._layerRec.texture : null;
GL.PopMatrix();
this.prepareGL(EditorCanvas.guiTextureClipMat);
Graphics.DrawTexture(layerRec.bounds.toRect(), layerRec.texture,
new UnityEngine.Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0,
layerRec.paint.color.toColor(), EditorCanvas.guiTextureClipMat);
RenderTexture.ReleaseTemporary(layerRec.texture);
layerRec.texture = null;
}
}
public void clipRect(Rect rect) {
if (rect.isInfinite) {
return;
}
this.pushClipRect(rect, this._transform);
}
public void clipRRect(RRect rect) {
if (rect.isInfinite) {
return;
}
this.pushClipRRect(rect, this._transform);
}
private void pushClipRect(Rect clipRect, Matrix4x4 transform) {
if (this._clipRec != null) {
throw new Exception("already a clipRec, considering using saveLayer.");
}
this._clipRec = new ClipRec(transform, rect: clipRect);
}
private void pushClipRRect(RRect clipRRect, Matrix4x4 transform) {
if (this._clipRec != null) {
throw new Exception("already a clipRec, considering using saveLayer.");
}
this._clipRec = new ClipRec(transform, rrect: clipRRect);
}
private void prepareGL(Material mat) {
if (this._clipRec != null) {
mat.SetMatrix("UIWidgets_GUIClipMatrix", this._clipRec.transform.inverse);
if (this._clipRec.rect != null) {
var rect = this._clipRec.rect;
mat.SetVector("UIWidgets_GUIClipRect", new Vector4(
(float) rect.left,
(float) rect.top,
(float) rect.width,
(float) rect.height));
mat.SetVector("UIWidgets_GUIClipRectRadius", new Vector4(0, 0, 0, 0));
} else {
var rrect = this._clipRec.rrect;
var rect = rrect.outerRect;
mat.SetVector("UIWidgets_GUIClipRect", new Vector4(
(float) rect.left,
(float) rect.top,
(float) rect.width,
(float) rect.height));
mat.SetVector("UIWidgets_GUIClipRectRadius",
new Vector4(
(float) rrect.tlRadius,
(float) rrect.trRadius,
(float) rrect.brRadius,
(float) rrect.blRadius));
}
} else {
mat.SetMatrix("UIWidgets_GUIClipMatrix", Matrix4x4.identity);
var rect = Rect.largest;
mat.SetVector("UIWidgets_GUIClipRect", new Vector4(
(float) rect.left,
(float) rect.top,
(float) rect.width,
(float) rect.height));
mat.SetVector("UIWidgets_GUIClipRectRadius", new Vector4(0, 0, 0, 0));
}
GL.MultMatrix(this._transform);
}
private class ClipRec {
public ClipRec(Matrix4x4 transform, Rect rect = null, RRect rrect = null) {
this.transform = transform;
this.rect = rect;
this.rrect = rrect;
}
public readonly Matrix4x4 transform;
public readonly Rect rect;
public readonly RRect rrect;
}
private class LayerRec {
public Rect bounds;
public Paint paint;
public RenderTexture texture;
}
private class CanvasRec {
public Matrix4x4 transform;
public ClipRec clipRect;
public LayerRec layerRec;
}
}
}

/Assets/UIWidgets/ui/painting/editor_canvas.cs.meta → /Assets/UIWidgets/ui/painting/canvas_impl.cs.meta

正在加载...
取消
保存