/// <summary>
        ///  <para>Loads Font from given Zip-File and Entry.</para>
        /// </summary>
        private Font LoadFontFrom(ZipFile zipFile, ZipEntry fontEntry)
        {
            string ResourceName = Path.GetFileNameWithoutExtension(fontEntry.Name).ToLowerInvariant();

            if (FontCache.Fonts.Contains(ResourceName))
            {
                return(null);
            }

            var byteBuffer = new byte[zipBufferSize];

            Stream zipStream = zipFile.GetInputStream(fontEntry);
            //Will throw exception is missing or wrong password. Handle this.

            var memStream = new MemoryStream();

            StreamUtils.Copy(zipStream, memStream, byteBuffer);
            memStream.Position = 0;

            Font loadedFont = Font.FromStream(ResourceName, memStream, (int)memStream.Length, 9, false);

            loadedFont.AntiAlias = true;
            loadedFont.Refresh();

            memStream.Close();
            zipStream.Close();
            memStream.Dispose();
            zipStream.Dispose();

            return(loadedFont);
        }
예제 #2
0
        private void LoadFont()
        {
            FileStream fs = new FileStream("CALIBRI.TTF", FileMode.Open);

            Font loadedFont = Graphics.Font.FromStream("calibri", fs, (int)fs.Length, 10, false);

            fs.Close();

            font = loadedFont;
        }
예제 #3
0
 public GorgonLibrary.Graphics.Font GetGorgonFont(string fontName, float fontSize)
 {
     for (int i = 0; i < FontCache.Fonts.Count; i++)
     {
         GorgonLibrary.Graphics.Font font = FontCache.Fonts[i];
         if (font.Name.Equals(fontName + "_" + fontSize))
         {
             return(font);
         }
     }
     return(null);
 }
예제 #4
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------
        //------------------------------------------- DRAWING TEXT  ------------------------------------------------------------------------------
        //-------------------------------------------------------------------------------------------------------------------------------------------------
        public void DrawText(string text, string fontName, float fontSize, Point pDest, Color color, int rotation, bool wordWrap, Rectangle rectDest, float worldScale)
        {
            try
            {
                GorgonLibrary.Graphics.Font textFont = GetGorgonFont(fontName, fontSize);
                if (textFont != null)
                {
                    textSprite.Font = textFont;
                }
                else
                {
                    if (fontName.Equals("DEFAULT"))
                    {
                        textFont = new GorgonLibrary.Graphics.Font(fontName + "_" + fontSize,
                                                                   new System.Drawing.Font(SystemFonts.DefaultFont.FontFamily, fontSize));
                    }
                    else
                    {
                        textFont = new GorgonLibrary.Graphics.Font(fontName + "_" + fontSize,
                                                                   new System.Drawing.Font(fontName, fontSize));
                    }

                    textSprite.Font = textFont;
                }
                textSprite.Bounds   = null;
                textSprite.WordWrap = false;
                textSprite.Color    = color;
                textSprite.Text     = text;
                textSprite.SetAxis((int)((float)rectDest.Width) / 2, (int)((float)rectDest.Height) / 2);
                textSprite.Rotation = rotation;

                if (wordWrap == false)
                {
                    textSprite.Position = new Vector2D((int)((float)pDest.X * worldScale), (int)((float)pDest.Y * worldScale));
                }
                else
                {
                    textSprite.SetPosition((float)(rectDest.X + textSprite.Axis.X) * worldScale, (float)(rectDest.Y + textSprite.Axis.Y) * worldScale);
                    textSprite.Bounds = new Viewport(0, 0, (int)((float)rectDest.Width), 0);

                    textSprite.WordWrap = wordWrap;
                }



                textSprite.SetScale(worldScale, worldScale);
                textSprite.Draw();
            }
            catch (Exception ex)
            {
            }
        }
        /// <summary>
        ///  <para>Loads the embedded base files.</para>
        /// </summary>
        public void LoadBaseResources()
        {
            Assembly _assembly = Assembly.GetExecutingAssembly();;
            Stream   _stream;

            _stream = _assembly.GetManifestResourceStream("SS14.Client.Services._EmbeddedBaseResources.bluehigh.ttf");
            if (_stream != null)
            {
                _fonts.Add("base_font", Font.FromStream("base_font", _stream, (int)_stream.Length, 10));
            }
            _stream = null;

            _stream = _assembly.GetManifestResourceStream("SS14.Client.Services._EmbeddedBaseResources.noSprite.png");
            if (_stream != null)
            {
                Image nospriteimage = Image.FromStream("nospriteimage", _stream, (int)_stream.Length);
                _images.Add("nosprite", nospriteimage);
                _sprites.Add("nosprite", new Sprite("nosprite", nospriteimage));
            }
            _stream = null;
        }
