public static void GetBindingDictionaryFromActionMap(ActionMap actionMap, BindingDictionary bindingDictionary) { var actions = actionMap.actions; foreach (var scheme in actionMap.controlSchemes) { var bindings = scheme.bindings; for (var i = 0; i < bindings.Count; i++) { var binding = bindings[i]; var action = actions[i].name; List <VRInputDevice.VRControl> controls; if (!bindingDictionary.TryGetValue(action, out controls)) { controls = new List <VRInputDevice.VRControl>(); bindingDictionary[action] = controls; } foreach (var source in binding.sources) { bindingDictionary[action].Add((VRInputDevice.VRControl)source.controlIndex); } } } }
void Start() { // Clear selection so we can't manipulate things Selection.activeGameObject = null; m_ToolMenu = this.InstantiateMenuUI(rayOrigin, m_MenuPrefab); var createPrimitiveMenu = m_ToolMenu.GetComponent <CreatePrimitiveMenu>(); this.ConnectInterfaces(createPrimitiveMenu, rayOrigin); createPrimitiveMenu.selectPrimitive = SetSelectedPrimitive; createPrimitiveMenu.close = Close; var controls = new BindingDictionary(); InputUtils.GetBindingDictionaryFromActionMap(standardActionMap, controls); foreach (var control in controls) { foreach (var id in control.Value) { var request = this.GetFeedbackRequestObject <ProxyFeedbackRequest>(this); request.node = node; request.control = id; request.tooltipText = "Draw"; this.AddFeedbackRequest(request); } } }
private Expression CreateExpressionArray <TItem>(BindingDictionary <TItem> items) where TItem : IBinding { if (items.Count == 0) { return(Expression.Constant(null, typeof(string[]))); } var strings = ((IEnumerable <KeyValuePair <Symbol, TItem> >)items).Select(pair => Expression.Constant(pair.Key.Value, typeof(string))); return(Expression.NewArrayInit(typeof(string), strings)); }
/// <summary> /// Internal! This is used by the Installer to create new classes. /// </summary> /// <param name="runtime">Smalltalk runtime this class is part of.</param> /// <param name="name">Name of the class.</param> /// <param name="superclass">Optional binding to the class' superclass.</param> /// <param name="instanceState">State of the class' instances (named, object-indexable, byte-indexable).</param> /// <param name="instanceVariables">Instance variables bindings. Those are initially not initialized.</param> /// <param name="classVariables">Class variable binding.</param> /// <param name="classInstanceVariables">Class-instance variables bindings. Those are initially not initialized.</param> /// <param name="importedPools">Collection of pools that are imported by the class.</param> /// <param name="instanceMethods">Collection with the methods defining the instance behaviors.</param> /// <param name="classMethods">Collection with the methods defining the class behaviors.</param> public SmalltalkClass(SmalltalkRuntime runtime, Symbol name, ClassBinding superclass, InstanceStateEnum instanceState, BindingDictionary <InstanceVariableBinding> instanceVariables, DiscreteBindingDictionary <ClassVariableBinding> classVariables, BindingDictionary <ClassInstanceVariableBinding> classInstanceVariables, DiscreteBindingDictionary <PoolBinding> importedPools, InstanceMethodDictionary instanceMethods, ClassMethodDictionary classMethods) { if (runtime == null) { throw new ArgumentNullException("runtime"); } if ((name == null) || (name.Value.Length == 0)) { throw new ArgumentNullException("name"); } if (!SmalltalkClass.ValidateIdentifiers <InstanceVariableBinding>(instanceVariables)) { throw new ArgumentException("Invalid or duplicate instance variable name found", "instanceVariables"); } if (!SmalltalkClass.ValidateIdentifiers <ClassVariableBinding>(classVariables)) { throw new ArgumentException("Invalid or duplicate class variable name found", "classVariables"); } if (!SmalltalkClass.ValidateIdentifiers <ClassInstanceVariableBinding>(classInstanceVariables)) { throw new ArgumentException("Invalid or duplicate class instance variable name found", "classInstanceVariables"); } if (!SmalltalkClass.ValidateIdentifiers <PoolBinding>(importedPools)) { throw new ArgumentException("Invalid or duplicate imported pool name found", "importedPools"); } if (!SmalltalkClass.CheckDuplicates <InstanceVariableBinding, ClassVariableBinding>(instanceVariables, classVariables)) { throw new ArgumentException("Duplicate instance or class variable name. Instance and class variable names must be unique."); } if (!SmalltalkClass.CheckDuplicates <ClassInstanceVariableBinding, ClassVariableBinding>(classInstanceVariables, classVariables)) { throw new ArgumentException("Duplicate class-instance or class variable name. Class-instance and class variable names must be unique."); } this.Runtime = runtime; this.ClassInstanceVariableBindings = classInstanceVariables ?? new BindingDictionary <ClassInstanceVariableBinding>(this.Runtime, 1); this.ClassBehavior = classMethods ?? new ClassMethodDictionary(this.Runtime); this.ClassVariableBindings = classVariables ?? new DiscreteBindingDictionary <ClassVariableBinding>(this.Runtime, 1); this.ImportedPoolBindings = importedPools ?? new DiscreteBindingDictionary <PoolBinding>(this.Runtime, 1); this.InstanceBehavior = instanceMethods ?? new InstanceMethodDictionary(this.Runtime); this.InstanceState = instanceState; this.InstanceVariableBindings = instanceVariables ?? new BindingDictionary <InstanceVariableBinding>(this.Runtime, 1); this.Name = name; this.SuperclassBinding = superclass; // Null is OK .... Object has null this.InstanceSize = 0; this.ClassInstanceSize = 0; this.ClassInstanceVariables = new object[0]; }
void Start() { // Clear selection so we can't manipulate things Selection.activeGameObject = null; SetupPreferences(); m_SmoothInput.Reset(0.0f); if (primary) { this.AddRayVisibilitySettings(rayOrigin, this, false, false); SetupBrushUI(); HandleBrushSize(m_Preferences.brushSize); m_ToolMenu = this.InstantiateMenuUI(rayOrigin, m_MenuPrefab); var contextMenu = m_ToolMenu.GetComponent <AnnotationContextMenu>(); this.ConnectInterfaces(contextMenu, rayOrigin); contextMenu.close = Close; contextMenu.colorChanged = OnAnnotationColorChanged; OnAnnotationColorChanged(m_Preferences.annotationColor); contextMenu.preferences = m_Preferences; contextMenu.toolRayOrigin = rayOrigin; var controls = new BindingDictionary(); InputUtils.GetBindingDictionaryFromActionMap(m_ActionMap, controls); foreach (var control in controls) { var tooltipText = control.Key; var suppressExisting = control.Key == "Vertical" || control.Key == "StickButton"; if (suppressExisting) { tooltipText = null; } foreach (var id in control.Value) { var request = (ProxyFeedbackRequest)this.GetFeedbackRequestObject(typeof(ProxyFeedbackRequest)); request.node = node; request.control = id; request.priority = 1; request.tooltipText = tooltipText; request.suppressExisting = suppressExisting; this.AddFeedbackRequest(request); } } } }
/// <summary> /// Create the class object (and sets the value of the binding). /// </summary> /// <param name="installer">Context within which the class is to be created.</param> /// <returns>Returns true if successful, otherwise false.</returns> protected internal override bool CreateGlobalObject(IDefinitionInstallerContext installer) { if (installer == null) { throw new ArgumentNullException(); } // 1. Get the binding to the global Symbol name = installer.Runtime.GetSymbol(this.Name.Value); ClassBinding binding = installer.GetLocalClassBinding(name); // 2. Check consistency that we didn't mess up in the implementation. if (binding == null) { throw new InvalidOperationException("Should have found a binding, because CreateGlobalBinding() created it!"); } if (binding.Value != null) { throw new InvalidOperationException("Should be an empty binding, because CreateGlobalBinding() complained if one already existed!"); } // 3. Prepare stuff .... SmalltalkClass.InstanceStateEnum instanceState = this.InstanceState.Value; ClassBinding superclass; if (this.SuperclassName.Value.Length == 0) { superclass = null; // Object has no superclass } else { superclass = installer.GetClassBinding(this.SuperclassName.Value); if (superclass == null) { return(installer.ReportError(this.SuperclassName, InstallerErrors.ClassInvalidSuperclass)); } } // Create the collection of class, class-instance, instance variables and imported pools BindingDictionary <InstanceVariableBinding> instVars = new BindingDictionary <InstanceVariableBinding>(installer.Runtime); DiscreteBindingDictionary <ClassVariableBinding> classVars = new DiscreteBindingDictionary <ClassVariableBinding>(installer.Runtime, this.ClassVariableNames.Count()); BindingDictionary <ClassInstanceVariableBinding> classInstVars = new BindingDictionary <ClassInstanceVariableBinding>(installer.Runtime); DiscreteBindingDictionary <PoolBinding> pools = new DiscreteBindingDictionary <PoolBinding>(installer.Runtime); // Validate class variable names ... foreach (SourceReference <string> identifier in this.ClassVariableNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) { return(installer.ReportError(identifier, InstallerErrors.ClassClassVariableNotIdentifier)); } if (classVars.Any <ClassVariableBinding>(varBinding => varBinding.Name == varName)) { return(installer.ReportError(identifier, InstallerErrors.ClassClassVariableNotUnique)); } classVars.Add(new ClassVariableBinding(varName)); } // Validate instance variable names ... foreach (SourceReference <string> identifier in this.InstanceVariableNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) { return(installer.ReportError(identifier, InstallerErrors.ClassInstanceVariableNotIdentifier)); } if (((IEnumerable <InstanceVariableBinding>)instVars).Any(varBinding => varBinding.Name == varName)) { return(installer.ReportError(identifier, InstallerErrors.ClassInstanceVariableNotUnique)); } if (classVars.Any <ClassVariableBinding>(varBinding => varBinding.Name == varName)) { return(installer.ReportError(identifier, InstallerErrors.ClassInstanceOrClassVariableNotUnique)); } instVars.Add(new InstanceVariableBinding(varName)); } // Validate class instance variable names ... foreach (SourceReference <string> identifier in this.ClassInstanceVariableNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) { return(installer.ReportError(identifier, InstallerErrors.ClassClassInstanceVariableNotIdentifier)); } if (classInstVars.Any <ClassInstanceVariableBinding>(varBinding => varBinding.Name == varName)) { return(installer.ReportError(identifier, InstallerErrors.ClassClassInstanceVariableNotUnique)); } if (classVars.Any <ClassVariableBinding>(varBinding => varBinding.Name == varName)) { return(installer.ReportError(identifier, InstallerErrors.ClassClassInstanceOrClassVariableNotUnique)); } classInstVars.Add(new ClassInstanceVariableBinding(varName)); } // Validate imported pool names ... foreach (SourceReference <string> identifier in this.ImportedPoolNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) { return(installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotIdentifier)); } if (pools.Any <PoolBinding>(varBinding => varBinding.Name == varName)) { return(installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotUnique)); } PoolBinding pool = installer.GetPoolBinding(varName); if (pool == null) { return(installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotDefined)); } pools.Add(pool); } // 4. Finally, create the behavior object binding.SetValue(new SmalltalkClass( installer.Runtime, binding.Name, superclass, instanceState, instVars, classVars, classInstVars, pools)); return(true); }
/// <summary> /// Internal! This is used by the Installer to create new classes. /// </summary> /// <param name="runtime">Smalltalk runtime this class is part of.</param> /// <param name="name">Name of the class.</param> /// <param name="superclass">Optional binding to the class' superclass.</param> /// <param name="instanceState">State of the class' instances (named, object-indexable, byte-indexable).</param> /// <param name="instanceVariables">Instance variables bindings. Those are initially not initialized.</param> /// <param name="classVariables">Class variable binding.</param> /// <param name="classInstanceVariables">Class-instance variables bindings. Those are initially not initialized.</param> /// <param name="importedPools">Collection of pools that are imported by the class.</param> public SmalltalkClass(SmalltalkRuntime runtime, Symbol name, ClassBinding superclass, InstanceStateEnum instanceState, BindingDictionary <InstanceVariableBinding> instanceVariables, DiscreteBindingDictionary <ClassVariableBinding> classVariables, BindingDictionary <ClassInstanceVariableBinding> classInstanceVariables, DiscreteBindingDictionary <PoolBinding> importedPools) : this(runtime, name, superclass, instanceState, instanceVariables, classVariables, classInstanceVariables, importedPools, null, null) { }
/// <summary> /// Create the class object (and sets the value of the binding). /// </summary> /// <param name="installer">Context within which the class is to be created.</param> /// <returns>Returns true if successful, otherwise false.</returns> protected internal override bool CreateGlobalObject(IInstallerContext installer) { if (installer == null) throw new ArgumentNullException(); // 1. Get the binding to the global Symbol name = installer.Runtime.GetSymbol(this.Name.Value); ClassBinding binding = installer.GetLocalClassBinding(name); // 2. Check consistency that we didn't mess up in the implementation. if (binding == null) throw new InvalidOperationException("Should have found a binding, because CreateGlobalBinding() created it!"); if (binding.Value != null) throw new InvalidOperationException("Should be an empty binding, because CreateGlobalBinding() complained if one already existed!"); // 3. Prepare stuff .... SmalltalkClass.InstanceStateEnum instanceState = this.InstanceState.Value; ClassBinding superclass; if (this.SuperclassName.Value.Length == 0) { superclass = null; // Object has no superclass } else { superclass = installer.GetClassBinding(this.SuperclassName.Value); if (superclass == null) return installer.ReportError(this.SuperclassName, InstallerErrors.ClassInvalidSuperclass); } // Create the collection of class, class-instance, instance variables and imported pools BindingDictionary<InstanceVariableBinding> instVars = new BindingDictionary<InstanceVariableBinding>(installer.Runtime); DiscreteBindingDictionary<ClassVariableBinding> classVars = new DiscreteBindingDictionary<ClassVariableBinding>(installer.Runtime, this.ClassVariableNames.Count()); BindingDictionary<ClassInstanceVariableBinding> classInstVars = new BindingDictionary<ClassInstanceVariableBinding>(installer.Runtime); DiscreteBindingDictionary<PoolBinding> pools = new DiscreteBindingDictionary<PoolBinding>(installer.Runtime); // Validate class variable names ... foreach (SourceReference<string> identifier in this.ClassVariableNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) return installer.ReportError(identifier, InstallerErrors.ClassClassVariableNotIdentifier); if (classVars.Any<ClassVariableBinding>(varBinding => varBinding.Name == varName)) return installer.ReportError(identifier, InstallerErrors.ClassClassVariableNotUnique); classVars.Add(new ClassVariableBinding(varName)); } // Validate instance variable names ... foreach (SourceReference<string> identifier in this.InstanceVariableNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) return installer.ReportError(identifier, InstallerErrors.ClassInstanceVariableNotIdentifier); if (((IEnumerable<InstanceVariableBinding>) instVars).Any(varBinding => varBinding.Name == varName)) return installer.ReportError(identifier, InstallerErrors.ClassInstanceVariableNotUnique); if (classVars.Any<ClassVariableBinding>(varBinding => varBinding.Name == varName)) return installer.ReportError(identifier, InstallerErrors.ClassInstanceOrClassVariableNotUnique); instVars.Add(new InstanceVariableBinding(varName)); } // Validate class instance variable names ... foreach (SourceReference<string> identifier in this.ClassInstanceVariableNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) return installer.ReportError(identifier, InstallerErrors.ClassClassInstanceVariableNotIdentifier); if (classInstVars.Any<ClassInstanceVariableBinding>(varBinding => varBinding.Name == varName)) return installer.ReportError(identifier, InstallerErrors.ClassClassInstanceVariableNotUnique); if (classVars.Any<ClassVariableBinding>(varBinding => varBinding.Name == varName)) return installer.ReportError(identifier, InstallerErrors.ClassClassInstanceOrClassVariableNotUnique); classInstVars.Add(new ClassInstanceVariableBinding(varName)); } // Validate imported pool names ... foreach (SourceReference<string> identifier in this.ImportedPoolNames) { Symbol varName = installer.Runtime.GetSymbol(identifier.Value); if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value)) return installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotIdentifier); if (pools.Any<PoolBinding>(varBinding => varBinding.Name == varName)) return installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotUnique); PoolBinding pool = installer.GetPoolBinding(varName); if (pool == null) return installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotDefined); pools.Add(pool); } // 4. Finally, create the behavior object binding.SetValue(new SmalltalkClass( installer.Runtime, binding.Name, superclass, instanceState, instVars, classVars, classInstVars, pools)); return true; }
void Start() { // Clear selection so we can't manipulate things Selection.activeGameObject = null; SetupPreferences(); if (primary) { this.AddRayVisibilitySettings(rayOrigin, this, false, false); SetupBrushUI(); HandleBrushSize(m_Preferences.brushSize); m_ColorPickerActivator = this.InstantiateUI(m_ColorPickerActivatorPrefab); var otherRayOrigin = otherRayOrigins.First(); var otherAltMenu = this.GetCustomAlternateMenuOrigin(otherRayOrigin); const float UIOffset = 0.1f; var colorPickerActivatorTransform = m_ColorPickerActivator.transform; colorPickerActivatorTransform.SetParent(otherAltMenu); colorPickerActivatorTransform.localRotation = Quaternion.identity; colorPickerActivatorTransform.localPosition = (node == Node.LeftHand ? Vector3.left : Vector3.right) * UIOffset; colorPickerActivatorTransform.localScale = Vector3.one; var activator = m_ColorPickerActivator.GetComponentInChildren <ColorPickerActivator>(); m_ColorPicker = activator.GetComponentInChildren <ColorPickerUI>(true); m_ColorPicker.onHideCalled = HideColorPicker; m_ColorPicker.toolRayOrigin = rayOrigin; m_ColorPicker.onColorPicked = OnColorPickerValueChanged; OnColorPickerValueChanged(m_Preferences.annotationColor); activator.node = node; activator.rayOrigin = otherRayOrigin; activator.showColorPicker = ShowColorPicker; activator.hideColorPicker = HideColorPicker; var controls = new BindingDictionary(); InputUtils.GetBindingDictionaryFromActionMap(m_ActionMap, controls); foreach (var control in controls) { var tooltipText = control.Key; var suppressExisting = control.Key == "Vertical" || control.Key == "StickButton"; if (suppressExisting) { tooltipText = null; } foreach (var id in control.Value) { var request = (ProxyFeedbackRequest)this.GetFeedbackRequestObject(typeof(ProxyFeedbackRequest)); request.node = node; request.control = id; request.priority = 1; request.tooltipText = tooltipText; request.suppressExisting = suppressExisting; this.AddFeedbackRequest(request); } } } }
public static void CreateClass(SmalltalkRuntime runtime, SmalltalkNameScope scope, ClassBinding binding, string superclassName, SmalltalkClass.InstanceStateEnum instanceState, string[] classVarNames, string[] instVarNames, string[] classInstVarNames, string[] importedPools, Func <SmalltalkClass, Dictionary <Symbol, CompiledMethod> > classMethodDicInitializer, Func <SmalltalkClass, Dictionary <Symbol, CompiledMethod> > instanceMethodDicInitializer) { if (runtime == null) { throw new ArgumentNullException("runtime"); } if (scope == null) { throw new ArgumentNullException("scope"); } if (binding == null) { throw new ArgumentNullException("binding"); } if (classMethodDicInitializer == null) { throw new ArgumentNullException("classMethodDicInitializer"); } if (instanceMethodDicInitializer == null) { throw new ArgumentNullException("instanceMethodDicInitializer"); } // 3. Prepare stuff .... ClassBinding superclass; if (String.IsNullOrWhiteSpace(superclassName)) { superclass = null; // Object has no superclass } else { superclass = scope.GetClassBinding(superclassName); if (superclass == null) { throw new InvalidOperationException("Should have found a binding for the superclass"); } } // Create the collection of class, class-instance, instance variables and imported pools BindingDictionary <InstanceVariableBinding> instVars = new BindingDictionary <InstanceVariableBinding>(runtime); DiscreteBindingDictionary <ClassVariableBinding> classVars = new DiscreteBindingDictionary <ClassVariableBinding>(runtime, ((classVarNames == null) ? 0 : classVarNames.Length)); BindingDictionary <ClassInstanceVariableBinding> classInstVars = new BindingDictionary <ClassInstanceVariableBinding>(runtime); DiscreteBindingDictionary <PoolBinding> pools = new DiscreteBindingDictionary <PoolBinding>(runtime); // Add class variable names ... if (classVarNames != null) { foreach (string identifier in classVarNames) { Symbol varName = runtime.GetSymbol(identifier); classVars.Add(new ClassVariableBinding(varName)); } } // Add instance variable names ... if (instVarNames != null) { foreach (string identifier in instVarNames) { Symbol varName = runtime.GetSymbol(identifier); instVars.Add(new InstanceVariableBinding(varName)); } } // Add class instance variable names ... if (classInstVarNames != null) { foreach (string identifier in classInstVarNames) { Symbol varName = runtime.GetSymbol(identifier); classInstVars.Add(new ClassInstanceVariableBinding(varName)); } } // Add imported pool names ... if (importedPools != null) { foreach (string identifier in importedPools) { Symbol varName = runtime.GetSymbol(identifier); PoolBinding pool = scope.GetPoolBinding(varName); if (pool == null) { throw new InvalidOperationException(String.Format("Should have found a binding for pool {0}", identifier)); } pools.Add(pool); } } // Create method dictionaries MethodDictionaryInitializer clsMthInitializer = new MethodDictionaryInitializer(classMethodDicInitializer); MethodDictionaryInitializer instMthInitializer = new MethodDictionaryInitializer(instanceMethodDicInitializer); ClassMethodDictionary classMethods = new ClassMethodDictionary(runtime, clsMthInitializer.Initialize); InstanceMethodDictionary instanceMethods = new InstanceMethodDictionary(runtime, instMthInitializer.Initialize); // 4. Finally, create the behavior object SmalltalkClass cls = new SmalltalkClass(runtime, binding.Name, superclass, instanceState, instVars, classVars, classInstVars, pools, instanceMethods, classMethods); clsMthInitializer.Class = cls; instMthInitializer.Class = cls; binding.SetValue(cls); }