Esempio n. 1
0
 public BytePixels(Microsoft.Xna.Framework.Graphics.Texture2D t2d)
 {
     var tp = new TexturePlus(t2d);
     _size = new SizeInt32(tp.Width, tp.Height);
     _data = (byte[])tp.GetData().Data.Clone();
     _Bpp = _data.Length / _size.Total;
 }
Esempio n. 2
0
 public Brush()
 {
     _lastUsedSize = new SizeInt32(0, 0);
     _image = new BitmapImage(new Uri(@"pack://application:,,,/TEdit;component/Images/Tools/paintbrush.png"));
     _name = "Brush";
     _type = ToolType.Brush;
     _isActive = false;
 }
Esempio n. 3
0
        public BytePixels(Microsoft.Xna.Framework.Graphics.Texture2D t2d)
        {
            var tp = new TexturePlus(t2d);

            _size = new SizeInt32(tp.Width, tp.Height);
            _data = (byte[])tp.GetData().Data.Clone();
            _Bpp  = _data.Length / _size.Total;
        }
        private RectI TileViewportRect()
        {
            var vm = (WorldViewModel)DataContext;
            var partView = (ScrollViewer)FindName("WorldScrollViewer");

            var xy   = new PointInt32((int)(partView.HorizontalOffset / vm.Zoom), (int)(partView.VerticalOffset / vm.Zoom));
            var size = new SizeInt32 ((int)(partView.ActualWidth      / vm.Zoom), (int)(partView.ActualHeight   / vm.Zoom));
            return new RectI(xy, size);
        }
Esempio n. 5
0
 public BytePixels(SizeInt32 size, int Bpp)
 {
     _Bpp  = Bpp;
     _size = new SizeInt32(size.W, size.H);
     _data = new byte[size.Total * _Bpp];
 }
Esempio n. 6
0
 public BytePixels(SizeInt32 size, byte[] data)
 {
     _size = new SizeInt32(size.W, size.H);
     _data = (byte[])data.Clone();
     _Bpp  = _data.Length / _size.Total;
 }
Esempio n. 7
0
 public bool Equals(SizeInt32 p)
 {
     return MatchFields(this, p);
 }
Esempio n. 8
0
 public RectI(PointInt32 topLeft, SizeInt32 size)
 {
     _topLeft = topLeft;
     _bottomRight = new PointInt32(size.Width + topLeft.X - 1, size.Height + topLeft.Y - 1);
 }
 public ClipboardBuffer(SizeInt32 size)
 {
     Size = size;
     Tiles = new Tile[size.W, size.H];
 }
Esempio n. 10
0
 public SizeInt32(SizeInt32 s)
 {
     _Width  = s.Width;
     _Height = s.Height;
 }
Esempio n. 11
0
 public BytePixels(TexturePlus tp)
 {
     _size = new SizeInt32(tp.Width, tp.Height);
     _data = (byte[])tp.GetData().Data.Clone();
     _Bpp  = _data.Length / _size.Total;
 }
Esempio n. 12
0
 public BytePixels(int w, int h, byte[] data)
 {
     _size = new SizeInt32(w, h);
     _data = (byte[])data.Clone();
     _Bpp  = _data.Length / _size.Total;
 }
Esempio n. 13
0
 public BytePixels(SizeInt32 size, int Bpp)
 {
     _Bpp  = Bpp;
     _size = new SizeInt32(size.W, size.H);
     _data = new byte[size.Total * _Bpp];
 }
Esempio n. 14
0
 public BytePixels(SizeInt32 size, byte[] data)
 {
     _size = new SizeInt32(size.W, size.H);
     _data = (byte[])data.Clone();
     _Bpp  = _data.Length / _size.Total;
 }
Esempio n. 15
0
 private static bool MatchFields(SizeInt32 a, SizeInt32 m)
 {
     return (a != null && m != null && a.Width == m.Width && a.Height == m.Height);
 }
Esempio n. 16
0
 public BytePixels(int w, int h, byte[] data)
 {
     _size = new SizeInt32(w, h);
     _data = (byte[])data.Clone();
     _Bpp  = _data.Length / _size.Total;
 }
