浏览代码

some updates.

/main
kg 6 年前
当前提交
90ac4089
共有 9 个文件被更改,包括 246 次插入98 次删除
  1. 31
      Assets/UIWidgets/Tests/RenderBoxes.cs
  2. 9
      Assets/UIWidgets/editor/editor_window.cs
  3. 68
      Assets/UIWidgets/painting/borders.cs
  4. 124
      Assets/UIWidgets/painting/box_border.cs
  5. 89
      Assets/UIWidgets/painting/box_decoration.cs
  6. 7
      Assets/UIWidgets/painting/box_shadow.cs
  7. 1
      Assets/UIWidgets/rendering/object.cs
  8. 10
      Assets/UIWidgets/rendering/proxy_box.cs
  9. 5
      Assets/UIWidgets/ui/painting/canvas_impl.cs

31
Assets/UIWidgets/Tests/RenderBoxes.cs


using System;
using System.Linq;
using UIWidgets.editor;
using UIWidgets.painting;
using UIWidgets.ui;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.Tests {
public class RenderBoxes : EditorWindow {

RenderBoxes() {
this._options = new Func<RenderBox>[] {
this.test1,
this.none,
this.decoratedBox,
};
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray();
this._selected = 0;

[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.rendererBindings.setRoot(renderBox);
}
if (this.windowAdapter != null) {
this.windowAdapter.OnGUI();
}
}

this.rendererBindings = null;
}
RenderBox test1() {
RenderBox none() {
}
RenderBox decoratedBox() {
return new RenderConstrainedOverflowBox(
minWidth: 100,
maxWidth: 100,
minHeight: 100,
maxHeight: 100,
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
color: new Color(0xFFFFFFFF),
borderRadius: BorderRadius.all(3)
)
)
);
}
}
}

9
Assets/UIWidgets/editor/editor_window.cs


