Browse code

handle z order draft

devnewton authored on 13/09/2015 14:58:32
Showing 4 changed files
... ...
@@ -9,7 +9,7 @@ namespace scenimp {
9 9
     group::~group() {
10 10
     }
11 11
 
12
-    const node_list& group::children() const {
12
+    const node_set& group::children() const {
13 13
         return children_;
14 14
     }
15 15
 
... ...
@@ -18,5 +18,10 @@ namespace scenimp {
18 18
             c->render(r);
19 19
         }
20 20
     }
21
+    
22
+    void group::set_z(node* child, int z) {
23
+        auto it = children_.find(child);
24
+        children_.modify(it, [z](node* n) { n->z_ = z; });
25
+    }
21 26
 
22 27
 }
... ...
@@ -1,10 +1,30 @@
1 1
 #pragma once
2 2
 
3
-
4 3
 #include "node.h"
4
+#include <boost/multi_index_container.hpp>
5
+#include <boost/multi_index/ordered_index.hpp>
6
+#include <boost/multi_index/hashed_index.hpp>
7
+#include <boost/multi_index/identity.hpp>
8
+#include <boost/multi_index/mem_fun.hpp>
5 9
 
6 10
 namespace scenimp {
7 11
 
12
+    namespace container {
13
+        using namespace boost::multi_index;
14
+        
15
+        struct z_index {};
16
+
17
+        typedef multi_index_container<
18
+        node*,
19
+        indexed_by<
20
+            hashed_unique< identity< node* > >,
21
+            ordered_non_unique< tag< z_index >, const_mem_fun<node, int, &node::z > >
22
+        >
23
+        > node_set;
24
+    }
25
+    
26
+    using container::node_set;
27
+
8 28
     class scene;
9 29
     class rendering;
10 30
 
... ...
@@ -14,13 +34,14 @@ namespace scenimp {
14 34
         group(const group&) = delete;
15 35
         virtual ~group();
16 36
 
17
-        const node_list& children() const;
37
+        const node_set& children() const;
38
+        void set_z(node* child, int z);
18 39
 
19 40
     protected:
20 41
         virtual void do_render(rendering& r);
21 42
 
22 43
     private:
23
-        node_list children_;
44
+        node_set children_;
24 45
 
25 46
         friend class scene;
26 47
     };
... ...
@@ -5,7 +5,8 @@
5 5
 namespace scenimp {
6 6
 
7 7
     node::node()
8
-    : parent_(nullptr) {
8
+    : parent_(nullptr),
9
+    z_(0) {
9 10
     }
10 11
 
11 12
     node::~node() {
... ...
@@ -24,4 +25,8 @@ namespace scenimp {
24 25
         do_render(r);
25 26
         r.pop_pos(*this);
26 27
     }
28
+
29
+    int node::z() const {
30
+        return z_;
31
+    }
27 32
 }
... ...
@@ -1,7 +1,6 @@
1 1
 #pragma once
2 2
 
3 3
 #include "geometry.h"
4
-#include <boost/container/flat_set.hpp>
5 4
 
6 5
 namespace scenimp {
7 6
 
... ...
@@ -19,6 +18,7 @@ namespace scenimp {
19 18
 
20 19
         const point& pos() const;
21 20
         point& pos();
21
+        int z() const;
22 22
 
23 23
     protected:
24 24
         virtual void do_render(rendering& r) = 0;
... ...
@@ -26,12 +26,12 @@ namespace scenimp {
26 26
     private:
27 27
         point pos_;
28 28
         group* parent_;
29
+        int z_;
29 30
 
30 31
         friend class scene;
32
+        friend class group;
31 33
     };
32 34
 
33
-    typedef boost::container::flat_set<node* > node_list;
34
-
35 35
 }
36 36
 
37 37