Move draw order sorting into SceneElement

This commit is contained in:
Jonas Kulla 2013-09-06 13:10:41 +02:00
parent 5ca513fcec
commit 3bd9df1191
2 changed files with 19 additions and 5 deletions

View File

@ -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);

View File

@ -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<SceneElement> link;