UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
node.h
Go to the documentation of this file.
1 #ifndef UGDK_GRAPHIC_NODE_H_
2 #define UGDK_GRAPHIC_NODE_H_
3 
4 #include <vector>
5 #include <ugdk/graphic.h>
7 
8 namespace ugdk {
9 namespace graphic {
10 
12 class Node {
13  public:
14  typedef std::vector<Node*> NodeSet;
15 
16  Node(Drawable* drawable = NULL, Modifier* modifier = NULL)
17  : modifier_(modifier),
18  drawable_(drawable),
19  light_(NULL),
20  active_(true),
21  zindex_(0.0),
22  parent_(NULL),
23  must_sort_(false) {}
24 
25  ~Node();
26 
28  void Update(double dt);
29  void Render() const;
30  void RenderLight() const;
31 
32  void set_drawable(Drawable* drawable) { drawable_ = drawable; }
33  void set_light(Light* light) { light_ = light; }
34  void set_active(const bool active) { active_ = active; }
35  void set_zindex(const double zindex);
36 
37  Modifier* modifier() { return (modifier_ != NULL) ? modifier_ : (modifier_ = new Modifier); }
38  const Modifier* modifier() const { return modifier_; }
39  Drawable* drawable() { return drawable_; }
40  const Drawable* drawable() const { return drawable_; }
41  Light* light() { return light_; }
42  const Light* light() const { return light_; }
43  bool active() const { return active_; }
44  double zindex() const { return zindex_; }
45 
46  void AddChild(Node *new_child) {
47  if(new_child->parent_) new_child->parent_->RemoveChild(new_child);
48  childs_.push_back(new_child);
49  new_child->parent_ = this;
50  must_sort_ = true;
51  }
52  void RemoveChild(Node *child);
53 
54 
55  static bool CompareByZIndex(const Node *a, const Node *b);
56  void SortChildren();
57 
58  private:
59  Modifier* modifier_;
60  Drawable* drawable_;
61  Light* light_;
62  bool active_;
63  double zindex_;
64 
65  NodeSet childs_;
66  Node* parent_;
67  bool must_sort_;
68 };
69 
70 } // namespace graphic
71 } // namespace ugdk
72 
73 #endif // UGDK_GRAPHIC_NODE_H_