-
Notifications
You must be signed in to change notification settings - Fork 7
/
LayerOrderer.hx
78 lines (68 loc) · 1.99 KB
/
LayerOrderer.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package guise.layer;
import composure.injectors.Injector;
import composure.traits.AbstractTrait;
import guise.controls.ControlLayers;
import guise.platform.types.DisplayAccessTypes;
import org.tbyrne.collections.UniqueList;
import msignal.Signal;
import composure.traitCheckers.TraitTypeChecker;
import guise.platform.PlatformAccessor;
/**
* ...
* @author Tom Byrne
*/
class LayerOrderer extends AbstractTrait
{
public var sorting(default,set_sorting):Array<String>;
private function set_sorting(value:Array<String>):Array<String> {
sorting = value;
if (sorting != null && _layerOrderAccess!=null) {
checkDepths();
}
return value;
}
private var _layerOrderAccess:ILayerOrderAccess;
public function new(?sorting:Array<String>, childMode:Bool=true)
{
super();
this.sorting = sorting;
addSiblingTrait(new PlatformAccessor(ILayerOrderAccess, null, onLayeringAdd, onLayeringRemove));
}
public function onLayeringAdd(access:ILayerOrderAccess):Void {
_layerOrderAccess = access;
_layerOrderAccess.layeringChanged.add(onLayeringChanged);
if (sorting != null) {
checkDepths();
}
}
private function onLayeringChanged(from:ILayerOrderAccess):Void {
if (sorting != null )checkDepths();
}
public function onLayeringRemove(access:ILayerOrderAccess):Void {
_layerOrderAccess.layeringChanged.remove(onLayeringChanged);
_layerOrderAccess = null;
}
private function checkDepths():Void {
var layers = _layerOrderAccess.layers;
var depth1:Int = 0;
while (depth1 < layers.length - 1) {
var layer1 = layers[depth1];
var index1 = Lambda.indexOf(sorting, layer1);
if (index1 != -1) {
var depth2:Int = depth1 + 1;
while(depth2 < layers.length){
var layer2 = layers[depth2];
var index2 = Lambda.indexOf(sorting, layer2);
if (index2 != -1 && index1 > index2) {
_layerOrderAccess.swapDepths(layer1, layer2);
}
++depth2;
}
}
++depth1;
}
}
/*private function onSortingChanged(from:LayerSorting):Void {
checkDepths();
}*/
}