Exemple #1
0
        /// <summary>Sends the request off and defines a callback to run when the result is ready.</summary>
        /// <param name="imageReady">The callback to run when the graphic has been retrieved.
        /// Note that the callback must check if the result is <see cref="PowerUI.ImagePackage.Ok"/>.</param>
        public void Get(OnImageReady imageReady)
        {
            ImageReady += imageReady;

            if (string.IsNullOrEmpty(Url))
            {
                ImageReady(this);
                return;
            }

            // Exception - Is it an animation that has been cached?
            if (File.Filetype == "spa")
            {
                // Might already be loaded - let's check:
                SPA animation = SPA.Get(Url);
                if (animation != null)
                {
                    //It's already been loaded - use that.
                    GotGraphic(animation);
                    return;
                }
            }

            // Do we have a file protocol handler available?
            FileProtocol fileProtocol = File.Handler;

            if (fileProtocol != null)
            {
                fileProtocol.OnGetGraphic(this, File);
            }
        }
        /// <summary>Gets an already loaded SPA from the cache.</summary>
        /// <returns>An SPA object if found; null otherwise.</returns>
        public static SPA Get(string name)
        {
            SPA result = null;

            Instances.TryGetValue(name, out result);
            return(result);
        }
Exemple #3
0
 /// <summary>Called by the file handler when an animation was retrieved successfully.</summary>
 /// <param name="animation">The animation received.</param>
 public void GotGraphic(SPA animation)
 {
     Clear();
     Animated = true;
     SPAFile  = animation;
     ImageReady(this);
 }
 /// <summary>Creates a new playable instance of the given SPA animation.</summary>
 public SPAInstance(SPA animation)
 {
     Animation        = animation;
     AnimatedMaterial = new Material(SPA.IsolationShader);
     SetSprite(0);
     FrameDelay = 1f / (float)Animation.FrameRate;
 }
    /// <summary>Clears all content from the UI and all WorldUI's.
    /// Please note that it is safer to set innerHTML to a blank string for a particular UI than calling this.</summary>
    public static void ClearAll()
    {
        content = null;

        if (Renderer != null)
        {
            Renderer.Destroy();
            Renderer = null;
            document = null;
        }

        Fonts.Clear();
        AtlasStacks.Clear();
        Http.Clear();
        SPA.Clear();
        UIAnimation.Clear();
        DynamicTexture.RemoveAll();
        PowerUI.Input.Clear();
        ScreenInfo.Clear();
        WorldUI currentWorldUI = FirstWorldUI;

        while (currentWorldUI != null)
        {
            currentWorldUI.Destroy();
            currentWorldUI = currentWorldUI.UIAfter;
        }

        LastWorldUI  = null;
        FirstWorldUI = null;
    }
Exemple #6
0
        /// <summary>Attempts to get a graphic from the given location using this protocol.</summary>
        /// <param name="package">The image request. GotGraphic must be called on this when the protocol is done.</param>
        /// <param name="path">The location of the file to retrieve using this protocol.</param>
        public override void OnGetGraphic(ImagePackage package, FilePath path)
        {
            if (path.Filetype == "spa")
            {
                // Grab a runtime SPA:
                package.GotGraphic(SPA.Get(path.Path));
                return;
            }

            package.GotGraphic(ImageCache.Get(path.Path));
        }
Exemple #7
0
 /// <summary>Removes all content from this image package.</summary>
 private void Clear()
 {
     // Clear any animation:
     GoingOffDisplay();
     Error = null;
                 #if !MOBILE
     Video = null;
                 #endif
     Image        = null;
     SPAFile      = null;
     IsVideo      = false;
     Animated     = false;
     IsDynamic    = false;
     DynamicImage = null;
 }
		public override void Clear(){
			SPAFile=null;
		}
