/// <summary> /// Import the flatten objects from the <see cref="PrototypeLoader"/> /// </summary> /// <param name="loader">the loader with the ui data</param> public void ImportFlatten(PrototypeLoader loader) { Objects.AddRange(loader.Objects.ToList().ConvertAll((p) => p.Value.Flatten())); foreach (var s in loader.Status) { Status[s.Key] = s.Value; } }
/// <summary> /// Main program /// </summary> /// <param name="args"></param> static void Main(string[] args) { try { //hook unhandled exceptions Application.ThreadException += Application_ThreadException; //create renderer for presenting using (var renderer = new Graphix.Rendering.Renderer()) { //setup renderer on screen with index 0 renderer.SetupForm("Graphix Demo", 0); //setup rendering classes for basic objects renderer.SetupBaseRenderer(); //set loader function of all assets renderer.LoadAssets += () => { //load a visual prototype PrototypeLoader pl = new PrototypeLoader(); pl.Load(@"ui\demo.xml"); renderer.Import(pl); }; //setup debug if (Debug) { renderer.ShowFps = true; renderer.VSync = false; } else { renderer.ShowFps = false; renderer.VSync = true; } //start the renderer and display main window renderer.Run(); //this method is running during the whole application lifetime //cleanup renderer.CurrentStatus = null; } } catch (Exception e) { Logger.Error(e); } }
/// <summary> /// Create a value wrapper that can contain and bind values. The name need to be registred first /// </summary> /// <param name="prototypeLoader">a prototype loader (could be null)</param> /// <param name="prototype">a prototype that could contains this value (could be null)</param> /// <param name="name">the name of the type for this value wrapper</param> /// <param name="value">the string text for the value for this wrapper</param> /// <returns>a loaded value wrapper</returns> public IValueWrapper CreateValue(PrototypeLoader prototypeLoader, PrototypeBase prototype, string name, string value) { var type = PrototypeLoaderAccess.ParameterTypes[name]; if (type == null) { throw new KeyNotFoundException("Parameter type '" + name + "' is not registered"); } var parameter = (IValueWrapper)Activator.CreateInstance(type); parameter.Name = name; parameter.Value = PrototypeLoaderAccess.ParameterConverter[name].DynamicInvoke(prototypeLoader, prototype, value); parameter.Exists = true; return(parameter); }
/// <summary> /// Get a loaded prototype from the loader /// </summary> /// <param name="prototypeLoader">the loader with the loaded prototypes</param> /// <param name="name">The name of the searches prototype</param> /// <returns>the loaded prototype</returns> public PrototypeBase LoadPrototype(PrototypeLoader prototypeLoader, string name) { if (prototypeLoader == null) { throw new ArgumentNullException("prototypeLoader"); } if (name == null) { throw new ArgumentNullException("name"); } if (prototypeLoader.Prototypes.TryGetValue(name, out PrototypeBase prototype)) { return(prototype); } else { return(null); } }
/// <summary> /// Register the provides Types and functions to the Graphix core. This would be done /// automaticly after <see cref="ScriptAccess"/> is first used. /// </summary> public static void Register() { if (registed) { return; } registed = true; //a list of all types the js is allowed to create CoreTypes = new Dictionary <string, Type> { { "int", typeof(int) }, { "double", typeof(double) }, { "string", typeof(string) }, { "bool", typeof(bool) }, { "PrototypeLoader", typeof(PrototypeLoader) }, { "DisplayChannel", typeof(DisplayChannel) }, { "AnimationGroup", typeof(AnimationGroup) }, }; //register activator and effect PrototypeLoader.AddActivator <ScriptActivator>("Script", (pl, pb, a, node) => { PrototypeLoaderAccess.SetParameter(pl, node.Attributes["enable"]?.Value, a.Enabled, pb, false, PrototypeLoaderAccess.ParameterConverter["Bool"]); PrototypeLoaderAccess.SetParameter(pl, node.Attributes["key"]?.Value, a.Key, pb, false, PrototypeLoaderAccess.ParameterConverter["String"]); }); PrototypeLoader.AddEffect <ScriptEffect>("Script", (pl, pb, e, node) => { PrototypeLoaderAccess.EffectBase(pl, pb, e, node); PrototypeLoaderAccess.SetParameter(pl, node.Attributes["code"]?.Value, e.Code, pb, false, PrototypeLoaderAccess.ParameterConverter["String"]); var code = node.InnerText.Trim(); if (code != "") { e.Code.Value = code; e.Code.Exists = true; } }); }
/// <summary> /// Get a loaded object from a prototype loader /// </summary> /// <param name="prototypeLoader">the prototype loader</param> /// <param name="name">the name of the object</param> /// <returns>loaded object</returns> public PrototypeBase GetObject(PrototypeLoader prototypeLoader, string name) { return(prototypeLoader.Objects[name]); }
/// <summary> /// Transform a value string to the target value using the registered conversion functions /// </summary> /// <param name="prototypeLoader">a prototype loader (could be null)</param> /// <param name="prototype">a prototype that could contains this value (could be null)</param> /// <param name="name">the name of the type</param> /// <param name="value">the string representation</param> /// <returns>converted value</returns> public object TransformValue(PrototypeLoader prototypeLoader, PrototypeBase prototype, string name, string value) { return(PrototypeLoaderAccess.ParameterConverter[name].DynamicInvoke(prototypeLoader, prototype, value)); }
public static void EffectBase(PrototypeLoader pl, PrototypeBase pb, AnimationEffect e, XmlNode node) { PrototypeLoader.EffectBase(pl, pb, e, node); }
public static void SetParameter(PrototypeLoader pl, string value, IValueWrapper target, PrototypeBase current, bool forceref = false, Delegate customConverter = null) { pl.SetParameter(value, target, current, forceref, customConverter); }