openMSX
Trackball.hh
Go to the documentation of this file.
1 #ifndef TRACKBALL_HH
2 #define TRACKBALL_HH
3 
4 #include "JoystickDevice.hh"
5 #include "MSXEventListener.hh"
6 #include "StateChangeListener.hh"
7 #include "serialize_meta.hh"
8 
9 namespace openmsx {
10 
11 class MSXEventDistributor;
12 class StateChangeDistributor;
13 
14 class Trackball final : public JoystickDevice, private MSXEventListener
15  , private StateChangeListener
16 {
17 public:
18  Trackball(MSXEventDistributor& eventDistributor,
19  StateChangeDistributor& stateChangeDistributor);
20  ~Trackball() override;
21 
22  template<typename Archive>
23  void serialize(Archive& ar, unsigned version);
24 
25 private:
26  void createTrackballStateChange(EmuTime::param time,
27  int deltaX, int deltaY, byte press, byte release);
28 
29  void syncCurrentWithTarget(EmuTime::param time);
30 
31  // Pluggable
32  [[nodiscard]] std::string_view getName() const override;
33  [[nodiscard]] std::string_view getDescription() const override;
34  void plugHelper(Connector& connector, EmuTime::param time) override;
35  void unplugHelper(EmuTime::param time) override;
36 
37  // JoystickDevice
38  [[nodiscard]] byte read(EmuTime::param time) override;
39  void write(byte value, EmuTime::param time) override;
40 
41  // MSXEventListener
42  void signalMSXEvent(const Event& event,
43  EmuTime::param time) noexcept override;
44  // StateChangeListener
45  void signalStateChange(const StateChange& event) override;
46  void stopReplay(EmuTime::param time) noexcept override;
47 
48 private:
49  MSXEventDistributor& eventDistributor;
50  StateChangeDistributor& stateChangeDistributor;
51 
52  EmuTime lastSync; // last time we synced current with target
53  signed char targetDeltaX, targetDeltaY; // immediately follows host events
54  signed char currentDeltaX, currentDeltaY; // follows targetXY with some delay
55  byte lastValue;
56  byte status;
57  bool smooth; // always true, except for bw-compat savestates
58 };
60 
61 } // namespace openmsx
62 
63 #endif
Represents something you can plug devices into.
Definition: Connector.hh:21
Base class for all external MSX state changing events.
Definition: StateChange.hh:20
Trackball(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor)
Definition: Trackball.cc:50
~Trackball() override
Definition: Trackball.cc:63
void serialize(Archive &ar, unsigned version)
Definition: Trackball.cc:277
This file implemented 3 utility functions:
Definition: Autofire.cc:9
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)