openMSX
Trackball.hh
Go to the documentation of this file.
1#ifndef TRACKBALL_HH
2#define TRACKBALL_HH
3
4#include "EmuTime.hh"
5#include "JoystickDevice.hh"
6#include "MSXEventListener.hh"
8#include "serialize_meta.hh"
9#include <cstdint>
10
11namespace openmsx {
12
13class MSXEventDistributor;
14class StateChangeDistributor;
15
16class Trackball final : public JoystickDevice, private MSXEventListener
17 , private StateChangeListener
18{
19public:
20 Trackball(MSXEventDistributor& eventDistributor,
21 StateChangeDistributor& stateChangeDistributor);
22 ~Trackball() override;
23
24 template<typename Archive>
25 void serialize(Archive& ar, unsigned version);
26
27private:
28 void createTrackballStateChange(EmuTime::param time,
29 int deltaX, int deltaY, uint8_t press, uint8_t release);
30
31 void syncCurrentWithTarget(EmuTime::param time);
32
33 // Pluggable
34 [[nodiscard]] std::string_view getName() const override;
35 [[nodiscard]] std::string_view getDescription() const override;
36 void plugHelper(Connector& connector, EmuTime::param time) override;
37 void unplugHelper(EmuTime::param time) override;
38
39 // JoystickDevice
40 [[nodiscard]] uint8_t read(EmuTime::param time) override;
41 void write(uint8_t value, EmuTime::param time) override;
42
43 // MSXEventListener
44 void signalMSXEvent(const Event& event,
45 EmuTime::param time) noexcept override;
46 // StateChangeListener
47 void signalStateChange(const StateChange& event) override;
48 void stopReplay(EmuTime::param time) noexcept override;
49
50private:
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};
62
63} // namespace openmsx
64
65#endif
Represents something you can plug devices into.
Definition Connector.hh:21
static constexpr uint8_t JOY_BUTTONA
static constexpr uint8_t JOY_BUTTONB
Base class for all external MSX state changing events.
~Trackball() override
Definition Trackball.cc:58
void serialize(Archive &ar, unsigned version)
Definition Trackball.cc:272
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:446
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)