浏览代码

color, paint => struct

/main
xingwei.zhu 5 年前
当前提交
631f4f96
共有 4 个文件被更改,包括 272 次插入0 次删除
  1. 82
      Runtime/ui/utils/renderer/common/color.cs
  2. 11
      Runtime/ui/utils/renderer/common/color.cs.meta
  3. 168
      Runtime/ui/utils/renderer/common/paint.cs
  4. 11
      Runtime/ui/utils/renderer/common/paint.cs.meta

82
Runtime/ui/utils/renderer/common/color.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
public struct uiColor {
public readonly long value;
public uiColor(long value) {
this.value = value & 0xFFFFFFFF;
}
public static readonly uiColor clear = new uiColor(0x00000000);
public static readonly uiColor black = new uiColor(0xFF000000);
public static readonly uiColor white = new uiColor(0xFFFFFFFF);
public int alpha {
get { return (int) ((0xff000000 & this.value) >> 24); }
}
public float opacity {
get { return this.alpha / 255.0f; }
}
public int red {
get { return (int) ((0x00ff0000 & this.value) >> 16); }
}
public int green {
get { return (int) ((0x0000ff00 & this.value) >> 8); }
}
public int blue {
get { return (int) ((0x000000ff & this.value) >> 0); }
}
public static uiColor fromColor(Color color) {
return new uiColor(color.value);
}
public static uiColor fromARGB(int a, int r, int g, int b) {
return new uiColor(
(((a & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF);
}
public static uiColor fromRGBO(int r, int g, int b, float opacity) {
return new uiColor(
((((int) (opacity * 0xff) & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF);
}
public uiColor withAlpha(int a) {
return fromARGB(a, this.red, this.green, this.blue);
}
public uiColor withOpacity(float opacity) {
return this.withAlpha((int) (opacity * 255));
}
static float _linearizeColorComponent(float component) {
if (component <= 0.03928f) {
return component / 12.92f;
}
return Mathf.Pow((component + 0.055f) / 1.055f, 2.4f);
}
public float computeLuminance() {
float R = _linearizeColorComponent(this.red / 0xFF);
float G = _linearizeColorComponent(this.green / 0xFF);
float B = _linearizeColorComponent(this.blue / 0xFF);
return 0.2126f * R + 0.7152f * G + 0.0722f * B;
}
}
}

11
Runtime/ui/utils/renderer/common/color.cs.meta


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

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


using UnityEngine;
namespace Unity.UIWidgets.ui {
public struct uiMaskFilter {
uiMaskFilter(BlurStyle style, float sigma) {
this.style = style;
this.sigma = sigma;
}
public static uiMaskFilter blur(BlurStyle style, float sigma) {
return new uiMaskFilter(style, sigma);
}
public readonly BlurStyle style;
public readonly float sigma;
}
public struct uiColorFilter {
uiColorFilter(uiColor color, BlendMode blendMode) {
this.color = color;
this.blendMode = blendMode;
}
public static uiColorFilter mode(uiColor color, BlendMode blendMode) {
return new uiColorFilter(color, blendMode);
}
public readonly uiColor color;
public readonly BlendMode blendMode;
}
public interface uiImageFilter {
}
public static class uiImageFilterHelper {
public static uiImageFilter blur(float sigmaX = 0.0f, float sigmaY = 0.0f) {
return new _uiBlurImageFilter(sigmaX, sigmaY);
}
public static uiImageFilter matrix(uiMatrix3 transform, FilterMode filterMode = FilterMode.Point) {
return new _uiMatrixImageFilter(transform, filterMode);
}
}
struct _uiBlurImageFilter : uiImageFilter {
public _uiBlurImageFilter(float sigmaX, float sigmaY) {
this.sigmaX = sigmaX;
this.sigmaY = sigmaY;
}
public readonly float sigmaX;
public readonly float sigmaY;
}
struct _uiMatrixImageFilter : uiImageFilter {
public _uiMatrixImageFilter(uiMatrix3 transform, FilterMode filterMode) {
this.transform = transform;
this.filterMode = filterMode;
}
public readonly uiMatrix3 transform;
public readonly FilterMode filterMode;
}
public struct uiPaint {
static readonly uiColor _kColorDefault = new uiColor(0xFFFFFFFF);
public uiColor color;
public BlendMode blendMode;
public PaintingStyle style;
public float strokeWidth;
public StrokeCap strokeCap;
public StrokeJoin strokeJoin;
public float strokeMiterLimit;
public FilterMode filterMode;
public uiColorFilter? colorFilter;
public uiMaskFilter? maskFilter;
public uiImageFilter backdrop;
public PaintShader shader;
public bool invertColors;
public uiPaint(
uiColor? color = null,
BlendMode blendMode = BlendMode.srcOver,
PaintingStyle style = PaintingStyle.fill,
float strokeWidth = 0f,
StrokeCap strokeCap = StrokeCap.butt,
StrokeJoin strokeJoin = StrokeJoin.miter,
float strokeMiterLimit = 4.0f,
FilterMode filterMode = FilterMode.Point,
uiColorFilter? colorFilter = null,
uiMaskFilter? maskFilter = null,
uiImageFilter backdrop = null,
PaintShader shader = null,
bool invertColors = false
) {
this.color = color ?? _kColorDefault;
this.blendMode = blendMode;
this.style = style;
this.strokeWidth = strokeWidth;
this.strokeCap = strokeCap;
this.strokeJoin = strokeJoin;
this.strokeMiterLimit = strokeMiterLimit;
this.filterMode = filterMode;
this.colorFilter = colorFilter;
this.maskFilter = maskFilter;
this.backdrop = backdrop;
this.shader = shader;
this.invertColors = invertColors;
}
public uiPaint(uiPaint paint) {
this.color = paint.color;
this.blendMode = paint.blendMode;
this.style = paint.style;
this.strokeWidth = paint.strokeWidth;
this.strokeCap = paint.strokeCap;
this.strokeJoin = paint.strokeJoin;
this.strokeMiterLimit = paint.strokeMiterLimit;
this.filterMode = paint.filterMode;
this.colorFilter = paint.colorFilter;
this.maskFilter = paint.maskFilter;
this.backdrop = paint.backdrop;
this.shader = paint.shader;
this.invertColors = paint.invertColors;
}
public static uiPaint shapeOnly(uiPaint paint) {
return new uiPaint(
style : paint.style,
strokeWidth : paint.strokeWidth,
strokeCap : paint.strokeCap,
strokeJoin : paint.strokeJoin,
strokeMiterLimit : paint.strokeMiterLimit
);
}
public static uiPaint fromPaint(Paint paint) {
uiImageFilter filter = null;
if (paint.backdrop is _BlurImageFilter) {
var blurFilter = (_BlurImageFilter) paint.backdrop;
filter = uiImageFilterHelper.blur(blurFilter.sigmaX, blurFilter.sigmaY);
} else if (paint.backdrop is _MatrixImageFilter) {
var matrixFilter = (_MatrixImageFilter) paint.backdrop;
filter = uiImageFilterHelper.matrix(uiMatrix3.fromMatrix3(matrixFilter.transform),
matrixFilter.filterMode);
}
return new uiPaint(
color : uiColor.fromColor(paint.color),
blendMode: paint.blendMode,
style: paint.style,
strokeWidth: paint.strokeWidth,
strokeCap: paint.strokeCap,
strokeJoin: paint.strokeJoin,
strokeMiterLimit: paint.strokeMiterLimit,
filterMode: paint.filterMode,
colorFilter: uiColorFilter.mode(uiColor.fromColor(paint.colorFilter.color), paint.colorFilter.blendMode),
maskFilter: uiMaskFilter.blur(paint.maskFilter.style, paint.maskFilter.sigma),
backdrop: filter,
shader: paint.shader,
invertColors: paint.invertColors
);
}
}
}

11
Runtime/ui/utils/renderer/common/paint.cs.meta


fileFormatVersion: 2
guid: 9bde84e37c33148879131974b64a62aa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存