public void Update() {
bool dirty = false;
if (this._devicePixelRatio != EditorGUIUtility.pixelsPerPoint) {
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint;
this._lastPosition = this.editorWindow.position;
this._physicalSize = new Size(this._lastPosition.width, this._lastPosition.height);
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint;
this._lastPosition = this.editorWindow.position;
this._physicalSize = new Size(
this._lastPosition.width * EditorGUIUtility.pixelsPerPoint,
this._lastPosition.height * EditorGUIUtility.pixelsPerPoint);
if (this._onMetricsChanged != null) {
this._onMetricsChanged();
}

68
Assets/UIWidgets/painting/borders.cs


namespace UIWidgets.painting {
public abstract class ShapeBorder {
public abstract EdgeInsets dimensions { get; }
using System;
using UIWidgets.ui;
namespace UIWidgets.painting {
public class BorderSide : IEquatable<BorderSide> {
public BorderSide(
Color color = null,
double width = 1.0
) {
this.color = color ?? new Color(0xFF000000);
this.width = width;
}
public static BorderSide merge(BorderSide a, BorderSide b) {
return new BorderSide(
color: a.color,
width: a.width + b.width
);
}
public readonly Color color;
public readonly double width;
public static readonly BorderSide none = new BorderSide(width: 0.0);
public BorderSide copyWith(
Color color = null,
double? width = null
) {
return new BorderSide(
color: color ?? this.color,
width: width ?? this.width
);
}
public static bool canMerge(BorderSide a, BorderSide b) {
return a.color == b.color;
}
public bool Equals(BorderSide other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return object.Equals(this.color, other.color) && this.width.Equals(other.width);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return this.Equals((BorderSide) obj);
}
public override int GetHashCode() {
unchecked {
return ((this.color != null ? this.color.GetHashCode() : 0) * 397) ^ this.width.GetHashCode();
}
}
public static bool operator ==(BorderSide lhs, BorderSide rhs) {
return object.Equals(lhs, rhs);
}
public static bool operator !=(BorderSide lhs, BorderSide rhs) {
return !(lhs == rhs);
}
}
}

124
Assets/UIWidgets/painting/box_border.cs


using UnityEditor;
namespace UIWidgets.painting {
public class BorderSide : IEquatable<BorderSide> {
public BorderSide(
Color color = null,
double width = 1.0
) {
this.color = color ?? Color.fromARGB(255, 0, 0, 0);
this.width = width;
}
public readonly Color color;
public readonly double width;
public static readonly BorderSide none = new BorderSide(width: 0.0);
public bool Equals(BorderSide other) {
return this.color.Equals(other.color) && this.width.Equals(other.width);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) return false;
return obj is BorderSide && Equals((BorderSide) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.color.GetHashCode();
hashCode = (hashCode * 397) ^ this.width.GetHashCode();
return hashCode;
}
}
public static bool operator ==(BorderSide lhs, BorderSide rhs) {
return lhs.Equals(rhs);
}
public static bool operator !=(BorderSide lhs, BorderSide rhs) {
return !(lhs == rhs);
}
}
public class Border : ShapeBorder {
public class Border : IEquatable<Border> {
public Border(
BorderSide top = null,
BorderSide right = null,

public readonly BorderSide bottom;
public readonly BorderSide left;
public static Border all(
Color color = null,
double width = 1.0
) {
BorderSide side = new BorderSide(color: color, width: width);
return new Border(top: side, right: side, bottom: side, left: side);
}
public override EdgeInsets dimensions {
get { return null; }
public static Border merge(Border a, Border b) {
return new Border(
top: BorderSide.merge(a.top, b.top),
right: BorderSide.merge(a.right, b.right),
bottom: BorderSide.merge(a.bottom, b.bottom),
left: BorderSide.merge(a.left, b.left)
);
}
public EdgeInsets dimensions {
get {
return EdgeInsets.fromLTRB(
this.left.width,
this.top.width,
this.right.width,
this.bottom.width);
}
return this.right.color == topColor && this.bottom.color == topColor && this.left.color == topColor;
return this.right.color == topColor
&& this.bottom.color == topColor
&& this.left.color == topColor;
}
}
public Border add(Border other) {
if (BorderSide.canMerge(this.top, other.top) &&
BorderSide.canMerge(this.right, other.right) &&
BorderSide.canMerge(this.bottom, other.bottom) &&
BorderSide.canMerge(this.left, other.left)) {
return Border.merge(this, other);
return null;
}
public void paint(Canvas canvas, Rect rect, BorderRadius borderRadius = null) {

canvas.drawRect(rect,
BorderWidth.only(this.top.width, this.right.width, this.bottom.width, this.left.width),
borderRadius ?? BorderRadius.zero, paint);
borderRadius, paint);
}
if (borderRadius != null) {
canvas.save();
canvas.clipRRect(RRect.fromRectAndCorners(rect,
borderRadius.topLeft, borderRadius.topRight,
borderRadius.bottomRight, borderRadius.bottomLeft));
}
if (this.top.width > 0) {

};
canvas.drawPloygon4(points, paint);
}
if (borderRadius != null) {
canvas.restore();
}
}
public bool Equals(Border other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return object.Equals(this.top, other.top)
&& object.Equals(this.right, other.right)
&& object.Equals(this.bottom, other.bottom)
&& object.Equals(this.left, other.left);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return this.Equals((Border) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (this.top != null ? this.top.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.right != null ? this.right.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.bottom != null ? this.bottom.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.left != null ? this.left.GetHashCode() : 0);
return hashCode;
}
public class ImageConfiguration {
public ImageConfiguration(Size size = null) {

89
Assets/UIWidgets/painting/box_decoration.cs


using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.ui;
using UnityEditor;
public class BoxDecoration : Decoration {
public class BoxDecoration : Decoration, IEquatable<BoxDecoration> {
public BoxDecoration(
Color color = null,
DecorationImage image = null,

public override BoxPainter createBoxPainter(VoidCallback onChanged = null) {
return new _BoxDecorationPainter(this, onChanged);
}
public bool Equals(BoxDecoration other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return object.Equals(this.color, other.color)
&& object.Equals(this.image, other.image)
&& object.Equals(this.border, other.border)
&& object.Equals(this.borderRadius, other.borderRadius)
&& object.Equals(this.boxShadow, other.boxShadow)
&& object.Equals(this.gradient, other.gradient);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return this.Equals((BoxDecoration) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (this.color != null ? this.color.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.image != null ? this.image.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.border != null ? this.border.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.borderRadius != null ? this.borderRadius.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.boxShadow != null ? this.boxShadow.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.gradient != null ? this.gradient.GetHashCode() : 0);
return hashCode;
}
}
public static bool operator ==(BoxDecoration a, BoxDecoration b) {
return object.Equals(a, b);
}
public static bool operator !=(BoxDecoration a, BoxDecoration b) {
return !(a == b);
}
public _BoxDecorationPainter(BoxDecoration _decoration, VoidCallback onChanged) : base(onChanged) {
this._decoration = _decoration;
public _BoxDecorationPainter(BoxDecoration decoration, VoidCallback onChanged)
: base(onChanged) {
this._decoration = decoration;
public Rect _rectForCachedBackgroundPaint;
public Paint _getBackgroundPaint(Rect rect) {

}
foreach (BoxShadow boxShadow in this._decoration.boxShadow) {
Paint paint = boxShadow.toPaint();
Paint paint = new Paint {
color = boxShadow.color,
blurSigma = boxShadow.blurRadius
};
canvas.drawRectShadow(bounds, paint);
}
}

this._paintBox(canvas, rect, this._getBackgroundPaint(rect));
var paint = this._getBackgroundPaint(rect);
canvas.drawRect(rect, null, this._decoration.borderRadius, paint);
}
}

}
// _imagePainter ??= _decoration.image.createPainter(onChanged);
// Path clipPath;
// switch (_decoration.shape) {
// case BoxShape.circle:
// clipPath = new Path()..addOval(rect);
// break;
// case BoxShape.rectangle:
// if (_decoration.borderRadius != null)
// clipPath = new Path()..addRRect(_decoration.borderRadius.resolve(configuration.textDirection).toRRect(rect));
// break;
// }
// _imagePainter.paint(canvas, rect, clipPath, configuration);
public void dispose() {
base.dispose();

Rect rect = offset & configuration.size;
this._paintShadows(canvas, rect);
// this._paintShadows(canvas, rect);
this._paintBackgroundImage(canvas, rect, configuration);
if (this._decoration.border != null) {
this._decoration.border.paint(
canvas,
rect,
borderRadius: (BorderRadius) this._decoration.borderRadius
);
}
// this._paintBackgroundImage(canvas, rect, configuration);
// if (this._decoration.border != null) {
// this._decoration.border.paint(
// canvas,
// rect,
// borderRadius: this._decoration.borderRadius
// );
// }
}
}
}

7
Assets/UIWidgets/painting/box_shadow.cs


get { return BoxShadow.convertRadiusToSigma(this.blurRadius); }
}
public Paint toPaint() {
return new Paint {
color = this.color,
blurSigma = this.blurSigma
};
}
public bool Equals(BoxShadow other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;

1
Assets/UIWidgets/rendering/object.cs


return;
}
this._needsPaint = true;
if (this.isRepaintBoundary) {
if (this.owner != null) {
this.owner._nodesNeedingPaint.Add(this);

10
Assets/UIWidgets/rendering/proxy_box.cs


}
}
public enum DecorationPosition {
background,
foreground,
}
public class RenderConstrainedBox : RenderProxyBox {
public RenderConstrainedBox(
RenderBox child = null,

}
}
public enum DecorationPosition {
background,
foreground,
}
public class RenderDecoratedBox : RenderProxyBox {
public RenderDecoratedBox(
Decoration decoration,

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


}
public CanvasImpl() {
this._transform = Matrix4x4.identity;
this._transform = Matrix4x4.Scale(new Vector3(
1.0f / EditorGUIUtility.pixelsPerPoint,
1.0f / EditorGUIUtility.pixelsPerPoint,
1.0f));
}
public void drawPloygon4(Offset[] points, Paint paint) {

正在加载...
取消
保存