//--------------------------------------
Exemple #10
0
    /// <summary>Updates the UI. Don't call this - PowerUI knows when it's needed; This is done from Start and WorldUI constructors.</summary>
    public static void InternalUpdate()
    {
        // Update any callbacks:
        if (Callbacks.FirstToRun != null)
        {
            Callbacks.RunAll();
        }

        // Update animations:
        SPA.Update();

        // Update any Http requests:
        Http.Update();

        if (WorldUI.LiveUpdatablesAvailable)
        {
            WorldUI.UpdateAll();
        }

        RedrawTimer += Time.deltaTime;

        if (RedrawTimer < RedrawRate)
        {
            return;
        }
        RedrawTimer = 0f;

        if (GUICamera == null)
        {
            return;
        }

        // Atlases:
        AtlasStacks.Update();

        // Screen size:
        ScreenInfo.Update();

        // Update Input (mouse/keys etc).
        PowerUI.Input.Update();

        // Animations:
        UIAnimation.Update();

        // Dynamic graphics:
        DynamicTexture.Update();

        // Redraw the root html document (if it needs to be redrawn):
        Renderer.Update();

        if (MainCameraPool != null && MainCameraPool.DidLayout)
        {
            // The main UI did a layout and we have a camera pool.
            // We now need to do some post-layout spring cleaning.
            MainCameraPool.ClearPool();
        }

        // Redraw any in-world documents (if they need it).

        // Did we call update all above?
        bool worldUIRequiresUpdate = !WorldUI.LiveUpdatablesAvailable;

        // Clear the flag:
        WorldUI.LiveUpdatablesAvailable = false;

        if (FirstWorldUI != null)
        {
            WorldUI current = FirstWorldUI;
            while (current != null)
            {
                if (worldUIRequiresUpdate)
                {
                    // Update:
                    current.Update();

                    // Was it destroyed?
                    if (current.Renderer == null)
                    {
                        // Hop to the next one:
                        current = current.UIAfter;

                        continue;
                    }
                }

                if (current.Expires)
                {
                    current.ExpiresIn -= RedrawRate;

                    if (current.ExpiresIn <= 0f)
                    {
                        // Expire it:
                        current.Expire();

                        // Hop to the next one:
                        current = current.UIAfter;

                        continue;
                    }
                }

                // Update the renderer:
                current.Renderer.Update();

                // Update the flag:
                if (current.PixelPerfect || current.AlwaysFaceCamera)
                {
                    // We have at least one which is updateable:
                    WorldUI.LiveUpdatablesAvailable = true;
                }

                current = current.UIAfter;
            }
        }

        // Flush any atlases:
        AtlasStacks.Flush();
    }
		/// <summary>Creates a new playable instance of the given SPA animation.</summary>
		public SPAInstance(SPA animation){
			Animation=animation;
			AnimatedMaterial=new Material(SPA.IsolationShader);
			SetSprite(0);
			FrameDelay=1f/(float)Animation.FrameRate;
		}
Exemple #12
0
        /// <summary>Loads a new sprite from the given binary stream.</summary>
        /// <param name="animation">The animation this sprite belongs to.</param>
        /// <param name="reader">The binary stream that contains this sprites data.</param>
        /// <param name="id">The ID of the sprite in the animation.</param>
        public SPASprite(SPA animation, BinaryReader reader, int id)
        {
            ID        = id;
            Animation = animation;

            // Read some bit flags - these give information about this frame:
            byte flags = reader.ReadByte();

            // Does it also have an alpha frame?
            // If it does, there are two images in this frame (alpha one second).
            bool hasAlphaFrame = ((flags & 1) == 1);

            // How many frames this sprite holds:
            FrameCount = reader.ReadUInt16();

            // How big is the image, in bytes:
            int dataSize = reader.ReadInt32();

            // Setup the sprite now:
            Sprite = new Texture2D(0, 0);

            // And load the image data:
            Sprite.LoadImage(reader.ReadBytes(dataSize));
            Width  = Sprite.width;
            Height = Sprite.height;

            // Make sure it filters correctly.
            // This is so we don't see parts of other frames around the edge of the image onscreen:
            Sprite.filterMode = FilterMode.Point;

            // Setup the scale:
            TextureScale       = new Vector2((float)Animation.FrameWidth / (float)Width, (float)Animation.FrameHeight / (float)Height);
            VerticalFrameCount = Height / Animation.FrameHeight;

            if (hasAlphaFrame)
            {
                int alphaImageSize = reader.ReadInt32();

                // Setup the temporary alpha texture:
                Texture2D alphaImage = new Texture2D(0, 0);

                // And load it's data:
                alphaImage.LoadImage(reader.ReadBytes(alphaImageSize));

                // Next, merge the alpha pixels into our main sprite.
                Color[] spritePixels = Sprite.GetPixels();
                Color[] alphaPixels  = alphaImage.GetPixels();

                if (spritePixels.Length != alphaPixels.Length)
                {
                    throw new Exception("Invalid SPA alpha channel image.");
                }

                // Set each alpha value from the grayscale of the alpha image:
                for (int i = spritePixels.Length - 1; i >= 0; i--)
                {
                    Color pixel = spritePixels[i];
                    pixel.a         = alphaPixels[i].grayscale;
                    spritePixels[i] = pixel;
                }

                // Write the pixels back:
                Sprite.SetPixels(spritePixels);
            }
        }
Exemple #13
0
 /// <summary>Creates an empty sprite.</summary>
 public SPASprite(SPA animation, int id)
 {
     Animation = animation;
     ID        = id;
 }
Exemple #14
0
 public override void Clear()
 {
     SPAFile = null;
 }
		/// <summary>Removes all content from this image package.</summary>
		private void Clear(){
			// Clear any animation:
			GoingOffDisplay();
			Error=null;
			#if !MOBILE
			Video=null;
			#endif
			Image=null;
			SPAFile=null;
			IsVideo=false;
			Animated=false;
			IsDynamic=false;
			DynamicImage=null;
		}
		/// <summary>Called by the file handler when an animation was retrieved successfully.</summary>
		/// <param name="animation">The animation received.</param>
		public void GotGraphic(SPA animation){
			Clear();
			Animated=true;
			SPAFile=animation;
			ImageReady(this);
		}