gewentao
6 年前
当前提交
5cbbdf04
共有 10 个文件被更改,包括 478 次插入 和 3 次删除
-
6Assets/UIWidgets/painting/image_provider.cs
-
25Assets/UIWidgets/painting/image_stream.cs
-
14Assets/UIWidgets/ui/window.cs
-
140Assets/UIWidgets/widgets/framework.cs
-
57Assets/UIWidgets/widgets/basic.cs
-
3Assets/UIWidgets/widgets/basic.cs.meta
-
52Assets/UIWidgets/widgets/binding.cs
-
3Assets/UIWidgets/widgets/binding.cs.meta
-
178Assets/UIWidgets/widgets/image.cs
-
3Assets/UIWidgets/widgets/image.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.ui; |
|||
using UnityEngine.Assertions; |
|||
|
|||
namespace UIWidgets.widgets { |
|||
public class RawImage : LeafRenderObjectWidget { |
|||
public RawImage(string key, ui.Image image, double width, double height, double scale, Color color, |
|||
BlendMode colorBlendMode, BoxFit fit, Rect centerSlice, Alignment alignment = null, |
|||
ImageRepeat repeat = ImageRepeat.noRepeat) : base(key) { |
|||
this.image = image; |
|||
this.width = width; |
|||
this.height = height; |
|||
this.scale = scale; |
|||
this.color = color; |
|||
this.blendMode = colorBlendMode; |
|||
this.centerSlice = centerSlice; |
|||
this.fit = fit; |
|||
this.alignment = alignment == null ? Alignment.center : alignment; |
|||
this.repeat = repeat; |
|||
} |
|||
|
|||
public override Element createElement() { |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public override RenderObject createRenderObject(BuildContext context) { |
|||
return new RenderImage( |
|||
this.image, |
|||
this.width, |
|||
this.height, |
|||
this.color, |
|||
this.blendMode, |
|||
this.fit, |
|||
this.repeat, |
|||
this.centerSlice, |
|||
this.alignment |
|||
); |
|||
} |
|||
|
|||
public ui.Image image; |
|||
public double width; |
|||
public double height; |
|||
public double scale; |
|||
public Color color; |
|||
public BlendMode blendMode; |
|||
public BoxFit fit; |
|||
public Alignment alignment; |
|||
public ImageRepeat repeat; |
|||
public Rect centerSlice; |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 69241aaa538e4e2baa651ffa39d6f355 |
|||
timeCreated: 1536564821 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.ui; |
|||
using UnityEngine.Assertions; |
|||
|
|||
namespace UIWidgets.widgets { |
|||
abstract class WidgetsBinding : RendererBinding { |
|||
protected WidgetsBinding(Window window) : base(window) { |
|||
this.buildOwner.onBuildScheduled = this._handleBuildScheduled; |
|||
window.onLocaleChanged += this.handleLocaleChanged; |
|||
window.onAccessibilityFeaturesChanged += handleAccessibilityFeaturesChanged; |
|||
} |
|||
|
|||
public BuildOwner buildOwner { |
|||
get { return this._buildOwner; } |
|||
} |
|||
|
|||
readonly BuildOwner _buildOwner; |
|||
|
|||
public Element renderViewElement { |
|||
get { return this._renderViewElement; } |
|||
} |
|||
|
|||
Element _renderViewElement; |
|||
|
|||
void _handleBuildScheduled() { |
|||
ensureVisualUpdate(); |
|||
} |
|||
|
|||
void handleLocaleChanged() { |
|||
// todo
|
|||
// dispatchLocaleChanged(window.locale);
|
|||
} |
|||
|
|||
void handleAccessibilityFeaturesChanged() { |
|||
// for (WidgetsBindingObserver observer in _observers) {
|
|||
// observer.didChangeAccessibilityFeatures();
|
|||
// }
|
|||
} |
|||
|
|||
public void drawFrame() { |
|||
if (renderViewElement != null) { |
|||
buildOwner.buildScope(renderViewElement); |
|||
} |
|||
base.drawFrame(); |
|||
buildOwner.finalizeTree(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 39d3379616cb4c64afdedd889e3ac2a2 |
|||
timeCreated: 1536213633 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.ui; |
|||
using UnityEngine; |
|||
using UnityEngine.Assertions; |
|||
using Color = UIWidgets.ui.Color; |
|||
using Rect = UnityEngine.Rect; |
|||
|
|||
namespace UIWidgets.widgets { |
|||
internal class Util { |
|||
public static ImageConfiguration createLocalImageConfiguration(BuildContext context, Size size) { |
|||
return new ImageConfiguration( |
|||
size: size |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class Image<T> : StatefulWidget { |
|||
public IImageProvider<System.Object> image; |
|||
public double width; |
|||
public double height; |
|||
public Color color; |
|||
public BoxFit fit; |
|||
public Alignment alignment; |
|||
public BlendMode colorBlendMode; |
|||
public ImageRepeat repeat; |
|||
public ui.Rect centerSlice; |
|||
|
|||
public bool gaplessPlayback; |
|||
|
|||
public Image( |
|||
string key, |
|||
ImageProvider<System.Object> image, |
|||
double width, |
|||
double height, |
|||
Color color, |
|||
BlendMode colorBlendMode, |
|||
BoxFit fit, |
|||
ui.Rect centerSlice, |
|||
Alignment alignment, |
|||
ImageRepeat repeat = ImageRepeat.noRepeat, |
|||
bool gaplessPlayback = false |
|||
) : base(key) { |
|||
this.image = image; |
|||
this.width = width; |
|||
this.height = height; |
|||
this.color = color; |
|||
this.colorBlendMode = colorBlendMode; |
|||
this.fit = fit; |
|||
this.alignment = alignment == null ? Alignment.center : alignment; |
|||
this.repeat = repeat; |
|||
this.centerSlice = centerSlice; |
|||
this.gaplessPlayback = gaplessPlayback; |
|||
} |
|||
|
|||
// Network Image
|
|||
public Image( |
|||
string src, |
|||
string key, |
|||
double width, |
|||
double height, |
|||
Color color, |
|||
BlendMode colorBlendMode, |
|||
BoxFit fit, |
|||
Alignment alignment, |
|||
ui.Rect centerSlice, |
|||
Dictionary<String, String> headers, |
|||
ImageRepeat repeat = ImageRepeat.noRepeat, |
|||
bool gaplessPlayback = false, |
|||
double scale = 1.0 |
|||
) : base(key) { |
|||
this.image = new NetworkImage(src, headers, scale); |
|||
this.width = width; |
|||
this.height = height; |
|||
this.color = color; |
|||
this.colorBlendMode = colorBlendMode; |
|||
this.fit = fit; |
|||
this.alignment = alignment; |
|||
this.centerSlice = centerSlice; |
|||
this.repeat = repeat; |
|||
this.gaplessPlayback = gaplessPlayback; |
|||
} |
|||
|
|||
public override State createState() { |
|||
return new _ImageState<T>(); |
|||
} |
|||
} |
|||
|
|||
public class _ImageState<T> : State { |
|||
ImageStream _imageStream; |
|||
ImageInfo _imageInfo; |
|||
bool _isListeningToStream = false; |
|||
|
|||
public override void didChangeDependencies() { |
|||
_resolveImage(); |
|||
// if (TickerMode.of(context))
|
|||
// _listenToStream();
|
|||
// else
|
|||
// _stopListeningToStream();
|
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
if (((Image<T>) widget).image != ((Image<T>) oldWidget).image) |
|||
_resolveImage(); |
|||
} |
|||
|
|||
public override void reassemble() { |
|||
_resolveImage(); // in case the image cache was flushed
|
|||
} |
|||
|
|||
void _resolveImage() { |
|||
var imageWidget = (Image<T>) widget; |
|||
ImageStream newStream = |
|||
imageWidget.image.resolve(Util.createLocalImageConfiguration( |
|||
context, |
|||
size: new Size(imageWidget.width, imageWidget.height) |
|||
)); |
|||
_updateSourceStream(newStream); |
|||
} |
|||
|
|||
void _handleImageChanged(ImageInfo imageInfo, bool synchronousCall) { |
|||
setState(() => { _imageInfo = imageInfo; }); |
|||
} |
|||
|
|||
void _updateSourceStream(ImageStream newStream) { |
|||
if ((_imageStream == null ? null : _imageStream.key) == (newStream == null ? null : newStream.key)) |
|||
return; |
|||
|
|||
if (_isListeningToStream) |
|||
_imageStream.removeListener(_handleImageChanged); |
|||
|
|||
if (!((Image<T>) widget).gaplessPlayback) { |
|||
setState(() => { _imageInfo = null; }); |
|||
|
|||
_imageStream = newStream; |
|||
if (_isListeningToStream) |
|||
_imageStream.addListener(_handleImageChanged); |
|||
} |
|||
} |
|||
|
|||
void _listenToStream() { |
|||
if (_isListeningToStream) |
|||
return; |
|||
_imageStream.addListener(_handleImageChanged); |
|||
_isListeningToStream = true; |
|||
} |
|||
|
|||
void _stopListeningToStream() { |
|||
if (!_isListeningToStream) |
|||
return; |
|||
_imageStream.removeListener(_handleImageChanged); |
|||
_isListeningToStream = false; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
var imageWidget = (Image<T>) widget; |
|||
RawImage image = new RawImage( |
|||
"", // todo
|
|||
_imageInfo == null ? null : _imageInfo.image, |
|||
imageWidget.width, |
|||
imageWidget.height, |
|||
_imageInfo == null ? 1.0 : _imageInfo.scale, |
|||
imageWidget.color, |
|||
imageWidget.colorBlendMode, |
|||
imageWidget.fit, |
|||
imageWidget.centerSlice, |
|||
imageWidget.alignment, |
|||
imageWidget.repeat |
|||
); |
|||
|
|||
return image; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d1d313d74f6044198caad151f52721b8 |
|||
timeCreated: 1536219326 |
撰写
预览
正在加载...
取消
保存
Reference in new issue