Take preferred position into account when ordering

Take overlay preferred position into account when ordering overlays.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-08-26 21:51:19 +02:00
parent 428832bcf9
commit 161c9f5ec3

View File

@@ -58,11 +58,19 @@ public class OverlayManager
@VisibleForTesting
static final Comparator<Overlay> OVERLAY_COMPARATOR = (a, b) ->
{
if (a.getPosition() != b.getPosition())
final OverlayPosition aPos = a.getPreferredPosition() != null
? a.getPreferredPosition()
: a.getPosition();
final OverlayPosition bPos = b.getPreferredPosition() != null
? b.getPreferredPosition()
: b.getPosition();
if (aPos != bPos)
{
// This is so non-dynamic overlays render after dynamic
// overlays, which are generally in the scene
return a.getPosition().compareTo(b.getPosition());
return aPos.compareTo(bPos);
}
// For dynamic overlays, higher priority means to
@@ -70,7 +78,7 @@ public class OverlayManager
// For non-dynamic overlays, higher priority means
// draw *first* so that they are closer to their
// defined position.
return a.getPosition() == OverlayPosition.DYNAMIC
return aPos == OverlayPosition.DYNAMIC
? a.getPriority().compareTo(b.getPriority())
: b.getPriority().compareTo(a.getPriority());
};