Пример #1
0
        public DeviceManager()
        {
            Device = new Rendering.DirectX11.Dx11RenderingDevice();

            // Recreate legacy environment
            {
                ___LegacyDevice = GraphicsDevice.New(((Rendering.DirectX11.Dx11RenderingDevice)Device).Device);
                LevelData.ImportedGeometry.Device = ___LegacyDevice;

                // Load legacy effects
                string dir = Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location);
                IEnumerable <string> effectFiles = Directory.EnumerateFiles(dir + "\\Rendering\\Legacy", "*.fx");
                foreach (string fileName in effectFiles)
                {
                    string effectName           = Path.GetFileNameWithoutExtension(fileName);
                    EffectCompilerResult effect = EffectCompiler.CompileFromFile(fileName);
                    if (effect.HasErrors)
                    {
                        string errors = "";
                        foreach (var err in effect.Logger.Messages)
                        {
                            errors += err + Environment.NewLine;
                        }
                        throw new Exception("Could not compile effect '" + fileName + "'" + Environment.NewLine + errors);
                    }
                    ___LegacyEffects.Add(effectName, new Effect(___LegacyDevice, effect.EffectData));
                }

                // Load legacy font
                SpriteFontData fontData = SpriteFontData.Load(ResourcesC.ResourcesC.font);
                fontData.DefaultCharacter = '\n'; // Don't crash on uncommon Unicode values
                ___LegacyFont             = SpriteFont.New(___LegacyDevice, fontData);
            }
        }
Пример #2
0
        public void TestSpriteFontDataLoad()
        {
            // Load a sprite font file generated with DirectTk.MakeSpriteFont command line tool.
            var test = SpriteFontData.Load("Arial16.spritefont");

            Assert.NotNull(test.Glyphs);
            Assert.True(test.Glyphs.Length > 0);
        }
Пример #3
0
        public SimpleText(GraphicsDevice device, string fontFilename)
        {
            this.device         = device;
            this.graphicsDevice = device;
            this.spriteFont     = SpriteFont.Load(graphicsDevice, fontFilename);
            var sfd = SpriteFontData.Load(fontFilename);

            this.spriteBatch = new SpriteBatch(graphicsDevice);
        }
Пример #4
0
        public static SpriteFont Load(string filePathAndName)
        {
            string baseDir  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string fullPath = Path.Combine(baseDir, filePathAndName);

            if (!File.Exists(fullPath))
            {
                Debugger.Break();
            }

            string compiledfile = string.Format("{0}comp", Path.GetFileNameWithoutExtension(fullPath));
            var    result       = FontCompiler.CompileAndSave(fullPath, compiledfile);

            if (result.HasErrors)
            {
                Debugger.Break();
            }

            return(SpriteFont.New(Engine.GraphicsContext.Device, SpriteFontData.Load(compiledfile)));
        }
