Panda3D

clientButtonDevice.h

00001 // Filename: clientButtonDevice.h
00002 // Created by:  drose (26Jan01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CLIENTBUTTONDEVICE_H
00016 #define CLIENTBUTTONDEVICE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "clientDevice.h"
00021 
00022 #include "buttonHandle.h"
00023 #include "buttonEvent.h"
00024 #include "buttonEventList.h"
00025 #include "pointerTo.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : ClientButtonDevice
00029 // Description : A device, attached to the ClientBase by a
00030 //               ButtonNode, that records the data from a single
00031 //               named button device.  The named device can contain
00032 //               any number of up/down style buttons, numbered in
00033 //               sequence beginning at zero; these are mapped by this
00034 //               class to a sequence of ButtonHandles specified by the
00035 //               user.
00036 ////////////////////////////////////////////////////////////////////
00037 class EXPCL_PANDA_DEVICE ClientButtonDevice : public ClientDevice {
00038 protected:
00039   ClientButtonDevice(ClientBase *client, const string &device_name);
00040 
00041 public:
00042   INLINE int get_num_buttons() const;
00043 
00044   INLINE void set_button_map(int index, ButtonHandle button);
00045   INLINE ButtonHandle get_button_map(int index) const;
00046 
00047   void set_button_state(int index, bool down);
00048   INLINE bool get_button_state(int index) const;
00049   INLINE bool is_button_known(int index) const;
00050 
00051   INLINE ButtonEventList *get_button_events() const;
00052 
00053   virtual void output(ostream &out) const;
00054   virtual void write(ostream &out, int indent_level = 0) const;
00055 
00056   void output_buttons(ostream &out) const;
00057   void write_buttons(ostream &out, int indent_level) const;
00058 
00059 private:
00060   void ensure_button_index(int index);
00061 
00062 protected:
00063   enum State {
00064     S_unknown,
00065     S_up,
00066     S_down
00067   };
00068 
00069   class ButtonState {
00070   public:
00071     INLINE ButtonState();
00072 
00073     ButtonHandle _handle;
00074     State _state;
00075   };
00076 
00077   typedef pvector<ButtonState> Buttons;
00078   Buttons _buttons;
00079 
00080   PT(ButtonEventList) _button_events;
00081 
00082 public:
00083   static TypeHandle get_class_type() {
00084     return _type_handle;
00085   }
00086   static void init_type() {
00087     ClientDevice::init_type();
00088     register_type(_type_handle, "ClientButtonDevice",
00089                   ClientDevice::get_class_type());
00090   }
00091   virtual TypeHandle get_type() const {
00092     return get_class_type();
00093   }
00094   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00095 
00096 private:
00097   static TypeHandle _type_handle;
00098   friend class ButtonState;
00099 };
00100 
00101 #include "clientButtonDevice.I"
00102 
00103 #endif
 All Classes Functions Variables Enumerations