浏览代码

update cache

/main
gewentao 6 年前
当前提交
e5d8044d
共有 3 个文件被更改,包括 28 次插入15 次删除
  1. 21
      Assets/UIWidgets/painting/decoration_image.cs
  2. 3
      Assets/UIWidgets/painting/image_cache.cs
  3. 19
      Assets/UIWidgets/painting/image_provider.cs

21
Assets/UIWidgets/painting/decoration_image.cs


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) // todo more parameters
ImageRepeat repeat = ImageRepeat.noRepeat, bool flipHorizontally = false)
{
if (rect.isEmpty)
return;

double dy = halfHeightDelta + alignment.y * halfHeightDelta;
Offset destinationPosition = rect.topLeft.translate(dx, dy);
Rect destinationRect = destinationPosition & destinationSize;
// todo repeat and flip
// bool needSave = repeat != ImageRepeat.noRepeat || flipHorizontally;
// if (needSave)
// canvas.save();
// if (repeat != ImageRepeat.noRepeat)
// canvas.clipRect(rect);
bool needSave = repeat != ImageRepeat.noRepeat || flipHorizontally;
if (needSave)
canvas.save();
if (repeat != ImageRepeat.noRepeat)
canvas.clipRect(rect);
// todo flip
// if (flipHorizontally) {
// dx = -(rect.left + rect.width / 2.0);
// canvas.translate(-dx, 0.0);

fittedSizes.source, Offset.zero & inputSize
);
foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) {
// canvas.drawImageRect(sourceRect, tileRect, paint, image);
canvas.drawImageRect(sourceRect, tileRect, paint, image);
}
} else {
// todo

}
}
// if (needSave)
// canvas.restore();
if (needSave)
canvas.restore();
}
public static List<Rect> _generateImageTileRects(Rect outputRect, Rect fundamentalRect,

{
for (int j = startY; j <= stopY; ++j)
tileRects.Add(fundamentalRect.shift(new Offset(i * strideX, j * strideY)));
// yield return fundamentalRect.shift(new Offset(i * strideX, j * strideY));
}
return tileRects;

3
Assets/UIWidgets/painting/image_cache.cs


using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using Object = System.Object;
namespace UIWidgets.painting

public delegate ImageStreamCompleter Loader();
[MethodImpl(MethodImplOptions.Synchronized)]
public ImageStreamCompleter putIfAbsent(Object key, Loader loader)
{
ImageStreamCompleter result;

19
Assets/UIWidgets/painting/image_provider.cs


{
public abstract class ImageProvider<T>
{
// ImageStream resolve(ImageConfiguration configuration) {
public ImageStream resolve(ImageConfiguration configuration)
{
ImageStream stream = new ImageStream();

public override string ToString()
{
return "NetworkImage with Url: " + this.url;
}
public bool Equals(NetworkImage other) {
return this.url.Equals(other.url) && this.scale.Equals(other.scale);
}
public override bool Equals(object obj) {
if (object.ReferenceEquals(null, obj)) return false;
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();
hashCode = (hashCode * 397) ^ this.scale.GetHashCode();
return hashCode;
}
}
}

正在加载...
取消
保存