Пример #5
0
        protected override void Initialize()
        {
            base.Initialize();
            SpriteBatch           = new SpriteBatch(GraphicsDevice);
            SpriteFont            = ToDisposeContent(SpriteFont.New(GraphicsDevice, SpriteFontData.Load(Properties.Resources.Arial8)));
            Window.IsMouseVisible = true;
            Window.Title          = Window.Name = "ShalzuthPerception";
            ((Form)Window.NativeWindow).FormBorderStyle = FormBorderStyle.None;
            Window.ClientSizeChanged += (s, ea) => { };
            ((Form)Window.NativeWindow).TransparencyKey = System.Drawing.Color.AntiqueWhite;
            Process process = default;

            while (process == default(Process))
            {
                process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName.Contains(Engine.Memory.Process.ProcessName) && p.MainWindowHandle != IntPtr.Zero);
                Thread.Sleep(1000);
            }
            SetWindowLong(((Form)Window.NativeWindow).Handle, -20, GetWindowLong(((Form)Window.NativeWindow).Handle, -20) | 0x80000 | 0x20);
            SetParent(((Form)Window.NativeWindow).Handle, (IntPtr)process.MainWindowHandle);
            SetWindowPos(((Form)Window.NativeWindow).Handle, 0, 0, 0, 1920, 1080, 0);
        }
        // Deconstructs a spritefont.
        private void DeConstruct(SpriteFontData spriteFontData)
        {
            spriteFontData.fontTexture        = spriteFont.Texture;
            spriteFontData.lineHeightSpaceing = spriteFont.LineSpacing;
            spriteFontData.spaceing           = spriteFont.Spacing;
            spriteFontData.dgyphs             = spriteFont.GetGlyphs();
            spriteFontData.defaultglyph       = new SpriteFont.Glyph();
            if (spriteFont.DefaultCharacter.HasValue)
            {
                spriteFontData.defaultchar  = (char)(spriteFont.DefaultCharacter.Value);
                spriteFontData.defaultglyph = spriteFontData.dgyphs[spriteFontData.defaultchar];
            }
            else
            {
                // we could create a default value from like a pixel in the sprite font and add the glyph.
            }
            foreach (var item in spriteFontData.dgyphs)
            {
                spriteFontData.glyphBounds.Add(item.Value.BoundsInTexture);
                spriteFontData.glyphCroppings.Add(item.Value.Cropping);
                spriteFontData.glyphCharacters.Add(item.Value.Character);
                spriteFontData.glyphKernings.Add(new Vector3(item.Value.LeftSideBearing, item.Value.Width, item.Value.RightSideBearing));
            }
            spriteFontData.numberOfGlyphs = spriteFontData.glyphCharacters.Count;

            spriteFontData.width  = spriteFont.Texture.Width;
            spriteFontData.height = spriteFont.Texture.Height;

            Color[] colorarray = new Color[spriteFont.Texture.Width * spriteFont.Texture.Height];
            spriteFont.Texture.GetData <Color>(colorarray); //,0, width* height
            List <Color> pixels = new List <Color>();

            foreach (var c in colorarray)
            {
                pixels.Add(c);
            }
            spriteFontData.pixelColorData = pixels;
        }
 /// <summary>
 /// Give this a sprite font to deconstruct it to data.
 /// </summary>
 public SpriteFontManipulator(SpriteFont spriteFont)
 {
     this.spriteFont = spriteFont; // how to handle disposing the fonts texture in this particular case im not sure.
     spriteFontData  = new SpriteFontData();
     DeConstruct(spriteFontData);
 }
            public void WriteFile(string fullFilePath, SpriteFontData sfData)
            {
                var filename  = Path.GetFileNameWithoutExtension(fullFilePath);
                var colordata = sfData.pixelColorData;

                width              = sfData.width;
                height             = sfData.height;
                rleEncodedByteData = EncodeColorArrayToDataRLE(colordata, sfData.width, sfData.height);

                var charsAsString     = CharArrayToStringClassFormat("chars", sfData.glyphCharacters.ToArray());
                var boundsAsString    = RectangleToStringClassFormat("bounds", sfData.glyphBounds.ToArray());
                var croppingsAsString = RectangleToStringClassFormat("croppings", sfData.glyphCroppings.ToArray());
                var kerningsAsString  = Vector3ToStringClassFormat("kernings", sfData.glyphKernings.ToArray());
                var rleDataAsString   = ByteArrayToStringClassFormat("rleByteData", rleEncodedByteData.ToArray());


                theCsText.Append(
                    "\n//" +
                    "\n// This file is programatically generated this class is hard coded instance data for a instance of a spritefont." +
                    "\n// Use the LoadHardCodeSpriteFont to load it." +
                    "\n// Be aware i believe you should dispose its texture in game1 unload as this won't have been loaded thru the content manager." +
                    "\n//" +
                    "\n//");

                theCsText
                .Append("\n using System;")
                .Append("\n using System.Text;")
                .Append("\n using System.Collections.Generic;")
                .Append("\n using Microsoft.Xna.Framework;")
                .Append("\n using Microsoft.Xna.Framework.Graphics;")
                .Append("\n using Microsoft.Xna.Framework.Input;")
                .Append("\n")
                .Append("\n namespace Microsoft.Xna.Framework")
                .Append("\n {")
                .Append("\n ")
                .Append("\n  public class SpriteFontAsClassFile_").Append(filename)
                .Append("\n  {")
                .Append("\n ")
                .Append("\n  int width=").Append(width).Append(";")
                .Append("\n  int height=").Append(height).Append(";")
                .Append("\n  char defaultChar =  Char.Parse(\"").Append(sfData.defaultchar).Append("\");")
                .Append("\n  int lineHeightSpaceing =").Append(sfData.lineHeightSpaceing).Append(";")
                .Append("\n  float spaceing =").Append(sfData.spaceing).Append(";")
                .Append("\n ")
                .Append("\n   public SpriteFont LoadHardCodeSpriteFont(GraphicsDevice device)")
                .Append("\n   {")
                .Append("\n       Texture2D t = DecodeToTexture(device, rleByteData, width, height);")
                .Append("\n       return new SpriteFont(t, bounds, croppings, chars, lineHeightSpaceing, spaceing, kernings, defaultChar);")
                .Append("\n   }")
                .Append("\n ")
                .Append("\n   private Texture2D DecodeToTexture(GraphicsDevice device, List<byte> rleByteData, int _width, int _height)")
                .Append("\n   {")
                .Append("\n       Color[] colData = DecodeDataRLE(rleByteData);")
                .Append("\n       Texture2D tex = new Texture2D(device, _width, _height);")
                .Append("\n       tex.SetData<Color>(colData);")
                .Append("\n       return tex;")
                .Append("\n   }")
                .Append("\n ")
                .Append("\n   private Color[] DecodeDataRLE(List<byte> rleByteData)")
                .Append("\n   {")
                .Append("\n       List <Color> colAry = new List<Color>();")
                .Append("\n       for (int i = 0; i < rleByteData.Count; i++)")
                .Append("\n       {")
                .Append("\n           var val = (rleByteData[i] & 0x7F) * 2;")
                .Append("\n           if (val > 252)")
                .Append("\n               val = 255;")
                .Append("\n           Color color = new Color();")
                .Append("\n           if (val > 0)")
                .Append("\n               color = new Color(val, val, val, val);")
                .Append("\n           if ((rleByteData[i] & 0x80) > 0)")
                .Append("\n           {")
                .Append("\n               var runlen = rleByteData[i + 1];")
                .Append("\n               for (int j = 0; j < runlen; j++)")
                .Append("\n                   colAry.Add(color);")
                .Append("\n               i += 1;")
                .Append("\n           }")
                .Append("\n           colAry.Add(color);")
                .Append("\n       }")
                .Append("\n       return colAry.ToArray();")
                .Append("\n   }")
                .Append("\n ")
                .Append("\n     ").Append(charsAsString)
                .Append("\n     ").Append(boundsAsString)
                .Append("\n     ").Append(croppingsAsString)
                .Append("\n     ").Append(kerningsAsString)
                .Append("\n ")
                .Append("\n       // pixelsCompressed: ").Append(pixels).Append(" bytesTallied: ").Append(bytestallyed).Append(" byteDataCount: ").Append(bytedataCount)
                .Append("\n     ").Append(rleDataAsString)
                .Append("\n ")
                .Append("\n ")
                .Append("\n  }")
                .Append("\n ")
                .Append("\n }")     // end of namespace
                .Append("\n ").Append(" ")
                ;

                //MgPathFolderFileOps.WriteStringToFile(fullFilePath, theCsText.ToString());
                File.WriteAllText(fullFilePath, theCsText.ToString());
            }