| 1 |
#ifndef MOUSE_HH |
| 2 |
#define MOUSE_HH |
| 3 |
|
| 4 |
#include "Display.hh" |
| 5 |
#include "EmuTime.hh" |
| 6 |
#include "JoystickDevice.hh" |
| 7 |
#include "MSXEventListener.hh" |
| 8 |
#include "StateChangeListener.hh" |
| 9 |
#include "serialize_meta.hh" |
| 10 |
|
| 11 |
#include "gl_vec.hh" |
| 12 |
|
| 13 |
namespace openmsx { |
| 14 |
|
| 15 |
class MSXEventDistributor; |
| 16 |
class StateChangeDistributor; |
| 17 |
|
| 18 |
class Mouse final : public JoystickDevice, private MSXEventListener |
| 19 |
, private StateChangeListener |
| 20 |
{ |
| 21 |
public: |
| 22 |
Mouse(MSXEventDistributor& eventDistributor, |
| 23 |
StateChangeDistributor& stateChangeDistributor, |
| 24 |
Display& display); |
| 25 |
~Mouse() override; |
| 26 |
|
| 27 |
template<typename Archive> |
| 28 |
void serialize(Archive& ar, unsigned version); |
| 29 |
|
| 30 |
private: |
| 31 |
|
| 32 |
[[nodiscard]] zstring_view getName() const override; |
| 33 |
[[nodiscard]] zstring_view getDescription() const override; |
| 34 |
void plugHelper(Connector& connector, EmuTime time) override; |
| 35 |
void unplugHelper(EmuTime time) override; |
| 36 |
|
| 37 |
|
| 38 |
[[nodiscard]] uint8_t read(EmuTime time) override; |
| 39 |
void write(uint8_t value, EmuTime time) override; |
| 40 |
|
| 41 |
|
| 42 |
void signalMSXEvent(const Event& event, |
| 43 |
EmuTime time) noexcept override; |
| 44 |
|
| 45 |
void signalStateChange(const StateChange& event) override; |
| 46 |
void stopReplay(EmuTime time) noexcept override; |
| 47 |
|
| 48 |
void createMouseStateChange(EmuTime time, |
| 49 |
int deltaX, int deltaY, uint8_t press, uint8_t release); |
| 50 |
void emulateJoystick(); |
| 51 |
void plugHelper2(); |
| 52 |
|
| 53 |
private: |
| 54 |
MSXEventDistributor& eventDistributor; |
| 55 |
StateChangeDistributor& stateChangeDistributor; |
| 56 |
Display& display; |
| 57 |
|
| 58 |
EmuTime lastTime = EmuTime::zero(); |
| 59 |
int phase; |
| 60 |
int xRel = 0, yRel = 0; |
| 61 |
int curXRel = 0, curYRel = 0; |
| 62 |
gl::vec2 fractional; |
| 63 |
uint8_t status = JOY_BUTTONA | JOY_BUTTONB; |
| 64 |
bool mouseMode = true; |
| 65 |
}; |
| 66 |
SERIALIZE_CLASS_VERSION(Mouse, 4); |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
#endif |