// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #if USE_LARGE_WORLDS using Real = System.Double; #else using Real = System.Single; #endif using FlaxEngine; // ReSharper disable RedundantAssignment namespace FlaxEditor.GUI { partial class CurveEditor { /// /// The generic keyframe value accessor object for curve editor. /// /// The keyframe value type. public interface IKeyframeAccess where U : new() { /// /// Gets the default value. /// /// The value. void GetDefaultValue(out U value); /// /// Gets the curve components count. Vector types should return amount of component to use for value editing. /// /// The components count. int GetCurveComponents(); /// /// Gets the value of the component for the curve. /// /// The keyframe value. /// The component index. /// The curve value. float GetCurveValue(ref U value, int component); /// /// Sets the curve value of the component. /// /// The curve value to assign. /// The keyframe value. /// The component index. void SetCurveValue(float curve, ref U value, int component); } private class KeyframeAccess : IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess, IKeyframeAccess { void IKeyframeAccess.GetDefaultValue(out bool value) { value = false; } int IKeyframeAccess.GetCurveComponents() { return 1; } float IKeyframeAccess.GetCurveValue(ref bool value, int component) { return value ? 1 : 0; } void IKeyframeAccess.SetCurveValue(float curve, ref bool value, int component) { value = curve >= 0.5f; } void IKeyframeAccess.GetDefaultValue(out int value) { value = 0; } int IKeyframeAccess.GetCurveComponents() { return 1; } float IKeyframeAccess.GetCurveValue(ref int value, int component) { return value; } void IKeyframeAccess.SetCurveValue(float curve, ref int value, int component) { value = (int)curve; } void IKeyframeAccess.GetDefaultValue(out double value) { value = 0.0; } int IKeyframeAccess.GetCurveComponents() { return 1; } float IKeyframeAccess.GetCurveValue(ref double value, int component) { return (float)value; } void IKeyframeAccess.SetCurveValue(float curve, ref double value, int component) { value = (double)curve; } void IKeyframeAccess.GetDefaultValue(out float value) { value = 0.0f; } int IKeyframeAccess.GetCurveComponents() { return 1; } float IKeyframeAccess.GetCurveValue(ref float value, int component) { return value; } void IKeyframeAccess.SetCurveValue(float curve, ref float value, int component) { value = (float)curve; } void IKeyframeAccess.GetDefaultValue(out Vector2 value) { value = Vector2.Zero; } int IKeyframeAccess.GetCurveComponents() { return 2; } float IKeyframeAccess.GetCurveValue(ref Vector2 value, int component) { return (float)value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Vector2 value, int component) { value[component] = (Real)curve; } void IKeyframeAccess.GetDefaultValue(out Vector3 value) { value = Vector3.Zero; } int IKeyframeAccess.GetCurveComponents() { return 3; } float IKeyframeAccess.GetCurveValue(ref Vector3 value, int component) { return (float)value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Vector3 value, int component) { value[component] = (Real)curve; } void IKeyframeAccess.GetDefaultValue(out Vector4 value) { value = Vector4.Zero; } int IKeyframeAccess.GetCurveComponents() { return 4; } float IKeyframeAccess.GetCurveValue(ref Vector4 value, int component) { return (float)value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Vector4 value, int component) { value[component] = (Real)curve; } void IKeyframeAccess.GetDefaultValue(out Float2 value) { value = Float2.Zero; } int IKeyframeAccess.GetCurveComponents() { return 2; } float IKeyframeAccess.GetCurveValue(ref Float2 value, int component) { return value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Float2 value, int component) { value[component] = curve; } void IKeyframeAccess.GetDefaultValue(out Float3 value) { value = Float3.Zero; } int IKeyframeAccess.GetCurveComponents() { return 3; } float IKeyframeAccess.GetCurveValue(ref Float3 value, int component) { return value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Float3 value, int component) { value[component] = curve; } void IKeyframeAccess.GetDefaultValue(out Float4 value) { value = Float4.Zero; } int IKeyframeAccess.GetCurveComponents() { return 4; } float IKeyframeAccess.GetCurveValue(ref Float4 value, int component) { return value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Float4 value, int component) { value[component] = curve; } void IKeyframeAccess.GetDefaultValue(out Double2 value) { value = Double2.Zero; } int IKeyframeAccess.GetCurveComponents() { return 2; } float IKeyframeAccess.GetCurveValue(ref Double2 value, int component) { return (float)value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Double2 value, int component) { value[component] = curve; } void IKeyframeAccess.GetDefaultValue(out Double3 value) { value = Double3.Zero; } int IKeyframeAccess.GetCurveComponents() { return 3; } float IKeyframeAccess.GetCurveValue(ref Double3 value, int component) { return (float)value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Double3 value, int component) { value[component] = curve; } void IKeyframeAccess.GetDefaultValue(out Double4 value) { value = Double4.Zero; } int IKeyframeAccess.GetCurveComponents() { return 4; } float IKeyframeAccess.GetCurveValue(ref Double4 value, int component) { return (float)value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Double4 value, int component) { value[component] = curve; } public void GetDefaultValue(out Quaternion value) { value = Quaternion.Identity; } int IKeyframeAccess.GetCurveComponents() { return 3; } float IKeyframeAccess.GetCurveValue(ref Quaternion value, int component) { return value.EulerAngles[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Quaternion value, int component) { var euler = value.EulerAngles; euler[component] = (float)curve; Quaternion.Euler(euler.X, euler.Y, euler.Z, out value); } void IKeyframeAccess.GetDefaultValue(out Color value) { value = Color.Black; } int IKeyframeAccess.GetCurveComponents() { return 4; } float IKeyframeAccess.GetCurveValue(ref Color value, int component) { return value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Color value, int component) { value[component] = (float)curve; } void IKeyframeAccess.GetDefaultValue(out Color32 value) { value = Color32.Black; } int IKeyframeAccess.GetCurveComponents() { return 4; } float IKeyframeAccess.GetCurveValue(ref Color32 value, int component) { return value[component]; } void IKeyframeAccess.SetCurveValue(float curve, ref Color32 value, int component) { value[component] = (byte)Mathf.Clamp(curve, 0, 255); } } } }