Drop the bool operator for ObjectURI, to avoid getting the kind of side-effect that...
[gnash.git] / gui / InputDevice.h
blob5e49befa05b61c1b6aa2c8064137a474ee63de0e
1 //
2 // Copyright (C) 2010 Free Software Foundation, Inc
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef GNASH_INPUTDEVICE_H
19 #define GNASH_INPUTDEVICE_H
21 #ifdef HAVE_CONFIG_H
22 #include "gnashconfig.h"
23 #endif
25 #include <boost/scoped_array.hpp>
26 #include <boost/shared_array.hpp>
27 #include <boost/scoped_ptr.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/cstdint.hpp>
31 #include "gui.h"
33 #include <linux/input.h>
35 namespace gnash {
37 // Define if you want to support multiple input devices of the same type.
38 // The default is to support the devices we prefer for moluse, keyboard,
39 // and touchscreen.
40 // #define MULTIPLE_DEVICES 1
42 // Forward declarations
43 class Gui;
45 // If we have a mouse, but the size isn't specified, then this is the
46 // default size.
47 static const int DEFAULT_BUFFER_SIZE = 256;
49 // This is an InputDevice class to cover the various touchscreens, Mice, or
50 // keyboards supported.
51 class InputDevice
53 public:
54 typedef enum {
55 UNKNOWN,
56 KEYBOARD,
57 MOUSE,
58 TOUCHSCREEN,
59 TOUCHMOUSE,
60 POWERBUTTON,
61 SLEEPBUTTON,
62 SERIALUSB,
63 INFRARED
64 } devicetype_e;
65 InputDevice();
66 InputDevice(Gui *gui);
67 virtual ~InputDevice();
69 virtual bool init();
70 bool init(devicetype_e type);
71 bool init(devicetype_e type, size_t size);
72 bool init(devicetype_e type, const std::string &filespec);
73 bool init(devicetype_e type, const std::string &filespec, size_t size);
74 virtual bool init(const std::string &filespec, size_t size) = 0;
75 virtual bool check() = 0;
77 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
79 InputDevice::devicetype_e getType() { return _type; };
81 // Read data into the Device input buffer.
82 boost::shared_array<boost::uint8_t> readData(size_t size);
84 void dump();
86 protected:
87 devicetype_e _type;
88 std::string _filespec;
89 int _fd;
90 int _x;
91 int _y;
92 // Touchscreens don't have buttons
93 int _button;
94 size_t _position;
95 boost::scoped_array<boost::uint8_t> _buffer;
96 // We don't control the memory associated with the Gui, we just use
97 // it to propogate the events from this device.
98 Gui *_gui;
101 class MouseDevice : public InputDevice
103 public:
104 MouseDevice();
105 MouseDevice(Gui *gui);
106 virtual bool init();
107 virtual bool init(const std::string &filespec, size_t size);
108 virtual bool check();
110 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
112 /// Sends a command to the mouse and waits for the response
113 bool command(unsigned char cmd, unsigned char *buf, int count);
116 class TouchDevice : public InputDevice
118 public:
119 TouchDevice();
120 TouchDevice(Gui *gui);
121 virtual ~TouchDevice();
122 virtual bool init();
123 virtual bool init(const std::string &filespec, size_t size);
124 virtual bool check();
126 void apply_ts_calibration(float* cx, float* cy, int rawx, int rawy);
128 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
129 private:
130 // Although the value is only set when using a touchscreen, it takes up little
131 // memory to initialize a pointer to avoid lots of messy ifdefs.
132 struct tsdev *_tsDev;
135 class EventDevice : public InputDevice
137 public:
138 EventDevice();
139 EventDevice(Gui *gui);
140 virtual bool init();
141 virtual bool init(const std::string &filespec, size_t size);
142 virtual bool check();
144 gnash::key::code scancode_to_gnash_key(int code, bool shift);
146 // This looks for all the input event devices.
147 static std::vector<boost::shared_ptr<InputDevice> > scanForDevices(Gui *gui);
149 private:
150 // Keyboard SHIFT/CTRL/ALT states (left + right)
151 bool keyb_lshift, keyb_rshift, keyb_lctrl, keyb_rctrl, keyb_lalt, keyb_ralt;
152 struct input_id _device_info;
155 } // end of gnash namespace
157 // end of GNASH_INPUTDEVICE_H
158 #endif
160 // Local Variables:
161 // mode: C++
162 // indent-tabs-mode: nil
163 // End: