public override void Evaluate(int SpreadMax) { //calc input spreadcount int inputSpreadCount = GetSpreadMax(); //create or delete button groups int diff = inputSpreadCount - FControllerGroups.Count; if (diff > 0) { for (int i = 0; i < diff; i++) { FControllerGroups.Add(new ToggleButtonGroup()); } } else if (diff < 0) { for (int i = 0; i < -diff; i++) { FControllerGroups.RemoveAt(FControllerGroups.Count - 1 - i); } } //update parameters int slice; if (FCountXIn.PinIsChanged || FCountYIn.PinIsChanged || FSizeXIn.PinIsChanged || FSizeYIn.PinIsChanged || FTransformIn.PinIsChanged || FColorIn.PinIsChanged || FOverColorIn.PinIsChanged || FActiveColorIn.PinIsChanged) { for (slice = 0; slice < inputSpreadCount; slice++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[slice]; Matrix4x4 trans; Vector2D count, size; RGBAColor col, over, active; FTransformIn.GetMatrix(slice, out trans); FCountXIn.GetValue(slice, out count.x); FCountYIn.GetValue(slice, out count.y); FSizeXIn.GetValue(slice, out size.x); FSizeYIn.GetValue(slice, out size.y); FColorIn.GetColor(slice, out col); FOverColorIn.GetColor(slice, out over); FActiveColorIn.GetColor(slice, out active); group.UpdateTransform(trans, count, size, col, over, active); } } //get spread counts int outcount = 0; FSpreadCountsOut.SliceCount = inputSpreadCount; for (slice = 0; slice < inputSpreadCount; slice++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[slice]; outcount += group.FControllers.Length; FSpreadCountsOut.SetValue(slice, group.FControllers.Length); } //update mouse and colors bool valueSet = false; if (FMouseXIn.PinIsChanged || FMouseYIn.PinIsChanged || FLeftButtonIn.PinIsChanged || FColorIn.PinIsChanged || FOverColorIn.PinIsChanged || FActiveColorIn.PinIsChanged || FCountXIn.PinIsChanged || FCountYIn.PinIsChanged || FLastMouseLeft) { Vector2D mouse; double mouseLeft; FMouseXIn.GetValue(0, out mouse.x); FMouseYIn.GetValue(0, out mouse.y); FLeftButtonIn.GetValue(0, out mouseLeft); bool mouseDown = mouseLeft >= 0.5; bool mousDownEdge = mouseDown && !FLastMouseLeft; for (slice = 0; slice < inputSpreadCount; slice++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[slice]; valueSet |= group.UpdateMouse(mouse, mousDownEdge, mouseDown); } FLastMouseLeft = mouseDown; } //set value slice = 0; if (FValueIn.PinIsChanged || FSetValueIn.PinIsChanged) { for (int i = 0; i < inputSpreadCount; i++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[i]; int pcount = group.FControllers.Length; for (int j = 0; j < pcount; j++) { double val; FSetValueIn.GetValue(slice, out val); if (val >= 0.5) { //update value FValueIn.GetValue(slice, out val); group.UpdateValue((ToggleButton)group.FControllers[j], val >= 0.5); valueSet = true; } else if (FFirstframe) { //load from config pin on first frame FInternalValueConfig.GetValue(slice, out val); group.UpdateValue((ToggleButton)group.FControllers[j], val >= 0.5); } slice++; } } } //write output to pins FValueOut.SliceCount = outcount; if (outcount != FInternalValueConfig.SliceCount) { FInternalValueConfig.SliceCount = outcount; } FTransformOut.SliceCount = outcount; FColorOut.SliceCount = outcount; FHitOut.SliceCount = outcount; FActiveOut.SliceCount = outcount; FMouseOverOut.SliceCount = outcount; slice = 0; for (int i = 0; i < inputSpreadCount; i++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[i]; int pcount = group.FControllers.Length; for (int j = 0; j < pcount; j++) { ToggleButton s = (ToggleButton)group.FControllers[j]; FTransformOut.SetMatrix(slice, s.Transform); FColorOut.SetColor(slice, s.CurrentCol); FValueOut.SetValue(slice, s.Value ? 1 : 0); FMouseOverOut.SetValue(slice, s.MouseOver ? 1 : 0); FHitOut.SetValue(slice, s.Hit ? 1 : 0); FActiveOut.SetValue(slice, s.Active ? 1 : 0); //update config pin if (valueSet) { double val; FInternalValueConfig.GetValue(slice, out val); if (Math.Abs(s.Value ? 1 : 0 - val) > 0.00000001) { FInternalValueConfig.SetValue(slice, s.Value ? 1 : 0); } } slice++; } } //end of frame FFirstframe = false; }
public override void Evaluate(int SpreadMax) { //calc input spreadcount int inputSpreadCount = GetSpreadMax(); //create or delete button groups int diff = inputSpreadCount - FControllerGroups.Count; if (diff > 0) { for (int i = 0; i < diff; i++) { FControllerGroups.Add(new ToggleButtonGroup()); } } else if (diff < 0) { for (int i = 0; i < -diff; i++) { FControllerGroups.RemoveAt(FControllerGroups.Count - 1 - i); } } //update parameters int slice; if (AnyParameterPinChanged()) { for (slice = 0; slice < inputSpreadCount; slice++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[slice]; group.UpdateTransform(FTransformIn[slice], FCountIn[slice], FSizeIn[slice], FColorIn[slice], FOverColorIn[slice], FActiveColorIn[slice]); } } //get spread counts int outcount = 0; FSpreadCountsOut.SliceCount = inputSpreadCount; for (slice = 0; slice < inputSpreadCount; slice++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[slice]; outcount += group.FControllers.Length; FSpreadCountsOut[slice] = group.FControllers.Length; } //update mouse and colors bool valueSet = UpdateMouse <ToggleButtonGroup, ToggleButton>(inputSpreadCount); //set value slice = 0; if (FValueIn.IsChanged || FSetValueIn.IsChanged) { for (int i = 0; i < inputSpreadCount; i++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[i]; int pcount = group.FControllers.Length; for (int j = 0; j < pcount; j++) { if (FSetValueIn[slice]) { //update value group.UpdateValue((ToggleButton)group.FControllers[j], FValueIn[slice]); valueSet = true; } else if (FFirstframe) { //load from config pin on first frame group.UpdateValue((ToggleButton)group.FControllers[j], FInternalValueConfig[slice]); } slice++; } } } //write output to pins FValueOut.SliceCount = outcount; if (outcount != FInternalValueConfig.SliceCount) { FInternalValueConfig.SliceCount = outcount; } FTransformOut.SliceCount = outcount; FColorOut.SliceCount = outcount; FHitOut.SliceCount = outcount; FActiveOut.SliceCount = outcount; FMouseOverOut.SliceCount = outcount; slice = 0; for (int i = 0; i < inputSpreadCount; i++) { ToggleButtonGroup group = (ToggleButtonGroup)FControllerGroups[i]; int pcount = group.FControllers.Length; for (int j = 0; j < pcount; j++) { ToggleButton s = (ToggleButton)group.FControllers[j]; FTransformOut[slice] = s.Transform; FColorOut[slice] = s.CurrentCol; FValueOut[slice] = s.Value; FMouseOverOut[slice] = s.GetAndResetMouseOver(); FHitOut[slice] = s.Hit; FActiveOut[slice] = s.Active; //update config pin if (valueSet && FAutoSave[0]) { if (FInternalValueConfig[slice] != s.Value) { FInternalValueConfig[slice] = s.Value; } } slice++; } } //end of frame FFirstframe = false; }