private static bool IsAxis(SDLFeatureDescriptor feature, SDLAxisUsage axis) { return(feature.featureType == JoystickFeatureType.Axis && feature.usageHint == (int)axis); }
internal InputControlLayout Build() { var builder = new InputControlLayout.Builder { stateFormat = new FourCC('L', 'J', 'O', 'Y'), extendsLayout = parentLayout }; for (var i = 0; i < descriptor.controls.Count; i++) { SDLFeatureDescriptor feature = descriptor.controls[i]; switch (feature.featureType) { case JoystickFeatureType.Axis: { SDLAxisUsage usage = (SDLAxisUsage)feature.usageHint; string featureName = SDLSupport.GetAxisNameFromUsage(usage); string parameters = "scale,scaleFactor=65538,clamp,clampMin=-1,clampMax=1"; if (IsAxisX(feature) && i + 1 < descriptor.controls.Count) { SDLFeatureDescriptor nextFeature = descriptor.controls[i + 1]; if (IsAxisY(nextFeature)) { BuildStickFeature(ref builder, feature, nextFeature); } } if (IsAxisY(feature)) { parameters += ",invert"; } builder.AddControl(featureName) .WithLayout("Analog") .WithByteOffset((uint)feature.offset) .WithFormat(InputStateBlock.kTypeInt) .WithParameters(parameters); } break; case JoystickFeatureType.Ball: { //TODO } break; case JoystickFeatureType.Button: { SDLButtonUsage usage = (SDLButtonUsage)feature.usageHint; string featureName = SDLSupport.GetButtonNameFromUsage(usage); if (featureName != null) { builder.AddControl(featureName) .WithLayout("Button") .WithByteOffset((uint)feature.offset) .WithBitOffset((uint)feature.bit) .WithFormat(InputStateBlock.kTypeBit); } } break; case JoystickFeatureType.Hat: { SDLAxisUsage usage = (SDLAxisUsage)feature.usageHint; string featureName = SDLSupport.GetAxisNameFromUsage(usage); string parameters = "scale,scaleFactor=2147483647,clamp,clampMin=-1,clampMax=1"; if (i + 1 < descriptor.controls.Count) { SDLFeatureDescriptor nextFeature = descriptor.controls[i + 1]; if (IsHatY(nextFeature) && HatNumber(feature) == HatNumber(nextFeature)) { BuildHatFeature(ref builder, feature, nextFeature); } } if (IsHatY(feature)) { parameters += ",invert"; } builder.AddControl(featureName) .WithLayout("Analog") .WithByteOffset((uint)feature.offset) .WithFormat(InputStateBlock.kTypeInt) .WithParameters(parameters); } break; default: { throw new NotImplementedException(String.Format("SDLLayoutBuilder.Build: Trying to build an SDL device with an unknown feature of type {0}.", feature.featureType)); } } } return(builder.Build()); }
public static string GetAxisNameFromUsage(SDLAxisUsage usage) { return(Enum.GetName(typeof(SDLAxisUsage), usage)); }