コード例 #1
0
ファイル: ImagePackage.cs プロジェクト: profK/powerui
        /// <summary>Sends the request off. Callbacks such as onreadystatechange will be triggered.</summary>
        public void send()
        {
            if (readyState_ == 0)
            {
                // Act like it just opened:
                readyState = 1;
            }

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

            if (fileProtocol == null)
            {
                return;
            }

            // Some protocols enforce a particular content type.
            // E.g. Dynamic:// always is "dyn".
            string fileType = fileProtocol.ContentType(location);

            // Some file formats internally cache.
            // This means we can entirely avoid hitting the protocol system.

            // Get the format for the type:
            Contents = ImageFormats.GetInstance(fileType);

            // Did it internally cache?
            if (Contents.InternallyCached(location, this))
            {
                // Yes it did!
                return;
            }

            fileProtocol.OnGetGraphic(this);
        }
コード例 #2
0
        /// <summary>Gets a format by the given file type. Note: These are global!</summary>
        /// <param name="type">The name of the format, e.g. "png".</param>
        /// <returns>An ImageFormat if found; unrecognised handler otherwise.</returns>
        public static ImageFormat Get(string type)
        {
            if (Formats == null)
            {
                // Load the formats now!
                Modular.AssemblyScanner.FindAllSubTypesNow(typeof(ImageFormat),
                                                           delegate(Type t){
                    // Add it as format:
                    ImageFormats.Add(t);
                }
                                                           );
            }

            if (type == null)
            {
                type = "";
            }

            ImageFormat result = null;

            if (!Formats.TryGetValue(type.ToLower(), out result))
            {
                // Get the unrecognised handler:
                Formats.TryGetValue(UnrecognisedImageHandler, out result);
            }

            return(result);
        }
コード例 #3
0
ファイル: ImagePackage.cs プロジェクト: profK/powerui
        /// <summary>Assign the given image to this package.</summary>
        public void AssignImage(Texture image)
        {
            // Get the contents as a picture block:
            PictureFormat picture = Contents as PictureFormat;

            if (picture == null)
            {
                // Clear the package:
                Clear();

                // Get the picture format:
                Contents = ImageFormats.GetInstance("pict");

                // Update picture var:
                picture = Contents as PictureFormat;
            }

            // Apply the image:
            picture.Image = image;
        }