| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <QToolButton> |
| 7 |
#include <QWidget> |
| 8 |
|
| 9 |
#include <chrono> |
| 10 |
#include <deque> |
| 11 |
|
| 12 |
#include "Core/HW/WiimoteEmu/Dynamics.h" |
| 13 |
#include "InputCommon/ControllerEmu/ControlGroup/IRPassthrough.h" |
| 14 |
#include "InputCommon/ControllerEmu/StickGate.h" |
| 15 |
|
| 16 |
namespace ControllerEmu |
| 17 |
{ |
| 18 |
class Control; |
| 19 |
class ControlGroup; |
| 20 |
class Cursor; |
| 21 |
class Force; |
| 22 |
class MixedTriggers; |
| 23 |
} |
| 24 |
|
| 25 |
class QPainter; |
| 26 |
class QPaintEvent; |
| 27 |
class QTimer; |
| 28 |
|
| 29 |
class CalibrationWidget; |
| 30 |
class MappingWidget; |
| 31 |
|
| 32 |
namespace ciface::MappingCommon |
| 33 |
{ |
| 34 |
class ReshapableInputMapper; |
| 35 |
class CalibrationBuilder; |
| 36 |
} |
| 37 |
|
| 38 |
class MappingIndicator : public QWidget |
| 39 |
{ |
| 40 |
public: |
| 41 |
QPen GetBBoxPen() const; |
| 42 |
QBrush GetBBoxBrush() const; |
| 43 |
QColor GetRawInputColor() const; |
| 44 |
QPen GetInputShapePen() const; |
| 45 |
QColor GetCenterColor() const; |
| 46 |
QColor GetAdjustedInputColor() const; |
| 47 |
QColor GetDeadZoneColor() const; |
| 48 |
QPen GetDeadZonePen() const; |
| 49 |
QBrush GetDeadZoneBrush(QPainter&) const; |
| 50 |
QColor GetTextColor() const; |
| 51 |
QColor GetAltTextColor() const; |
| 52 |
void AdjustGateColor(QColor*); |
| 53 |
|
| 54 |
protected: |
| 55 |
virtual void Draw() {} |
| 56 |
virtual void Update(float elapsed_seconds) {} |
| 57 |
|
| 58 |
private: |
| 59 |
void paintEvent(QPaintEvent*) override; |
| 60 |
|
| 61 |
Clock::time_point m_last_update = Clock::now(); |
| 62 |
}; |
| 63 |
|
| 64 |
class ButtonIndicator final : public MappingIndicator |
| 65 |
{ |
| 66 |
public: |
| 67 |
ButtonIndicator(ControlReference* control_ref); |
| 68 |
|
| 69 |
private: |
| 70 |
ControlReference* const m_control_ref; |
| 71 |
QSize sizeHint() const override; |
| 72 |
void Draw() override; |
| 73 |
}; |
| 74 |
|
| 75 |
class SquareIndicator : public MappingIndicator |
| 76 |
{ |
| 77 |
protected: |
| 78 |
SquareIndicator(); |
| 79 |
|
| 80 |
qreal GetContentsScale() const; |
| 81 |
void DrawBoundingBox(QPainter&); |
| 82 |
void TransformPainter(QPainter&); |
| 83 |
}; |
| 84 |
|
| 85 |
class ReshapableInputIndicator : public SquareIndicator |
| 86 |
{ |
| 87 |
public: |
| 88 |
void SetCalibrationWidget(CalibrationWidget* widget); |
| 89 |
|
| 90 |
virtual QColor GetGateBrushColor() const = 0; |
| 91 |
|
| 92 |
protected: |
| 93 |
void DrawReshapableInput(ControllerEmu::ReshapableInput& group, |
| 94 |
std::optional<ControllerEmu::ReshapableInput::ReshapeData> adj_coord); |
| 95 |
|
| 96 |
virtual void DrawUnderGate(QPainter&) {} |
| 97 |
|
| 98 |
bool IsCalibrating() const; |
| 99 |
|
| 100 |
void UpdateCalibrationWidget(Common::DVec2 point); |
| 101 |
|
| 102 |
private: |
| 103 |
CalibrationWidget* m_calibration_widget{}; |
| 104 |
}; |
| 105 |
|
| 106 |
class AnalogStickIndicator : public ReshapableInputIndicator |
| 107 |
{ |
| 108 |
public: |
| 109 |
explicit AnalogStickIndicator(ControllerEmu::ReshapableInput& stick) : m_group(stick) {} |
| 110 |
|
| 111 |
QColor GetGateBrushColor() const final; |
| 112 |
|
| 113 |
private: |
| 114 |
void Draw() override; |
| 115 |
|
| 116 |
ControllerEmu::ReshapableInput& m_group; |
| 117 |
}; |
| 118 |
|
| 119 |
class TiltIndicator : public ReshapableInputIndicator |
| 120 |
{ |
| 121 |
public: |
| 122 |
explicit TiltIndicator(ControllerEmu::Tilt& tilt) : m_group(tilt) {} |
| 123 |
|
| 124 |
QColor GetGateBrushColor() const final; |
| 125 |
|
| 126 |
private: |
| 127 |
void Draw() override; |
| 128 |
void Update(float elapsed_seconds) override; |
| 129 |
|
| 130 |
ControllerEmu::Tilt& m_group; |
| 131 |
WiimoteEmu::MotionState m_motion_state{}; |
| 132 |
}; |
| 133 |
|
| 134 |
class CursorIndicator : public ReshapableInputIndicator |
| 135 |
{ |
| 136 |
public: |
| 137 |
explicit CursorIndicator(ControllerEmu::Cursor& cursor) : m_cursor_group(cursor) {} |
| 138 |
|
| 139 |
QColor GetGateBrushColor() const final; |
| 140 |
|
| 141 |
private: |
| 142 |
void Draw() override; |
| 143 |
|
| 144 |
ControllerEmu::Cursor& m_cursor_group; |
| 145 |
}; |
| 146 |
|
| 147 |
class MixedTriggersIndicator : public MappingIndicator |
| 148 |
{ |
| 149 |
public: |
| 150 |
explicit MixedTriggersIndicator(ControllerEmu::MixedTriggers& triggers); |
| 151 |
|
| 152 |
private: |
| 153 |
void Draw() override; |
| 154 |
|
| 155 |
ControllerEmu::MixedTriggers& m_group; |
| 156 |
}; |
| 157 |
|
| 158 |
class SwingIndicator : public ReshapableInputIndicator |
| 159 |
{ |
| 160 |
public: |
| 161 |
explicit SwingIndicator(ControllerEmu::Force& swing) : m_swing_group(swing) {} |
| 162 |
|
| 163 |
QColor GetGateBrushColor() const final; |
| 164 |
|
| 165 |
private: |
| 166 |
void Draw() override; |
| 167 |
void Update(float elapsed_seconds) override; |
| 168 |
|
| 169 |
void DrawUnderGate(QPainter& p) override; |
| 170 |
|
| 171 |
ControllerEmu::Force& m_swing_group; |
| 172 |
WiimoteEmu::MotionState m_motion_state{}; |
| 173 |
}; |
| 174 |
|
| 175 |
class ShakeMappingIndicator : public SquareIndicator |
| 176 |
{ |
| 177 |
public: |
| 178 |
explicit ShakeMappingIndicator(ControllerEmu::Shake& shake) : m_shake_group(shake) {} |
| 179 |
|
| 180 |
private: |
| 181 |
void Draw() override; |
| 182 |
void Update(float elapsed_seconds) override; |
| 183 |
|
| 184 |
ControllerEmu::Shake& m_shake_group; |
| 185 |
WiimoteEmu::MotionState m_motion_state{}; |
| 186 |
|
| 187 |
struct ShakeSample |
| 188 |
{ |
| 189 |
ControllerEmu::Shake::StateData state; |
| 190 |
float age = 0.f; |
| 191 |
}; |
| 192 |
|
| 193 |
std::deque<ShakeSample> m_position_samples; |
| 194 |
float m_grid_line_position = 0; |
| 195 |
}; |
| 196 |
|
| 197 |
class AccelerometerMappingIndicator : public SquareIndicator |
| 198 |
{ |
| 199 |
public: |
| 200 |
explicit AccelerometerMappingIndicator(ControllerEmu::IMUAccelerometer& accel) |
| 201 |
: m_accel_group(accel) |
| 202 |
{ |
| 203 |
} |
| 204 |
|
| 205 |
private: |
| 206 |
void Draw() override; |
| 207 |
|
| 208 |
ControllerEmu::IMUAccelerometer& m_accel_group; |
| 209 |
}; |
| 210 |
|
| 211 |
class GyroMappingIndicator : public SquareIndicator |
| 212 |
{ |
| 213 |
public: |
| 214 |
explicit GyroMappingIndicator(ControllerEmu::IMUGyroscope& gyro) : m_gyro_group(gyro) {} |
| 215 |
|
| 216 |
private: |
| 217 |
void Draw() override; |
| 218 |
void Update(float elapsed_seconds) override; |
| 219 |
|
| 220 |
ControllerEmu::IMUGyroscope& m_gyro_group; |
| 221 |
Common::Quaternion m_state = Common::Quaternion::Identity(); |
| 222 |
Common::Vec3 m_previous_velocity = {}; |
| 223 |
float m_stable_time = 0; |
| 224 |
}; |
| 225 |
|
| 226 |
class IRPassthroughMappingIndicator : public SquareIndicator |
| 227 |
{ |
| 228 |
public: |
| 229 |
explicit IRPassthroughMappingIndicator(ControllerEmu::IRPassthrough& ir_group) |
| 230 |
: m_ir_group(ir_group) |
| 231 |
{ |
| 232 |
} |
| 233 |
|
| 234 |
private: |
| 235 |
void Draw() override; |
| 236 |
|
| 237 |
ControllerEmu::IRPassthrough& m_ir_group; |
| 238 |
}; |
| 239 |
|
| 240 |
class CalibrationWidget : public QToolButton |
| 241 |
{ |
| 242 |
public: |
| 243 |
CalibrationWidget(MappingWidget& mapping_widget, ControllerEmu::ReshapableInput& input, |
| 244 |
ReshapableInputIndicator& indicator); |
| 245 |
|
| 246 |
void Update(Common::DVec2 point); |
| 247 |
|
| 248 |
void Draw(QPainter& p, Common::DVec2 point); |
| 249 |
|
| 250 |
bool IsActive() const; |
| 251 |
|
| 252 |
private: |
| 253 |
void DrawInProgressMapping(QPainter& p); |
| 254 |
void DrawInProgressCalibration(QPainter& p, Common::DVec2 point); |
| 255 |
|
| 256 |
bool IsMapping() const; |
| 257 |
bool IsCalibrating() const; |
| 258 |
|
| 259 |
void StartMappingAndCalibration(); |
| 260 |
void StartCalibration(std::optional<Common::DVec2> center = Common::DVec2{}); |
| 261 |
|
| 262 |
void FinishCalibration(); |
| 263 |
|
| 264 |
void ResetActions(); |
| 265 |
void DeleteAllActions(); |
| 266 |
|
| 267 |
MappingWidget& m_mapping_widget; |
| 268 |
ControllerEmu::ReshapableInput& m_input; |
| 269 |
ReshapableInputIndicator& m_indicator; |
| 270 |
|
| 271 |
std::unique_ptr<ciface::MappingCommon::ReshapableInputMapper> m_mapper; |
| 272 |
std::unique_ptr<ciface::MappingCommon::CalibrationBuilder> m_calibrator; |
| 273 |
|
| 274 |
double GetAnimationElapsedSeconds() const; |
| 275 |
void RestartAnimation(); |
| 276 |
|
| 277 |
Clock::time_point m_animation_start_time{}; |
| 278 |
|
| 279 |
static constexpr auto STOP_SPINNING_DURATION = std::chrono::seconds{2}; |
| 280 |
|
| 281 |
Clock::time_point m_stop_spinning_time{}; |
| 282 |
}; |