• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

InputDevice.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2010 Free Software Foundation, Inc
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018 #ifndef GNASH_INPUTDEVICE_H
00019 #define GNASH_INPUTDEVICE_H
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include "gnashconfig.h"
00023 #endif
00024 
00025 #include <boost/scoped_array.hpp>
00026 #include <boost/shared_array.hpp>
00027 #include <boost/scoped_ptr.hpp>
00028 #include <boost/shared_ptr.hpp>
00029 #include <boost/cstdint.hpp>
00030 
00031 #include "gui.h"
00032 
00033 #include <linux/input.h>
00034 
00035 namespace gnash {
00036 
00037 // Define if you want to support multiple input devices of the same type.
00038 // The default is to support the devices we prefer for moluse, keyboard,
00039 // and touchscreen.
00040 // #define MULTIPLE_DEVICES 1
00041 
00042 // Forward declarations
00043 class Gui;
00044 
00045 // If we have a mouse, but the size isn't specified, then this is the
00046 // default size.
00047 static const int DEFAULT_BUFFER_SIZE = 256;
00048 
00049 // This is an InputDevice class to cover the various touchscreens, Mice, or
00050 // keyboards supported.
00051 class InputDevice
00052 {
00053 public:
00054     typedef enum {
00055         UNKNOWN,
00056         KEYBOARD,
00057         MOUSE,
00058         TOUCHSCREEN,
00059         TOUCHMOUSE,
00060         POWERBUTTON,
00061         SLEEPBUTTON,
00062         SERIALUSB,
00063         INFRARED
00064     } devicetype_e;
00065     InputDevice();
00066     InputDevice(Gui *gui);
00067     virtual ~InputDevice();
00068     
00069     virtual bool init();
00070     bool init(devicetype_e type);
00071     bool init(devicetype_e type, size_t size);
00072     bool init(devicetype_e type, const std::string &filespec);
00073     bool init(devicetype_e type, const std::string &filespec, size_t size);
00074     virtual bool init(const std::string &filespec, size_t size) = 0;
00075     virtual bool check() = 0;
00076 
00077     static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
00078 
00079     InputDevice::devicetype_e getType() { return _type; };
00080 
00081     // Read data into the Device input buffer.
00082     boost::shared_array<boost::uint8_t> readData(size_t size);
00083 
00084     void dump();
00085     
00086 protected:
00087     devicetype_e        _type;
00088     std::string         _filespec;
00089     int                 _fd;
00090     int                 _x;
00091     int                 _y;
00092     // Touchscreens don't have buttons
00093     int                 _button;
00094     size_t              _position;
00095     boost::scoped_array<boost::uint8_t> _buffer;
00096     // We don't control the memory associated with the Gui, we just use
00097     // it to propogate the events from this device.
00098     Gui                 *_gui;
00099 };
00100 
00101 class MouseDevice : public InputDevice
00102 {
00103 public:    
00104     MouseDevice();
00105     MouseDevice(Gui *gui);
00106     virtual bool init();
00107     virtual bool init(const std::string &filespec, size_t size);
00108     virtual bool check();
00109 
00110     static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
00111     
00113     bool command(unsigned char cmd, unsigned char *buf, int count);
00114 };
00115 
00116 class TouchDevice : public InputDevice
00117 {
00118 public:
00119     TouchDevice();
00120     TouchDevice(Gui *gui);
00121     virtual ~TouchDevice();
00122     virtual bool init();
00123     virtual bool init(const std::string &filespec, size_t size);
00124     virtual bool check();
00125 
00126     void apply_ts_calibration(float* cx, float* cy, int rawx, int rawy);
00127     
00128     static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
00129 private:
00130     // Although the value is only set when using a touchscreen, it takes up little
00131     // memory to initialize a pointer to avoid lots of messy ifdefs.
00132     struct tsdev *_tsDev;
00133 };
00134 
00135 class EventDevice : public InputDevice
00136 {
00137 public:    
00138     EventDevice();
00139     EventDevice(Gui *gui);
00140     virtual bool init();
00141     virtual bool init(const std::string &filespec, size_t size);
00142     virtual bool check();
00143 
00144     gnash::key::code scancode_to_gnash_key(int code, bool shift);
00145 
00146     // This looks for all the input event devices.
00147     static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
00148     
00149 private:
00150     // Keyboard SHIFT/CTRL/ALT states (left + right)
00151      bool keyb_lshift, keyb_rshift, keyb_lctrl, keyb_rctrl, keyb_lalt, keyb_ralt;
00152     struct input_id _device_info;
00153 };
00154 
00155 } // end of gnash namespace
00156 
00157 // end of GNASH_INPUTDEVICE_H
00158 #endif
00159 
00160 // Local Variables:
00161 // mode: C++
00162 // indent-tabs-mode: nil
00163 // End:

Generated on Thu Sep 30 2010 14:34:59 for Gnash by  doxygen 1.7.1