/// <summary>Builds a Loonim filter from the given set of one or more CSS functions.</summary> public static void BuildFilter(Css.Value value, RenderableData context, FilterEventDelegate fe) { if (value is Css.Functions.UrlFunction) { // - (A URL to an SVG filter) (not supported yet here) // - A URL to a Loonim filter (with a property called source0) // Load it now! DataPackage dp = new DataPackage(value.Text, context.Document.basepath); dp.onload = delegate(UIEvent e){ // Got the data! Load a filter now: SurfaceTexture st = null; // Create: st = new SurfaceTexture(); // Load it: st.Load(dp.responseBytes); // Run the callback: fe(context, st); }; // Send: dp.send(); } else { Loonim.TextureNode first = null; Loonim.TextureNode last = null; // - One or more filter functions if (value is Css.CssFunction) { // Just one: first = last = value.ToLoonimNode(context); } else if (value is Css.ValueSet) { // Many for (int i = 0; i < value.Count; i++) { // Convert to a Loonim node: Loonim.TextureNode next = value[i].ToLoonimNode(context); if (next == null) { // Quit! first = null; last = null; break; } // Hook it on: if (first == null) { first = last = next; } else { // Add it to the chain: next.Sources[0] = last; last = next; } } } SurfaceTexture st = null; if (last != null) { // Create the texture: st = new SurfaceTexture(); st.Set("source0", (UnityEngine.Texture)null); st.Root = last; first.Sources[0] = new Loonim.Property(st, "source0"); } // Run the callback now! fe(context, st); } }