浏览代码

update format

/main
gewentao 6 年前
当前提交
f4905eb9
共有 21 个文件被更改,包括 259 次插入527 次删除
  1. 45
      Assets/UIWidgets/Tests/CanvasAndLayers.cs
  2. 60
      Assets/UIWidgets/painting/alignment.cs
  3. 14
      Assets/UIWidgets/painting/binding.cs
  4. 25
      Assets/UIWidgets/painting/box_fit.cs
  5. 62
      Assets/UIWidgets/painting/decoration_image.cs
  6. 81
      Assets/UIWidgets/painting/image_cache.cs
  7. 52
      Assets/UIWidgets/painting/image_provider.cs
  8. 73
      Assets/UIWidgets/painting/image_stream.cs
  9. 24
      Assets/UIWidgets/promise/EnumerableExt.cs
  10. 40
      Assets/UIWidgets/promise/PromiseHelpers.cs
  11. 18
      Assets/UIWidgets/promise/PromiseStateException.cs
  12. 77
      Assets/UIWidgets/promise/PromiseTimer.cs
  13. 33
      Assets/UIWidgets/promise/Tuple.cs
  14. 9
      Assets/UIWidgets/rendering/box.cs
  15. 138
      Assets/UIWidgets/rendering/image.cs
  16. 8
      Assets/UIWidgets/ui/geometry.cs
  17. 3
      Assets/UIWidgets/ui/painting/canvas.cs
  18. 3
      Assets/UIWidgets/ui/painting/canvas_impl.cs
  19. 3
      Assets/UIWidgets/ui/painting/draw_cmd.cs
  20. 3
      Assets/UIWidgets/ui/painting/image.cs
  21. 15
      Assets/UIWidgets/ui/painting/painting.cs

45
Assets/UIWidgets/Tests/CanvasAndLayers.cs


