浏览代码

replace color, paint with uicolor and uipaint

/main
xingwei.zhu 5 年前
当前提交
a28a8d29
共有 10 个文件被更改,包括 239 次插入109 次删除
  1. 2
      Runtime/ui/painting/shadow_utils.cs
  2. 62
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  3. 27
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_shader.cs
  4. 4
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/render_layer.cs
  5. 58
      Runtime/ui/utils/renderer/common/base_canvas.cs
  6. 30
      Runtime/ui/utils/renderer/common/draw_cmd.cs
  7. 6
      Runtime/ui/utils/renderer/common/paint.cs
  8. 8
      Runtime/ui/utils/renderer/common/picture.cs
  9. 18
      Runtime/ui/utils/renderer/compositeCanvas/flow/physical_shape_layer.cs
  10. 133
      Runtime/ui/utils/renderer/geometry/path/path.cs

2
Runtime/ui/painting/shadow_utils.cs


namespace Unity.UIWidgets.ui {
static class ShadowUtils {
public static bool kUseFastShadow = true;
public const bool kUseFastShadow = true;
public const float kAmbientHeightFactor = 1.0f / 128.0f;
public const float kAmbientGeomFactor = 64.0f;

62
Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs


readonly uiOffset[] _saveLayer_Points = new uiOffset[4];
void _saveLayer(uiRect bounds, Paint paint) {
void _saveLayer(uiRect bounds, uiPaint paint) {
D.assert(paint != null);
var parentLayer = this._currentLayer;
var state = parentLayer.currentState;

this._saveLayer_Points[2],
this._saveLayer_Points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
layer.draws.Add(renderDraw);
var blurLayer = this._createBlurLayer(layer, filter.sigmaX, filter.sigmaY, layer);

this._saveLayer_Points[2],
this._saveLayer_Points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
layer.draws.Add(renderDraw);
}
}

return;
}
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint, mesh, layer);
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint.Value, mesh, layer);
currentLayer.draws.Add(renderDraw);
}

}
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, _drawPathDrawMeshCallbackDelegate drawCallback,
Paint paint, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh mesh) {
uiPaint paint, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh mesh) {
var textureWidth = Mathf.CeilToInt(maskBounds.width * this._devicePixelRatio);
if (textureWidth < 1) {
textureWidth = 1;

var maskState = maskLayer.states[maskLayer.states.Count - 1];
maskState.matrix = parentState.matrix;
drawCallback.Invoke(Paint.shapeOnly(paint), mesh, convex, alpha, tex, texBound, textMesh);
drawCallback.Invoke(uiPaint.shapeOnly(paint), mesh, convex, alpha, tex, texBound, textMesh);
var removed = this._layers.removeLast();
D.assert(removed == maskLayer);

return blurYLayer;
}
void _drawWithMaskFilter(uiRect meshBounds, Paint paint, MaskFilter maskFilter,
void _drawWithMaskFilter(uiRect meshBounds, uiPaint paint, uiMaskFilter maskFilter,
uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh,
_drawPathDrawMeshCallbackDelegate drawCallback) {
var layer = this._currentLayer;

layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
}
delegate void _drawPathDrawMeshCallbackDelegate(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh);
delegate void _drawPathDrawMeshCallbackDelegate(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh);
void _drawPathDrawMeshCallback(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(mesh.bounds)) {
mesh.dispose();
return;

}
}
void _drawPathDrawMeshCallback2(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(mesh.bounds)) {
mesh.dispose();
return;

layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate()));
}
void _drawTextDrawMeshCallback(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(textBlobBounds)) {
textMesh.dispose();
return;

mesh.dispose();
}
void _drawPath(uiPath path, Paint paint) {
void _drawPath(uiPath path, uiPaint paint) {
D.assert(paint != null);
if (paint.style == PaintingStyle.fill) {
var state = this._currentLayer.currentState;

var fillMesh = cache.getFillMesh(out convex);
var mesh = fillMesh.transform(state.matrix);
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter, mesh, convex, 0, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback);
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, convex, 0, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback);
return;
}

