浏览代码

fix issue2 matrix4x4 -> matrix3

/main
xingwei.zhu 6 年前
当前提交
a1166ec6
共有 18 个文件被更改,包括 196 次插入79 次删除
  1. 1
      Runtime/flow/container_layer.cs
  2. 3
      Runtime/painting/matrix_utils.cs
  3. 4
      Runtime/rendering/box.cs
  4. 18
      Runtime/rendering/layer.cs
  5. 14
      Runtime/rendering/object.cs
  6. 42
      Runtime/rendering/proxy_box.cs
  7. 2
      Runtime/rendering/proxy_box.mixin.gen.cs
  8. 2
      Runtime/rendering/proxy_box.mixin.njk
  9. 14
      Runtime/rendering/sliver.cs
  10. 2
      Runtime/rendering/sliver_multi_box_adaptor.cs
  11. 2
      Runtime/rendering/sliver_padding.cs
  12. 11
      Runtime/rendering/view.cs
  13. 8
      Runtime/rendering/viewport.cs
  14. 4
      Runtime/ui/compositing.cs
  15. 111
      Runtime/ui/matrix.cs
  16. 15
      Runtime/widgets/basic.cs
  17. 7
      Runtime/widgets/container.cs
  18. 15
      Runtime/widgets/widget_inspector.cs

1
Runtime/flow/container_layer.cs


using System.Collections.Generic;
using Unity.UIWidgets.ui;
using Matrix4x4 = UnityEngine.Matrix4x4;
namespace Unity.UIWidgets.flow {
public abstract class ContainerLayer : Layer {

3
Runtime/painting/matrix_utils.cs


return inverse.transformRect(rect);
}
public static Offset getAsTranslation(this Matrix4x4 transform) {
public static Offset getAsTranslation(this Matrix4x4 transform)
{
if (transform.m00 == 1.0 &&
transform.m10 == 0.0 &&
transform.m20 == 0.0 &&

4
Runtime/rendering/box.cs


return false;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
D.assert(child != null);
D.assert(child.parent == this);
D.assert(() => {

var childParentData = (BoxParentData) child.parentData;
var offset = childParentData.offset;
transform = Matrix4x4.Translate(offset.toVector()) * transform;
transform = Matrix3.makeTrans(offset.toVector()) * transform;
}
public Offset globalToLocal(Offset point, RenderObject ancestor = null) {

18
Runtime/rendering/layer.cs


}
}
public virtual void applyTransform(Layer child, ref Matrix4x4 transform) {
public virtual void applyTransform(Layer child, ref Matrix3 transform) {
D.assert(child != null);
}

}
public class TransformLayer : OffsetLayer {
public TransformLayer(Matrix4x4? transform = null, Offset offset = null) : base(offset) {
this._transform = transform ?? Matrix4x4.identity;
public TransformLayer(Matrix3 transform = null, Offset offset = null) : base(offset) {
this._transform = transform ?? Matrix3.identity;
public Matrix4x4 transform {
public Matrix3 transform {
Matrix4x4 _transform;
Matrix4x4 _lastEffectiveTransform;
Matrix3 _transform;
Matrix3 _lastEffectiveTransform;
public override void addToScene(SceneBuilder builder, Offset layerOffset) {
this._lastEffectiveTransform = this.transform;

this._lastEffectiveTransform =
Matrix4x4.Translate(totalOffset.toVector()) * this._lastEffectiveTransform;
Matrix3.makeTrans(totalOffset.toVector()) * this._lastEffectiveTransform;
}
builder.pushTransform(this._lastEffectiveTransform);

public override void applyTransform(Layer child, ref Matrix4x4 transform) {
public override void applyTransform(Layer child, ref Matrix3 transform) {
D.assert(child != null);
transform = transform * this._lastEffectiveTransform;
}

properties.add(new DiagnosticsProperty<Matrix4x4>("transform", this.transform));
properties.add(new DiagnosticsProperty<Matrix3>("transform", this.transform));
}
}

14
Runtime/rendering/object.cs


}
}
public void pushTransform(bool needsCompositing, Offset offset, Matrix4x4 transform,
public void pushTransform(bool needsCompositing, Offset offset, Matrix3 transform,
var effectiveTransform = Matrix4x4.Translate(offset.toVector())
* transform * Matrix4x4.Translate(-offset.toVector());
var effectiveTransform = Matrix3.makeTrans(offset.toVector())
* transform * Matrix3.makeTrans(-offset.toVector());
if (needsCompositing) {
this.pushLayer(

);
} else {
this.canvas.save();
this.canvas.concat(effectiveTransform.toMatrix3());
this.canvas.concat(effectiveTransform);
painter(this, offset);
this.canvas.restore();
}

public virtual void paint(PaintingContext context, Offset offset) {
}
public virtual void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public virtual void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
public Matrix4x4 getTransformTo(RenderObject ancestor) {
public Matrix3 getTransformTo(RenderObject ancestor) {
D.assert(this.attached);
if (ancestor == null) {

renderers.Add(renderer);
}
var transform = Matrix4x4.identity;
var transform = Matrix3.identity;
for (int index = renderers.Count - 1; index > 0; index -= 1) {
renderers[index].applyPaintTransform(renderers[index - 1], ref transform);
}

42
Runtime/rendering/proxy_box.cs


public class RenderTransform : RenderProxyBox {
public RenderTransform(
Matrix4x4 transform,
Matrix3 transform,
Offset origin = null,
Alignment alignment = null,
bool transformHitTests = true,

public bool transformHitTests;
public Matrix4x4 transform {
public Matrix3 transform {
set {
if (this._transform == value) {
return;

}
}
Matrix4x4 _transform;
Matrix3 _transform;
this._transform = Matrix4x4.identity;
this._transform = Matrix3.identity;
this._transform = Matrix4x4.Rotate(Quaternion.Euler((float) degrees, 0, 0)) * this._transform;
this.markNeedsPaint();
//2D, do nothing
this._transform = Matrix4x4.Rotate(Quaternion.Euler(0, (float) degrees, 0)) * this._transform;
this.markNeedsPaint();
//2D, do nothing
this._transform = Matrix4x4.Rotate(Quaternion.Euler(0, 0, (float) degrees)) * this._transform;
this._transform = Matrix3.makeRotate((float) degrees) * this._transform;
this._transform = Matrix4x4.Translate(new Vector3((float) x, (float) y, (float) z)) * this._transform;
this._transform = Matrix3.makeTrans((float)x, (float)y) * this._transform;
this._transform = Matrix4x4.Scale(new Vector3((float) x, (float) y, (float) z)) * this._transform;
this._transform = Matrix3.makeScale((float) x, (float) y) * this._transform;
Matrix4x4 _effectiveTransform {
Matrix3 _effectiveTransform {
get {
Alignment resolvedAlignment = this.alignment;
if (this._origin == null && resolvedAlignment == null) {

var result = Matrix4x4.identity;
var result = Matrix3.identity;
result = Matrix4x4.Translate(new Vector2((float) this._origin.dx, (float) this._origin.dy)) *
result = Matrix3.makeTrans(new Vector2((float) this._origin.dx, (float) this._origin.dy)) *
result;
}

result = Matrix4x4.Translate(new Vector2((float) translation.dx, (float) translation.dy)) * result;
result = Matrix3.makeTrans(new Vector2((float) translation.dx, (float) translation.dy)) * result;
result = Matrix4x4.Translate(new Vector2((float) -translation.dx, (float) -translation.dy)) *
result = Matrix3.makeTrans(new Vector2((float) -translation.dx, (float) -translation.dy)) *
result = Matrix4x4.Translate(new Vector2((float) -this._origin.dx, (float) -this._origin.dy)) *
result = Matrix3.makeTrans(new Vector2((float) -this._origin.dx, (float) -this._origin.dy)) *
result;
}

public override bool hitTest(HitTestResult result, Offset position = null) {
return this.hitTestChildren(result, position: position);
}
protected override bool hitTestChildren(HitTestResult result, Offset position = null) {
if (this.transformHitTests) {
var transform = this._effectiveTransform;

}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
if (this.child != null)
{
if (childOffset == null) {
context.pushTransform(this.needsCompositing, offset, transform, base.paint);
} else {

}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
properties.add(new DiagnosticsProperty<Matrix4x4>("transform matrix", this._transform));
properties.add(new DiagnosticsProperty<Matrix3>("transform matrix", this._transform));
properties.add(new DiagnosticsProperty<Offset>("origin", this.origin));
properties.add(new DiagnosticsProperty<Alignment>("alignment", this.alignment));
properties.add(new DiagnosticsProperty<bool>("transformHitTests", this.transformHitTests));

2
Runtime/rendering/proxy_box.mixin.gen.cs


return false;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
}
public override void paint(PaintingContext context, Offset offset) {

2
Runtime/rendering/proxy_box.mixin.njk


return false;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
}
public override void paint(PaintingContext context, Offset offset) {

14
Runtime/rendering/sliver.cs


public class SliverPhysicalParentData : ParentData {
public Offset paintOffset = Offset.zero;
public void applyPaintTransform(ref Matrix4x4 transform) {
transform = Matrix4x4.Translate(this.paintOffset.toVector()) * transform;
public void applyPaintTransform(ref Matrix3 transform) {
transform = Matrix3.makeTrans(this.paintOffset.toVector()) * transform;
}
public override string ToString() {

return 0.0;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
D.assert(() => { throw new UIWidgetsError(this.GetType() + " does not implement applyPaintTransform."); });
}

}
public static void applyPaintTransformForBoxChild(this RenderSliver it, RenderBox child,
ref Matrix4x4 transform) {
ref Matrix3 transform) {
bool rightWayUp = _getRightWayUp(it.constraints);
double delta = it.childMainAxisPosition(child);
double crossAxisDelta = it.childCrossAxisPosition(child);

delta = it.geometry.paintExtent - child.size.width - delta;
}
transform = Matrix4x4.Translate(new Vector2((float) delta, (float) crossAxisDelta)) * transform;
transform = Matrix3.makeTrans(new Vector2((float) delta, (float) crossAxisDelta)) * transform;
break;
case Axis.vertical:
if (!rightWayUp) {

transform = Matrix4x4.Translate(new Vector2((float) crossAxisDelta, (float) delta)) * transform;
transform = Matrix3.makeTrans(new Vector2((float) crossAxisDelta, (float) delta)) * transform;
break;
}
}

return -this.constraints.scrollOffset;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
D.assert(child != null);
D.assert(child == this.child);

2
Runtime/rendering/sliver_multi_box_adaptor.cs


return childParentData.layoutOffset;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
this.applyPaintTransformForBoxChild((RenderBox) child, ref transform);
}

2
Runtime/rendering/sliver_padding.cs


return this.beforePadding;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
D.assert(child != null);
D.assert(child == this.child);

11
Runtime/rendering/view.cs


public readonly double devicePixelRatio;
public Matrix4x4 toMatrix() {
return Matrix4x4.identity;
public Matrix3 toMatrix() {
return Matrix3.identity;
}
public override string ToString() {

this.owner.requestVisualUpdate();
}
Matrix4x4 _rootTransform;
Matrix3 _rootTransform;
public Layer _updateMatricesAndCreateNewRootLayer() {
this._rootTransform = this.configuration.toMatrix();

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

get
{
D.assert(_rootTransform != null);
return MatrixUtils.transformRect(_rootTransform, Offset.zero & size);
return _rootTransform.transformRect(Offset.zero & size);
//return MatrixUtils.transformRect(_rootTransform, Offset.zero & size);
}
}

8
Runtime/rendering/viewport.cs


RenderObject descendant;
rect = rect ?? target.paintBounds;
Matrix4x4 transform;
Matrix3 transform;
if (target is RenderBox) {
RenderBox targetBox = (RenderBox) target;

return 0.0;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
D.assert(child != null);
var childParentData = (SliverPhysicalParentData) child.parentData;

return pinnedExtent;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
public override void applyPaintTransform(RenderObject child, ref Matrix3 transform) {
transform = Matrix4x4.Translate(offset.toVector()) * transform;
transform = Matrix3.makeTrans(offset.toVector()) * transform;
}
protected override double computeChildMainAxisPosition(RenderSliver child, double parentMainAxisPosition) {

4
Runtime/ui/compositing.cs


this._currentLayer = layer;
}
public void pushTransform(Matrix4x4 matrix) {
public void pushTransform(Matrix3 matrix) {
layer.transform = matrix.toMatrix3();
layer.transform = matrix;
this._pushLayer(layer);
}

111
Runtime/ui/matrix.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using UnityEngine;
namespace Unity.UIWidgets.ui {

return m;
}
public static Matrix3 makeRotate(float degree)
{
var m = new Matrix3();
m.setRotate(degree);
return m;
}
public static Matrix3 makeTrans(Vector2 vector)
{
return makeTrans((float) vector.x, (float) vector.y);
}
public static Matrix3 makeAll(
float scaleX, float skewX, float transX,
float skewY, float scaleY, float transY,

public void copyFrom(Matrix3 other) {
Array.Copy(other.fMat, this.fMat, 9);
this.fTypeMask = other.fTypeMask;
}
public Matrix3 Value
{
get
{
var m = new Matrix3();
m.copyFrom(this);
return m;
}
}
[Flags]

public static bool operator !=(Matrix3 a, Matrix3 b) {
return !(a == b);
}
private static Matrix3 _identity = null;
public static Matrix3 identity
{
get
{
if (_identity != null) return _identity;
_identity = new Matrix3();
_identity.reset();
return _identity;
}
}
public static Matrix3 operator *(Matrix3 a, Matrix3 b)
{
return concat(a, b);
}
public Offset getAsTranslation()
{
if (isTranslate()) return new Offset(fMat[kMTransX], fMat[kMTransY]);
return null;
}
public override string ToString()
{
return "Matrix3(" + string.Join(",", Array.ConvertAll(fMat, i => i.ToString())) + ")";
}
public Rect inverseTransformRect(Rect rect)
{
D.assert(rect != null);
D.assert(this.determinant != 0.0);
if (this.isIdentity()) {
return rect;
}
var inverse = this.inverse;
return inverse.transformRect(rect);
//var matrix4 = this.toMatrix4x4();
//return matrix4.inverseTransformRect(rect);
}
public Rect transformRect(Rect rect)
{
//var matrix4 = this.toMatrix4x4();
//return matrix4.transformRect(rect);
return mapRect(rect);
}
public float determinant
{
get
{
TypeMask mask = this.getType();
int isPersp = (int) (mask & TypeMask.kPerspective_Mask);
double invDet = ScalarUtils.inv_determinant(fMat, isPersp);
D.assert(invDet != 0);
return (float)(1.0 / invDet);
//var matrix4 = this.toMatrix4x4();
//return matrix4.determinant;
}
}
public Matrix3 inverse
{
get
{
//return this.toMatrix4x4().inverse.toMatrix3();
var m = new Matrix3();
var invertable = this.invert(m);
D.assert(invertable);
return m;
}
}
public Offset transformPoint(Offset point)
{
//return this.toMatrix4x4().transformPoint(point);
return this.mapXY((float)point.dx, (float)point.dy);
}
public static Matrix3 I() {
var m = new Matrix3();

15
Runtime/widgets/basic.cs


public class Transform : SingleChildRenderObjectWidget {
public Transform(
Key key = null,
Matrix4x4? transform = null,
Matrix3 transform = null,
Offset origin = null,
Alignment alignment = null,
bool transformHitTests = true,

Widget child = null,
double degree = 0.0
) : base(key: key, child: child) {
this.transform = Matrix4x4.Rotate(Quaternion.Euler(0, 0, (float) degree));
this.transform = Matrix3.makeRotate((float) degree);
this.origin = origin;
this.alignment = alignment;
this.transformHitTests = transformHitTests;

Widget child = null
) : base(key: key, child: child) {
D.assert(offset != null);
this.transform = Matrix4x4.Translate(new Vector3((float) offset.dx, (float) offset.dy, 0.0f));
this.transform = Matrix3.makeTrans(new Vector2((float) offset.dx, (float) offset.dy));
this.origin = null;
this.alignment = null;
this.transformHitTests = transformHitTests;

bool transformHitTests = true,
Widget child = null
) : base(key: key, child: child) {
this.transform = Matrix4x4.Scale(new Vector3((float) scale, (float) scale, 1.0f));
this.transform = Matrix3.makeScale((float) scale, (float) scale);
this.origin = origin;
this.alignment = alignment;
this.transformHitTests = transformHitTests;

return new Transform(key, scale, origin, alignment, transformHitTests, child);
}
public readonly Matrix4x4 transform;
public readonly Matrix3 transform;
public override RenderObject createRenderObject(BuildContext context) {
public override RenderObject createRenderObject(BuildContext context)
{
Debug.Log("create render object");
return new RenderTransform(
transform: this.transform,
origin: this.origin,

7
Runtime/widgets/container.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;

double? height = null,
BoxConstraints constraints = null,
EdgeInsets margin = null,
Matrix4x4? transfrom = null,
Matrix3 transfrom = null,
Widget child = null
) : base(key) {
D.assert(margin == null || margin.isNonNegative);

public readonly Decoration foregroundDecoration;
public readonly BoxConstraints constraints;
public readonly EdgeInsets margin;
public readonly Matrix4x4? transform;
public readonly Matrix3 transform;
EdgeInsets _paddingIncludingDecoration {
get {

this.constraints, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<EdgeInsets>("margin",
this.margin, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(ObjectFlagProperty<Matrix4x4?>.has("transform",
properties.add(ObjectFlagProperty<Matrix3>.has("transform",
this.transform));
}
}

15
Runtime/widgets/widget_inspector.cs


List<RenderObject> edgeHits,
Offset position,
RenderObject renderObject,
Matrix4x4 transform
Matrix3 transform
Matrix4x4 inverse = transform.inverse;
var localPosition = MatrixUtils.transformPoint(inverse, position);
Matrix3 inverse = transform.inverse;
//var localPosition = MatrixUtils.transformPoint(inverse, position);
var localPosition = inverse.transformPoint(position);
List<DiagnosticsNode> children = renderObject.debugDescribeChildren();
for (int i = children.Count - 1; i >= 0; --i)

continue;
}
Matrix4x4 childTransform = transform;
var childTransform = transform;
renderObject.applyPaintTransform(child, ref childTransform);
if (_hitTestHelper(hits, edgeHits, position, child, childTransform))
{

class _TransformedRect:IEquatable<_TransformedRect>
{
public readonly Rect rect;
public readonly Matrix4x4 transform;
public readonly Matrix3 transform;
public _TransformedRect(RenderObject obj)
{

var borderPaint = new Paint(){color = _kHighlightedRenderObjectBorderColor, style = PaintingStyle.stroke, strokeWidth = 1};
Rect selectedPaintRect = state.selected.rect.deflate(0.5);
canvas.save();
canvas.setMatrix(state.selected.transform.toMatrix3());
canvas.setMatrix(state.selected.transform);
canvas.drawRect(selectedPaintRect, fillPaint);
canvas.drawRect(selectedPaintRect, borderPaint);
canvas.restore();

canvas.save();
canvas.setMatrix(transformedRect.transform.toMatrix3());
canvas.setMatrix(transformedRect.transform);
canvas.drawRect(transformedRect.rect.deflate(0.5), borderPaint);
canvas.restore();
}

正在加载...
取消
保存