duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

playstation_mouse.h (1375B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include "controller.h"
      7 
      8 #include <memory>
      9 
     10 class PlayStationMouse final : public Controller
     11 {
     12 public:
     13   enum class Binding : u8
     14   {
     15     Left = 0,
     16     Right = 1,
     17     ButtonCount = 2,
     18 
     19     PointerX = 2,
     20     PointerY = 3,
     21     BindingCount = 4,
     22   };
     23 
     24   static const Controller::ControllerInfo INFO;
     25 
     26   PlayStationMouse(u32 index);
     27   ~PlayStationMouse() override;
     28 
     29   static std::unique_ptr<PlayStationMouse> Create(u32 index);
     30 
     31   ControllerType GetType() const override;
     32 
     33   void Reset() override;
     34   bool DoState(StateWrapper& sw, bool apply_input_state) override;
     35 
     36   float GetBindState(u32 index) const override;
     37   void SetBindState(u32 index, float value) override;
     38 
     39   void ResetTransferState() override;
     40   bool Transfer(const u8 data_in, u8* data_out) override;
     41 
     42   void LoadSettings(SettingsInterface& si, const char* section, bool initial) override;
     43 
     44 private:
     45   enum class TransferState : u8
     46   {
     47     Idle,
     48     Ready,
     49     IDMSB,
     50     ButtonsLSB,
     51     ButtonsMSB,
     52     DeltaX,
     53     DeltaY
     54   };
     55 
     56   float m_sensitivity_x = 1.0f;
     57   float m_sensitivity_y = 1.0f;
     58 
     59   // buttons are active low
     60   u16 m_button_state = UINT16_C(0xFFFF);
     61   float m_delta_x = 0;
     62   float m_delta_y = 0;
     63 
     64   TransferState m_transfer_state = TransferState::Idle;
     65 };