var mesh = strokenMesh.transform(state.matrix);
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter, mesh, false, alpha, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback2);
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, false, alpha, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback2);
return;
}

void _drawImage(Image image, uiOffset offset, Paint paint) {
void _drawImage(Image image, uiOffset offset, uiPaint paint) {
D.assert(paint != null);
this._drawImageRect(image,
null,

paint);
}
void _drawImageRect(Image image, uiRect? src, uiRect dst, Paint paint) {
void _drawImageRect(Image image, uiRect? src, uiRect dst, uiPaint paint) {
D.assert(paint != null);
if (src == null) {
src = uiRectHelper.one;

layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image));
}
void _drawImageNine(Image image, uiRect? src, uiRect center, uiRect dst, Paint paint) {
void _drawImageNine(Image image, uiRect? src, uiRect center, uiRect dst, uiPaint paint) {
D.assert(paint != null);
var scaleX = 1f / image.width;
var scaleY = 1f / image.height;

break;
case DrawSaveLayer cmd: {
saveCount++;
this._saveLayer(uiRectHelper.fromRect(cmd.rect), cmd.paint);
this._saveLayer(uiRectHelper.fromRect(cmd.rect), uiPaint.fromPaint(cmd.paint));
break;
}
case DrawRestore _: {

}
case DrawPath cmd: {
var uipath = uiPath.fromPath(cmd.path);
this._drawPath(uipath, cmd.paint);
this._drawPath(uipath, uiPaint.fromPaint(cmd.paint));
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint);
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, uiPaint.fromPaint(cmd.paint));
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst), cmd.paint);
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst), uiPaint.fromPaint(cmd.paint));
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.center), uiRectHelper.fromRect(cmd.dst), cmd.paint);
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.center), uiRectHelper.fromRect(cmd.dst), uiPaint.fromPaint(cmd.paint));
break;
}
case DrawPicture cmd: {

case DrawTextBlob cmd: {
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint);
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value, uiPaint.fromPaint(cmd.paint));
break;
}
default:

}
}
void _drawTextBlob(TextBlob textBlob, uiOffset offset, Paint paint) {
void _drawTextBlob(TextBlob textBlob, uiOffset offset, uiPaint paint) {
D.assert(paint != null);
var state = this._currentLayer.currentState;
var scale = state.scale * this._devicePixelRatio;

var tex = font.material.mainTexture;
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {
this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter, null, false, 0, tex, textBlobBounds, mesh, this._drawTextDrawMeshCallback);
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter.Value, null, false, 0, tex, textBlobBounds, mesh, this._drawTextDrawMeshCallback);
return;
}

27
Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_shader.cs


static readonly int _mfImgIncId = Shader.PropertyToID("_mf_imgInc");
static readonly int _mfKernelId = Shader.PropertyToID("_mf_kernel");
static Vector4 _colorToVector4(uiColor c) {
return new Vector4(
c.red / 255f,
c.green / 255f,
c.blue / 255f,
c.alpha / 255f
);
}
static Vector4 _colorToVector4(Color c) {
return new Vector4(
c.red / 255f,

}
static void _getShaderPassAndProps(
PictureFlusher.RenderLayer layer, Paint paint, uiMatrix3? meshMatrix, float alpha,
PictureFlusher.RenderLayer layer, uiPaint paint, uiMatrix3? meshMatrix, float alpha,
out int pass, out MaterialPropertyBlockWrapper props) {
Vector4 viewport = layer.viewport;

}
}
public static PictureFlusher.CmdDraw convexFill(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw convexFill(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh) {
var mat = _convexFillMat.getMaterial(paint.blendMode, layer.ignoreClip);
_getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, out var pass, out var props);

);
}
public static PictureFlusher.CmdDraw fill1(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw fill1(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh) {
var mat = _fill1Mat.getMaterial(paint.blendMode);
_getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, out var pass, out var props);

return ret;
}
public static PictureFlusher.CmdDraw stroke0(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw stroke0(PictureFlusher.RenderLayer layer, uiPaint paint,
float alpha, uiMeshMesh mesh) {
var mat = _stroke0Mat.getMaterial(paint.blendMode, layer.ignoreClip);
_getShaderPassAndProps(layer, paint, mesh.matrix, alpha, out var pass, out var props);

);
}
public static PictureFlusher.CmdDraw tex(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw tex(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, Image image) {
var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);
_getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, out var pass, out var props);

);
}
public static PictureFlusher.CmdDraw texRT(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texRT(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, PictureFlusher.RenderLayer renderLayer) {
var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);
_getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, out var pass, out var props);

);
}
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, uiPaint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, uiPaint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, Paint paint,
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, TextBlobMesh textMesh, Texture tex) {
var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);

