2
2
#include < spdlog/spdlog.h>
3
3
4
4
#include " controller/controldevice/controller/mapping/keyboard/KeyboardKeyToAxisDirectionMapping.h"
5
+ #include " controller/controldevice/controller/mapping/mouse/MouseButtonToAxisDirectionMapping.h"
5
6
6
7
#include " controller/controldevice/controller/mapping/factories/AxisDirectionMappingFactory.h"
7
8
11
12
#include < sstream>
12
13
#include < algorithm>
13
14
15
+ #include " Context.h"
16
+
14
17
// for some reason windows isn't seeing M_PI
15
18
// this is copied from my system's math.h
16
19
#ifndef M_PI
22
25
23
26
namespace Ship {
24
27
ControllerStick::ControllerStick (uint8_t portIndex, StickIndex stickIndex)
25
- : mPortIndex (portIndex), mStickIndex (stickIndex), mUseKeydownEventToCreateNewMapping (false ),
26
- mKeyboardScancodeForNewMapping (KbScancode::LUS_KB_UNKNOWN) {
28
+ : mPortIndex (portIndex), mStickIndex (stickIndex), mUseEventInputToCreateNewMapping (false ),
29
+ mKeyboardScancodeForNewMapping (KbScancode::LUS_KB_UNKNOWN), mMouseButtonForNewMapping(LUS_MOUSE_BTN_UNKNOWN) {
27
30
mSensitivityPercentage = DEFAULT_STICK_SENSITIVITY_PERCENTAGE;
28
31
mSensitivity = 1 .0f ;
29
32
mDeadzonePercentage = DEFAULT_STICK_DEADZONE_PERCENTAGE;
@@ -268,12 +271,20 @@ void ControllerStick::Process(int8_t& x, int8_t& y) {
268
271
bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress (Direction direction, std::string id) {
269
272
std::shared_ptr<ControllerAxisDirectionMapping> mapping = nullptr ;
270
273
271
- mUseKeydownEventToCreateNewMapping = true ;
274
+ mUseEventInputToCreateNewMapping = true ;
272
275
if (mKeyboardScancodeForNewMapping != LUS_KB_UNKNOWN) {
273
276
mapping = std::make_shared<KeyboardKeyToAxisDirectionMapping>(mPortIndex , mStickIndex , direction,
274
277
mKeyboardScancodeForNewMapping );
278
+ } else if (!Context::GetInstance ()->GetWindow ()->GetGui ()->IsMouseOverAnyGuiItem () &&
279
+ Context::GetInstance ()->GetWindow ()->GetGui ()->IsMouseOverActivePopup ()) {
280
+ if (mMouseButtonForNewMapping != LUS_MOUSE_BTN_UNKNOWN) {
281
+ mapping = std::make_shared<MouseButtonToAxisDirectionMapping>(mPortIndex , mStickIndex , direction,
282
+ mMouseButtonForNewMapping );
283
+ } else {
284
+ mapping = AxisDirectionMappingFactory::CreateAxisDirectionMappingFromMouseWheelInput (
285
+ mPortIndex , mStickIndex , direction);
286
+ }
275
287
}
276
-
277
288
if (mapping == nullptr ) {
278
289
mapping =
279
290
AxisDirectionMappingFactory::CreateAxisDirectionMappingFromSDLInput (mPortIndex , mStickIndex , direction);
@@ -284,7 +295,8 @@ bool ControllerStick::AddOrEditAxisDirectionMappingFromRawPress(Direction direct
284
295
}
285
296
286
297
mKeyboardScancodeForNewMapping = LUS_KB_UNKNOWN;
287
- mUseKeydownEventToCreateNewMapping = false ;
298
+ mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN;
299
+ mUseEventInputToCreateNewMapping = false ;
288
300
289
301
if (id != " " ) {
290
302
ClearAxisDirectionMapping (direction, id);
@@ -319,7 +331,7 @@ void ControllerStick::UpdatePad(int8_t& x, int8_t& y) {
319
331
}
320
332
321
333
bool ControllerStick::ProcessKeyboardEvent (KbEventType eventType, KbScancode scancode) {
322
- if (mUseKeydownEventToCreateNewMapping ) {
334
+ if (mUseEventInputToCreateNewMapping ) {
323
335
if (eventType == LUS_KB_EVENT_KEY_DOWN) {
324
336
mKeyboardScancodeForNewMapping = scancode;
325
337
return true ;
@@ -343,6 +355,31 @@ bool ControllerStick::ProcessKeyboardEvent(KbEventType eventType, KbScancode sca
343
355
return result;
344
356
}
345
357
358
+ bool ControllerStick::ProcessMouseButtonEvent (bool isPressed, MouseBtn button) {
359
+ if (mUseEventInputToCreateNewMapping ) {
360
+ if (isPressed) {
361
+ mMouseButtonForNewMapping = button;
362
+ return true ;
363
+ } else {
364
+ mMouseButtonForNewMapping = LUS_MOUSE_BTN_UNKNOWN;
365
+ }
366
+ }
367
+
368
+ bool result = false ;
369
+ for (auto [direction, mappings] : mAxisDirectionMappings ) {
370
+ for (auto [id, mapping] : mappings) {
371
+ if (mapping->GetMappingType () == MAPPING_TYPE_MOUSE) {
372
+ std::shared_ptr<MouseButtonToAxisDirectionMapping> mtoadMapping =
373
+ std::dynamic_pointer_cast<MouseButtonToAxisDirectionMapping>(mapping);
374
+ if (mtoadMapping != nullptr ) {
375
+ result = result || mtoadMapping->ProcessMouseButtonEvent (isPressed, button);
376
+ }
377
+ }
378
+ }
379
+ }
380
+ return result;
381
+ }
382
+
346
383
void ControllerStick::SetSensitivity (uint8_t sensitivityPercentage) {
347
384
mSensitivityPercentage = sensitivityPercentage;
348
385
mSensitivity = sensitivityPercentage / 100 .0f ;
0 commit comments