OXYGENHUB
◆ main openmsx / src / input / Trackball.hh
1.9 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef TRACKBALL_HH
2
#define TRACKBALL_HH
3
4
#include "EmuTime.hh"
5
#include "JoystickDevice.hh"
6
#include "MSXEventListener.hh"
7
#include "StateChangeListener.hh"
8
#include "serialize_meta.hh"
9
#include <cstdint>
10
11
namespace openmsx {
12
13
class MSXEventDistributor;
14
class StateChangeDistributor;
15
16
class Trackball final : public JoystickDevice, private MSXEventListener
17
                      , private StateChangeListener
18
{
19
public:
20
	Trackball(MSXEventDistributor& eventDistributor,
21
	          StateChangeDistributor& stateChangeDistributor);
22
	~Trackball() override;
23
24
	template<typename Archive>
25
	void serialize(Archive& ar, unsigned version);
26
27
private:
28
	void createTrackballStateChange(EmuTime time,
29
		int deltaX, int deltaY, uint8_t press, uint8_t release);
30
31
	void syncCurrentWithTarget(EmuTime time);
32
33
	// Pluggable
34
	[[nodiscard]] zstring_view getName() const override;
35
	[[nodiscard]] zstring_view getDescription() const override;
36
	void plugHelper(Connector& connector, EmuTime time) override;
37
	void unplugHelper(EmuTime time) override;
38
39
	// JoystickDevice
40
	[[nodiscard]] uint8_t read(EmuTime time) override;
41
	void write(uint8_t value, EmuTime time) override;
42
43
	// MSXEventListener
44
	void signalMSXEvent(const Event& event,
45
	                    EmuTime time) noexcept override;
46
	// StateChangeListener
47
	void signalStateChange(const StateChange& event) override;
48
	void stopReplay(EmuTime time) noexcept override;
49
50
private:
51
	MSXEventDistributor& eventDistributor;
52
	StateChangeDistributor& stateChangeDistributor;
53
54
	EmuTime lastSync = EmuTime::zero(); // last time we synced current with target
55
	int8_t targetDeltaX = 0, targetDeltaY = 0; // immediately follows host events
56
	int8_t currentDeltaX = 0, currentDeltaY = 0; // follows targetXY with some delay
57
	uint8_t lastValue = 0;
58
	uint8_t status = JOY_BUTTONA | JOY_BUTTONB;
59
	bool smooth = true; // always true, except for bw-compat savestates
60
};
61
SERIALIZE_CLASS_VERSION(Trackball, 2);
62
63
} // namespace openmsx
64
65
#endif