4
Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/render_layer.cs


public FilterMode filterMode = FilterMode.Point;
public bool noMSAA = false;
public uiRect layerBounds;
public Paint layerPaint;
public uiPaint? layerPaint;
public readonly List<RenderCmd> draws = new List<RenderCmd>(128);
public readonly List<RenderLayer> layers = new List<RenderLayer>(16);
public readonly List<State> states = new List<State>(16);

}
public static RenderLayer create(int rtID = 0, int width = 0, int height = 0, FilterMode filterMode = FilterMode.Point,
bool noMSAA = false, uiRect? layerBounds = null, Paint layerPaint = null, bool ignoreClip = true) {
bool noMSAA = false, uiRect? layerBounds = null, uiPaint? layerPaint = null, bool ignoreClip = true) {
D.assert(layerBounds != null);
var newLayer = ItemPoolManager.alloc<RenderLayer>();
newLayer.rtID = rtID;

58
Runtime/ui/utils/renderer/common/base_canvas.cs


this._saveCount++;
this._recorder.addDrawCmd(uiDrawSaveLayer.create(
rect : uiRectHelper.fromRect(rect),
paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

}
public void drawLine(Offset from, Offset to, Paint paint) {
var path = new Path();
var path = new uiPath();
path : uiPath.fromPath(path),
paint : new Paint(paint)
path : path,
paint : uiPaint.fromPaint(paint)
));
}

return;
}
var path = new Path();
var path = new uiPath();
path : uiPath.fromPath(path),
paint : new Paint(paint)
path : path,
paint : uiPaint.fromPaint(paint)
var path = new Path();
var path = new uiPath();
path : uiPath.fromPath(path),
paint : new Paint(paint)
path : path,
paint : uiPaint.fromPaint(paint)
var path = new Path();
var path = new uiPath();
path : uiPath.fromPath(path),
paint : new Paint(paint)
path : path,
paint : uiPaint.fromPaint(paint)
));
}

var path = new Path();
var path = new uiPath();
path : uiPath.fromPath(path),
paint : new Paint(paint)
path : path,
paint : uiPaint.fromPaint(paint)
var path = new Path();
var path = new uiPath();
path : uiPath.fromPath(path),
paint : new Paint(paint)
path : path,
paint : uiPaint.fromPaint(paint)
var path = new Path();
var path = new uiPath();
if (useCenter) {
var center = rect.center;

}
this._recorder.addDrawCmd(uiDrawPath.create(
path : uiPath.fromPath(path),
paint : new Paint(paint)
path : path,
paint : uiPaint.fromPaint(paint)
));
}

paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

offset : uiOffset.fromOffset(offset),
paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

src : null,
dst : uiRectHelper.fromRect(dst),
paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

src : uiRectHelper.fromRect(src),
dst : uiRectHelper.fromRect(dst),
paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