예제 #6
0
        public EntitySpawnSelectButton(EntityTemplate entityTemplate, string templateName,
                                       IResourceManager resourceManager)
        {
            _resourceManager = resourceManager;

            var spriteNameParam = entityTemplate.GetBaseSpriteParamaters().FirstOrDefault();
            string SpriteName = "";
            if (spriteNameParam != null)
            {
                SpriteName = spriteNameParam.GetValue<string>();
            }
            string ObjectName = entityTemplate.Name;

            associatedTemplate = entityTemplate;
            associatedTemplateName = templateName;

            objectSprite = _resourceManager.GetSprite(SpriteName);

            font = _resourceManager.GetFont("CALIBRI");
            name = new TextSprite("Label" + SpriteName, "Name", font);
            name.Color = Color.Black;
            name.Text = ObjectName;
        }
        public EntitySpawnSelectButton(EntityTemplate entityTemplate, string templateName,
                                       IResourceManager resourceManager)
        {
            _resourceManager = resourceManager;

            var    spriteNameParam = entityTemplate.GetBaseSpriteParamaters().FirstOrDefault();
            string SpriteName      = "";

            if (spriteNameParam != null)
            {
                SpriteName = spriteNameParam.GetValue <string>();
            }
            string ObjectName = entityTemplate.Name;

            associatedTemplate     = entityTemplate;
            associatedTemplateName = templateName;

            objectSprite = _resourceManager.GetSprite(SpriteName);

            font       = _resourceManager.GetFont("CALIBRI");
            name       = new TextSprite("Label" + SpriteName, "Name", font);
            name.Color = Color.Black;
            name.Text  = ObjectName;
        }
