Beispiel #1
0
        /// <summary>Flattens this element.
        /// Returns a promise which fires when the image has been rendered at least once.
        /// The promise contains a direct reference to the latest image.</summary>
        public Promise flatten()
        {
            // Obtain the raster data from the render data:
            RasterDisplayableProperty rdp = RenderData.RasterProperty;

            // Create the resultant promise:
            Promise p = new Promise();

            // Check if we already have an image:
            Texture img = rdp == null ? null : rdp.Output;

            if (img != null)
            {
                // Already got one! Resolve right away:
                p.resolve(img);
                return(p);
            }

            // If we don't have an RDP then request a flatten.
            // Output is null so we know it'll be getting drawn on the next update.
            if (rdp == null)
            {
                // (no full Loonim effects on this element):
                style.Computed.ChangeTagProperty("-spark-filter", "flatten");
            }

            Dom.EventListener listener = null;

            // Wait for the imagechange event:
            listener = new Dom.EventListener <Dom.Event>(delegate(Dom.Event e){
                // Image changed! Remove this listener:
                removeEventListener("imagechange", listener);

                // Update the promise:
                Texture current = flatImage;

                if (current == null)
                {
                    // Unable to flatten this (This should never happen).
                    p.reject(FLATTEN_FAILED);
                }
                else
                {
                    p.resolve(flatImage);
                }
            });

            // Add it:
            addEventListener("imagechange", listener);

            return(p);
        }
        internal override void start()
        {
            // Pause it now!
            Timeline tl = track.timeline;

            tl.setPause(true);

            if (tl.backwards)
            {
                tl.currentTime = 1f - computedStart;
            }
            else
            {
                tl.currentTime = computedStart;
            }

            // Hook up cue elements now:
            HTMLCollection targs = cuedBy;

            if (targs != null && eventName != null)
            {
                foreach (Element e in targs)
                {
                    Dom.EventListener <Dom.Event> d = new Dom.EventListener <Dom.Event>(delegate(Dom.Event ev){
                        // Cued by the cue point!
                        element.cue();
                    });

                    CueElementData ced = new CueElementData(eventName, d, e);

                    // Add to a list on the timeline:
                    if (track.timeline.cueElements == null)
                    {
                        track.timeline.cueElements = new List <CueElementData>();
                    }

                    track.timeline.cueElements.Add(ced);

                    // Add listener:
                    e.addEventListener(eventName, d);
                }
            }

            base.start();
        }
 internal CueElementData(string name, Dom.EventListener <Dom.Event> listener, Element target)
 {
     eventName     = name;
     eventListener = listener;
     this.target   = target;
 }