UGDK
|
00001 #ifndef UGDK_GRAPHIC_NODE_H_ 00002 #define UGDK_GRAPHIC_NODE_H_ 00003 00004 #include <vector> 00005 #include <ugdk/graphic.h> 00006 #include <ugdk/graphic/modifier.h> 00007 00008 namespace ugdk { 00009 namespace graphic { 00010 00012 class Node { 00013 public: 00014 typedef std::vector<Node*> NodeSet; 00015 00016 Node(Drawable* drawable = NULL, Modifier* modifier = NULL) 00017 : modifier_(modifier), 00018 drawable_(drawable), 00019 light_(NULL), 00020 active_(true), 00021 zindex_(0.0), 00022 parent_(NULL), 00023 must_sort_(false) {} 00024 00025 ~Node(); 00026 00028 void Update(double dt); 00029 void Render() const; 00030 void RenderLight() const; 00031 00032 void set_drawable(Drawable* drawable) { drawable_ = drawable; } 00033 void set_light(Light* light) { light_ = light; } 00034 void set_active(const bool active) { active_ = active; } 00035 void set_zindex(const double zindex); 00036 00037 Modifier* modifier() { return (modifier_ != NULL) ? modifier_ : (modifier_ = new Modifier); } 00038 const Modifier* modifier() const { return modifier_; } 00039 Drawable* drawable() { return drawable_; } 00040 const Drawable* drawable() const { return drawable_; } 00041 Light* light() { return light_; } 00042 const Light* light() const { return light_; } 00043 bool active() const { return active_; } 00044 double zindex() const { return zindex_; } 00045 00046 void AddChild(Node *new_child) { 00047 if(new_child->parent_) new_child->parent_->RemoveChild(new_child); 00048 childs_.push_back(new_child); 00049 new_child->parent_ = this; 00050 must_sort_ = true; 00051 } 00052 void RemoveChild(Node *child); 00053 00054 00055 static bool CompareByZIndex(const Node *a, const Node *b); 00056 void SortChildren(); 00057 00058 private: 00059 Modifier* modifier_; 00060 Drawable* drawable_; 00061 Light* light_; 00062 bool active_; 00063 double zindex_; 00064 00065 NodeSet childs_; 00066 Node* parent_; 00067 bool must_sort_; 00068 }; 00069 00070 } // namespace graphic 00071 } // namespace ugdk 00072 00073 #endif // UGDK_GRAPHIC_NODE_H_