Created
November 25, 2022 12:08
-
-
Save theoknock/8deae32ffb2d440c4cb9fcb3f202c32a to your computer and use it in GitHub Desktop.
Mapping property values to normalized control values. Includes a gamma parameter that, for example, makes a UISlider control more less sensitive to adjustments made at the lower end of the scale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const double kVideoZoomFactorPowerCoefficient = 3.333f; | |
// | |
// | |
// | |
static double (^ _Nonnull control_property_value)(double, double, double, double) = ^ double (double control_value, double property_value_min, double property_value_max, double gamma) { | |
return ((pow(control_value, gamma) * (property_value_max - property_value_min)) + property_value_min); | |
}; | |
static double (^ _Nonnull property_control_value)(double, double, double, double) = ^ double (double property_value, double property_value_min, double property_value_max, double inverse_gamma) { | |
return pow((property_value - property_value_min) / (property_value_max - property_value_min), 1.f / inverse_gamma); | |
}; | |
// | |
// | |
// | |
self.videoZoomFactorSlider.minimumValue = 0.0; | |
self.videoZoomFactorSlider.maximumValue = 1.0; | |
self.videoZoomFactorSlider.value = property_control_value(self.videoDevice.videoZoomFactor, self.videoDevice.minAvailableVideoZoomFactor, self.videoDevice.activeFormat.videoMaxZoomFactor, kVideoZoomFactorPowerCoefficient); | |
// | |
// | |
// | |
[self.videoDevice setVideoZoomFactor:control_property_value(sender.value, self.videoDevice.minAvailableVideoZoomFactor, self.videoDevice.activeFormat.videoMaxZoomFactor, kVideoZoomFactorPowerCoefficient)]; | |
// | |
// | |
// | |
[self.videoZoomFactorSlider setValue:property_control_value([newValue doubleValue], self.videoDevice.minAvailableVideoZoomFactor, self.videoDevice.activeFormat.videoMaxZoomFactor, kVideoZoomFactorPowerCoefficient)]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment