mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 09:06:23 +02:00
Implement full canvas compositing and redraw only on state change
This commit is contained in:
@@ -1,29 +1,49 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace RemSox.Utils;
|
||||
|
||||
public abstract class ChangedPropertiesTracker : INotifyPropertyChanged
|
||||
{
|
||||
private readonly Dictionary<string, object?> changedProperties = [];
|
||||
private readonly Dictionary<string, object?> properties = [];
|
||||
private readonly HashSet<string> changedPropertyNames = [];
|
||||
|
||||
public IReadOnlyDictionary<string, object?> ChangedProperties => changedProperties;
|
||||
public IReadOnlyDictionary<string, object?> ChangedProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
var changes = new Dictionary<string, object?>();
|
||||
foreach (var name in changedPropertyNames)
|
||||
{
|
||||
if (properties.TryGetValue(name, out var value))
|
||||
{
|
||||
changes[name] = value;
|
||||
}
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, object?> AllProperties => properties;
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public bool AnyPropertyChanged => changedProperties.Count > 0;
|
||||
public bool AnyPropertyChanged => changedPropertyNames.Count > 0;
|
||||
|
||||
protected void SetProperty<T>(string name, ref T field, T value)
|
||||
{
|
||||
if (!EqualityComparer<T>.Default.Equals(field, value))
|
||||
{
|
||||
field = value;
|
||||
changedProperties[name] = value;
|
||||
properties[name] = value;
|
||||
changedPropertyNames.Add(name);
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearChangedProperties() => changedProperties.Clear();
|
||||
public void ClearChangedProperties() => changedPropertyNames.Clear();
|
||||
|
||||
public bool IsPropertyChanged(string name) => changedProperties.ContainsKey(name);
|
||||
public bool IsPropertyChanged(string name) => changedPropertyNames.Contains(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user