public HidAccessPropertyRatioRect() { _Value = new RatioRect(); UpdateLeftBytes(); UpdateTopBytes(); // need not to call UpdateWidthBytes and UpdateHeightBytes OnValueUpdated(); }
public void UpdateDeviceSettings(EgsDeviceSettings deviceSettings) { RatioRect RightHandDetectionAreaRatioRect = new RatioRect(); RatioRect LeftHandDetectionAreaRatioRect = new RatioRect(); RightHandDetectionAreaRatioRect.XRange.From = (float)(CaptureImageRightHandDetectionArea.X / CaptureImageWidth); RightHandDetectionAreaRatioRect.XRange.To = (float)((CaptureImageRightHandDetectionArea.X + CaptureImageRightHandDetectionArea.Width) / CaptureImageWidth); RightHandDetectionAreaRatioRect.YRange.From = (float)(CaptureImageRightHandDetectionArea.Y / CaptureImageHeight); RightHandDetectionAreaRatioRect.YRange.To = (float)((CaptureImageRightHandDetectionArea.Y + CaptureImageRightHandDetectionArea.Height) / CaptureImageHeight); LeftHandDetectionAreaRatioRect.XRange.From = (float)(CaptureImageLeftHandDetectionArea.X / CaptureImageWidth); LeftHandDetectionAreaRatioRect.XRange.To = (float)((CaptureImageLeftHandDetectionArea.X + CaptureImageLeftHandDetectionArea.Width) / CaptureImageWidth); LeftHandDetectionAreaRatioRect.YRange.From = (float)(CaptureImageLeftHandDetectionArea.Y / CaptureImageHeight); LeftHandDetectionAreaRatioRect.YRange.To = (float)((CaptureImageLeftHandDetectionArea.Y + CaptureImageLeftHandDetectionArea.Height) / CaptureImageHeight); var newHandDetectionScaleForEgsDevice = HandDetectionScaleForEgsDevice_DividedBy_CaptureImagePalmImageWidth * CaptureImagePalmImageWidth; if (newHandDetectionScaleForEgsDevice > HandDetectionScaleForEgsDeviceMaximum) { if (false) { Debug.WriteLine("newHandDetectionScaleForEgsDevice: " + newHandDetectionScaleForEgsDevice); } } int HandDetectionScaleForEgsDevice = (int)Math.Min(newHandDetectionScaleForEgsDevice, short.MaxValue); if (HandDetectionScaleForEgsDevice == 0) { // TODO: MUSTDO: Test another way. if (deviceSettings.IsToDetectHandsOnDevice.Value != false) { deviceSettings.IsToDetectHandsOnDevice.Value = false; } } else { try { // It has to set Value property atomically. deviceSettings.RightHandDetectionAreaOnFixed.Value = RightHandDetectionAreaRatioRect; deviceSettings.RightHandDetectionScaleOnFixed.RangedValue.Value = HandDetectionScaleForEgsDevice; deviceSettings.LeftHandDetectionAreaOnFixed.Value = LeftHandDetectionAreaRatioRect; deviceSettings.LeftHandDetectionScaleOnFixed.RangedValue.Value = HandDetectionScaleForEgsDevice; var newIsToDetectHandsOnDevice = deviceSettings.IsToDetectHands.Value; if (deviceSettings.IsToDetectHandsOnDevice.Value != newIsToDetectHandsOnDevice) { deviceSettings.IsToDetectHandsOnDevice.Value = newIsToDetectHandsOnDevice; } } catch (Exception ex) { if (ApplicationCommonSettings.IsDebugging) { Debugger.Break(); } } } }