From 3bd9df11914db8fef79a2c0690d7a9f261567cec Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Fri, 6 Sep 2013 13:10:41 +0200 Subject: [PATCH] Move draw order sorting into SceneElement --- src/scene.cpp | 20 +++++++++++++++----- src/scene.h | 4 ++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/scene.cpp b/src/scene.cpp index 5cce1ec..8384fa2 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -38,12 +38,8 @@ void Scene::insert(SceneElement &element) { SceneElement *e = iter->data; - if (element.z <= e->z) + if (element < *e) { - if (element.z == e->z) - if (element.creationStamp > e->creationStamp) - continue; - elements.insertBefore(element.link, *iter); return; } @@ -140,6 +136,20 @@ void SceneElement::setVisible(bool value) visible = value; } +bool SceneElement::operator<(const SceneElement &o) const +{ + if (z <= o.z) + { + if (z == o.z) + if (creationStamp > o.creationStamp) + return false; + + return true; + } + + return false; +} + void SceneElement::unlink() { scene->elements.remove(link); diff --git a/src/scene.h b/src/scene.h index 655d9e5..0e2ed0f 100644 --- a/src/scene.h +++ b/src/scene.h @@ -81,6 +81,10 @@ protected: virtual void draw() = 0; virtual void onGeometryChange(const Scene::Geometry &) {} + /* Compares to elements in terms of their display priority; + * elements with lower priority are drawn earlier */ + bool operator<(const SceneElement &o) const; + void unlink(); IntruListLink link;