Esempio n. 17
0
 public BytePixels(TexturePlus tp)
 {
     _size = new SizeInt32(tp.Width, tp.Height);
     _data = (byte[])tp.GetData().Data.Clone();
     _Bpp  = _data.Length / _size.Total;
 }
Esempio n. 18
0
 private static bool MatchFields(SizeInt32 a, SizeInt32 m)
 {
     return(a != null && m != null && a.Width == m.Width && a.Height == m.Height);
 }
Esempio n. 19
0
        public override bool PressTool(TileMouseEventArgs e)
        {
            tilesChecked = new bool[_world.Header.WorldBounds.Total];

            if (!_isRightDown && !_isLeftDown)
                _startPoint = e.Tile;

            if ((_properties.Height > 0 && _properties.Width > 0) &&
                (_lastUsedSize.Width != _properties.Width || _lastUsedSize.Height != _properties.Height))
                _lastUsedSize = new SizeInt32(_properties.Width, _properties.Height);

            CheckDirectionandDraw(e);
            _isLeftDown = (e.LeftButton == MouseButtonState.Pressed);
            _isRightDown = (e.RightButton == MouseButtonState.Pressed);
            return true;
        }
Esempio n. 20
0
 public bool Equals(SizeInt32 p)
 {
     return(MatchFields(this, p));
 }
Esempio n. 21
0
 public RectI(int X, int Y, SizeInt32 size)
 {
     _topLeft = new PointInt32(X, Y);
     _bottomRight = new PointInt32(size.Width + X - 1, size.Height + Y - 1);
 }
Esempio n. 22
0
 public SizeInt32(SizeInt32 s)
 {
     _Width = s.Width;
     _Height = s.Height;
 }
Esempio n. 23
0
 public RectI(int X, int Y, SizeInt32 size)
 {
     _topLeft     = new PointInt32(X, Y);
     _bottomRight = new PointInt32(size.Width + X - 1, size.Height + Y - 1);
 }
Esempio n. 24
0
        private BytePixels GetTextureLayer(string layerType, int y, Tile tile)
        {
            var size   = 8;
            var sizeI  = new SizeInt32(size, size);
            var pixels = new BytePixels(sizeI, 4);
            var rect00 = new RectI(0, 0, sizeI);
            string key = String.Empty;

            switch (layerType)
            {
                case "TilePixel":
                    Color c = GetTileColor(y, tile);

                    var b = new byte[4];
                    b[0] = c.B;
                    b[1] = c.G;
                    b[2] = c.R;
                    b[3] = c.A;
                    pixels = new BytePixels(1, 1, b);
                    break;

                case "Wall":
                    key = GetTileKey(y, tile, 'W');
                    if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key);

                    // FIXME: A complete wall is actually 16x16 big, with 3x3 variations, depending how many tiles exist //
                    if (tile.Wall > 0)
                        pixels = WorldSettings.Walls[tile.Wall].Texture.GetData(new RectI(166, 58, sizeI));  // tile with most coverage (will be eventually replaced per FIXME)
                    else {
                        // FIXME: These are actually pretty large bitmaps //
                        // Might need to go on a WallsBack layer... //

                        if (y >= _world.Header.WorldBounds.Bottom - 192)
                            pixels = WorldSettings.GlobalColors["Hell"].Texture.GetData(rect00);
                        else if (y > _world.Header.WorldRockLayer)
                            pixels = WorldSettings.GlobalColors["Rock"].Texture.GetData(rect00);
                        else if (y > _world.Header.WorldSurface)
                            pixels = WorldSettings.GlobalColors["Earth"].Texture.GetData(rect00);
                        else
                            pixels = WorldSettings.GlobalColors["Sky"].Texture.GetData(rect00);
                    }
                    break;

                case "TileBack":
                    key = GetTileKey(y, tile, 'T');
                    if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key);

                    // FIXME: Need XML property for larger than 8x8 sizes
                    if (tile.IsActive && !WorldSettings.Tiles[tile.Type].IsSolid) {
                        var rect = (WorldSettings.Tiles[tile.Type].IsFramed) ?
                            new RectI(tile.Frame.X / 2, tile.Frame.Y / 2, sizeI) :
                            rect00;
                        pixels = WorldSettings.Tiles[tile.Type].Texture.GetData(rect);
                    }
                    break;

                // FIXME: NPC layer would go here... //

                case "TileFront":
                    key = GetTileKey(y, tile, 'T');
                    if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key);

                    // FIXME: Need XML property for larger than 8x8 sizes
                    if (tile.IsActive && WorldSettings.Tiles[tile.Type].IsSolid) {
                        var rect = (WorldSettings.Tiles[tile.Type].IsFramed) ?
                            new RectI(tile.Frame.X / 2, tile.Frame.Y / 2, sizeI) :
                            rect00;
                        pixels = WorldSettings.Tiles[tile.Type].Texture.GetData(rect);
                    }
                    break;

                case "Liquid":
                    key = GetTileKey(y, tile, 'L');
                    if (textureCache.Contains(key)) return (BytePixels)textureCache.Get(key);

                    if (tile.Liquid > 0) {
                        // Should use Liquid levels to determine final height //
                        // Actually, bottom 4x4 should be for 255, and top 4x4 for anything else //
                        if (tile.IsLava)
                            pixels = WorldSettings.GlobalColors["Lava"].Texture.GetData(rect00);
                        else
                            pixels = WorldSettings.GlobalColors["Water"].Texture.GetData(rect00);
                    }
                    break;
            }

            // Cache policy for new cache items
            var cachePolicy = new CacheItemPolicy();
            cachePolicy.SlidingExpiration = new TimeSpan(0, 5, 0);  // 5 minute duration if not used
            if (shortKeyRegEx.IsMatch(key)) cachePolicy.Priority = CacheItemPriority.NotRemovable;  // single unframed tiles and walls get perma-cached

            textureCache.Add(key, pixels, cachePolicy);
            return pixels;
        }
