/*#region Constants * * /// <summary> * /// The total number of part group part Ids. * /// </summary> * private const int PartCount = Categories.Sprites.SpriteSelection.PartCount; * /// <summary> * /// True if HG-3 image data is cached in the <see cref="ISpritePart"/>. * /// </summary> * private readonly static bool CacheHg3s = true; * #endregion*/ /*#region Fields * * /// <summary> * /// The container that holds all images. * /// </summary> * private Grid PART_Container; * /// <summary> * /// The difference from the total size of all sprites combined. Used for margins. * /// </summary> * private Thickness expandShrink; * /// <summary> * /// The current parts being displayed. * /// </summary> * private readonly ISpritePart[] parts = new ISpritePart[PartCount]; * /// <summary> * /// The images inside the <see cref="PART_Container"/>. * /// </summary> * private readonly Image[] images = new Image[PartCount]; * #endregion*/ /*#region Dependency Properties * * /// <summary> * /// The property for the sprite database used to get the sprite parts from. * /// </summary> * public static readonly DependencyProperty SpriteDatabaseProperty = * DependencyProperty.Register( * "SpriteDatabase", * typeof(SpriteDatabase), * typeof(SpriteImage), * new FrameworkPropertyMetadata( * OnSpriteDatabaseChanged)); * /// <summary> * /// The property for the sprite selection that determines what parts to draw. * /// </summary> * public static readonly DependencyProperty SpriteSelectionProperty = * DependencyProperty.Register( * "SpriteSelection", * typeof(IReadOnlySpriteSelection), * typeof(SpriteImage), * new FrameworkPropertyMetadata( * OnSpriteSelectionChanged)); * /// <summary> * /// The property to determine if the image should be expanded to the total size of all sprites combined. * /// </summary> * public static readonly DependencyProperty ExpandProperty = * DependencyProperty.Register( * "Expand", * typeof(bool), * typeof(SpriteImage), * new FrameworkPropertyMetadata( * false, * OnExpandChanged)); * * private static void OnSpriteDatabaseChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { * SpriteImage control = (SpriteImage) d; * * if (e.OldValue is SpriteDatabase oldSpriteDb) * oldSpriteDb.BuildComplete -= control.OnSpriteDatabaseBuildComplete; * if (e.NewValue is SpriteDatabase newSpriteDb) * newSpriteDb.BuildComplete += control.OnSpriteDatabaseBuildComplete; * * control.UpdateSelection(); * } * private static void OnSpriteSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { * SpriteImage control = (SpriteImage) d; * IReadOnlySpriteSelection oldValue = (IReadOnlySpriteSelection) e.OldValue; * IReadOnlySpriteSelection newValue = (IReadOnlySpriteSelection) e.NewValue; * * if (oldValue is INotifyPropertyChanged oldPropChanged) * oldPropChanged.PropertyChanged -= control.OnSpriteSelectionPropertyChanged; * if (newValue is INotifyPropertyChanged newPropChanged) * newPropChanged.PropertyChanged += control.OnSpriteSelectionPropertyChanged; * * if (oldValue?.GroupPartIds is INotifyCollectionChanged oldColChanged) * oldColChanged.CollectionChanged -= control.OnSpriteSelectionGroupPartsChanged; * if (newValue?.GroupPartIds is INotifyCollectionChanged newColChanged) * newColChanged.CollectionChanged += control.OnSpriteSelectionGroupPartsChanged; * * control.UpdateSelection(); * } * private static void OnExpandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { * SpriteImage control = (SpriteImage) d; * control.UpdateMargins(); * } * * /// <summary> * /// Gets or sets the sprite database used to get the sprite parts from. * /// </summary> * public SpriteDatabase SpriteDatabase { * get => (SpriteDatabase) GetValue(SpriteDatabaseProperty); * set => SetValue(SpriteDatabaseProperty, value); * } * /// <summary> * /// Gets or sets the sprite selection that determines what parts to draw. * /// </summary> * public IReadOnlySpriteSelection SpriteSelection { * get => (IReadOnlySpriteSelection) GetValue(SpriteSelectionProperty); * set => SetValue(SpriteSelectionProperty, value); * } * /// <summary> * /// Gets or sets if the image should be expanded to the total size of all sprites combined. * /// </summary> * public bool Expand { * get => (bool) GetValue(ExpandProperty); * set => SetValue(ExpandProperty, value); * } * #endregion*/ #region Static Constructor static SpriteImage() { DefaultStyleKeyProperty.AddOwner(typeof(SpriteImage), new FrameworkPropertyMetadata(typeof(SpriteImage))); }