Browse Source

SceneGraph: added Object::move().

pull/459/head
Vladimír Vondruš 6 years ago
parent
commit
8b9bf07dce
  1. 4
      doc/changelog.dox
  2. 17
      src/Magnum/SceneGraph/Object.h
  3. 23
      src/Magnum/SceneGraph/Test/ObjectTest.cpp

4
doc/changelog.dox

@ -66,6 +66,10 @@ See also:
- Added @ref Math::fmod() (see [mosra/magnum#454](https://github.com/mosra/magnum/pull/454))
- Added @ref Math::binomialCoefficient() (see [mosra/magnum#461](https://github.com/mosra/magnum/pull/461))
@subsubsection changelog-latest-new-scenegraph SceneGraph library
- Added @ref SceneGraph::Object::move()
@subsection changelog-latest-changes Changes and improvements
@subsubsection changelog-latest-changes-gl GL library

17
src/Magnum/SceneGraph/Object.h

@ -157,6 +157,23 @@ template<class Transformation> class Object: public AbstractObject<Transformatio
return Containers::LinkedListItem<Object<Transformation>, Object<Transformation>>::list();
}
/**
* @brief Move a child object before another
* @return Reference to self (for method chaining)
* @m_since_latest
*
* Doesn't have any effect on draw order, only on the child order when
* iterating through @ref children(). The @p child is expected to be a
* child of this object, @p before is either a child of this object or
* @cpp nullptr @ce in which case the @p child is moved to the last
* position in the child list.
* @see @ref Corrade::Containers::LinkedList::move()
*/
Object<Transformation>& move(Object<Transformation>& child, Object<Transformation>* before) {
Containers::LinkedList<Object<Transformation>>::move(&child, before);
return *this;
}
/** @brief Previous sibling object or `nullptr`, if this is the first object */
Object<Transformation>* previousSibling() {
return Containers::LinkedListItem<Object<Transformation>, Object<Transformation>>::previous();

23
src/Magnum/SceneGraph/Test/ObjectTest.cpp

@ -40,6 +40,7 @@ struct ObjectTest: TestSuite::Tester {
void parenting();
void addChild();
void move();
void scene();
void setParentKeepTransformation();
void setParentKeepTransformationInvalid();
@ -78,6 +79,7 @@ ObjectTest::ObjectTest() {
&ObjectTest::parenting,
&ObjectTest::addChild,
&ObjectTest::move,
&ObjectTest::scene,
&ObjectTest::setParentKeepTransformation,
&ObjectTest::setParentKeepTransformationInvalid,
@ -154,6 +156,27 @@ void ObjectTest::addChild() {
CORRADE_COMPARE(p.parent(), &o);
}
void ObjectTest::move() {
Scene3D scene;
Object3D* a = new Object3D{&scene};
Object3D* b = new Object3D{&scene};
Object3D* c = new Object3D{&scene};
CORRADE_COMPARE(a->nextSibling(), b);
CORRADE_COMPARE(b->nextSibling(), c);
CORRADE_COMPARE(c->nextSibling(), nullptr);
scene.move(*a, c);
CORRADE_COMPARE(b->nextSibling(), a);
CORRADE_COMPARE(a->nextSibling(), c);
CORRADE_COMPARE(c->nextSibling(), nullptr);
scene.move(*a, nullptr);
CORRADE_COMPARE(b->nextSibling(), c);
CORRADE_COMPARE(c->nextSibling(), a);
CORRADE_COMPARE(a->nextSibling(), nullptr);
}
void ObjectTest::scene() {
Scene3D scene;
CORRADE_VERIFY(scene.scene() == &scene);

Loading…
Cancel
Save