Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/device/clientButtonDevice.h

Go to the documentation of this file.
00001 // Filename: clientButtonDevice.h
00002 // Created by:  drose (26Jan01)
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 CLIENTBUTTONDEVICE_H
00020 #define CLIENTBUTTONDEVICE_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "clientDevice.h"
00025 
00026 #include "buttonHandle.h"
00027 #include "buttonEvent.h"
00028 #include "buttonEventList.h"
00029 #include "pointerTo.h"
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : ClientButtonDevice
00033 // Description : A device, attached to the ClientBase by a
00034 //               ButtonNode, that records the data from a single
00035 //               named button device.  The named device can contain
00036 //               any number of up/down style buttons, numbered in
00037 //               sequence beginning at zero; these are mapped by this
00038 //               class to a sequence of ButtonHandles specified by the
00039 //               user.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDA ClientButtonDevice : public ClientDevice {
00042 protected:
00043   ClientButtonDevice(ClientBase *client, const string &device_name);
00044 
00045 public:
00046   INLINE int get_num_buttons() const;
00047 
00048   INLINE void set_button_map(int index, ButtonHandle button);
00049   INLINE ButtonHandle get_button_map(int index) const;
00050 
00051   void set_button_state(int index, bool down);
00052   INLINE bool get_button_state(int index) const;
00053   INLINE bool is_button_known(int index) const;
00054 
00055   INLINE ButtonEventList *get_button_events() const;
00056 
00057   virtual void output(ostream &out) const;
00058   virtual void write(ostream &out, int indent_level = 0) const;
00059 
00060   void output_buttons(ostream &out) const;
00061   void write_buttons(ostream &out, int indent_level) const;
00062 
00063 private:
00064   void ensure_button_index(int index);
00065 
00066 protected:
00067   enum State {
00068     S_unknown,
00069     S_up,
00070     S_down
00071   };
00072 
00073   class ButtonState {
00074   public:
00075     INLINE ButtonState();
00076 
00077     ButtonHandle _handle;
00078     State _state;
00079   };
00080 
00081   typedef pvector<ButtonState> Buttons;
00082   Buttons _buttons;
00083 
00084   PT(ButtonEventList) _button_events;
00085 
00086 public:
00087   static TypeHandle get_class_type() {
00088     return _type_handle;
00089   }
00090   static void init_type() {
00091     ClientDevice::init_type();
00092     register_type(_type_handle, "ClientButtonDevice",
00093                   ClientDevice::get_class_type());
00094   }
00095   virtual TypeHandle get_type() const {
00096     return get_class_type();
00097   }
00098   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00099 
00100 private:
00101   static TypeHandle _type_handle;
00102   friend class ButtonState;
00103 };
00104 
00105 #include "clientButtonDevice.I"
00106 
00107 #endif

Generated on Fri May 2 00:36:11 2003 for Panda by doxygen1.3