public SequenceRainbow() { var fxr = new FxRainbow { HueCyclePixelLength = 94 / 3, HueSecondsPerCycle = 8 }; mFxRainbowCycle = new FxScale(fxr); AddLuminanceControl(v => mFxRainbowCycle.Luminance = v); AddSaturationControl(v => mFxRainbowCycle.Saturation = v); var ictl = new ControlVariableInteger(2, 200, 1) { Value = fxr.HueCyclePixelLength }; ictl.ValueChanged += (s, e) => fxr.HueCyclePixelLength = ictl.Value; Controls.Add("Length", ictl); var dctl = new ControlVariableDouble(0.1, 30) { Value = fxr.HueSecondsPerCycle }; dctl.ValueChanged += (s, e) => fxr.HueSecondsPerCycle = dctl.Value; Controls.Add("Period", dctl); }
void AddJsonControl(JsonObject jctl) { var name = jctl["Name"].AsString(); var typestr = jctl["Type"].AsString(); IControlVariable ctl; if (!Enum.TryParse <ControlType>(typestr, out ControlType type)) { throw new JsonValueInvalidException(jctl["Type"], "Type must be one of: " + string.Join(",", Enum.GetNames(typeof(ControlType)))); } switch (type) { case ControlType.Ratio: if (jctl.TryGetValue("Default", out JsonValue jctlvalue)) { ctl = new ControlVariableRatio { Value = jctlvalue.AsNumber() }; } else { ctl = new ControlVariableRatio(); } break; case ControlType.Integer: int min = int.MinValue; int max = int.MaxValue; int step = 1; if (jctl.TryGetValue("Min", out JsonValue jmin)) { min = (int)jmin.AsNumber(); } if (jctl.TryGetValue("Max", out JsonValue jmax)) { max = (int)jmax.AsNumber(); } if (jctl.TryGetValue("Step", out JsonValue jstep)) { step = (int)jstep.AsNumber(); } if (jctl.TryGetValue("Default", out JsonValue jdef)) { ctl = new ControlVariableInteger(min, max, step) { Value = (int)jdef.AsNumber() }; } else { ctl = new ControlVariableInteger(min, max, step); } break; case ControlType.Double: double dmin = double.MinValue; double dmax = double.MaxValue; if (jctl.TryGetValue("Min", out jmin)) { dmin = jmin.AsNumber(); } if (jctl.TryGetValue("Max", out jmax)) { dmax = jmax.AsNumber(); } ctl = new ControlVariableDouble(dmin, dmax); break; case ControlType.Colour: // @todo: implement colour parsing ctl = new ControlVariableColour(); throw new NotImplementedException("Nopeity nope.. haven't implemented Colour variables"); //break; default: throw new ArgumentException("Unknown ControlType value"); } Program.AddControl(name, ctl); }