50
50
kJoy0R3 ,
51
51
kJoy0Select ,
52
52
kJoy0Start ,
53
+ kJoy0LeftAnalogX ,
54
+ kJoy0LeftAnalogY ,
55
+ kJoy0RightAnalogX ,
56
+ kJoy0RightAnalogY ,
53
57
54
58
kJoy1Up ,
55
59
kJoy1Down ,
67
71
kJoy1R3 ,
68
72
kJoy1Select ,
69
73
kJoy1Start ,
74
+ kJoy1LeftAnalogX ,
75
+ kJoy1LeftAnalogY ,
76
+ kJoy1RightAnalogX ,
77
+ kJoy1RightAnalogY ,
70
78
71
79
// State management
72
80
kSaveState1 ,
@@ -127,9 +135,11 @@ enum
127
135
static const char * bindingNames[] = {
128
136
" J0_UP" , " J0_DOWN" , " J0_LEFT" , " J0_RIGHT" , " J0_X" , " J0_Y" , " J0_A" , " J0_B" ,
129
137
" J0_L" , " J0_R" , " J0_L2" , " J0_R2" , " J0_L3" , " J0_R3" , " J0_SELECT" , " J0_START" ,
138
+ " J0_LSTICK_X" , " J0_LSTICK_Y" , " J0_RSTICK_X" , " J0_RSTICK_Y" ,
130
139
131
140
" J1_UP" , " J1_DOWN" , " J1_LEFT" , " J1_RIGHT" , " J1_X" , " J1_Y" , " J1_A" , " J1_B" ,
132
141
" J1_L" , " J1_R" , " J1_L2" , " J1_R2" , " J1_L3" , " J1_R3" , " J1_SELECT" , " J1_START" ,
142
+ " J1_LSTICK_X" , " J1_LSTICK_Y" , " J1_RSTICK_X" , " J1_RSTICK_Y" ,
133
143
134
144
" SAVE1" , " SAVE2" , " SAVE3" , " SAVE4" , " SAVE5" , " SAVE6" , " SAVE7" , " SAVE8" , " SAVE9" , " SAVE0" ,
135
145
" LOAD1" , " LOAD2" , " LOAD3" , " LOAD4" , " LOAD5" , " LOAD6" , " LOAD7" , " LOAD8" , " LOAD9" , " LOAD0" ,
@@ -170,6 +180,10 @@ bool KeyBinds::init(libretro::LoggerComponent* logger)
170
180
_bindings[kJoy0R2 ] = { 0 , SDL_CONTROLLER_AXIS_TRIGGERRIGHT, Binding::Type::Axis, 0 };
171
181
_bindings[kJoy0L3 ] = { 0 , SDL_CONTROLLER_BUTTON_LEFTSTICK, Binding::Type::Button, 0 };
172
182
_bindings[kJoy0R3 ] = { 0 , SDL_CONTROLLER_BUTTON_RIGHTSTICK, Binding::Type::Button, 0 };
183
+ _bindings[kJoy0LeftAnalogX ] = { 0 , SDL_CONTROLLER_AXIS_LEFTX, Binding::Type::Axis, 0 };
184
+ _bindings[kJoy0LeftAnalogY ] = { 0 , SDL_CONTROLLER_AXIS_LEFTY, Binding::Type::Axis, 0 };
185
+ _bindings[kJoy0RightAnalogX ] = { 0 , SDL_CONTROLLER_AXIS_RIGHTX, Binding::Type::Axis, 0 };
186
+ _bindings[kJoy0RightAnalogY ] = { 0 , SDL_CONTROLLER_AXIS_RIGHTY, Binding::Type::Axis, 0 };
173
187
_bindings[kJoy0Select ] = { 0 , SDL_CONTROLLER_BUTTON_BACK, Binding::Type::Button, 0 };
174
188
_bindings[kJoy0Start ] = { 0 , SDL_CONTROLLER_BUTTON_START, Binding::Type::Button, 0 };
175
189
}
@@ -391,6 +405,34 @@ KeyBinds::Action KeyBinds::translateButtonReleased(int button, unsigned* extra)
391
405
}
392
406
}
393
407
408
+ KeyBinds::Action KeyBinds::translateAnalog (int button, Sint16 value, unsigned * extra)
409
+ {
410
+ KeyBinds::Action action;
411
+ unsigned controller;
412
+
413
+ switch (button)
414
+ {
415
+ case kJoy0LeftAnalogX : action = Action::kAxisLeftX ; controller = 0 ; break ;
416
+ case kJoy0LeftAnalogY : action = Action::kAxisLeftY ; controller = 0 ; break ;
417
+ case kJoy0RightAnalogX : action = Action::kAxisRightX ; controller = 0 ; break ;
418
+ case kJoy0RightAnalogY : action = Action::kAxisRightY ; controller = 0 ; break ;
419
+ case kJoy1LeftAnalogX : action = Action::kAxisLeftX ; controller = 1 ; break ;
420
+ case kJoy1LeftAnalogY : action = Action::kAxisLeftY ; controller = 1 ; break ;
421
+ case kJoy1RightAnalogX : action = Action::kAxisRightX ; controller = 1 ; break ;
422
+ case kJoy1RightAnalogY : action = Action::kAxisRightY ; controller = 1 ; break ;
423
+
424
+ default :
425
+ return Action::kNothing ;
426
+ }
427
+
428
+ /* if we pass -32768, it sometimes causes an overflow and acts like a positive value */
429
+ if (value == -32768 )
430
+ value = -32767 ;
431
+
432
+ *extra = (((unsigned )value) & 0xFFFF ) | (controller << 16 );
433
+ return action;
434
+ }
435
+
394
436
KeyBinds::Action KeyBinds::translate (const SDL_KeyboardEvent* key, unsigned * extra)
395
437
{
396
438
if (key->repeat )
@@ -409,7 +451,7 @@ KeyBinds::Action KeyBinds::translate(const SDL_KeyboardEvent* key, unsigned* ext
409
451
{
410
452
if (_bindings[i].type == Binding::Type::Key)
411
453
{
412
- if (key->keysym .sym == _bindings[i].button && mod == _bindings[i].modifiers )
454
+ if (( uint32_t ) key->keysym .sym == _bindings[i].button && mod == _bindings[i].modifiers )
413
455
{
414
456
if (key->state == SDL_PRESSED)
415
457
return translateButtonPress (i, extra);
@@ -447,19 +489,48 @@ KeyBinds::Action KeyBinds::translate(const SDL_ControllerButtonEvent* cbutton, u
447
489
return Action::kNothing ;
448
490
}
449
491
492
+ static bool IsAnalog (int button)
493
+ {
494
+ switch (button)
495
+ {
496
+ case kJoy0LeftAnalogX :
497
+ case kJoy0LeftAnalogY :
498
+ case kJoy0RightAnalogX :
499
+ case kJoy0RightAnalogY :
500
+ case kJoy1LeftAnalogX :
501
+ case kJoy1LeftAnalogY :
502
+ case kJoy1RightAnalogX :
503
+ case kJoy1RightAnalogY :
504
+ return true ;
505
+
506
+ default :
507
+ return false ;
508
+ }
509
+ }
510
+
450
511
void KeyBinds::translate (const SDL_ControllerAxisEvent* caxis, Input& input,
451
512
Action* action1, unsigned * extra1, Action* action2, unsigned * extra2)
452
513
{
453
514
*action1 = *action2 = Action::kNothing ;
454
515
455
516
int threshold = static_cast <int >(32767 * input.getJoystickSensitivity (caxis->which ));
517
+ int analogThreshold = threshold / 4 ;
456
518
for (size_t i = 0 ; i < kMaxBindings ; i++)
457
519
{
458
520
if (_bindings[i].type == Binding::Type::Axis)
459
521
{
460
522
if (caxis->axis == _bindings[i].button && caxis->which == _bindings[i].joystick_id )
461
523
{
462
- if ((_bindings[i].modifiers & 0xFF ) == 0xFF ) // negative axis
524
+ if (IsAnalog (i))
525
+ {
526
+ if (caxis->value > analogThreshold || caxis->value < -analogThreshold)
527
+ *action1 = translateAnalog (i, caxis->value , extra1);
528
+ else
529
+ *action1 = translateAnalog (i, 0 , extra1);
530
+
531
+ break ;
532
+ }
533
+ else if ((_bindings[i].modifiers & 0xFF ) == 0xFF ) // negative axis
463
534
{
464
535
if (caxis->value < -threshold)
465
536
*action1 = translateButtonPress (i, extra1);
@@ -661,7 +732,6 @@ bool KeyBinds::deserializeBindings(const char* json)
661
732
}
662
733
else if (event == JSONSAX_STRING)
663
734
{
664
- int binding = 0 ;
665
735
for (int i = 0 ; i < kMaxBindings ; ++i)
666
736
{
667
737
if (ud->key == bindingNames[i])
@@ -799,7 +869,8 @@ class ChangeInputDialog : public Dialog
799
869
const KeyBinds::Binding getButtonDescriptor () const { return _buttonDescriptor; }
800
870
801
871
Input* _input = nullptr ;
802
- bool _isOpen;
872
+ bool _isOpen = false ;
873
+ bool _isAnalog = false ;
803
874
804
875
bool show (HWND hParent)
805
876
{
@@ -823,6 +894,9 @@ class ChangeInputDialog : public Dialog
823
894
case WM_KEYDOWN:
824
895
case WM_SYSKEYDOWN:
825
896
{
897
+ if (_isAnalog)
898
+ break ;
899
+
826
900
const auto code = WindowsScanCodeToSDLScanCode (msg.lParam , msg.wParam );
827
901
const auto sdlKey = SDL_GetKeyFromScancode (code);
828
902
switch (sdlKey)
@@ -903,6 +977,25 @@ class ChangeInputDialog : public Dialog
903
977
_isOpen = false ;
904
978
}
905
979
980
+ bool MakeAnalog (KeyBinds::Binding& button)
981
+ {
982
+ if (button.type != KeyBinds::Binding::Type::Axis)
983
+ return false ;
984
+
985
+ switch (button.button )
986
+ {
987
+ case SDL_CONTROLLER_AXIS_LEFTX:
988
+ case SDL_CONTROLLER_AXIS_LEFTY:
989
+ case SDL_CONTROLLER_AXIS_RIGHTX:
990
+ case SDL_CONTROLLER_AXIS_RIGHTY:
991
+ button.modifiers = 0 ;
992
+ return true ;
993
+
994
+ default :
995
+ return false ;
996
+ }
997
+ }
998
+
906
999
INT_PTR dialogProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) override
907
1000
{
908
1001
switch (msg)
@@ -930,6 +1023,9 @@ class ChangeInputDialog : public Dialog
930
1023
KeyBinds::Binding button = _input->captureButtonPress ();
931
1024
if (button.type != KeyBinds::Binding::Type::None)
932
1025
{
1026
+ if (_isAnalog && !MakeAnalog (button))
1027
+ break ;
1028
+
933
1029
_buttonDescriptor = button;
934
1030
char buffer[32 ];
935
1031
KeyBinds::getBindingString (buffer, _buttonDescriptor);
@@ -951,7 +1047,7 @@ class InputDialog : public Dialog
951
1047
_bindings = bindings;
952
1048
953
1049
const WORD WIDTH = 478 ;
954
- const WORD HEIGHT = 144 ;
1050
+ const WORD HEIGHT = 200 ;
955
1051
956
1052
addButtonInput (0 , 1 , " L2" , kJoy0L2 + base);
957
1053
addButtonInput (0 , 9 , " R2" , kJoy0R2 + base);
@@ -968,6 +1064,13 @@ class InputDialog : public Dialog
968
1064
addButtonInput (4 , 1 , " Down" , kJoy0Down + base);
969
1065
addButtonInput (4 , 9 , " B" , kJoy0B + base);
970
1066
1067
+ addButtonInput (5 , 1 , " L3" , kJoy0L3 + base);
1068
+ addButtonInput (5 , 9 , " R3" , kJoy0R3 + base);
1069
+ addButtonInput (6 , 0 , " Left Analog X" , kJoy0LeftAnalogX + base);
1070
+ addButtonInput (6 , 2 , " Left Analog Y" , kJoy0LeftAnalogY + base);
1071
+ addButtonInput (6 , 8 , " Right Analog X" , kJoy0RightAnalogX + base);
1072
+ addButtonInput (6 , 10 , " Right Analog Y" , kJoy0RightAnalogY + base);
1073
+
971
1074
addButton (" OK" , IDOK, WIDTH - 55 - 50 , HEIGHT - 14 , 50 , 14 , true );
972
1075
addButton (" Cancel" , IDCANCEL, WIDTH - 50 , HEIGHT - 14 , 50 , 14 , false );
973
1076
}
@@ -1081,6 +1184,7 @@ class InputDialog : public Dialog
1081
1184
ChangeInputDialog db;
1082
1185
db.init (buffer);
1083
1186
db._input = _input;
1187
+ db._isAnalog = IsAnalog (button);
1084
1188
1085
1189
GetDlgItemText (hwnd, 10000 + button, buffer, sizeof (buffer));
1086
1190
db.addLabel (buffer, ChangeInputDialog::ID_LABEL, 0 , 0 , 100 , 15 );
0 commit comments