예제 #8
0
        public SizeF GetTextSize(string text, string fontName, float fontSize, Point pDest, bool wordWrap, Rectangle rectDest)
        {
            try
            {
                GorgonLibrary.Graphics.Font textFont = GetGorgonFont(fontName, fontSize);
                if (textFont != null)
                {
                    textSprite.Font = textFont;
                }
                else
                {
                    if (fontName.Equals("DEFAULT"))
                    {
                        textFont = new GorgonLibrary.Graphics.Font(fontName + "_" + fontSize,
                                                                   new System.Drawing.Font(SystemFonts.DefaultFont.FontFamily, fontSize));
                    }
                    else
                    {
                        textFont = new GorgonLibrary.Graphics.Font(fontName + "_" + fontSize,
                                                                   new System.Drawing.Font(fontName, fontSize));
                    }

                    textSprite.Font = textFont;
                }
                textSprite.Bounds   = null;
                textSprite.WordWrap = false;

                textSprite.Text = text;
                textSprite.SetAxis((int)((float)rectDest.Width) / 2, (int)((float)rectDest.Height) / 2);
                textSprite.Rotation = 0;

                if (wordWrap == false)
                {
                    textSprite.Position = new Vector2D(pDest.X, pDest.Y);
                }
                else
                {
                    textSprite.SetPosition(rectDest.X + textSprite.Axis.X, rectDest.Y + textSprite.Axis.Y);
                    textSprite.Bounds = new Viewport(0, 0, rectDest.Width, 0);
                }

                textSprite.WordWrap = wordWrap;

                //Get the max width of all lines
                float maxLineWidth = 0;
                for (int i = 0; i < textSprite.LineCount; i++)
                {
                    float lineWidth = textSprite.MeasureLine(i);
                    if (lineWidth > maxLineWidth)
                    {
                        maxLineWidth = lineWidth;
                    }
                }

                float finalWidth = rectDest.Width;
                if (finalWidth < maxLineWidth)
                {
                    finalWidth = maxLineWidth;
                }

                return(new SizeF(finalWidth, textSprite.Height));
            }
            catch (Exception ex)
            {
                return(new SizeF(0, 0));
            }
        }
        /// <summary>
        ///  <para>Loads all Resources from given Zip into the respective Resource Lists and Caches</para>
        /// </summary>
        public void LoadResourceZip(string path = null, string pw = null)
        {
            string zipPath  = path ?? _configurationManager.GetResourcePath();
            string password = pw ?? _configurationManager.GetResourcePassword();


            if (!File.Exists(zipPath))
            {
                throw new FileNotFoundException("Specified Zip does not exist: " + zipPath);
            }

            FileStream zipFileStream = File.OpenRead(zipPath);
            var        zipFile       = new ZipFile(zipFileStream);

            if (!string.IsNullOrWhiteSpace(password))
            {
                zipFile.Password = password;
            }

            var directories = from ZipEntry a in zipFile
                              where a.IsDirectory
                              orderby a.Name.ToLowerInvariant() == "textures" descending
                              select a;

            Dictionary <string, List <ZipEntry> > sorted = new Dictionary <string, List <ZipEntry> >();

            foreach (ZipEntry dir in directories)
            {
                if (sorted.ContainsKey(dir.Name.ToLowerInvariant()))
                {
                    continue;                                                  //Duplicate folder? shouldnt happen.
                }
                List <ZipEntry> folderContents = (from ZipEntry entry in zipFile
                                                  where entry.Name.ToLowerInvariant().Contains(dir.Name.ToLowerInvariant())
                                                  where entry.IsFile
                                                  select entry).ToList();

                sorted.Add(dir.Name.ToLowerInvariant(), folderContents);
            }

            sorted = sorted.OrderByDescending(x => x.Key == "textures/").ToDictionary(x => x.Key, x => x.Value); //Textures first.

            foreach (KeyValuePair <string, List <ZipEntry> > current in sorted)
            {
                switch (current.Key)
                {
                case ("textures/"):
                    foreach (ZipEntry texture in current.Value)
                    {
                        if (supportedImageExtensions.Contains(Path.GetExtension(texture.Name).ToLowerInvariant()))
                        {
                            Image loadedImg = LoadImageFrom(zipFile, texture);
                            if (loadedImg == null)
                            {
                                continue;
                            }
                            else
                            {
                                _images.Add(loadedImg.Name, loadedImg);
                            }
                        }
                    }
                    break;

                case ("tai/"):
                    foreach (ZipEntry tai in current.Value)
                    {
                        if (Path.GetExtension(tai.Name).ToLowerInvariant() == ".tai")
                        {
                            IEnumerable <Sprite> loadedSprites = LoadSpritesFrom(zipFile, tai);
                            foreach (Sprite currentSprite in loadedSprites.Where(currentSprite => !_sprites.ContainsKey(currentSprite.Name)))
                            {
                                _sprites.Add(currentSprite.Name, currentSprite);
                            }
                        }
                    }
                    break;

                case ("fonts/"):
                    foreach (ZipEntry font in current.Value)
                    {
                        if (Path.GetExtension(font.Name).ToLowerInvariant() == ".ttf")
                        {
                            Font loadedFont = LoadFontFrom(zipFile, font);
                            if (loadedFont == null)
                            {
                                continue;
                            }
                            else
                            {
                                _fonts.Add(loadedFont.Name, loadedFont);
                            }
                        }
                    }
                    break;

                case ("particlesystems/"):
                    foreach (ZipEntry particles in current.Value)
                    {
                        if (Path.GetExtension(particles.Name).ToLowerInvariant() == ".xml")
                        {
                            ParticleSettings particleSettings = LoadParticlesFrom(zipFile, particles);
                            if (particleSettings == null)
                            {
                                continue;
                            }
                            else
                            {
                                _particles.Add(Path.GetFileNameWithoutExtension(particles.Name), particleSettings);
                            }
                        }
                    }
                    break;

                case ("shaders/"):
                    foreach (ZipEntry shader in current.Value)
                    {
                        if (Path.GetExtension(shader.Name).ToLowerInvariant() == ".fx")
                        {
                            FXShader loadedShader = LoadShaderFrom(zipFile, shader);
                            if (loadedShader == null)
                            {
                                continue;
                            }
                            else
                            {
                                _shaders.Add(loadedShader.Name, loadedShader);
                            }
                        }
                    }
                    break;

                case ("animations/"):
                    foreach (ZipEntry animation in current.Value)
                    {
                        if (Path.GetExtension(animation.Name).ToLowerInvariant() == ".xml")
                        {
                            AnimationCollection animationCollection = LoadAnimationCollectionFrom(zipFile, animation);
                            if (animationCollection == null)
                            {
                                continue;
                            }
                            else
                            {
                                _animationCollections.Add(animationCollection.Name, animationCollection);
                            }
                        }
                    }
                    break;
                }
            }

            sorted = null;

            zipFile.Close();
            zipFileStream.Close();
            zipFileStream.Dispose();

            GC.Collect();
        }
예제 #10
0
        private void LoadFont()
        {
            FileStream fs = new FileStream("CALIBRI.TTF", FileMode.Open);

            Font loadedFont = Graphics.Font.FromStream("calibri", fs, (int)fs.Length, 10, false);

            fs.Close();

            font = loadedFont;
        }