浏览代码

refine image

/main
gewentao 6 年前
当前提交
8143c534
共有 6 个文件被更改,包括 55 次插入30 次删除
  1. 3
      Assets/UIWidgets/Tests/Widgets.cs
  2. 22
      Assets/UIWidgets/painting/decoration_image.cs
  3. 16
      Assets/UIWidgets/rendering/image.cs
  4. 2
      Assets/UIWidgets/rendering/proxy_box.cs
  5. 6
      Assets/UIWidgets/ui/painting/canvas_impl.cs
  6. 36
      Assets/UIWidgets/ui/painting/image.cs

3
Assets/UIWidgets/Tests/Widgets.cs


var image = new widgets.Image(
"https://tse3.mm.bing.net/th?id=OIP.XOAIpvR1kh-CzISe_Nj9GgHaHs&pid=Api",
width: 100,
height: 100
height: 100,
repeat: ImageRepeat.repeatX
);
var container = new widgets.Container(
width: 200,

22
Assets/UIWidgets/painting/decoration_image.cs


using System;
using UIWidgets.ui;
using System.Collections.Generic;
using UnityEngine;
using Canvas = UIWidgets.ui.Canvas;
using Rect = UIWidgets.ui.Rect;
namespace UIWidgets.painting {
/// How to paint any portions of a box not covered by an image.

}
public static class DecorationImageUtil {
public static void paintImage(Canvas canvas, Rect rect, ui.Image image) {
canvas.drawImageRect(Rect.fromLTWH(0, 0, 100, 100), rect, new Paint(), image);
}
// todo refine logic below, no just draw in Rect(0, 0, 100, 100) for testing widgets
/*
public static void paintImage(Canvas canvas, Rect rect, ui.Image image, BoxFit fit, Rect centerSlice,
public static void paintImage(
Canvas canvas,
Rect rect,
ui.Image image,
// ColorFilter colorFileter,
BoxFit fit,
Rect centerSlice,
ImageRepeat repeat = ImageRepeat.noRepeat) {
ImageRepeat repeat = ImageRepeat.noRepeat
// bool flipHorizontally = false
) {
if (rect.isEmpty)
return;
alignment = alignment ?? Alignment.center;

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

16
Assets/UIWidgets/rendering/image.cs


using UIWidgets.ui;
using UIWidgets.painting;
using UnityEngine;
using Color = UIWidgets.ui.Color;
using Rect = UIWidgets.ui.Rect;
namespace UIWidgets.rendering {
class RenderImage : RenderBox {

constraints = BoxConstraints.tightFor(
_width,
_height
);
constraints = constraints.enforce(constraints);
).enforce(constraints);
if (_image == null)
return constraints.smallest;

DecorationImageUtil.paintImage(
context.canvas,
offset & size,
_image
// _fit,
// _centerSlice,
// _resolvedAlignment,
// _repeat
_image,
_fit,
_centerSlice,
_resolvedAlignment,
_repeat
);
}
}

2
Assets/UIWidgets/rendering/proxy_box.cs


public override double computeMaxIntrinsicWidth(double height) {
if (this._additionalConstraints.hasBoundedWidth && this._additionalConstraints.hasTightWidth) {
return this._additionalConstraints.maxWidth;
return this._additionalConstraints.minWidth;
}
double width = base.computeMaxIntrinsicWidth(height);

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


}
public void drawImageRect(Rect src, Rect dst, Paint paint, Image image) {
if (image != null) {
Texture2D _texture = new Texture2D(0, 0);
_texture.LoadImage(image.rawData);
Graphics.DrawTexture(dst.toRect(), _texture);
if (image != null && image.texture != null) {
Graphics.DrawTexture(dst.toRect(), image.texture);
}
}

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


using System;
using System.Collections.Generic;
using UIWidgets.painting;
using UnityEngine;
namespace UIWidgets.ui

public Image(byte[] raw, int height = 100, int width = 100) {
this.rawData = raw;
this.height = height;
this.width = width;
public Image(byte[] raw) {
rawData = raw;
public int height;
public int width;
public int height {
get {
return texture != null ? texture.height : 0;
}
}
public int width {
get {
return texture != null ? texture.width : 0;
}
}
public Texture2D texture {
get {
if (_texture == null && rawData.Length != 0) {
_texture = new Texture2D(2, 2);
_texture.LoadImage(rawData);
}
return _texture;
}
}
private Texture2D _texture;
}
}
正在加载...
取消
保存