00001 // Filename: ButtonNode.h 00002 // Created by: drose (12Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef BUTTONNODE_H 00020 #define BUTTONNODE_H 00021 00022 #include "pandabase.h" 00023 00024 #include "clientBase.h" 00025 #include "clientButtonDevice.h" 00026 #include "dataNode.h" 00027 #include "buttonEventList.h" 00028 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : ButtonNode 00032 // Description : This is the primary interface to on/off button 00033 // devices associated with a ClientBase. This creates a 00034 // node that connects to the named button device, if it 00035 // exists, and provides hooks to the user to read the 00036 // state of any of the sequentially numbered buttons 00037 // associated with that device. 00038 // 00039 // It also can associate an arbitrary ButtonHandle with 00040 // each button; when buttons are associated with 00041 // ButtonHandles, this node will put appropriate up and 00042 // down events on the data graph for each button state 00043 // change. 00044 //////////////////////////////////////////////////////////////////// 00045 class EXPCL_PANDA ButtonNode : public DataNode { 00046 PUBLISHED: 00047 ButtonNode(ClientBase *client, const string &device_name); 00048 virtual ~ButtonNode(); 00049 00050 INLINE bool is_valid() const; 00051 00052 INLINE int get_num_buttons() const; 00053 00054 INLINE void set_button_map(int index, ButtonHandle button); 00055 INLINE ButtonHandle get_button_map(int index) const; 00056 00057 INLINE bool get_button_state(int index) const; 00058 INLINE bool is_button_known(int index) const; 00059 00060 public: 00061 virtual void output(ostream &out) const; 00062 virtual void write(ostream &out, int indent_level = 0) const; 00063 00064 private: 00065 PT(ClientButtonDevice) _button; 00066 00067 protected: 00068 // Inherited from DataNode 00069 virtual void do_transmit_data(const DataNodeTransmit &input, 00070 DataNodeTransmit &output); 00071 00072 private: 00073 // outputs 00074 int _button_events_output; 00075 PT(ButtonEventList) _button_events; 00076 00077 public: 00078 static TypeHandle get_class_type() { 00079 return _type_handle; 00080 } 00081 static void init_type() { 00082 DataNode::init_type(); 00083 register_type(_type_handle, "ButtonNode", 00084 DataNode::get_class_type()); 00085 } 00086 virtual TypeHandle get_type() const { 00087 return get_class_type(); 00088 } 00089 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00090 00091 private: 00092 static TypeHandle _type_handle; 00093 }; 00094 00095 #include "buttonNode.I" 00096 00097 #endif