/// <summary>Updates the render texture.</summary> private void ChangeImage(int width, int height) { if (Texture != null) { // Destroy existing one: GameObject.Destroy(Texture); } // Create tex: Texture = new RenderTexture(width, height, 16, RenderTextureFormat.ARGB32); // Hook it up: SourceCamera.targetTexture = Texture; // If we have a filter, update its input: if (Filter_ == null) { // Fire an imagechange event into the window: Dom.Event e = new Dom.Event("imagechange"); e.SetTrusted(false); document.window.dispatchEvent(e); } else { // Connect up the filter // (which will fire an imagechange for us): ConnectFilter(); } }
/// <summary>Handles events on the widget itself.</summary> protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase) { if (bubblePhase) { OnEvent(e); } return(base.HandleLocalEvent(e, bubblePhase)); }
/// <summary>Dispatches the DOMContentLoaded event.</summary> protected void ContentLoadedEvent() { // ReadyState is now 1 (interactive): ReadyStateChange(1); // Dom content loaded: Dom.Event de = new Dom.Event("DOMContentLoaded"); de.SetTrusted(true); dispatchEvent(de); }
/// <summary>Called when the output changes. /// Essentially forwards an imagechange event to this node.</summary> private void ChangedOutputEvent(Dom.Event e) { // Dispatch the event here too: RenderData.Node.dispatchEvent(e); if (Material != null) { // Hook up the output: Material.SetTexture("_MainTex", Output); } }
/// <summary>Gets or creates a script engine of the given type.</summary> public ScriptEngine GetScriptEngine(string type) { type = type.ToLower().Trim(); if (Engines == null) { // Create: Engines = new Dictionary <string, ScriptEngine>(); } ScriptEngine engine; if (Engines.TryGetValue(type, out engine)) { return(engine); } // Try and instance it now! Get the global engine: engine = ScriptEngines.Get(type); if (engine == null) { // Don't know how to handle this type of script. Dom.Log.Add("Warning: Some script has been ignored due to its type ('" + type + "'). Did you mean 'text/javascript'?"); return(null); } // Instance it: engine = engine.Instance(this); if (engine == null) { // Security problem (it would've logged it for us). return(null); } // Set doc: engine.Document = this; // Hook it up for each of this engines types: string[] types = engine.GetTypes(); for (int i = 0; i < types.Length; i++) { Engines[types[i].ToLower().Trim()] = engine; } Dom.Event e = new Dom.Event("scriptengineload"); dispatchEvent(e); return(engine); }
/// <summary>Changes the ready state of this document.</summrry> protected void ReadyStateChange(int state) { readyState_ = state; if (state == 0) { return; } // Fire event: Dom.Event de = new Dom.Event("readystatechange"); de.SetTrusted(true); dispatchEvent(de); }
protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase) { if (e.type == "mousedown") { // Get the scroll bar: HtmlScrollbarElement scroll = parentElement as HtmlScrollbarElement; // And scroll it: scroll.ScrollBy(IsStart?-1:1); } // Handle locally: return(base.HandleLocalEvent(e, bubblePhase)); }
/// <summary>Connects a filter to the camera's output. /// Fires an imagechange event too as this updates Texture to the filtered version.</summary> private void ConnectFilter() { if (Filter_ != null) { if (FilterDrawInfo == null) { FilterDrawInfo = new Loonim.DrawInfo(); } // Update draw info: FilterDrawInfo.SetSize(pixelWidth, pixelHeight); // Update source: Filter_.Set("source0", SourceCamera.targetTexture); // Reallocate the filter: Filter_.PreAllocate(FilterDrawInfo); // Grab the main output (always a RT): Texture = Filter_.Texture as RenderTexture; if (Texture == null) { // This isn't a valid filter! // It either had no nodes or e.g. e.g. a solid colour. Debug.Log("Invalid filter was set to a FlatWorldUI - removed it."); Filter_ = null; } } if (Filter_ == null) { // Clear draw info: FilterDrawInfo = null; // Revert to the camera's output: Texture = SourceCamera.targetTexture; } // Fire an imagechange event into the window: Dom.Event e = new Dom.Event("imagechange"); e.SetTrusted(false); document.window.dispatchEvent(e); }
/// <summary>Exits a fullscreen viewing.</summary> public void exitFullscreen() { if (fullscreenElement == null) { return; } // Trigger fullscreen event: Dom.Event e = new Dom.Event("fullscreenchange"); e.SetTrusted(); if (!dispatchEvent(e)) { // Something killed the request. return; } // Restore style: fullscreenElement.style.cssText = HtmlElement.CachedFullscreenStyle; // Restore original parent: if (HtmlElement.CachedFullscreenParent != null) { fullscreenElement.parentNode.removeChild(fullscreenElement); HtmlElement.CachedFullscreenParent.appendChild(fullscreenElement); // Clear: HtmlElement.CachedFullscreenParent = null; } // Clear it: HtmlElement.CachedFullscreenStyle = null; // Clear attrib: fullscreenElement.removeAttribute("fullscreen"); // Update local style: fullscreenElement.style.Computed.RefreshLocal(); // Clear fullscreen ele: fullscreenElement = null; }
protected override bool HandleLocalEvent(Dom.Event e, bool bubblePhase) { if (base.HandleLocalEvent(e, bubblePhase)) { // It was blocked. Don't run the default. return(true); } if (e.type == "mousedown") { // Get the scroll bar: HtmlScrollbarElement scroll = parentElement as HtmlScrollbarElement; // And scroll it: scroll.ScrollBy(IsStart?-1:1); } return(false); }
/// <summary>Triggers a '{name}' event on the widget itself, and optionally on the source element.</summary> public void trigger(string name, Dictionary <string, object> globals) { // Create the event: Dom.Event e = document.createEvent("uievent", name); e.SetTrusted(); if (element != null) { // Trigger it now on the element: element.dispatchEvent(e); } // On this object (which is an event target): dispatchEvent(e); // Try on the original anchor element too: HtmlElement source = GetAnchor(globals); if (source != null) { // Trigger there too: source.dispatchEvent(e); } }
/// <summary>Called when the widget receives an event.</summary> protected virtual void OnEvent(Dom.Event e) { }
internal override void Layout(LayoutBox box, Renderman renderer) { // Dimensions: float width = box.Width; float height = box.Height; if (Renderer == null) { // Create the FWUI now: Renderer = new FlatWorldUI("#Internal-PowerUI-Raster-" + RasterID, (int)width, (int)height); Renderer.Renderer.AllowLayout = false; RasterID++; // Add the listener: Renderer.document.window.addEventListener("imagechange", delegate(Dom.Event ev){ ChangedOutputEvent(ev); }); if (PendingFilter != null) { // Setting the filter will cause an imagechange event anyway: Renderer.Filter = PendingFilter; PendingFilter = null; } else { // Invoke our change event now: Dom.Event e = new Dom.Event("imagechange"); e.SetTrusted(false); ChangedOutputEvent(e); } } // Does the given renderer belong to the worldUI? if (renderer == Renderer.Renderer) { // Yes! We're actually drawing the element. return; } // Next we'll draw the rastered image. // It's essentially just the output from the renderer. // Get the top left inner corner (inside margin and border): float top = box.Y; float left = box.X; // Update the FlatWorldUI next: UpdateRenderer(box, width, height); // Always isolated: Isolate(); // Make sure the renderer stalls and doesn't draw anything else of this element or its kids. renderer.StallStatus = 2; // Setup boundary: BoxRegion boundary = new BoxRegion(left, top, width, height); if (!boundary.Overlaps(renderer.ClippingBoundary)) { if (Visible) { SetVisibility(false); } return; } else if (!Visible) { // ImageLocation will allocate here if it's needed. SetVisibility(true); } // Texture time - get its location on that atlas: if (LocatedAt == null) { LocatedAt = new AtlasLocation(width, height); } else { // Dimensions changed? int w = (int)width; int h = (int)height; if (LocatedAt.Width != w || LocatedAt.Height != h) { // Update it: LocatedAt.UpdateFixed(width, height); } } boundary.ClipBy(renderer.ClippingBoundary); // Ensure we have a batch: renderer.SetupBatch(this, null, null); if (Material == null) { // Create the material now using the isolated shader: Material = new Material(renderer.CurrentShaderSet.Isolated); // Hook up the output: Material.SetTexture("_MainTex", Output); } // Allocate the block: MeshBlock block = Add(renderer); // Set current material: SetBatchMaterial(renderer, Material); // Set the (overlay) colour: block.SetColour(renderer.ColorOverlay); block.TextUV = null; // Z-index (same as a background-image): float zIndex = (RenderData.computedStyle.ZIndex - 0.003f); BoxRegion screenRegion = new BoxRegion(); screenRegion.Set(left, top, width, height); // Setup the block: block.ImageUV = block.SetClipped(boundary, screenRegion, renderer, zIndex, LocatedAt, block.ImageUV); // Flush it: block.Done(renderer.Transform); }