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;