inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg__switch 00005 #define inlib_sg__switch 00006 00007 // NOTE : "switch" is a C/C++ keyword. Have "_switch" as a class name. 00008 00009 #include "group" 00010 #include "sf" 00011 00012 namespace inlib { 00013 namespace sg { 00014 00015 class _switch : public group { 00016 void add_fields(){ 00017 add_field(&which); 00018 } 00019 public: 00020 sf<int> which; 00021 public: //node 00022 virtual void render(render_action& a_action) { 00023 int index = which.value(); 00024 if(index==(-1)) { 00025 std::vector<node*>::iterator it; 00026 for(it=m_children.begin();it!=m_children.end();++it) { 00027 (*it)->render(a_action); 00028 } 00029 } else if((index>=0)&&(index<(int)m_children.size())) { 00030 m_children[index]->render(a_action); 00031 } 00032 } 00033 virtual void pick(pick_action& a_action) { 00034 int index = which.value(); 00035 if(index==(-1)) { 00036 std::vector<node*>::iterator it; 00037 for(it=m_children.begin();it!=m_children.end();++it) { 00038 (*it)->pick(a_action); 00039 if(a_action.done()) break; 00040 } 00041 } else if((index>=0)&&(index<(int)m_children.size())) { 00042 m_children[index]->pick(a_action); 00043 } 00044 } 00045 virtual void bbox(bbox_action& a_action) { 00046 int index = which.value(); 00047 if(index==(-1)) { 00048 std::vector<node*>::iterator it; 00049 for(it=m_children.begin();it!=m_children.end();++it) { 00050 (*it)->bbox(a_action); 00051 } 00052 } else if((index>=0)&&(index<(int)m_children.size())) { 00053 m_children[index]->bbox(a_action); 00054 } 00055 } 00056 virtual void search(search_action& a_action) { 00057 int index = which.value(); 00058 if(index==(-1)) { 00059 std::vector<node*>::iterator it; 00060 for(it=m_children.begin();it!=m_children.end();++it) { 00061 (*it)->search(a_action); 00062 if(a_action.done()) break; 00063 } 00064 } else if((index>=0)&&(index<(int)m_children.size())) { 00065 m_children[index]->search(a_action); 00066 } 00067 } 00068 virtual void event(event_action& a_action) { 00069 int index = which.value(); 00070 if(index==(-1)) { 00071 std::vector<node*>::iterator it; 00072 for(it=m_children.begin();it!=m_children.end();++it) { 00073 (*it)->event(a_action); 00074 //if(a_action.handled()) break; 00075 } 00076 } else if((index>=0)&&(index<(int)m_children.size())) { 00077 m_children[index]->event(a_action); 00078 } 00079 } 00080 public: 00081 _switch() 00082 :group() 00083 ,which(-1) 00084 { 00085 add_fields(); 00086 } 00087 virtual ~_switch(){} 00088 protected: 00089 _switch(const _switch& a_from) 00090 :group(a_from) 00091 ,which(a_from.which) 00092 { 00093 add_fields(); 00094 } 00095 _switch& operator=(const _switch& a_from){ 00096 group::operator=(a_from); 00097 which = a_from.which; 00098 return *this; 00099 } 00100 }; 00101 00102 }} 00103 00104 #endif