public void ShowStateFromComboBox() { StateSave stateSave = this.StateComboBox.SelectedItem as StateSave; string asString = this.StateComboBox.SelectedItem as string; if (stateSave != null) { GlueViewCommands.Self.ElementCommands.ShowState(stateSave); } else if (asString != null) { if (asString == InterpolateBetweenConst) { // finish here IElement currentElement = GlueViewState.Self.CurrentElement; StateSave firstState = currentElement.GetStateRecursively(FirstInterpolatedStateName, this.CategoryName); StateSave secondState = currentElement.GetStateRecursively(SecondInterpolatedStateName, this.CategoryName); if (firstState != null && secondState != null) { float interpolationValue = 1 - (InterpolationValue / 100.0f); StateSave combined = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstState, secondState, interpolationValue); GlueViewCommands.Self.ElementCommands.ShowState(combined); } } } }
public static void InterpolateBetween(ElementRuntime elementRuntime, object firstStateSaveAsObject, object secondStateSaveAsObject, object interpolationValueAsObject, StringBuilder logStringBuilder = null) { StateSave firstStateSave = firstStateSaveAsObject as StateSave; StateSave secondStateSave = secondStateSaveAsObject as StateSave; float interpolationValue = 0; if (interpolationValueAsObject is float) { interpolationValue = (float)interpolationValueAsObject; } if (interpolationValueAsObject is double) { interpolationValue = (float)((double)interpolationValueAsObject); } else if (interpolationValueAsObject is int) { interpolationValue = (int)interpolationValueAsObject; } if (float.IsNaN(interpolationValue)) { throw new Exception("InterpolationValue is NaN"); } StateSave resultingStateSave = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstStateSave, secondStateSave, interpolationValue); string nameOfObject = "unnamed object"; if (elementRuntime.AssociatedNamedObjectSave != null) { nameOfObject = elementRuntime.AssociatedNamedObjectSave.ToString(); } else if (elementRuntime.AssociatedIElement != null) { nameOfObject = elementRuntime.AssociatedIElement.ToString(); } if (logStringBuilder != null) { logStringBuilder.AppendLine("Interpolating " + nameOfObject + " between " + firstStateSave + " and " + secondStateSave + " with value " + interpolationValue); foreach (InstructionSave instruction in resultingStateSave.InstructionSaves) { logStringBuilder.AppendLine("\t" + instruction); } } try { elementRuntime.SetState(resultingStateSave, elementRuntime.AssociatedIElement); } catch (Exception e) { throw new StateSettingException("Error in script trying to interpolate " + nameOfObject + " between " + firstStateSave + " and " + secondStateSave + " with value " + interpolationValue); } }
public void Test() { StateSave firstState = new StateSave(); InstructionSave instructionSave = new InstructionSave(); instructionSave.Type = "float"; instructionSave.Value = 0.0f; instructionSave.Member = "X"; firstState.InstructionSaves.Add(instructionSave); StateSave secondState = new StateSave(); instructionSave = instructionSave.Clone(); instructionSave.Value = 10.0f; secondState.InstructionSaves.Add(instructionSave); StateSave combined = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstState, secondState, .5f); if (MathFunctions.RoundToInt((float)combined.InstructionSaves[0].Value) != 5) { throw new Exception("CreateCombined is not properly combining States"); } }