Exemplo n.º 1
0
        /// <summary>
        /// Registers some internal fonts places in theme/fonts folder.
        /// </summary>
        /// <param name="engine">ui engine</param>
        /// <param name="theme">theme object</param>
        private void Init(UIEngine engine, Theme theme)
        {
            lock (this)
            {
                if (null != this.addedFonts)
                {
                    engine.Logger.WriteLine(LogLevel.Info, "WinFontCreator init");

                    this.addedFonts = new List <Object>();

                    if (null != theme)
                    {
                        List <String> fontFiles = new List <String>();

                        String fontsFolder = theme.ThemeFolder + "fonts/";

                        engine.GetFiles(fontsFolder, fontFiles);

                        engine.Logger.WriteLine(LogLevel.Info, "Enumerating fonts (in " + fontsFolder + "):");

                        foreach (String fontFile in fontFiles)
                        {
                            String fullPath = fontsFolder + fontFile;

                            byte[] fileBytes = null;
                            uint   fileSize  = 0;
                            Object file      = null;

                            if (true == engine.OpenFile(fullPath, out fileBytes, out fileSize, out file))
                            {
                                Object fontHandle = FileUtils.Platform.AddFontResource(fileBytes);

                                if (null != fontHandle)
                                {
                                    this.addedFonts.Add(fontHandle);

                                    engine.Logger.WriteLine(LogLevel.Info, "Adding font " + fullPath);
                                }

                                engine.CloseFile(ref file);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates requested image. If image file not found creates dotted texture.
        /// </summary>
        internal IImage CreateImage(String fileName, UIEngine engine, Graphics graphics)
        {
            if (null == fileName)
            {
                var img = new Image(fileName, new byte[2 * 2 * 4], 2, 2, 32);

                return graphics.CreateImage((int)img.Width, (int)img.Height, img.Bytes);
            }

            IImage image = null;
            Object file = null;

            try
            {
                this.cachedImages.TryGetValue(fileName, out image);

                if (null != image)
                {
                    return image;
                }

                if (true == fileName.StartsWith("#shell32,"))
                {
                    image = engine.GetIcon(int.Parse(fileName.Substring("#shell32,".Length)), true, null);

                    if (null != image)
                    {
                        return image;
                    }
                }

                image = graphics.CreateImage(fileName);

                if (null != image)
                {
                    return image;
                }

                byte[] imageData = null;
                uint size = 0;

                if (true == engine.OpenFile(fileName, out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName);
                }
                else if (true == engine.OpenFile(fileName + ".png", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".png");
                }
                else if (true == engine.OpenFile(fileName + ".jpg", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".jpg");
                }
                else if (true == engine.OpenFile(fileName + ".tga", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".tga");

                    if (null == image)
                    {
                        IImageLoader imageLoader = new TgaImageLoader(engine);

                        Image img = imageLoader.CreateImage(fileName);

                        if (null != img)
                        {
                            image = graphics.CreateImage((int)img.Width, (int)img.Height, img.Bytes);
                        }
                    }
                }

                return image;
            }
            finally
            {
                if (null != image)
                {
                    image.Name = fileName;

                    image.AddRef();

                    this.cachedImages[fileName] = image;
                }

                if (null != file)
                {
                    engine.CloseFile(ref file);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Registers some internal fonts places in theme/fonts folder.
        /// </summary>
        /// <param name="engine">ui engine</param>
        /// <param name="theme">theme object</param>
        private void Init(UIEngine engine, Theme theme)
        {
            lock (this)
            {
                if (null != this.addedFonts)
                {
                    engine.Logger.WriteLine(LogLevel.Info, "WinFontCreator init");

                    this.addedFonts = new List<Object>();

                    if (null != theme)
                    {
                        List<String> fontFiles = new List<String>();

                        String fontsFolder = theme.ThemeFolder + "fonts/";

                        engine.GetFiles(fontsFolder, fontFiles);

                        engine.Logger.WriteLine(LogLevel.Info, "Enumerating fonts (in " + fontsFolder + "):");

                        foreach (String fontFile in fontFiles)
                        {
                            String fullPath = fontsFolder + fontFile;

                            byte[] fileBytes = null;
                            uint fileSize = 0;
                            Object file = null;

                            if (true == engine.OpenFile(fullPath, out fileBytes, out fileSize, out file))
                            {
                                Object fontHandle = FileUtils.Platform.AddFontResource(fileBytes);

                                if (null != fontHandle)
                                {
                                    this.addedFonts.Add(fontHandle);

                                    engine.Logger.WriteLine(LogLevel.Info, "Adding font " + fullPath);
                                }

                                engine.CloseFile(ref file);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates requested image. If image file not found creates dotted texture.
        /// </summary>
        internal IImage CreateImage(String fileName, UIEngine engine, Graphics graphics)
        {
            if (null == fileName)
            {
                var img = new Image(fileName, new byte[2 * 2 * 4], 2, 2, 32);

                return(graphics.CreateImage((int)img.Width, (int)img.Height, img.Bytes));
            }

            IImage image = null;
            Object file  = null;

            try
            {
                this.cachedImages.TryGetValue(fileName, out image);

                if (null != image)
                {
                    return(image);
                }

                if (true == fileName.StartsWith("#shell32,"))
                {
                    image = engine.GetIcon(int.Parse(fileName.Substring("#shell32,".Length)), true, null);

                    if (null != image)
                    {
                        return(image);
                    }
                }

                image = graphics.CreateImage(fileName);

                if (null != image)
                {
                    return(image);
                }

                byte[] imageData = null;
                uint   size      = 0;


                if (true == engine.OpenFile(fileName, out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName);
                }
                else if (true == engine.OpenFile(fileName + ".png", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".png");
                }
                else if (true == engine.OpenFile(fileName + ".jpg", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".jpg");
                }
                else if (true == engine.OpenFile(fileName + ".tga", out imageData, out size, out file))
                {
                    image = graphics.CreateImage(imageData, fileName + ".tga");

                    if (null == image)
                    {
                        IImageLoader imageLoader = new TgaImageLoader(engine);

                        Image img = imageLoader.CreateImage(fileName);

                        if (null != img)
                        {
                            image = graphics.CreateImage((int)img.Width, (int)img.Height, img.Bytes);
                        }
                    }
                }

                return(image);
            }
            finally
            {
                if (null != image)
                {
                    image.Name = fileName;

                    image.AddRef();

                    this.cachedImages[fileName] = image;
                }

                if (null != file)
                {
                    engine.CloseFile(ref file);
                }
            }
        }