comparison nuklear_ui/blastem_nuklear.c @ 2311:07aeea6cb068

Fix analog stick UI for real. Allow clearing a controller binding
author Michael Pavone <pavone@retrodev.com>
date Wed, 29 Mar 2023 22:36:34 -0700
parents b0ec82a59472
children 3f2ecd156453
comparison
equal deleted inserted replaced
2310:b0ec82a59472 2311:07aeea6cb068
731 bind_option_group(context, "System Buttons", system_buttons, sizeof(system_buttons)/sizeof(*system_buttons)); 731 bind_option_group(context, "System Buttons", system_buttons, sizeof(system_buttons)/sizeof(*system_buttons));
732 bind_option_group(context, "Emulator Control", emu_control, sizeof(emu_control)/sizeof(*emu_control)); 732 bind_option_group(context, "Emulator Control", emu_control, sizeof(emu_control)/sizeof(*emu_control));
733 bind_option_group(context, "Debugging", debugger, sizeof(debugger)/sizeof(*debugger)); 733 bind_option_group(context, "Debugging", debugger, sizeof(debugger)/sizeof(*debugger));
734 bind_option_group(context, "Speed Control", speeds, sizeof(speeds)/sizeof(*speeds)); 734 bind_option_group(context, "Speed Control", speeds, sizeof(speeds)/sizeof(*speeds));
735 735
736 nk_layout_row_static(context, context->style.font->height, (render_width() - 80)/4, 1); 736 nk_layout_row_static(context, context->style.font->height, (render_width() - 80)/4, 2);
737 if (nk_button_label(context, "Back")) { 737 if (nk_button_label(context, "Back")) {
738 pop_view();
739 }
740 if (nk_button_label(context, "Clear")) {
741 *current_bind_dest = NULL;
742 controller_binding_changed = 1;
738 pop_view(); 743 pop_view();
739 } 744 }
740 nk_end(context); 745 nk_end(context);
741 } 746 }
742 } 747 }
755 { 760 {
756 if (binds[i] & AXIS) { 761 if (binds[i] & AXIS) {
757 labels[i] = get_axis_label(&selected_controller_info, binds[i] & ~AXIS); 762 labels[i] = get_axis_label(&selected_controller_info, binds[i] & ~AXIS);
758 conf_vals[i] = &bindings->triggers[(binds[i] & ~AXIS) - SDL_CONTROLLER_AXIS_TRIGGERLEFT]; 763 conf_vals[i] = &bindings->triggers[(binds[i] & ~AXIS) - SDL_CONTROLLER_AXIS_TRIGGERLEFT];
759 } else if (binds[i] & STICKDIR) { 764 } else if (binds[i] & STICKDIR) {
760 static char const * dirs[] = {"Up", "Down", "Right", "Left"}; 765 static char const * dirs[] = {"Down", "Up", "Right", "Left"};
761 labels[i] = dirs[binds[i] & 3]; 766 labels[i] = dirs[binds[i] & 3];
762 conf_vals[i] = &(binds[i] & LEFTSTICK ? bindings->left_stick : bindings->right_stick)[binds[i] & 3]; 767 conf_vals[i] = &(binds[i] & LEFTSTICK ? bindings->left_stick : bindings->right_stick)[binds[i] & 3];
763 } else { 768 } else {
764 labels[i] = get_button_label(&selected_controller_info, binds[i]); 769 labels[i] = get_button_label(&selected_controller_info, binds[i]);
765 conf_vals[i] = &bindings->button_binds[binds[i]]; 770 conf_vals[i] = &bindings->button_binds[binds[i]];
826 } 831 }
827 switch (axis) 832 switch (axis)
828 { 833 {
829 case SDL_CONTROLLER_AXIS_LEFTX: 834 case SDL_CONTROLLER_AXIS_LEFTX:
830 case SDL_CONTROLLER_AXIS_LEFTY: 835 case SDL_CONTROLLER_AXIS_LEFTY:
831 bindings->left_stick[(axis - SDL_CONTROLLER_AXIS_LEFTX) * 2 + is_negative] = val.ptrval; 836 bindings->left_stick[(SDL_CONTROLLER_AXIS_LEFTY - axis) * 2 + is_negative] = val.ptrval;
832 break; 837 break;
833 case SDL_CONTROLLER_AXIS_RIGHTX: 838 case SDL_CONTROLLER_AXIS_RIGHTX:
834 case SDL_CONTROLLER_AXIS_RIGHTY: 839 case SDL_CONTROLLER_AXIS_RIGHTY:
835 bindings->right_stick[(axis - SDL_CONTROLLER_AXIS_RIGHTX) * 2 + is_negative] = val.ptrval; 840 bindings->right_stick[(SDL_CONTROLLER_AXIS_RIGHTX - axis) * 2 + is_negative] = val.ptrval;
836 break; 841 break;
837 case SDL_CONTROLLER_AXIS_TRIGGERLEFT: 842 case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
838 case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: 843 case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
839 bindings->triggers[axis-SDL_CONTROLLER_AXIS_TRIGGERLEFT] = val.ptrval; 844 bindings->triggers[axis-SDL_CONTROLLER_AXIS_TRIGGERLEFT] = val.ptrval;
840 break; 845 break;