private readonly string[] _optionStrings;
private int _selected;
CanvasAndLayers() {
this._options = new Action[] {
this.drawPloygon4,

void OnGUI() {
this._selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings);
if (_selected == 3)
{
if (GUI.Button(new UnityEngine.Rect(20, 50, 100, 20), "Image 1"))
{
if (_selected == 3) {
if (GUI.Button(new UnityEngine.Rect(20, 50, 100, 20), "Image 1")) {
"http://a.hiphotos.baidu.com/image/h%3D300/sign=10b374237f0e0cf3bff748fb3a47f23d/adaf2edda3cc7cd90df1ede83401213fb80e9127.jpg");
"http://a.hiphotos.baidu.com/image/h%3D300/sign=10b374237f0e0cf3bff748fb3a47f23d/adaf2edda3cc7cd90df1ede83401213fb80e9127.jpg");
if (GUI.Button(new UnityEngine.Rect(20, 150, 100, 20), "Image 2"))
{
if (GUI.Button(new UnityEngine.Rect(20, 150, 100, 20), "Image 2")) {
"http://a.hiphotos.baidu.com/image/pic/item/cf1b9d16fdfaaf519b4aa960875494eef11f7a47.jpg");
"http://a.hiphotos.baidu.com/image/pic/item/cf1b9d16fdfaaf519b4aa960875494eef11f7a47.jpg");
if (GUI.Button(new UnityEngine.Rect(20, 250, 100, 20), "Image 3"))
{
if (GUI.Button(new UnityEngine.Rect(20, 250, 100, 20), "Image 3")) {
"http://a.hiphotos.baidu.com/image/pic/item/2f738bd4b31c8701c1e721dd2a7f9e2f0708ffbc.jpg");
"http://a.hiphotos.baidu.com/image/pic/item/2f738bd4b31c8701c1e721dd2a7f9e2f0708ffbc.jpg");
private void LoadImage(string url)
{
private void LoadImage(string url) {
Dictionary<string, string> headers = new Dictionary<string, string>();
NetworkImage networkImage = new NetworkImage(url, headers);
ImageConfiguration imageConfig = new ImageConfiguration();

editorCanvas.drawPicture(picture);
}
void drawImageRect()
{
if (_stream == null || _stream.completer == null || _stream.completer._currentImgae == null)
{
void drawImageRect() {
if (_stream == null || _stream.completer == null || _stream.completer._currentImgae == null) {
var paint = new Paint
{
var paint = new Paint {
color = new Color(0xFFFF0000),
};

);
}
void clipRect()
{
void clipRect() {
var pictureRecorder = new PictureRecorder();
var canvas = new RecorderCanvas(pictureRecorder);

60
Assets/UIWidgets/painting/alignment.cs


using System;
using UIWidgets.ui;
namespace UIWidgets.painting
{
public class Alignment : IEquatable<Alignment>
{
public Alignment(double x, double y)
{
namespace UIWidgets.painting {
public class Alignment : IEquatable<Alignment> {
public Alignment(double x, double y) {
this.x = x;
this.y = y;
}

public static readonly Alignment bottomCenter = new Alignment(0.0, 1.0);
public static readonly Alignment bottomRight = new Alignment(1.0, 1.0);
public Alignment add(Alignment other)
{
public Alignment add(Alignment other) {
public static Alignment operator -(Alignment a, Alignment b)
{
public static Alignment operator -(Alignment a, Alignment b) {
public static Alignment operator +(Alignment a, Alignment b)
{
public static Alignment operator +(Alignment a, Alignment b) {
public static Alignment operator -(Alignment a)
{
public static Alignment operator -(Alignment a) {
public static Alignment operator *(Alignment a, double b)
{
public static Alignment operator *(Alignment a, double b) {
public static Alignment operator /(Alignment a, double b)
{
public static Alignment operator /(Alignment a, double b) {
public static Alignment operator %(Alignment a, double b)
{
public static Alignment operator %(Alignment a, double b) {
public Offset alongOffset(Offset other)
{
public Offset alongOffset(Offset other) {
public Offset alongSize(Size other)
{
public Offset alongSize(Size other) {
public Offset withinRect(Rect rect)
{
public Offset withinRect(Rect rect) {
double halfWidth = rect.width / 2.0;
double halfHeight = rect.height / 2.0;
return new Offset(

}
public Rect inscribe(Size size, Rect rect)
{
public Rect inscribe(Size size, Rect rect) {
double halfWidthDelta = (rect.width - size.width) / 2.0;
double halfHeightDelta = (rect.height - size.height) / 2.0;
return Rect.fromLTWH(

);
}
public bool Equals(Alignment other)
{
public bool Equals(Alignment other) {
public override bool Equals(object obj)
{
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;

public override int GetHashCode()
{
unchecked
{
public override int GetHashCode() {
unchecked {
public static bool operator ==(Alignment a, Alignment b)
{
public static bool operator ==(Alignment a, Alignment b) {
public static bool operator !=(Alignment a, Alignment b)
{
public static bool operator !=(Alignment a, Alignment b) {
return !(a == b);
}
}

14
Assets/UIWidgets/painting/binding.cs


namespace UIWidgets.painting {
public class PaintingBinding
{
public class PaintingBinding {
public static PaintingBinding instance
{
public static PaintingBinding instance {
public ImageCache imageCache
{
public ImageCache imageCache {
public ImageCache createImageCache()
{
public ImageCache createImageCache() {
public void initInstances() {
_instance = this;
_imageCache = createImageCache();

25
Assets/UIWidgets/painting/box_fit.cs


using UIWidgets.ui;
using System;
namespace UIWidgets.painting
{
public enum BoxFit
{
namespace UIWidgets.painting {
public enum BoxFit {
fill,
contain,
cover,

scaleDown,
}
public class FittedSizes
{
public FittedSizes(Size source, Size destination)
{
public class FittedSizes {
public FittedSizes(Size source, Size destination) {
this.source = source;
this.destination = destination;
}

public static FittedSizes applyBoxFit(BoxFit fit, Size inputSize, Size outputSize)
{
public static FittedSizes applyBoxFit(BoxFit fit, Size inputSize, Size outputSize) {
switch (fit)
{
switch (fit) {
case BoxFit.fill:
sourceSize = inputSize;
destinationSize = outputSize;

sourceSize.height * outputSize.width / sourceSize.width);
break;
case BoxFit.cover:
if (outputSize.width / outputSize.height > inputSize.width / inputSize.height)
{
if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) {
else
{
else {
sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height,
inputSize.height);
}

destinationSize = new Size(outputSize.width, outputSize.width / aspectRatio);
break;
}
return new FittedSizes(sourceSize, destinationSize);
}
}

62
Assets/UIWidgets/painting/decoration_image.cs


using UIWidgets.ui;
using System.Collections.Generic;
namespace UIWidgets.painting
{
namespace UIWidgets.painting {
public enum ImageRepeat
{
public enum ImageRepeat {
/// Repeat the image in both the x and y directions until the box is filled.
repeat,

noRepeat,
}
public class DecorationImage
{
public DecorationImage()
{
public class DecorationImage {
public DecorationImage() {
public static class DecorationImageUtil
{
public static void paintImage(Canvas canvas, Rect rect, ui.Image image, BoxFit fit, Rect centerSlice, Alignment alignment = null,
ImageRepeat repeat = ImageRepeat.noRepeat, bool flipHorizontally = false)
{
public static class DecorationImageUtil {
public static void paintImage(Canvas canvas, Rect rect, ui.Image image, BoxFit fit, Rect centerSlice,
Alignment alignment = null,
ImageRepeat repeat = ImageRepeat.noRepeat) {
if (rect.isEmpty)
return;
alignment = alignment ?? Alignment.center;

if (centerSlice != null)
{
if (centerSlice != null) {
sliceBorder = new Offset(
centerSlice.left + inputSize.width - centerSlice.right,
centerSlice.top + inputSize.height - centerSlice.bottom

FittedSizes fittedSizes = FittedSizes.applyBoxFit(fit, inputSize, outputSize);
Size sourceSize = fittedSizes.source;
Size destinationSize = fittedSizes.destination;
if (centerSlice != null)
{
if (centerSlice != null) {
if (repeat != ImageRepeat.noRepeat && destinationSize == outputSize) {
repeat = ImageRepeat.noRepeat;
}

// to nearest-neighbor.
// paint.filterQuality = FilterQuality.low;
}
double dx = halfWidthDelta + (flipHorizontally ? - alignment.x : alignment.x) * halfWidthDelta;
double dx = halfWidthDelta + alignment.x * halfWidthDelta;
bool needSave = repeat != ImageRepeat.noRepeat || flipHorizontally;
bool needSave = repeat != ImageRepeat.noRepeat;
// todo flip
// if (flipHorizontally) {
// dx = -(rect.left + rect.width / 2.0);
// canvas.translate(-dx, 0.0);
// canvas.scale(-1.0, 1.0);
// canvas.translate(dx, 0.0);
// }
if (centerSlice == null) {
Rect sourceRect = alignment.inscribe(
fittedSizes.source, Offset.zero & inputSize

}
} else {
}
else {
foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
{
foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) {
ImageRepeat repeat)
{
ImageRepeat repeat) {
if (repeat == ImageRepeat.noRepeat)
{
if (repeat == ImageRepeat.noRepeat) {
tileRects.Add(fundamentalRect);
return tileRects;
}

double strideX = fundamentalRect.width;
double strideY = fundamentalRect.height;
if (repeat == ImageRepeat.repeat || repeat == ImageRepeat.repeatX)
{
if (repeat == ImageRepeat.repeat || repeat == ImageRepeat.repeatX) {
if (repeat == ImageRepeat.repeat || repeat == ImageRepeat.repeatY)
{
if (repeat == ImageRepeat.repeat || repeat == ImageRepeat.repeatY) {
for (int i = startX; i <= stopX; ++i)
{
for (int i = startX; i <= stopX; ++i) {
for (int j = startY; j <= stopY; ++j)
tileRects.Add(fundamentalRect.shift(new Offset(i * strideX, j * strideY)));
}

81
Assets/UIWidgets/painting/image_cache.cs


using System.Collections.Generic;
using Object = System.Object;
namespace UIWidgets.painting
{
public class ImageCache
{
namespace UIWidgets.painting {
public class ImageCache {
private const int _kDefaultSize = 1000;
private const int _kDefaultSizeBytes = 20 << 20; // 20 MiB

private int _maximumSize = _kDefaultSize;
public int maximumSize
{
public int maximumSize {
set
{
if (value == maximumSize)
{
set {
if (value == maximumSize) {
if (maximumSize == 0)
{
if (maximumSize == 0) {
else
{
else {
public int currentSize
{
public int currentSize {
public int maximumSizeBytes
{
public int maximumSizeBytes {
set
{
if (value == _maximumSizeBytes)
{
set {
if (value == _maximumSizeBytes) {
if (_maximumSizeBytes == 0)
{
if (_maximumSizeBytes == 0) {
else
{
else {
_checkCacheSize();
}
}

public int currentSizeBytes
{
public int currentSizeBytes {
public void clear()
{
public void clear() {
_cache.Clear();
_lruKeys.Clear();
_currentSizeBytes = 0;

public ImageStreamCompleter putIfAbsent(Object key, Loader loader)
{
public ImageStreamCompleter putIfAbsent(Object key, Loader loader) {
if (_pendingImages.TryGetValue(key, out result))
{
if (_pendingImages.TryGetValue(key, out result)) {
if (_cache.TryGetValue(key, out image))
{
if (_cache.TryGetValue(key, out image)) {
if (image != null)
{
if (image != null) {
if (maximumSize > 0 && maximumSizeBytes > 0)
{
if (maximumSize > 0 && maximumSizeBytes > 0) {
result.addListener((info, syncCall) =>
{
result.addListener((info, syncCall) => {
if (maximumSizeBytes > 0 && imageSize > maximumSizeBytes)
{
if (maximumSizeBytes > 0 && imageSize > maximumSizeBytes) {
_maximumSize = imageSize + 1000;
}

return result;
}
void _checkCacheSize()
{
while (_currentSizeBytes > _maximumSizeBytes || _cache.Count > _maximumSize)
{
void _checkCacheSize() {
while (_currentSizeBytes > _maximumSizeBytes || _cache.Count > _maximumSize) {
if (image != null && removed)
{
if (image != null && removed) {
_currentSizeBytes -= image.sizeBytes;
_lruKeys.Remove(key);
}

public class _CachedImage
{
public _CachedImage(ImageStreamCompleter completer, int sizeBytes)
{
public class _CachedImage {
public _CachedImage(ImageStreamCompleter completer, int sizeBytes) {
this.completer = completer;
this.sizeBytes = sizeBytes;
}

52
Assets/UIWidgets/painting/image_provider.cs


using UIWidgets.ui;
using UnityEngine;
namespace UIWidgets.painting
{
public abstract class ImageProvider<T>
{
public ImageStream resolve(ImageConfiguration configuration)
{
namespace UIWidgets.painting {
public abstract class ImageProvider<T> {
public ImageStream resolve(ImageConfiguration configuration) {
ImageStream stream = new ImageStream();
T obtainedKey;
obtainedKey = obtainKey(configuration);

public abstract T obtainKey(ImageConfiguration configuration);
}
public class NetworkImage : ImageProvider<NetworkImage>
{
public NetworkImage(string url, Dictionary<string, string> headers, double scale = 1.0)
{
public class NetworkImage : ImageProvider<NetworkImage> {
public NetworkImage(string url, Dictionary<string, string> headers, double scale = 1.0) {
this.url = url;
this.headers = headers;
this.scale = scale;

/// The HTTP headers that will be used with [HttpClient.get] to fetch image from network.
Dictionary<string, string> headers;
public override NetworkImage obtainKey(ImageConfiguration configuration)
{
public override NetworkImage obtainKey(ImageConfiguration configuration) {
public override ImageStreamCompleter load(NetworkImage key)
{
public override ImageStreamCompleter load(NetworkImage key) {
public static IPromise<ImageInfo> _loadAsync(NetworkImage key)
{
public static IPromise<ImageInfo> _loadAsync(NetworkImage key) {
using (var client = new WebClient())
{
using (var client = new WebClient()) {
(s, ev) =>
{
if (ev.Error != null)
{
(s, ev) => {
if (ev.Error != null) {
else
{
else {
var bytes = ev.Result;
var imageInfo = new ImageInfo(new ui.Image(
bytes

return promise; // Return the promise so the caller can await resolution (or error).
}
public override string ToString()
{
public override string ToString() {
public bool Equals(NetworkImage other) {
return this.url.Equals(other.url) && this.scale.Equals(other.scale);
}

if (object.ReferenceEquals(this, obj)) return true;
return obj is NetworkImage && this.Equals((NetworkImage) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.url.GetHashCode();

}
}
public class ImageConfiguration
{
public ImageConfiguration(Size size = null)
{
public class ImageConfiguration {
public ImageConfiguration(Size size = null) {
public ImageConfiguration copyWith(Size size = null)
{
public ImageConfiguration copyWith(Size size = null) {
return new ImageConfiguration(
size: size ?? this.size
);

73
Assets/UIWidgets/painting/image_stream.cs


using System.IO;
using System.Linq;
namespace UIWidgets.painting
{
namespace UIWidgets.painting {
public class ImageInfo
{
public ImageInfo(Image image, double scale = 1.0)
{
public class ImageInfo {
public ImageInfo(Image image, double scale = 1.0) {
this.image = image;
this.scale = scale;
}

}
public class ImageStream
{
public ImageStream()
{
public class ImageStream {
public ImageStream() {
public ImageStreamCompleter completer
{
public ImageStreamCompleter completer {
public void setCompleter(ImageStreamCompleter value)
{
public void setCompleter(ImageStreamCompleter value) {
if (_listeners != null)
{
if (_listeners != null) {
foreach (_ImageListenerPair listenerPair in initialListeners)
{
foreach (_ImageListenerPair listenerPair in initialListeners) {
_completer.addListener(
listenerPair.listener,
listenerPair.errorListener

}
}
public abstract class ImageStreamCompleter
{
public abstract class ImageStreamCompleter {
public void addListener(ImageListener listener, ImageErrorListerner onError)
{
public void addListener(ImageListener listener, ImageErrorListerner onError) {
if (_currentImgae != null)
{
try
{
if (_currentImgae != null) {
try {
catch (Exception e)
{
catch (Exception e) {
Console.WriteLine("{0} Exception caught.", e);
}
}

public void removeListener(ImageListener listener)
{
public void removeListener(ImageListener listener) {
public void setImage(ImageInfo image)
{
public void setImage(ImageInfo image) {
if (_listeners.Count == 0)
{
if (_listeners.Count == 0) {
foreach (var lp in _listeners.ToList())
{
foreach (var lp in _listeners.ToList()) {
try
{
try {
catch (Exception e)
{
catch (Exception e) {
public class OneFrameImageStreamCompleter : ImageStreamCompleter
{
public OneFrameImageStreamCompleter(IPromise<ImageInfo> image)
{
public class OneFrameImageStreamCompleter : ImageStreamCompleter {
public OneFrameImageStreamCompleter(IPromise<ImageInfo> image) {
public class _ImageListenerPair
{
public _ImageListenerPair(ImageListener listener, ImageErrorListerner errorListener)
{
public class _ImageListenerPair {
public _ImageListenerPair(ImageListener listener, ImageErrorListerner errorListener) {
this.listener = listener;
this.errorListener = errorListener;
}

24
Assets/UIWidgets/promise/EnumerableExt.cs


using System;
using System.Collections.Generic;
namespace RSG.Promises
{
namespace RSG.Promises {
public static class EnumerableExt
{
public static void Each<T>(this IEnumerable<T> source, Action<T> fn)
{
foreach (var item in source)
{
public static class EnumerableExt {
public static void Each<T>(this IEnumerable<T> source, Action<T> fn) {
foreach (var item in source) {
public static void Each<T>(this IEnumerable<T> source, Action<T, int> fn)
{
public static void Each<T>(this IEnumerable<T> source, Action<T, int> fn) {
foreach (T item in source)
{
foreach (T item in source) {
fn.Invoke(item, index);
index++;
}

/// Convert a variable length argument list of items to an enumerable.
/// </summary>
public static IEnumerable<T> FromItems<T>(params T[] items)
{
foreach (var item in items)
{
public static IEnumerable<T> FromItems<T>(params T[] items) {
foreach (var item in items) {
yield return item;
}
}

40
Assets/UIWidgets/promise/PromiseHelpers.cs


namespace RSG
{
public static class PromiseHelpers
{
namespace RSG {
public static class PromiseHelpers {
public static IPromise<Tuple<T1, T2>> All<T1, T2>(IPromise<T1> p1, IPromise<T2> p2)
{
public static IPromise<Tuple<T1, T2>> All<T1, T2>(IPromise<T1> p1, IPromise<T2> p2) {
var val1 = default(T1);
var val2 = default(T2);
var numUnresolved = 2;

p1
.Then(val =>
{
.Then(val => {
if (numUnresolved <= 0)
{
if (numUnresolved <= 0) {
.Catch(e =>
{
if (!alreadyRejected)
{
.Catch(e => {
if (!alreadyRejected) {
promise.Reject(e);
}

p2
.Then(val =>
{
.Then(val => {
if (numUnresolved <= 0)
{
if (numUnresolved <= 0) {
.Catch(e =>
{
if (!alreadyRejected)
{
.Catch(e => {
if (!alreadyRejected) {
promise.Reject(e);
}

/// Returns a promise that resolves with all of the specified promises have resolved.
/// Returns a promise of a tuple of the resolved results.
/// </summary>
public static IPromise<Tuple<T1, T2, T3>> All<T1, T2, T3>(IPromise<T1> p1, IPromise<T2> p2, IPromise<T3> p3)
{
public static IPromise<Tuple<T1, T2, T3>> All<T1, T2, T3>(IPromise<T1> p1, IPromise<T2> p2, IPromise<T3> p3) {
return All(All(p1, p2), p3)
.Then(vals => Tuple.Create(vals.Item1.Item1, vals.Item1.Item2, vals.Item2));
}

/// Returns a promise of a tuple of the resolved results.
/// </summary>
public static IPromise<Tuple<T1, T2, T3, T4>> All<T1, T2, T3, T4>(IPromise<T1> p1, IPromise<T2> p2, IPromise<T3> p3, IPromise<T4> p4)
{
public static IPromise<Tuple<T1, T2, T3, T4>> All<T1, T2, T3, T4>(IPromise<T1> p1, IPromise<T2> p2,
IPromise<T3> p3, IPromise<T4> p4) {
return All(All(p1, p2), All(p3, p4))
.Then(vals => Tuple.Create(vals.Item1.Item1, vals.Item1.Item2, vals.Item2.Item1, vals.Item2.Item2));
}

18
Assets/UIWidgets/promise/PromiseStateException.cs


using System.Linq;
using System.Text;
namespace RSG.Exceptions
{
namespace RSG.Exceptions {
public class PromiseStateException : PromiseException
{
public PromiseStateException() { }
public class PromiseStateException : PromiseException {
public PromiseStateException() {
}
public PromiseStateException(string message) : base(message) { }
public PromiseStateException(string message) : base(message) {
}
public PromiseStateException(string message, Exception inner)
: base(message, inner)
{ }
public PromiseStateException(string message, Exception inner)
: base(message, inner) {
}
}
}

77
Assets/UIWidgets/promise/PromiseTimer.cs


using System;
using System.Collections.Generic;
namespace RSG
{
public class PromiseCancelledException : Exception
{
namespace RSG {
public class PromiseCancelledException : Exception {
public PromiseCancelledException()
{
public PromiseCancelledException() {
}
/// <summary>

public PromiseCancelledException(String message) : base(message)
{
public PromiseCancelledException(String message) : base(message) {
}
}

internal class PredicateWait
{
internal class PredicateWait {
/// <summary>
/// Predicate for resolving the promise
/// </summary>

/// <summary>
/// Time data specific to a particular pending promise.
/// </summary>
public struct TimeData
{
public struct TimeData {
/// <summary>
/// The amount of time that has elapsed since the pending promise started running
/// </summary>

public int elapsedUpdates;
}
public interface IPromiseTimer
{
public interface IPromiseTimer {
/// <summary>
/// Resolve the returned promise once the time has elapsed
/// </summary>

bool Cancel(IPromise promise);
}
public class PromiseTimer : IPromiseTimer
{
public class PromiseTimer : IPromiseTimer {
/// <summary>
/// The current running total for time that this PromiseTimer has run for
/// </summary>

/// <summary>
/// Resolve the returned promise once the time has elapsed
/// </summary>
public IPromise WaitFor(float seconds)
{
public IPromise WaitFor(float seconds) {
return WaitUntil(t => t.elapsedTime >= seconds);
}

public IPromise WaitWhile(Func<TimeData, bool> predicate)
{
public IPromise WaitWhile(Func<TimeData, bool> predicate) {
return WaitUntil(t => !predicate(t));
}

public IPromise WaitUntil(Func<TimeData, bool> predicate)
{
public IPromise WaitUntil(Func<TimeData, bool> predicate) {
var wait = new PredicateWait()
{
var wait = new PredicateWait() {
timeStarted = curTime,
pendingPromise = promise,
timeData = new TimeData(),

return promise;
}
public bool Cancel(IPromise promise)
{
public bool Cancel(IPromise promise) {
if (node == null)
{
if (node == null) {
return false;
}

return true;
}
LinkedListNode<PredicateWait> FindInWaiting(IPromise promise)
{
for (var node = waiting.First; node != null; node = node.Next)
{
if (node.Value.pendingPromise.Id.Equals(promise.Id))
{
LinkedListNode<PredicateWait> FindInWaiting(IPromise promise) {
for (var node = waiting.First; node != null; node = node.Next) {
if (node.Value.pendingPromise.Id.Equals(promise.Id)) {
return node;
}
}

/// <summary>
/// Update all pending promises. Must be called for the promises to progress and resolve at all.
/// </summary>
public void Update(float deltaTime)
{
public void Update(float deltaTime) {
while (node != null)
{
while (node != null) {
var wait = node.Value;
var newElapsedTime = curTime - wait.timeStarted;

wait.timeData.elapsedUpdates = newElapsedUpdates;
bool result;
try
{
try {
catch (Exception ex)
{
catch (Exception ex) {
wait.pendingPromise.Reject(ex);
node = RemoveNode(node);

if (result)
{
if (result) {
else
{
else {
node = node.Next;
}
}

/// Removes the provided node and returns the next node in the list.
/// </summary>
private LinkedListNode<PredicateWait> RemoveNode(LinkedListNode<PredicateWait> node)
{
private LinkedListNode<PredicateWait> RemoveNode(LinkedListNode<PredicateWait> node) {
var currentNode = node;
node = node.Next;

}
}
}
}

33
Assets/UIWidgets/promise/Tuple.cs


namespace RSG
{
namespace RSG {
public class Tuple
{
public class Tuple {
/// <summary>
/// Create a new 2-tuple, or pair.
/// </summary>

/// <param name="item2">The value of the second component of the tuple.</param>
/// <returns>A 2-tuple whose value is (item1, item2)</returns>
public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
{
public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2) {
return new Tuple<T1, T2>(item1, item2);
}

/// <param name="item2">The value of the second component of the tuple.</param>
/// <param name="item3">The value of the third component of the tuple.</param>
/// <returns>A 3-tuple whose value is (item1, item2, item3)</returns>
public static Tuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3)
{
public static Tuple<T1, T2, T3> Create<T1, T2, T3>(T1 item1, T2 item2, T3 item3) {
return new Tuple<T1, T2, T3>(item1, item2, item3);
}

/// <param name="item3">The value of the third component of the tuple.</param>
/// <param name="item4">The value of the fourth component of the tuple.</param>
/// <returns>A 3-tuple whose value is (item1, item2, item3, item4)</returns>
public static Tuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4)
{
public static Tuple<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 item1, T2 item2, T3 item3, T4 item4) {
return new Tuple<T1, T2, T3, T4>(item1, item2, item3, item4);
}
}

/// </summary>
/// <typeparam name="T1">The type of the tuple's first component.</typeparam>
/// <typeparam name="T2">The type of the tuple's second component.</typeparam>
public class Tuple<T1, T2>
{
internal Tuple(T1 item1, T2 item2)
{
public class Tuple<T1, T2> {
internal Tuple(T1 item1, T2 item2) {
Item1 = item1;
Item2 = item2;
}

/// <typeparam name="T1">The type of the tuple's first component.</typeparam>
/// <typeparam name="T2">The type of the tuple's second component.</typeparam>
/// <typeparam name="T3">The type of the tuple's third component.</typeparam>
public class Tuple<T1, T2, T3>
{
internal Tuple(T1 item1, T2 item2, T3 item3)
{
public class Tuple<T1, T2, T3> {
internal Tuple(T1 item1, T2 item2, T3 item3) {
Item1 = item1;
Item2 = item2;
Item3 = item3;

/// <typeparam name="T2">The type of the tuple's second component.</typeparam>
/// <typeparam name="T3">The type of the tuple's third component.</typeparam>
/// <typeparam name="T4">The type of the tuple's fourth component.</typeparam>
public class Tuple<T1, T2, T3, T4>
{
internal Tuple(T1 item1, T2 item2, T3 item3, T4 item4)
{
public class Tuple<T1, T2, T3, T4> {
internal Tuple(T1 item1, T2 item2, T3 item3, T4 item4) {
Item1 = item1;
Item2 = item2;
Item3 = item3;

9
Assets/UIWidgets/rendering/box.cs


);
}
public static BoxConstraints tightFor(double width, double height)
{
public static BoxConstraints tightFor(double width, double height) {
return new BoxConstraints(
width,
width,

}
public static BoxConstraints tightFor(
double? width = null,
double? height = null

: ContainerRenderObjectMixinRenderBox<ChildType, ParentDataType>
where ChildType : RenderBox
where ParentDataType : ContainerParentDataMixinBoxParentData<ChildType> {
public double? defaultComputeDistanceToFirstActualBaseline(TextBaseline baseline) {
var child = this.firstChild;
while (child != null) {

candidate += childParentData.offset.dy;
if (result != null) {
result = Math.Min(result.Value, candidate.Value);
} else {
}
else {
result = candidate;
}
}

138
Assets/UIWidgets/rendering/image.cs


using UnityEngine.Rendering;
using BlendMode = UIWidgets.ui.BlendMode;
namespace UIWidgets.rendering
{
class RenderImage : RenderBox
{
namespace UIWidgets.rendering {
class RenderImage : RenderBox {
public RenderImage(ui.Image image,
double width,
double height,

ImageRepeat repeat,
Rect centerSlice,
TextDirection textDirection,
bool matchTextDirection = false,
)
{
) {
this._image = image;
this._width = width;
this._height = height;

this._fit = fit;
this._repeat = repeat;
this._centerSlice = centerSlice;
this._matchTextDirection = matchTextDirection;
// this._textDir
this._textDirection = textDirection;
_updateColorFilter();
bool _flipHorizontally;
void _resolve()
{
void _resolve() {
_flipHorizontally = matchTextDirection && textDirection == TextDirection.rtl;
void _markNeedsResolution()
{
void _markNeedsResolution() {
_flipHorizontally = false;
public ui.Image image
{
public ui.Image image {
set
{
set {
if (value == _image)
return;
_image = value;

private double _width;
public double width
{
public double width {
set
{
set {
if (value == _width)
return;
_width = value;

private double _height;
public double height
{
public double height {
set
{
set {
if (value == _height)
return;
_height = value;

private double _scale;
public double scale
{
public double scale {
set
{
set {
if (value == _scale)
return;
_scale = value;

ColorFilter _colorFilter;
void _updateColorFilter()
{
if (_color == null)
_colorFilter = null;
else
{
_colorFilter = new ColorFilter(_color,
_colorBlendMode == BlendMode.None ? BlendMode.srcIn : _colorBlendMode);
}
}
public Color color
{
public Color color {
set
{
set {
_updateColorFilter();
// todo more parameters
public ui.BlendMode colorBlendMode
{
public ui.BlendMode colorBlendMode {
set
{
set {
_updateColorFilter();
markNeedsPaint();
}
}

public BoxFit fit
{
public BoxFit fit {
set
{
set {
if (value == _fit)
return;
_fit = value;

private Alignment _alignment;
public Alignment alignment
{
public Alignment alignment {
set
{
set {
if (value == _alignment)
return;
_alignment = value;

private ImageRepeat _repeat;
public ImageRepeat repeat
{
public ImageRepeat repeat {
set
{
set {
if (value == _repeat)
return;
_repeat = value;

private Rect _centerSlice;
public Rect centerSlice
{
public Rect centerSlice {
set
{
set {
if (value == _centerSlice)
return;
_centerSlice = value;

private bool _matchTextDirection;
public bool matchTextDirection
{
get { return _matchTextDirection; }
set
{
if (value == _matchTextDirection)
return;
_matchTextDirection = value;
_markNeedsResolution();
}
}
private TextDirection _textDirection;
public TextDirection textDirection
{
get { return _textDirection; }
set
{
if (_textDirection == value)
return;
_textDirection = value;
_markNeedsResolution();
}
}
Size _sizeForConstraints(BoxConstraints constraints)
{
Size _sizeForConstraints(BoxConstraints constraints) {
// Folds the given |width| and |height| into |constraints| so they can all
// be treated uniformly.
constraints = BoxConstraints.tightFor(

));
}
public override void paint(PaintingContext context, Offset offset)
{
public override void paint(PaintingContext context, Offset offset) {
if (_image == null)
return;
_resolve();

_fit,
_centerSlice,
_resolvedAlignment,
_repeat,
_flipHorizontally
// todo
_repeat
);
}
}

8
Assets/UIWidgets/ui/geometry.cs


public bool isEmpty {
get { return this.width <= 0.0 || this.height <= 0.0; }
}
public static Size operator +(Size a, Offset b) {
return new Size(a.width + b.dx, a.height + b.dy);
}

}
public static Size operator *(Size a, double operand) {
return new Size(a.width * operand, a.height * operand);
}

public bool contains(Offset offset) {
return offset.dx >= this.left && offset.dx < this.right && offset.dy >= this.top && offset.dy < this.bottom;
}
public bool contains(Rect rect) {
return this.contains(rect.topLeft) && this.contains(rect.bottomRight);
}

3
Assets/UIWidgets/ui/painting/canvas.cs


});
}
public void drawImageRect(Rect src, Rect dst, Paint paint, Image image)
{
public void drawImageRect(Rect src, Rect dst, Paint paint, Image image) {
this._recorder.addDrawCmd(new DrawImageRect
{
image = image,

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


this.restore();
}
public void drawImageRect(Rect src, Rect dst, Paint paint, Image image)
{
public void drawImageRect(Rect src, Rect dst, Paint paint, Image image) {
if (image != null)
{
Texture2D _texture = new Texture2D(0, 0);

3
Assets/UIWidgets/ui/painting/draw_cmd.cs


public Picture picture;
}
public class DrawImageRect : DrawCmd
{
public class DrawImageRect : DrawCmd {
public Image image;
public Rect src;
public Rect dst;

3
Assets/UIWidgets/ui/painting/image.cs


{
public class Image
{
public Image(byte[] raw, int height = 100, int width = 100)
{
public Image(byte[] raw, int height = 100, int width = 100) {
this.rawData = raw;
this.height = height;
this.width = width;

15
Assets/UIWidgets/ui/painting/painting.cs


};
}
}
public class ColorFilter
{
public ColorFilter(Color color, BlendMode blendMode)
{
public class ColorFilter {
public ColorFilter(Color color, BlendMode blendMode) {
_color = color;
_blendMode = blendMode;
}

}
public enum BlendMode
{
public enum BlendMode {
None = 0, // explicitly assign zero to make it more clear
clear,
src,

saturation,
color,
luminosity,
}
}
}
正在加载...
取消
保存