Esempio n. 25
0
 public RectI(PointInt32 topLeft, SizeInt32 size)
 {
     _topLeft     = topLeft;
     _bottomRight = new PointInt32(size.Width + topLeft.X - 1, size.Height + topLeft.Y - 1);
 }
Esempio n. 26
-1
        public void UpdateWorldImage(RectI area, bool isRenderedLayer = false, string renderMsg = "Render Update Complete.", WriteableBitmap img = null)
        {
            // validate area
            area.Rebound(_world.Header.WorldBounds);

            int width = area.Width;
            int height = area.Height;
            int rts = isRenderedLayer ? 8 : 1;
            string renderProgressMsg = isRenderedLayer ? "Rendering Textured World..." : "Rendering Pixel World...";

            if (img == null) img = isRenderedLayer ? _worldImage.Rendered : _worldImage.Image;
            var pixels = new BytePixels(area.Size * rts, 4);
            var stride = img.PixelWidth * img.Format.BitsPerPixel / 8;

            for (int x = area.X; x <= area.Right; x++)
            {
                int dx = x - area.X;
                if (renderMsg != null) OnProgressChanged(this, dx, width, renderProgressMsg);

                for (int y = area.Y; y <= area.Bottom; y++)
                {
                    int dy = y - area.Y;
                    Tile tile = _world.Tiles[x, y];
                    if (tile != null)
                    {
                        var xy = (new PointInt32(x, y) - area.TopLeft) * rts;
                        var bp = isRenderedLayer ? GetTexture(y, tile) : GetTextureLayer("TilePixel", y, tile);
                        bp.PutData(pixels, xy);
                    }
                }
            }

            SizeInt32 ts = new SizeInt32(rts, rts);
            var realArea = isRenderedLayer ? new RectI(new PointInt32(), area.Size * ts) : area; // Rendered layer starts at 0,0

            img.Lock();
            img.WritePixels(realArea, pixels.GetData(), stride, 0);
            if (!isRenderedLayer) img.AddDirtyRect(realArea);
            img.Unlock();

            if (renderMsg != null) OnProgressChanged(this, 100, 100, renderMsg);
        }