예제 #1
0
파일: Font.cs 프로젝트: shff/gk3tools
        public static FontInstance Load(FontSpec spec)
        {
            // see if this already loaded in our own cache
            var key = spec.Characters + "$" + spec.Bitmap;

            Font font;

            if (_fonts.TryGetValue(key, out font) == false)
            {
                font            = new Font();
                font.Characters = spec.Characters;
                font.Texture    = Resource.ResourceManager.Global.Load <Graphics.TextureResource>(spec.Bitmap);

                var bmp = spec.Bitmap;
                if (bmp.IndexOf('.') < 0)
                {
                    bmp += ".BMP";
                }

                Graphics.BitmapSurface map;
                using (System.IO.Stream stream = FileSystem.Open(bmp))
                {
                    map = new Gk3Main.Graphics.BitmapSurface(stream, Graphics.BitmapSurface.SourceType.Unknown, true);
                }

                font.buildCharacterInfo(spec.LineCount, map);

                // make the texture white
                for (int i = 0; i < map.Width * map.Height; i++)
                {
                    if (map.Pixels[i * 4 + 0] == font.DefaultColor.R &&
                        map.Pixels[i * 4 + 1] == font.DefaultColor.G &&
                        map.Pixels[i * 4 + 2] == font.DefaultColor.B)
                    {
                        map.Pixels[i * 4 + 0] = 255;
                        map.Pixels[i * 4 + 1] = 255;
                        map.Pixels[i * 4 + 2] = 255;
                    }
                }

                font.Texture = Graphics.RendererManager.CurrentRenderer.CreateTexture(spec.Bitmap, map, false);

                font.Instance.Font  = font;
                font.Instance.Color = font.DefaultColor;

                _fonts.Add(key, font);
            }

            var result = new FontInstance();

            result.Font  = font;
            result.Color = spec.DefaultColor;

            return(result);
        }
예제 #2
0
        public void DisplayGk3Bitmap(string name)
        {
            System.IO.Stream file = Gk3Main.FileSystem.Open(name);
            Gk3Main.Graphics.BitmapSurface bmp = new Gk3Main.Graphics.BitmapSurface(file);
            file.Dispose();

            System.Runtime.InteropServices.GCHandle pixels = System.Runtime.InteropServices.GCHandle.Alloc(bmp.Pixels, System.Runtime.InteropServices.GCHandleType.Pinned);
            Bitmap img = new Bitmap(bmp.Width, bmp.Height, bmp.Width * 4, System.Drawing.Imaging.PixelFormat.Format32bppRgb, pixels.AddrOfPinnedObject());

            pixels.Free();

            pictureBox1.Image = swapRedAndBlueChannels(img);

            img.Dispose();
        }
예제 #3
0
        public ActorPathfinder(string pathMapName, Math.Vector2 size, Math.Vector2 offset)
        {
            if (pathMapName == null)
            {
                throw new ArgumentNullException("pathMapName");
            }

            _scaledSize = size;
            _offset     = offset;

            if (pathMapName.EndsWith(".BMP", StringComparison.OrdinalIgnoreCase) == false)
            {
                pathMapName += ".BMP";
            }

            Graphics.BitmapSurface map;
            using (System.IO.Stream stream = FileSystem.Open(pathMapName))
            {
                // apparently the color doesn't matter, the weights are
                // stored as indices. So we don't want to convert!
                map = new Gk3Main.Graphics.BitmapSurface(stream, Graphics.BitmapSurface.SourceType.Unknown, false);
            }

            // temporary
            //Graphics.Utils.WriteTga("out.tga", map.Pixels, map.Width, map.Height);

            // read the pixels and convert them into weights
            _weightMap = new byte[map.Width * map.Height];
            _width     = map.Width;
            _height    = map.Height;

            for (int y = 0; y < map.Height; y++)
            {
                for (int x = 0; x < map.Width; x++)
                {
                    Graphics.Color color = map.ReadColorAt(x, y);

                    _weightMap[y * _width + x] = color.R;
                }
            }

            // create the working arrays
            _whichList = new int[_width * _height];
            _parents   = new int[_width * _height];
            _fCost     = new float[_width * _height];
            _gCost     = new float[_width * _height];
            _hCost     = new float[_width * _height];
        }