src : null,
center : uiRectHelper.fromRect(center),
dst : uiRectHelper.fromRect(dst),
paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

src : uiRectHelper.fromRect(src),
center : uiRectHelper.fromRect(center),
dst : uiRectHelper.fromRect(dst),
paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

this._recorder.addDrawCmd(uiDrawTextBlob.create(
textBlob : textBlob,
offset : uiOffset.fromOffset(offset),
paint : new Paint(paint)
paint : uiPaint.fromPaint(paint)
));
}

30
Runtime/ui/utils/renderer/common/draw_cmd.cs


public uiDrawSaveLayer() {
}
public static uiDrawSaveLayer create(uiRect? rect, Paint paint) {
public static uiDrawSaveLayer create(uiRect? rect, uiPaint paint) {
var drawSaveLayer = ItemPoolManager.alloc<uiDrawSaveLayer>();
drawSaveLayer.rect = rect;
drawSaveLayer.paint = paint;

public override void clear() {
this.rect = null;
this.paint = null;
public Paint paint;
public uiPaint paint;
}
public class uiDrawRestore : uiDrawCmd {

}
public static uiDrawPath create(uiPath path, Paint paint) {
public static uiDrawPath create(uiPath path, uiPaint paint) {
var drawPath = ItemPoolManager.alloc<uiDrawPath>();
drawPath.path = path;
drawPath.paint = paint;

public override void clear() {
this.path.dispose();
this.path = null;
this.paint = null;
public Paint paint;
public uiPaint paint;
}
public class uiDrawImage : uiDrawCmd {

public static uiDrawImage create(Image image, uiOffset? offset, Paint paint) {
public static uiDrawImage create(Image image, uiOffset? offset, uiPaint paint) {
var drawImage = ItemPoolManager.alloc<uiDrawImage>();
drawImage.image = image;
drawImage.offset = offset;

public override void clear() {
this.image = null;
this.offset = null;
this.paint = null;
public Paint paint;
public uiPaint paint;
}
public class uiDrawImageRect : uiDrawCmd {

public static uiDrawImageRect create(Image image, uiRect? src, uiRect? dst, Paint paint) {
public static uiDrawImageRect create(Image image, uiRect? src, uiRect? dst, uiPaint paint) {
var drawImageRect = ItemPoolManager.alloc<uiDrawImageRect>();
drawImageRect.image = image;
drawImageRect.src = src;

this.image = null;
this.src = null;
this.dst = null;
this.paint = null;
public Paint paint;
public uiPaint paint;
}
public class uiDrawImageNine : uiDrawCmd {

public static uiDrawImageNine create(Image image, uiRect? src, uiRect? center, uiRect? dst, Paint paint) {
public static uiDrawImageNine create(Image image, uiRect? src, uiRect? center, uiRect? dst, uiPaint paint) {
var drawImageNine = ItemPoolManager.alloc<uiDrawImageNine>();
drawImageNine.image = image;
drawImageNine.src = src;

this.src = null;
this.center = null;
this.dst = null;
this.paint = null;
}
public Image image;

public Paint paint;
public uiPaint paint;
}
public class uiDrawPicture : uiDrawCmd {

}
public static uiDrawTextBlob create(TextBlob textBlob, uiOffset? offset, Paint paint) {
public static uiDrawTextBlob create(TextBlob textBlob, uiOffset? offset, uiPaint paint) {
var drawTextBlob = ItemPoolManager.alloc<uiDrawTextBlob>();
drawTextBlob.textBlob = textBlob;
drawTextBlob.offset = offset;

public override void clear() {
this.textBlob = null;
this.offset = null;
this.paint = null;
public Paint paint;
public uiPaint paint;
}
}

6
Runtime/ui/utils/renderer/common/paint.cs


}
return new uiPaint(
color : uiColor.fromColor(paint.color),
color : paint.color == null ? (uiColor?)null : uiColor.fromColor(paint.color),
blendMode: paint.blendMode,
style: paint.style,
strokeWidth: paint.strokeWidth,

filterMode: paint.filterMode,
colorFilter: uiColorFilter.mode(uiColor.fromColor(paint.colorFilter.color), paint.colorFilter.blendMode),
maskFilter: uiMaskFilter.blur(paint.maskFilter.style, paint.maskFilter.sigma),
colorFilter: paint.colorFilter == null ? (uiColorFilter?) null : uiColorFilter.mode(uiColor.fromColor(paint.colorFilter.color), paint.colorFilter.blendMode),
maskFilter: paint.maskFilter == null ? (uiMaskFilter?) null : uiMaskFilter.blur(paint.maskFilter.style, paint.maskFilter.sigma),
backdrop: filter,
shader: paint.shader,
invertColors: paint.invertColors

8
Runtime/ui/utils/renderer/common/picture.cs


mesh = strokenMesh.transform(state.xform);
}
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {
float sigma = scale * paint.maskFilter.sigma;
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
float sigma = scale * paint.maskFilter.Value.sigma;
float sigma3 = 3 * sigma;
this._addPaintBounds(uiRectHelper.inflate(mesh.bounds, sigma3));
} else {

rect = state.xform.mapRect(rect);
var paint = cmd.paint;
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {
float sigma = scale * paint.maskFilter.sigma;
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
float sigma = scale * paint.maskFilter.Value.sigma;
float sigma3 = 3 * sigma;
this._addPaintBounds(uiRectHelper.inflate(rect, sigma3));
} else {

18
Runtime/ui/utils/renderer/compositeCanvas/flow/physical_shape_layer.cs


}
}
Paint _shadowPaint = new Paint();
public override void paint(PaintContext context) {
if (this._elevation != 0) {
drawShadow(context.canvas, this._path, this._shadow_color, this._elevation,

Paint paint = new Paint {color = this._color};
//todo: xingwei.zhu: process according to different clipBehavior, currently use antiAlias as default
context.canvas.drawPath(this._path, paint);
this._shadowPaint.color = this._color;
context.canvas.drawPath(this._path, this._shadowPaint);
context.canvas.save();
context.canvas.clipPath(this._path);

const float kAmbientAlpha = 0.039f;
const float kLightHeight = 600f;
const float kLightRadius = 800f;
const float kSpotAlpha = ShadowUtils.kUseFastShadow ? 0.1f : 0.25f;
float kAmbientAlpha = 0.039f;
float kSpotAlpha = ShadowUtils.kUseFastShadow ? 0.1f : 0.25f;
float kLightHeight = 600f;
float kLightRadius = 800f;
Rect bounds = path.getBounds();
float shadow_x = (bounds.left + bounds.right) / 2f;
float shadow_y = bounds.top - 600.0f;

133
Runtime/ui/utils/renderer/geometry/path/path.cs


this._appendLineTo(rect.right, rect.top);
this._appendClose();
}
public void addRect(Rect rect) {
this._appendMoveTo(rect.left, rect.top);
this._appendLineTo(rect.left, rect.bottom);
this._appendLineTo(rect.right, rect.bottom);
this._appendLineTo(rect.right, rect.top);
this._appendClose();
}
public void addRRect(RRect rrect) {
float w = rrect.width;

this._appendBezierTo(x + rxTL * (1 - _KAPPA90), y,
x, y + ryTL * (1 - _KAPPA90), x, y + ryTL);
this._appendClose();
}
public void moveTo(float x, float y) {
this._appendMoveTo(x, y);
}
public void lineTo(float x, float y) {
this._appendLineTo(x, y);
}
public void winding(PathWinding dir) {
this._appendWinding((float) dir);
}
public void addEllipse(float cx, float cy, float rx, float ry) {
this._appendMoveTo(cx - rx, cy);
this._appendBezierTo(cx - rx, cy + ry * _KAPPA90,
cx - rx * _KAPPA90, cy + ry, cx, cy + ry);
this._appendBezierTo(cx + rx * _KAPPA90, cy + ry,
cx + rx, cy + ry * _KAPPA90, cx + rx, cy);
this._appendBezierTo(cx + rx, cy - ry * _KAPPA90,
cx + rx * _KAPPA90, cy - ry, cx, cy - ry);
this._appendBezierTo(cx - rx * _KAPPA90, cy - ry,
cx - rx, cy - ry * _KAPPA90, cx - rx, cy);
this._appendClose();
}
public void addCircle(float cx, float cy, float r) {
this.addEllipse(cx, cy, r, r);
}
public void arcTo(Rect rect, float startAngle, float sweepAngle, bool forceMoveTo = true) {
var mat = Matrix3.makeScale(rect.width / 2, rect.height / 2);
var center = rect.center;
mat.postTranslate(center.dx, center.dy);
this._addArcCommands(0, 0, 1, startAngle, startAngle + sweepAngle,
sweepAngle >= 0 ? PathWinding.clockwise : PathWinding.counterClockwise, forceMoveTo, mat);
}
public void close() {
this._appendClose();
}
void _addArcCommands(
float cx, float cy, float r, float a0, float a1,
PathWinding dir, bool forceMoveTo, Matrix3 transform = null) {
// Clamp angles
float da = a1 - a0;
if (dir == PathWinding.clockwise) {
if (Mathf.Abs(da) >= Mathf.PI * 2) {
da = Mathf.PI * 2;
} else {
while (da < 0.0f) {
da += Mathf.PI * 2;
}
if (da <= 1e-5) {
return;
}
}
} else {
if (Mathf.Abs(da) >= Mathf.PI * 2) {
da = -Mathf.PI * 2;
} else {
while (da > 0.0f) {
da -= Mathf.PI * 2;
}
if (da >= -1e-5) {
return;
}
}
}
// Split arc into max 90 degree segments.
int ndivs = Mathf.Max(1, Mathf.Min((int) (Mathf.Abs(da) / (Mathf.PI * 0.5f) + 0.5f), 5));
float hda = (da / ndivs) / 2.0f;
float kappa = Mathf.Abs(4.0f / 3.0f * (1.0f - Mathf.Cos(hda)) / Mathf.Sin(hda));
if (dir == PathWinding.counterClockwise) {
kappa = -kappa;
}
PathCommand move = (forceMoveTo || this._commands.Count == 0) ? PathCommand.moveTo : PathCommand.lineTo;
float px = 0, py = 0, ptanx = 0, ptany = 0;
for (int i = 0; i <= ndivs; i++) {
float a = a0 + da * (i / (float) ndivs);
float dx = Mathf.Cos(a);
float dy = Mathf.Sin(a);
float x = cx + dx * r;
float y = cy + dy * r;
float tanx = -dy * r * kappa;
float tany = dx * r * kappa;
if (i == 0) {
float x1 = x, y1 = y;
if (transform != null) {
transform.mapXY(x1, y1, out x1, out y1);
}
if (move == PathCommand.moveTo) {
this._appendMoveTo(x1, y1);
} else {
this._appendLineTo(x1, y1);
}
} else {
float c1x = px + ptanx;
float c1y = py + ptany;
float c2x = x - tanx;
float c2y = y - tany;
float x1 = x;
float y1 = y;
if (transform != null) {
transform.mapXY(c1x, c1y, out c1x, out c1y);
transform.mapXY(c2x, c2y, out c2x, out c2y);
transform.mapXY(x1, y1, out x1, out y1);
}
this._appendBezierTo(c1x, c1y, c2x, c2y, x1, y1);
}
px = x;
py = y;
ptanx = tanx;
ptany = tany;
}
}
public static uiPath fromPath(Path path) {

正在加载...
取消
保存