mirror of
https://github.com/ZuneDev/ZuneShell.dll.git
synced 2026-07-27 13:11:51 -07:00
Simplified usages in UIX project
This commit is contained in:
@@ -35,10 +35,10 @@ namespace Microsoft.Iris.ViewItems
|
||||
|
||||
public Graphic()
|
||||
{
|
||||
this._horizontalAlignment = StripAlignment.Near;
|
||||
this._verticalAlignment = StripAlignment.Near;
|
||||
this._stretchMode = StretchingPolicy.Fill;
|
||||
this.SizingPolicy = SizingPolicy.SizeToContent;
|
||||
_horizontalAlignment = StripAlignment.Near;
|
||||
_verticalAlignment = StripAlignment.Near;
|
||||
_stretchMode = StretchingPolicy.Fill;
|
||||
SizingPolicy = SizingPolicy.SizeToContent;
|
||||
}
|
||||
|
||||
public static void EnsureFallbackImages()
|
||||
@@ -53,78 +53,78 @@ namespace Microsoft.Iris.ViewItems
|
||||
|
||||
protected override void OnDispose()
|
||||
{
|
||||
this.ReleaseInUseImage(this._contentImage, null);
|
||||
this.ReleaseInUseImage(this._preloadImage, null);
|
||||
this.ReleaseInUseImage(this.AcquiringImage, s_AcquiringDefaultImage);
|
||||
this.ReleaseInUseImage(this.ErrorImage, s_ErrorDefaultImage);
|
||||
this._preloadImage = null;
|
||||
this._contentImage = null;
|
||||
this.AsyncLoadCompleteHandler = null;
|
||||
ReleaseInUseImage(_contentImage, null);
|
||||
ReleaseInUseImage(_preloadImage, null);
|
||||
ReleaseInUseImage(AcquiringImage, s_AcquiringDefaultImage);
|
||||
ReleaseInUseImage(ErrorImage, s_ErrorDefaultImage);
|
||||
_preloadImage = null;
|
||||
_contentImage = null;
|
||||
AsyncLoadCompleteHandler = null;
|
||||
base.OnDispose();
|
||||
}
|
||||
|
||||
protected override void OnEffectChanged()
|
||||
{
|
||||
if (this._contents == null)
|
||||
if (_contents == null)
|
||||
return;
|
||||
this._contents.Effect = null;
|
||||
_contents.Effect = null;
|
||||
}
|
||||
|
||||
public UIImage Content
|
||||
{
|
||||
get => this._contentImage;
|
||||
get => _contentImage;
|
||||
set
|
||||
{
|
||||
if (this._contentImage == value)
|
||||
if (_contentImage == value)
|
||||
return;
|
||||
if (this._contentImage != null)
|
||||
if (_contentImage != null)
|
||||
{
|
||||
this.RemoveAsyncLoadCompleteHandler(this._contentImage);
|
||||
this._contentImage.RemoveUser(this);
|
||||
RemoveAsyncLoadCompleteHandler(_contentImage);
|
||||
_contentImage.RemoveUser(this);
|
||||
}
|
||||
this._contentImage = value;
|
||||
if (this._contentImage != null)
|
||||
_contentImage = value;
|
||||
if (_contentImage != null)
|
||||
{
|
||||
this._contentImage.AddUser(this);
|
||||
this._contentImage.Load();
|
||||
if (this._contentImage.Status == ImageStatus.Loading || this._contentImage.Status == ImageStatus.PendingLoad)
|
||||
this.AttachAsyncLoadCompleteHandler(this._contentImage);
|
||||
_contentImage.AddUser(this);
|
||||
_contentImage.Load();
|
||||
if (_contentImage.Status == ImageStatus.Loading || _contentImage.Status == ImageStatus.PendingLoad)
|
||||
AttachAsyncLoadCompleteHandler(_contentImage);
|
||||
}
|
||||
this.FireNotification(NotificationID.Content);
|
||||
this.NotifyContentChange();
|
||||
FireNotification(NotificationID.Content);
|
||||
NotifyContentChange();
|
||||
}
|
||||
}
|
||||
|
||||
public UIImage AcquiringImage
|
||||
{
|
||||
get => this.GetStatusImage(s_acquiringImageProperty, s_AcquiringDefaultImage);
|
||||
set => this.SetStatusImage(value, NotificationID.AcquiringImage, s_acquiringImageProperty, s_AcquiringDefaultImage);
|
||||
get => GetStatusImage(s_acquiringImageProperty, s_AcquiringDefaultImage);
|
||||
set => SetStatusImage(value, NotificationID.AcquiringImage, s_acquiringImageProperty, s_AcquiringDefaultImage);
|
||||
}
|
||||
|
||||
public UIImage ErrorImage
|
||||
{
|
||||
get => this.GetStatusImage(s_errorImageProperty, s_ErrorDefaultImage);
|
||||
set => this.SetStatusImage(value, NotificationID.ErrorImage, s_errorImageProperty, s_ErrorDefaultImage);
|
||||
get => GetStatusImage(s_errorImageProperty, s_ErrorDefaultImage);
|
||||
set => SetStatusImage(value, NotificationID.ErrorImage, s_errorImageProperty, s_ErrorDefaultImage);
|
||||
}
|
||||
|
||||
public UIImage PreloadContent
|
||||
{
|
||||
get => this._preloadImage;
|
||||
get => _preloadImage;
|
||||
set
|
||||
{
|
||||
if (this._preloadImage != null)
|
||||
this._preloadImage.RemoveUser(this);
|
||||
this._preloadImage = value;
|
||||
if (this._preloadImage == null)
|
||||
if (_preloadImage != null)
|
||||
_preloadImage.RemoveUser(this);
|
||||
_preloadImage = value;
|
||||
if (_preloadImage == null)
|
||||
return;
|
||||
this._preloadImage.AddUser(this);
|
||||
this._preloadImage.Load();
|
||||
_preloadImage.AddUser(this);
|
||||
_preloadImage.Load();
|
||||
}
|
||||
}
|
||||
|
||||
private UIImage GetStatusImage(DataCookie cookie, UIImage defaultImage)
|
||||
{
|
||||
object data = this.GetData(cookie);
|
||||
object data = GetData(cookie);
|
||||
return data != null ? (data != s_NullImage ? (UIImage)data : null) : defaultImage;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace Microsoft.Iris.ViewItems
|
||||
DataCookie cookie,
|
||||
UIImage defaultImage)
|
||||
{
|
||||
UIImage statusImage = this.GetStatusImage(cookie, defaultImage);
|
||||
UIImage statusImage = GetStatusImage(cookie, defaultImage);
|
||||
if (value == statusImage)
|
||||
return;
|
||||
object obj;
|
||||
@@ -143,30 +143,30 @@ namespace Microsoft.Iris.ViewItems
|
||||
obj = value;
|
||||
value.Load();
|
||||
if (value.Status == ImageStatus.Loading || value.Status == ImageStatus.PendingLoad)
|
||||
this.AttachAsyncLoadCompleteHandler(value);
|
||||
AttachAsyncLoadCompleteHandler(value);
|
||||
value.AddUser(this);
|
||||
}
|
||||
else
|
||||
obj = s_NullImage;
|
||||
this.ReleaseInUseImage(statusImage, defaultImage);
|
||||
this.SetData(cookie, obj);
|
||||
this.MarkPaintInvalid();
|
||||
this.FireNotification(name);
|
||||
ReleaseInUseImage(statusImage, defaultImage);
|
||||
SetData(cookie, obj);
|
||||
MarkPaintInvalid();
|
||||
FireNotification(name);
|
||||
}
|
||||
|
||||
private void OnAsyncLoadComplete(object image, ImageStatus status)
|
||||
{
|
||||
this.RemoveAsyncLoadCompleteHandler((UIImage)image);
|
||||
this.NotifyContentChange();
|
||||
RemoveAsyncLoadCompleteHandler((UIImage)image);
|
||||
NotifyContentChange();
|
||||
}
|
||||
|
||||
private void AttachAsyncLoadCompleteHandler(UIImage image)
|
||||
{
|
||||
ContentLoadCompleteHandler loadCompleteHandler = this.AsyncLoadCompleteHandler;
|
||||
ContentLoadCompleteHandler loadCompleteHandler = AsyncLoadCompleteHandler;
|
||||
if (loadCompleteHandler == null)
|
||||
{
|
||||
loadCompleteHandler = new ContentLoadCompleteHandler(this.OnAsyncLoadComplete);
|
||||
this.AsyncLoadCompleteHandler = loadCompleteHandler;
|
||||
loadCompleteHandler = new ContentLoadCompleteHandler(OnAsyncLoadComplete);
|
||||
AsyncLoadCompleteHandler = loadCompleteHandler;
|
||||
}
|
||||
image.LoadComplete += loadCompleteHandler;
|
||||
}
|
||||
@@ -175,13 +175,13 @@ namespace Microsoft.Iris.ViewItems
|
||||
{
|
||||
if (image == null)
|
||||
return;
|
||||
image.LoadComplete -= this.AsyncLoadCompleteHandler;
|
||||
image.LoadComplete -= AsyncLoadCompleteHandler;
|
||||
}
|
||||
|
||||
private void ReleaseInUseImage(UIImage image, UIImage defaultImage)
|
||||
{
|
||||
if (image != null && image != defaultImage && (image.Status == ImageStatus.Loading || image.Status == ImageStatus.PendingLoad))
|
||||
this.RemoveAsyncLoadCompleteHandler(image);
|
||||
RemoveAsyncLoadCompleteHandler(image);
|
||||
if (image == null || image == defaultImage)
|
||||
return;
|
||||
image.RemoveUser(this);
|
||||
@@ -189,60 +189,60 @@ namespace Microsoft.Iris.ViewItems
|
||||
|
||||
private void NotifyContentChange()
|
||||
{
|
||||
this.ForceContentChange();
|
||||
if (this.Layout is ImageLayout layout && this.UpdateSourceOnLayout(layout))
|
||||
this.MarkLayoutInvalid();
|
||||
this.MarkPaintInvalid();
|
||||
ForceContentChange();
|
||||
if (Layout is ImageLayout layout && UpdateSourceOnLayout(layout))
|
||||
MarkLayoutInvalid();
|
||||
MarkPaintInvalid();
|
||||
}
|
||||
|
||||
protected override void OnMinimumSizeChanged()
|
||||
{
|
||||
if (!(this.Layout is ImageLayout layout))
|
||||
if (!(Layout is ImageLayout layout))
|
||||
return;
|
||||
layout.MinimumSize = this.MinimumSize;
|
||||
layout.MinimumSize = MinimumSize;
|
||||
}
|
||||
|
||||
public SizingPolicy SizingPolicy
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!(this.Layout is ImageLayout layout))
|
||||
if (!(Layout is ImageLayout layout))
|
||||
return SizingPolicy.SizeToChildren;
|
||||
return layout.Fill ? SizingPolicy.SizeToConstraint : SizingPolicy.SizeToContent;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == this.SizingPolicy)
|
||||
if (value == SizingPolicy)
|
||||
return;
|
||||
if (value == SizingPolicy.SizeToChildren)
|
||||
{
|
||||
this.Layout = DefaultLayout.Instance;
|
||||
Layout = DefaultLayout.Instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageLayout imageLayout = new ImageLayout();
|
||||
this.UpdateSourceOnLayout(imageLayout);
|
||||
this.UpdateMaintainAspectRatioOnLayout(imageLayout);
|
||||
imageLayout.MinimumSize = this.MinimumSize;
|
||||
UpdateSourceOnLayout(imageLayout);
|
||||
UpdateMaintainAspectRatioOnLayout(imageLayout);
|
||||
imageLayout.MinimumSize = MinimumSize;
|
||||
imageLayout.Fill = value == SizingPolicy.SizeToConstraint;
|
||||
this.Layout = imageLayout;
|
||||
Layout = imageLayout;
|
||||
}
|
||||
this.FireNotification(NotificationID.SizingPolicy);
|
||||
FireNotification(NotificationID.SizingPolicy);
|
||||
}
|
||||
}
|
||||
|
||||
public StretchingPolicy StretchingPolicy
|
||||
{
|
||||
get => this._stretchMode;
|
||||
get => _stretchMode;
|
||||
set
|
||||
{
|
||||
if (this._stretchMode == value)
|
||||
if (_stretchMode == value)
|
||||
return;
|
||||
this._stretchMode = value;
|
||||
if (this.UpdateMaintainAspectRatioOnLayout(this.Layout as ImageLayout))
|
||||
this.MarkLayoutInvalid();
|
||||
this.MarkPaintInvalid();
|
||||
this.FireNotification(NotificationID.StretchingPolicy);
|
||||
_stretchMode = value;
|
||||
if (UpdateMaintainAspectRatioOnLayout(Layout as ImageLayout))
|
||||
MarkLayoutInvalid();
|
||||
MarkPaintInvalid();
|
||||
FireNotification(NotificationID.StretchingPolicy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace Microsoft.Iris.ViewItems
|
||||
bool flag1 = false;
|
||||
if (imageLayout != null)
|
||||
{
|
||||
bool flag2 = this._stretchMode == StretchingPolicy.Uniform;
|
||||
bool flag2 = _stretchMode == StretchingPolicy.Uniform;
|
||||
if (imageLayout.MaintainAspectRatio != flag2)
|
||||
{
|
||||
imageLayout.MaintainAspectRatio = flag2;
|
||||
@@ -265,9 +265,9 @@ namespace Microsoft.Iris.ViewItems
|
||||
{
|
||||
bool flag = false;
|
||||
Size size = Size.Zero;
|
||||
if (this._contentImage != null)
|
||||
if (_contentImage != null)
|
||||
{
|
||||
UIImage activeImage = this.GetActiveImage();
|
||||
UIImage activeImage = GetActiveImage();
|
||||
if (activeImage != null)
|
||||
size = activeImage.Size;
|
||||
}
|
||||
@@ -281,76 +281,76 @@ namespace Microsoft.Iris.ViewItems
|
||||
|
||||
public StripAlignment HorizontalAlignment
|
||||
{
|
||||
get => this._horizontalAlignment;
|
||||
get => _horizontalAlignment;
|
||||
set
|
||||
{
|
||||
if (this._horizontalAlignment == value)
|
||||
if (_horizontalAlignment == value)
|
||||
return;
|
||||
this._horizontalAlignment = value;
|
||||
this.MarkPaintInvalid();
|
||||
this.FireNotification(NotificationID.HorizontalAlignment);
|
||||
_horizontalAlignment = value;
|
||||
MarkPaintInvalid();
|
||||
FireNotification(NotificationID.HorizontalAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
public StripAlignment VerticalAlignment
|
||||
{
|
||||
get => this._verticalAlignment;
|
||||
get => _verticalAlignment;
|
||||
set
|
||||
{
|
||||
if (this._verticalAlignment == value)
|
||||
if (_verticalAlignment == value)
|
||||
return;
|
||||
this._verticalAlignment = value;
|
||||
this.MarkPaintInvalid();
|
||||
this.FireNotification(NotificationID.VerticalAlignment);
|
||||
_verticalAlignment = value;
|
||||
MarkPaintInvalid();
|
||||
FireNotification(NotificationID.VerticalAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
private ContentLoadCompleteHandler AsyncLoadCompleteHandler
|
||||
{
|
||||
get => (ContentLoadCompleteHandler)this.GetData(s_pendingLoadCompleteHandlerProperty);
|
||||
set => this.SetData(s_pendingLoadCompleteHandlerProperty, value);
|
||||
get => (ContentLoadCompleteHandler)GetData(s_pendingLoadCompleteHandlerProperty);
|
||||
set => SetData(s_pendingLoadCompleteHandlerProperty, value);
|
||||
}
|
||||
|
||||
public void CommitPreload() => this.Content = this.PreloadContent;
|
||||
public void CommitPreload() => Content = PreloadContent;
|
||||
|
||||
protected override bool HasContent() => this._contentImage != null;
|
||||
protected override bool HasContent() => _contentImage != null;
|
||||
|
||||
protected override void OnPaint(bool visible)
|
||||
{
|
||||
base.OnPaint(visible);
|
||||
if (this._contents == null)
|
||||
if (_contents == null)
|
||||
return;
|
||||
if (this._contents.Effect == null)
|
||||
if (_contents.Effect == null)
|
||||
{
|
||||
this._contents.Effect = EffectClass.CreateImageRenderEffectWithFallback(this.Effect, this, null);
|
||||
this._contents.Effect.UnregisterUsage(this);
|
||||
_contents.Effect = EffectClass.CreateImageRenderEffectWithFallback(Effect, this, null);
|
||||
_contents.Effect.UnregisterUsage(this);
|
||||
}
|
||||
this.UpdateEffectContents();
|
||||
this.UpdateCoordinateMaps();
|
||||
UpdateEffectContents();
|
||||
UpdateCoordinateMaps();
|
||||
}
|
||||
|
||||
private void UpdateEffectContents() => EffectClass.SetDefaultEffectProperty(this.Effect, this._contents.Effect, this.GetActiveImage()?.RenderImage);
|
||||
private void UpdateEffectContents() => EffectClass.SetDefaultEffectProperty(Effect, _contents.Effect, GetActiveImage()?.RenderImage);
|
||||
|
||||
internal void UpdateCoordinateMaps()
|
||||
{
|
||||
UIImage activeImage = this.GetActiveImage();
|
||||
UIImage activeImage = GetActiveImage();
|
||||
if (activeImage == null)
|
||||
return;
|
||||
if (this._stretchMode == StretchingPolicy.Fill && activeImage.NineGrid != Inset.Zero)
|
||||
if (_stretchMode == StretchingPolicy.Fill && activeImage.NineGrid != Inset.Zero)
|
||||
{
|
||||
this._contents.RelativeSize = true;
|
||||
this._contents.Size = Vector2.UnitVector;
|
||||
this._contents.SetNineGrid(activeImage.NineGrid.Left, activeImage.NineGrid.Top, activeImage.NineGrid.Right, activeImage.NineGrid.Bottom);
|
||||
_contents.RelativeSize = true;
|
||||
_contents.Size = Vector2.UnitVector;
|
||||
_contents.SetNineGrid(activeImage.NineGrid.Left, activeImage.NineGrid.Top, activeImage.NineGrid.Right, activeImage.NineGrid.Bottom);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 visualSize = this.VisualSize;
|
||||
Vector2 visualSize = VisualSize;
|
||||
Size layoutSize = new Size((int)visualSize.X, (int)visualSize.Y);
|
||||
Size size = activeImage.Size;
|
||||
RectangleF source;
|
||||
RectangleF destination;
|
||||
this.CalculatePaintRectangles(size, layoutSize, out source, out destination);
|
||||
switch (size.IsEmpty ? 1 : (int)this._stretchMode)
|
||||
CalculatePaintRectangles(size, layoutSize, out source, out destination);
|
||||
switch (size.IsEmpty ? 1 : (int)_stretchMode)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
@@ -369,21 +369,21 @@ namespace Microsoft.Iris.ViewItems
|
||||
coordMap.AddValue(1f, flValue2, Orientation.Horizontal);
|
||||
coordMap.AddValue(1f, flValue4, Orientation.Vertical);
|
||||
}
|
||||
this._contents.RelativeSize = false;
|
||||
this._contents.Position = new Vector3(destination.Left, destination.Top, 0.0f);
|
||||
this._contents.Size = new Vector2(destination.Width, destination.Height);
|
||||
this._contents.SetCoordMap(0, coordMap);
|
||||
_contents.RelativeSize = false;
|
||||
_contents.Position = new Vector3(destination.Left, destination.Top, 0.0f);
|
||||
_contents.Size = new Vector2(destination.Width, destination.Height);
|
||||
_contents.SetCoordMap(0, coordMap);
|
||||
break;
|
||||
case 1:
|
||||
this._contents.RelativeSize = true;
|
||||
this._contents.Size = Vector2.UnitVector;
|
||||
this._contents.SetCoordMap(0, null);
|
||||
_contents.RelativeSize = true;
|
||||
_contents.Size = Vector2.UnitVector;
|
||||
_contents.SetCoordMap(0, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UIImage GetActiveImage() => this._contentImage.Status != ImageStatus.Complete ? (this._contentImage.Status == ImageStatus.Loading || this._contentImage.Status == ImageStatus.PendingLoad ? this.AcquiringImage : this.ErrorImage) : this._contentImage;
|
||||
private UIImage GetActiveImage() => _contentImage.Status != ImageStatus.Complete ? (_contentImage.Status == ImageStatus.Loading || _contentImage.Status == ImageStatus.PendingLoad ? AcquiringImage : ErrorImage) : _contentImage;
|
||||
|
||||
private void CalculatePaintRectangles(
|
||||
Size originalSourceSize,
|
||||
@@ -391,7 +391,7 @@ namespace Microsoft.Iris.ViewItems
|
||||
out RectangleF source,
|
||||
out RectangleF destination)
|
||||
{
|
||||
if (this._stretchMode == StretchingPolicy.Fill)
|
||||
if (_stretchMode == StretchingPolicy.Fill)
|
||||
{
|
||||
source = RectangleF.Zero;
|
||||
destination = RectangleF.Zero;
|
||||
@@ -407,7 +407,7 @@ namespace Microsoft.Iris.ViewItems
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (this._stretchMode)
|
||||
switch (_stretchMode)
|
||||
{
|
||||
case StretchingPolicy.None:
|
||||
size1 = Size.Min(size1, size2);
|
||||
@@ -420,10 +420,10 @@ namespace Microsoft.Iris.ViewItems
|
||||
size1 = Size.LargestFit(size2, size1);
|
||||
break;
|
||||
}
|
||||
float dimensionOffset1 = this.CalculateDimensionOffset(size1.Width, originalSourceSize.Width, this._horizontalAlignment);
|
||||
float dimensionOffset2 = this.CalculateDimensionOffset(size2.Width, layoutSize.Width, this._horizontalAlignment);
|
||||
float dimensionOffset3 = this.CalculateDimensionOffset(size1.Height, originalSourceSize.Height, this._verticalAlignment);
|
||||
float dimensionOffset4 = this.CalculateDimensionOffset(size2.Height, layoutSize.Height, this._verticalAlignment);
|
||||
float dimensionOffset1 = CalculateDimensionOffset(size1.Width, originalSourceSize.Width, _horizontalAlignment);
|
||||
float dimensionOffset2 = CalculateDimensionOffset(size2.Width, layoutSize.Width, _horizontalAlignment);
|
||||
float dimensionOffset3 = CalculateDimensionOffset(size1.Height, originalSourceSize.Height, _verticalAlignment);
|
||||
float dimensionOffset4 = CalculateDimensionOffset(size2.Height, layoutSize.Height, _verticalAlignment);
|
||||
source = new RectangleF(dimensionOffset1, dimensionOffset3, size1.Width, size1.Height);
|
||||
destination = new RectangleF(dimensionOffset2, dimensionOffset4, size2.Width, size2.Height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user