2019-06-20 00:40:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
|
{
|
|
|
|
|
internal class DrawLayerManager
|
|
|
|
|
{
|
|
|
|
|
private SortedList<int, int> layerOrder = new SortedList<int, int>();
|
|
|
|
|
|
|
|
|
|
private Dictionary<int, HashSet<Guid>> layerIndexToComponentIDs = new Dictionary<int, HashSet<Guid>>();
|
|
|
|
|
private Dictionary<int, HashSet<GeneralRenderer>> layerIndexToGeneralRenderers = new Dictionary<int, HashSet<GeneralRenderer>>();
|
|
|
|
|
|
2019-06-20 05:38:56 +00:00
|
|
|
|
private Dictionary<Guid, int> componentIDToLayerIndex = new Dictionary<Guid, int>();
|
|
|
|
|
|
2019-06-20 00:40:01 +00:00
|
|
|
|
public IEnumerable<int> LayerOrder { get { return layerOrder.Values; } }
|
|
|
|
|
|
|
|
|
|
public void RegisterGeneralRendererWithLayer(GeneralRenderer renderer, int layer)
|
|
|
|
|
{
|
|
|
|
|
if (layerIndexToGeneralRenderers.ContainsKey(layer))
|
|
|
|
|
{
|
|
|
|
|
var set = layerIndexToGeneralRenderers[layer];
|
|
|
|
|
set.Add(renderer);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var set = new HashSet<GeneralRenderer>();
|
|
|
|
|
layerIndexToGeneralRenderers.Add(layer, set);
|
|
|
|
|
set.Add(renderer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!layerOrder.ContainsKey(layer))
|
|
|
|
|
{
|
|
|
|
|
layerOrder.Add(layer, layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UnregisterGeneralRendererWithLayer(GeneralRenderer renderer, int layer)
|
|
|
|
|
{
|
|
|
|
|
if (layerIndexToGeneralRenderers.ContainsKey(layer))
|
|
|
|
|
{
|
|
|
|
|
layerIndexToGeneralRenderers[layer].Remove(renderer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AdjustRendererLayer(GeneralRenderer renderer, int oldLayer, int newLayer)
|
|
|
|
|
{
|
|
|
|
|
UnregisterGeneralRendererWithLayer(renderer, oldLayer);
|
|
|
|
|
RegisterGeneralRendererWithLayer(renderer, newLayer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterComponentWithLayer(Guid id, int layer)
|
|
|
|
|
{
|
|
|
|
|
if (layerIndexToComponentIDs.ContainsKey(layer))
|
|
|
|
|
{
|
|
|
|
|
var set = layerIndexToComponentIDs[layer];
|
|
|
|
|
set.Add(id);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var set = new HashSet<Guid>();
|
|
|
|
|
layerIndexToComponentIDs.Add(layer, set);
|
|
|
|
|
set.Add(id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 05:38:56 +00:00
|
|
|
|
componentIDToLayerIndex[id] = layer;
|
|
|
|
|
|
2019-06-20 00:40:01 +00:00
|
|
|
|
if (!layerOrder.ContainsKey(layer))
|
|
|
|
|
{
|
|
|
|
|
layerOrder.Add(layer, layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 05:38:56 +00:00
|
|
|
|
public void UnRegisterComponentWithLayer(Guid id)
|
2019-06-20 00:40:01 +00:00
|
|
|
|
{
|
2019-06-20 05:38:56 +00:00
|
|
|
|
if (componentIDToLayerIndex.ContainsKey(id))
|
2019-06-20 00:40:01 +00:00
|
|
|
|
{
|
2019-06-20 05:38:56 +00:00
|
|
|
|
var layer = componentIDToLayerIndex[id];
|
2019-06-20 00:40:01 +00:00
|
|
|
|
layerIndexToComponentIDs[layer].Remove(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 05:38:56 +00:00
|
|
|
|
public void AdjustComponentLayer(Guid id, int layer)
|
2019-06-20 00:40:01 +00:00
|
|
|
|
{
|
2019-06-20 05:38:56 +00:00
|
|
|
|
UnRegisterComponentWithLayer(id);
|
|
|
|
|
RegisterComponentWithLayer(id, layer);
|
2019-06-20 00:40:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Guid> ComponentIDsByLayer(int layer)
|
|
|
|
|
{
|
|
|
|
|
return layerIndexToComponentIDs.ContainsKey(layer) ?
|
|
|
|
|
layerIndexToComponentIDs[layer] :
|
|
|
|
|
Enumerable.Empty<Guid>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<GeneralRenderer> GeneralRenderersByLayer(int layer)
|
|
|
|
|
{
|
|
|
|
|
return layerIndexToGeneralRenderers.ContainsKey(layer) ?
|
|
|
|
|
layerIndexToGeneralRenderers[layer] :
|
|
|
|
|
Enumerable.Empty<GeneralRenderer>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|