using System.Collections.Concurrent; using System.Collections.Generic; namespace BetterGenshinImpact.View.Drawable; public class DrawContent { /// /// 在遮罩窗口上绘制的矩形 /// public ConcurrentDictionary> RectList { get; set; } = new(); /// /// 在遮罩窗口上绘制的文本 /// public ConcurrentDictionary> TextList { get; set; } = new(); /// /// 在遮罩窗口上绘制的文本 /// public ConcurrentDictionary> LineList { get; set; } = new(); public void PutRect(string key, RectDrawable newRect) { if (RectList.TryGetValue(key, out var prevRect)) { if (prevRect.Count == 0 && newRect.Equals(prevRect[0])) { return; } } RectList[key] = [newRect]; MaskWindow.Instance().Refresh(); } public void PutOrRemoveRectList(string key, List? list) { bool changed = false; if (RectList.TryGetValue(key, out var prevRect)) { if (list == null) { RectList.TryRemove(key, out _); changed = true; } else if (prevRect.Count != list.Count) { RectList[key] = list; changed = true; } else { // 不逐一比较了,使用这个方法的地方,都是在每一帧都会刷新的 RectList[key] = list; changed = true; } } else { if (list is { Count: > 0 }) { RectList[key] = list; changed = true; } } if (changed) { MaskWindow.Instance().Refresh(); } } public void RemoveRect(string key) { if (RectList.TryGetValue(key, out _)) { RectList.TryRemove(key, out _); MaskWindow.Instance().Refresh(); } } public void PutLine(string key, LineDrawable newLine) { if (LineList.TryGetValue(key, out var prev)) { if (prev.Count == 0 && newLine.Equals(prev[0])) { return; } } LineList[key] = [newLine]; MaskWindow.Instance().Refresh(); } public void RemoveLine(string key) { if (LineList.TryGetValue(key, out _)) { LineList.TryRemove(key, out _); MaskWindow.Instance().Refresh(); } } /// /// 清理所有绘制内容 /// public void ClearAll() { if (RectList.IsEmpty && TextList.IsEmpty && LineList.IsEmpty) { return; } RectList.Clear(); TextList.Clear(); LineList.Clear(); MaskWindow.Instance().Refresh(); } }