openMSX
Touchpad.hh
Go to the documentation of this file.
1 #ifndef TOUCHPAD_HH
2 #define TOUCHPAD_HH
3 
4 #include "JoystickDevice.hh"
5 #include "MSXEventListener.hh"
6 #include "StateChangeListener.hh"
7 #include "StringSetting.hh"
8 #include "gl_mat.hh"
9 
10 namespace openmsx {
11 
12 class MSXEventDistributor;
13 class StateChangeDistributor;
14 class Display;
15 class CommandController;
16 class TclObject;
17 class Interpreter;
18 
19 class Touchpad final : public JoystickDevice, private MSXEventListener
20  , private StateChangeListener
21 {
22 public:
23  Touchpad(MSXEventDistributor& eventDistributor,
24  StateChangeDistributor& stateChangeDistributor,
25  Display& display,
26  CommandController& commandController);
27  ~Touchpad() override;
28 
29  template<typename Archive>
30  void serialize(Archive& ar, unsigned version);
31 
32 private:
33  void createTouchpadStateChange(EmuTime::param time,
34  byte x, byte y, bool touch, bool button);
35  void parseTransformMatrix(Interpreter& interp, const TclObject& value);
36  gl::ivec2 transformCoords(gl::ivec2 xy);
37 
38  // Pluggable
39  const std::string& getName() const override;
40  string_view getDescription() const override;
41  void plugHelper(Connector& connector, EmuTime::param time) override;
42  void unplugHelper(EmuTime::param time) override;
43 
44  // JoystickDevice
45  byte read(EmuTime::param time) override;
46  void write(byte value, EmuTime::param time) override;
47 
48  // MSXEventListener
49  void signalMSXEvent(const std::shared_ptr<const Event>& event,
50  EmuTime::param time) override;
51  // StateChangeListener
52  void signalStateChange(const std::shared_ptr<StateChange>& event) override;
53  void stopReplay(EmuTime::param time) override;
54 
55  MSXEventDistributor& eventDistributor;
56  StateChangeDistributor& stateChangeDistributor;
57  Display& display;
58 
59  StringSetting transformSetting;
60  gl::matMxN<2, 3, float> m; // transformation matrix
61 
62  EmuTime start; // last time when CS switched 0->1
63  gl::ivec2 hostPos; // host state
64  byte hostButtons; //
65  byte x, y; // msx state (different from host state
66  bool touch, button; // during replay)
67  byte shift; // shift register to both transmit and receive data
68  byte channel; // [0..3] 0->x, 3->y, 1,2->not used
69  byte last; // last written data, to detect transitions
70 };
71 
72 } // namespace openmsx
73 
74 #endif
Represents something you can plug devices into.
Definition: Connector.hh:20
Represents the output window/screen of openMSX.
Definition: Display.hh:31
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
~Touchpad() override
Definition: Touchpad.cc:93
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void serialize(Archive &ar, unsigned version)
Definition: Touchpad.cc:290
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
Touchpad(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, Display &display, CommandController &commandController)
Definition: Touchpad.cc:56