浏览代码

fix according to comments on 2019/1/3

/main
xingwei.zhu 6 年前
当前提交
c346a9ea
共有 12 个文件被更改,包括 119 次插入138 次删除
  1. 70
      Runtime/painting/matrix_utils.cs
  2. 4
      Runtime/rendering/box.cs
  3. 5
      Runtime/rendering/layer.cs
  4. 7
      Runtime/rendering/object.cs
  5. 18
      Runtime/rendering/proxy_box.cs
  6. 6
      Runtime/rendering/sliver.cs
  7. 3
      Runtime/rendering/view.cs
  8. 2
      Runtime/rendering/viewport.cs
  9. 132
      Runtime/ui/matrix.cs
  10. 6
      Runtime/widgets/basic.cs
  11. 2
      Runtime/widgets/container.cs
  12. 2
      Runtime/widgets/widget_inspector.cs

70
Runtime/painting/matrix_utils.cs


namespace Unity.UIWidgets.painting {
public static class MatrixUtils {
public static Matrix3 makeRotate(float degree)
{
var m = Matrix3.I();
m.setRotate(degree);
return m;
}
public static Matrix3 makeTrans(Vector2 vector)
{
var m = Matrix3.I();
m.setTranslate(vector.x, vector.y);
return m;
}
public static Matrix3 makeTrans(float dx, float dy)
{
var m = Matrix3.I();
m.setTranslate(dx, dy);
return m;
}
public static Matrix3 Value(this Matrix3 matrix3)
{
var m = Matrix3.I();
m.copyFrom(matrix3);
return m;
}
public static Matrix3 inverse(this Matrix3 matrix3)
{
var m = Matrix3.I();
var invertable = matrix3.invert(m);
D.assert(invertable);
return m;
}
public static Rect inverseTransformRect(this Matrix3 matrix3, Rect rect)
{
D.assert(rect != null);
D.assert(matrix3.determinant != 0.0);
if (matrix3.isIdentity()) {
return rect;
}
var inverse = matrix3.inverse();
return inverse.transformRect(rect);
}
public static Offset transformPoint(this Matrix3 matrix3, Offset point)
{
return matrix3.mapXY((float)point.dx, (float)point.dy);
}
public static Rect transformRect(this Matrix3 matrix3, Rect rect)
{
return matrix3.mapRect(rect);
}
public static Offset getAsTranslation(this Matrix3 matrix3)
{
if (matrix3.isTranslate()) return matrix3.mapXY(0, 0);
return null;
}
public static Offset transformPoint(this Matrix4x4 transform, Offset point) {
var position3 = new Vector3((float) point.dx, (float) point.dy, 0);
var transformed3 = transform.MultiplyPoint(position3);

4
Runtime/rendering/box.cs


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

}
transform = transform.inverse;
transform = transform.inverse();
return transform.transformPoint(point);
}

5
Runtime/rendering/layer.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.painting;
using UnityEngine;
using Rect = Unity.UIWidgets.ui.Rect;

public class TransformLayer : OffsetLayer {
public TransformLayer(Matrix3 transform = null, Offset offset = null) : base(offset) {
this._transform = transform ?? Matrix3.identity;
this._transform = transform ?? Matrix3.I();
}
public Matrix3 transform {

var totalOffset = this.offset + layerOffset;
if (totalOffset != Offset.zero) {
this._lastEffectiveTransform =
Matrix3.makeTrans(totalOffset.toVector()) * this._lastEffectiveTransform;
MatrixUtils.makeTrans(totalOffset.toVector()) * this._lastEffectiveTransform;
}
builder.pushTransform(this._lastEffectiveTransform);

7
Runtime/rendering/object.cs


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

renderers.Add(renderer);
}
var transform = Matrix3.identity;
var transform = Matrix3.I();
return transform;
}

18
Runtime/rendering/proxy_box.cs


Matrix3 _transform;
public void setIdentity() {
this._transform = Matrix3.identity;
this._transform = Matrix3.I();
this.markNeedsPaint();
}

}
public void rotateZ(double degrees) {
this._transform = Matrix3.makeRotate((float) degrees) * this._transform;
this._transform = MatrixUtils.makeRotate((float) degrees) * this._transform;
this._transform = Matrix3.makeTrans((float)x, (float)y) * this._transform;
this._transform = MatrixUtils.makeTrans((float)x, (float)y) * this._transform;
this.markNeedsPaint();
}

return this._transform;
}
var result = Matrix3.identity;
var result = Matrix3.I();
result = Matrix3.makeTrans(new Vector2((float) this._origin.dx, (float) this._origin.dy)) *
result = MatrixUtils.makeTrans(new Vector2((float) this._origin.dx, (float) this._origin.dy)) *
result;
}

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

return false;
}
position = transform.inverse.transformPoint(position);
position = transform.inverse().transformPoint(position);
}
return base.hitTestChildren(result, position: position);

6
Runtime/rendering/sliver.cs


public Offset paintOffset = Offset.zero;
public void applyPaintTransform(ref Matrix3 transform) {
transform = Matrix3.makeTrans(this.paintOffset.toVector()) * transform;
transform = MatrixUtils.makeTrans(this.paintOffset.toVector()) * transform;
}
public override string ToString() {

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

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

3
Runtime/rendering/view.cs


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

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

2
Runtime/rendering/viewport.cs


D.assert(child != null);
Offset offset = this.paintOffsetOf((RenderSliver) child);
transform = Matrix3.makeTrans(offset.toVector()) * transform;
transform = MatrixUtils.makeTrans(offset.toVector()) * transform;
}
protected override double computeChildMainAxisPosition(RenderSliver child, double parentMainAxisPosition) {

132
Runtime/ui/matrix.cs


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]

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();
m.reset();

}
return hash;
}
}
public static Matrix3 operator *(Matrix3 a, Matrix3 b)
{
return concat(a, b);
}
public override string ToString()
{
return "Matrix3(" + string.Join(",", Array.ConvertAll(fMat, i => i.ToString())) + ")";
}
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);
}
}
}

6
Runtime/widgets/basic.cs


Widget child = null
) : base(key, child) {
D.assert(transform != null);
this.transform = transform.Value;
this.transform = transform.Value();
this.origin = origin;
this.alignment = alignment;
this.transformHitTests = transformHitTests;

Widget child = null,
double degree = 0.0
) : base(key: key, child: child) {
this.transform = Matrix3.makeRotate((float) degree);
this.transform = MatrixUtils.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 = Matrix3.makeTrans(new Vector2((float) offset.dx, (float) offset.dy));
this.transform = MatrixUtils.makeTrans(new Vector2((float) offset.dx, (float) offset.dy));
this.origin = null;
this.alignment = null;
this.transformHitTests = transformHitTests;

2
Runtime/widgets/container.cs


}
if (this.transform != null) {
current = new Transform(transform: this.transform.Value, child: current);
current = new Transform(transform: this.transform.Value(), child: current);
}
return current;

2
Runtime/widgets/widget_inspector.cs


) {
var hit = false;
Matrix3 inverse = transform.inverse;
Matrix3 inverse = transform.inverse();
//var localPosition = MatrixUtils.transformPoint(inverse, position);
var localPosition = inverse.transformPoint(position);

正在加载...
取消
保存