Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_sg_event_dispatcher 4 #ifndef tools_sg_event_dispatcher 5 #define tools_sg_event_dispatcher 5 #define tools_sg_event_dispatcher 6 6 7 // Node that holds "callbacks" that can be tr 7 // Node that holds "callbacks" that can be triggered when an event_action 8 // traversed it. A typical example is to handl 8 // traversed it. A typical example is to handle a mouse resize of the viewer/window 9 // and response to it by changing some geomtry 9 // and response to it by changing some geomtry in the scene graphs (for example 10 // to arrange that a tools::sg::plots maps the 10 // to arrange that a tools::sg::plots maps the full viewer/window area). 11 11 12 #include "node" 12 #include "node" 13 #include "cbks" 13 #include "cbks" 14 #include "event_action" 14 #include "event_action" 15 #include "ecbk" 15 #include "ecbk" 16 16 17 namespace tools { 17 namespace tools { 18 namespace sg { 18 namespace sg { 19 19 20 class event_dispatcher : public node { 20 class event_dispatcher : public node { 21 TOOLS_NODE(event_dispatcher,tools::sg::event 21 TOOLS_NODE(event_dispatcher,tools::sg::event_dispatcher,node) 22 public: 22 public: 23 virtual void event(event_action& a_action) { 23 virtual void event(event_action& a_action) { 24 ecbk::exec_event_cbks(m_cbks.callbacks(),a 24 ecbk::exec_event_cbks(m_cbks.callbacks(),a_action.get_event(),&a_action,this); 25 } 25 } 26 public: 26 public: 27 event_dispatcher():parent(),m_cbks(){} 27 event_dispatcher():parent(),m_cbks(){} 28 virtual ~event_dispatcher(){} 28 virtual ~event_dispatcher(){} 29 public: 29 public: 30 event_dispatcher(const event_dispatcher& a_f 30 event_dispatcher(const event_dispatcher& a_from):parent(a_from),m_cbks(a_from.m_cbks){} 31 event_dispatcher& operator=(const event_disp 31 event_dispatcher& operator=(const event_dispatcher& a_from){ 32 parent::operator=(a_from); 32 parent::operator=(a_from); 33 m_cbks = a_from.m_cbks; 33 m_cbks = a_from.m_cbks; 34 return *this; 34 return *this; 35 } 35 } 36 public: 36 public: 37 const sg::cbks& cbks() const {return m_cbks; 37 const sg::cbks& cbks() const {return m_cbks;} 38 //sg::cbks& cbks() {return m_cbks;} 38 //sg::cbks& cbks() {return m_cbks;} 39 void add_callback(bcbk* a_cbk) {m_cbks.add(a 39 void add_callback(bcbk* a_cbk) {m_cbks.add(a_cbk);} //we take ownership of a_cbk 40 void copy_cbks(const sg::cbks& a_from,bool a 40 void copy_cbks(const sg::cbks& a_from,bool a_clear = true) {m_cbks.copy(a_from,a_clear);} 41 void clear_cbks(){m_cbks.clear();} 41 void clear_cbks(){m_cbks.clear();} 42 protected: 42 protected: 43 sg::cbks m_cbks; 43 sg::cbks m_cbks; 44 }; 44 }; 45 45 46 }} 46 }} 47 47 48 #endif 48 #endif