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  [[nodiscard]] gl::ivec2 transformCoords(gl::ivec2 xy);
37 
38  // Pluggable
39  [[nodiscard]] std::string_view getName() const override;
40  [[nodiscard]] std::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  [[nodiscard]] byte read(EmuTime::param time) override;
46  void write(byte value, EmuTime::param time) override;
47 
48  // MSXEventListener
49  void signalMSXEvent(const Event& event,
50  EmuTime::param time) noexcept override;
51  // StateChangeListener
52  void signalStateChange(const StateChange& event) override;
53  void stopReplay(EmuTime::param time) noexcept override;
54 
55 private:
56  MSXEventDistributor& eventDistributor;
57  StateChangeDistributor& stateChangeDistributor;
58  Display& display;
59 
60  StringSetting transformSetting;
61  gl::matMxN<2, 3, float> m; // transformation matrix
62 
63  EmuTime start; // last time when CS switched 0->1
64  gl::ivec2 hostPos; // host state
65  byte hostButtons; //
66  byte x, y; // msx state (different from host state
67  bool touch, button; // during replay)
68  byte shift; // shift register to both transmit and receive data
69  byte channel; // [0..3] 0->x, 3->y, 1,2->not used
70  byte last; // last written data, to detect transitions
71 };
72 
73 } // namespace openmsx
74 
75 #endif
Represents something you can plug devices into.
Definition: Connector.hh:21
Represents the output window/screen of openMSX.
Definition: Display.hh:33
Base class for all external MSX state changing events.
Definition: StateChange.hh:20
~Touchpad() override
Definition: Touchpad.cc:92
void serialize(Archive &ar, unsigned version)
Definition: Touchpad.cc:281
Touchpad(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, Display &display, CommandController &commandController)
Definition: Touchpad.cc:55
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:118