Beispiel #1
0
        public TextureResource Crop(Rectangle region)
        {
            Rectangle rect = ClampRectangle(region, Bounds);

            if (Rectangle.IsAreaNegativeOrEmpty(rect))
            {
                return(new TextureResource(0, 0));
            }

            TextureResource sub = new TextureResource(rect.Width, rect.Height);

            int priScan = ScanlineSize;
            int subScan = sub.ScanlineSize;

            int sourceOffset = rect.Y * priScan + rect.X * _bytesPerPixel;

            for (int y = 0; y < rect.Height; y++)
            {
                int sourceIndex = sourceOffset + y * priScan;
                int destIndex   = y * subScan;
                Array.Copy(_data, sourceIndex, sub._data, destIndex, subScan);
            }

            return(sub);
        }
Beispiel #2
0
        public virtual void Update (TextureResource textureData)
        {
            foreach (DependentTile tile in _dependents)
                tile.UpdateFromBase(textureData);

            OnTextureModified(EventArgs.Empty);
        }
Beispiel #3
0
        public void Set(TextureResource data, Point location)
        {
            if (data == null)
            {
                return;
            }

            Rectangle rect = ClampRectangle(new Rectangle(location, data.Size), Bounds);

            if (Rectangle.IsAreaNegativeOrEmpty(rect))
            {
                return;
            }

            int dataScan  = data.ScanlineSize;
            int clampScan = rect.Width * _bytesPerPixel;

            int sourceOffset = (rect.Y - location.Y) * dataScan + (rect.X - location.X) * _bytesPerPixel;
            int targetOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel;

            for (int y = 0; y < rect.Height; y++)
            {
                int sourceIndex = sourceOffset + y * dataScan;
                int destIndex   = targetOffset + y * ScanlineSize;
                Array.Copy(data._data, sourceIndex, _data, destIndex, clampScan);
            }
        }
Beispiel #4
0
        public void SetComposite(TextureResource data, Point location)
        {
            Rectangle rect = ClampRectangle(new Rectangle(location, data.Size), Bounds);

            if (Rectangle.IsAreaNegativeOrEmpty(rect))
            {
                return;
            }

            int dataScan  = data.ScanlineSize;
            int clampScan = rect.Width * _bytesPerPixel;

            int sourceOffset = (rect.Y - location.Y) * dataScan + (rect.X - location.X) * _bytesPerPixel;
            int targetOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel;

            for (int y = 0; y < rect.Height; y++)
            {
                for (int x = 0; x < rect.Width; x++)
                {
                    int sourceIndex = sourceOffset + y * dataScan + x * _bytesPerPixel;
                    int destIndex   = targetOffset + y * ScanlineSize + x * _bytesPerPixel;

                    float alpha = data._data[sourceIndex + 3] / 255f;
                    _data[destIndex + 0] = (byte)(_data[destIndex + 0] * (1f - alpha) + data._data[sourceIndex + 0] * alpha);
                    _data[destIndex + 1] = (byte)(_data[destIndex + 1] * (1f - alpha) + data._data[sourceIndex + 1] * alpha);
                    _data[destIndex + 2] = (byte)(_data[destIndex + 2] * (1f - alpha) + data._data[sourceIndex + 2] * alpha);
                    _data[destIndex + 3] = (byte)Math.Min(255, _data[destIndex + 3] * (1f - alpha) + data._data[sourceIndex + 3]);
                }
            }
        }
Beispiel #5
0
 public ObjectClass(string name, TextureResource image)
     : this(name)
 {
     _image = image;
     _imageBounds = image.Bounds;
     _maskBounds = image.Bounds;
 }
Beispiel #6
0
        public static XmlProxy ToXmlProxy(TextureResource tex)
        {
            if (tex == null)
            {
                return(null);
            }

            return(new XmlProxy()
            {
                Width = tex._width,
                Height = tex._height,
                RawData = tex._data,
            });
        }
Beispiel #7
0
        private ObjectClass(LibraryX.ObjectClassX proxy, TexturePool texturePool)
            : this(proxy.Name)
        {
            _uid = proxy.Uid;
            _textureId = proxy.Texture;
            _image = texturePool.GetResource(_textureId);
            _imageBounds = proxy.ImageBounds;
            _maskBounds = proxy.MaskBounds;
            _origin = proxy.Origin;

            if (proxy.Properties != null) {
                foreach (var propertyProxy in proxy.Properties)
                    CustomProperties.Add(Property.FromXmlProxy(propertyProxy));
            }
        }
Beispiel #8
0
        public ObjectClass(string name, ObjectClass template)
            : this(name)
        {
            if (template != null) {
                if (template.Image != null)
                    _image = template.Image.Crop(template.Image.Bounds);

                _canRotate = template._canRotate;
                _canScale = template._canScale;
                _imageBounds = template._imageBounds;
                _maskBounds = template._maskBounds;
                _origin = template._origin;

                foreach (var item in template.PropertyManager.CustomProperties)
                    PropertyManager.CustomProperties.Add(item.Clone() as Property);
            }
        }
Beispiel #9
0
        public override TextureResource Transform(TextureResource data, int width, int height)
        {
            //byte[] tdata = new byte[width * height];

            TextureResource transData = new TextureResource(width, height);
            transData.Apply((c, x, y) =>
            {
                return data[height - x, width - y];
            });

            /*for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    int dindex = y * width + x;
                    int tindex = (width - x) * height + y;
                    tdata[tindex] = data.RawData[dindex];
                }
            }*/

            return transData;
        }
Beispiel #10
0
        public ImportObject(ObjectClass obj)
        {
            InitializeForm();

            base.Text = "Edit Object";

            _sourceImage = obj.Image.Crop(obj.Image.Bounds);
            _sourceFileValid = true;
            _name = obj.Name;

            _originX = obj.Origin.X;
            _originY = obj.Origin.Y;
            _maskLeft = obj.MaskBounds.Left;
            _maskTop = obj.MaskBounds.Top;
            _maskRight = obj.MaskBounds.Right;
            _maskBottom = obj.MaskBounds.Bottom;

            UpdateMaskPropertyFields();

            _validateController.UnregisterControl(_textSource);
            _validateController.Validate();
        }
Beispiel #11
0
 public void AddResource(TextureResource resource)
 {
     _pools[MapAndCheckUid(_default)].AddResource(resource);
 }
Beispiel #12
0
        public void AddResource(TextureResource resource)
        {
            if (resource == null)
                throw new ArgumentNullException("resource");

            if (_resources.ContainsKey(resource.Uid)) {
                _useCount[resource.Uid]++;
                return;
            }

            _resources.Add(resource.Uid, resource);
            _useCount.Add(resource.Uid, 1);

            OnResourceAdded(new ResourceEventArgs(resource.Uid));
        }
Beispiel #13
0
 private void SetTransparentColor(TextureResource resource)
 {
     ClearTransparentColor(resource);
     resource.Apply(c => {
         if (c.Equals(_transColor))
             return Colors.Transparent;
         else
             return c;
     });
 }
Beispiel #14
0
        private TilePool LoadFile(ITilePoolManager manager)
        {
            if (_fileStream == null) {
                return null;
            }

            if (_fileStream.Position != 0) {
                _fileStream.Position = 0;
            }

            _localManager.Reset();

            TextureResource resource = TextureResourceBitmapExt.CreateTextureResource(_fileStream);
            TilePool.TileImportOptions options = new TilePool.TileImportOptions()
            {
                TileHeight = (int)_numTileHeight.Value,
                TileWidth = (int)_numTileWidth.Value,
                SpaceX = (int)_numXSpacing.Value,
                SpaceY = (int)_numYSpacing.Value,
                MarginX = (int)_numXMargin.Value,
                MarginY = (int)_numYMargin.Value,
                ImportPolicty = TileImportPolicy.SetUnique,
            };

            _previewPool = _localManager.ImportPool(_textName.Text, resource, options);
            _originalResource = _previewPool.TileSource.Crop(_previewPool.TileSource.Bounds);

            if (_useTransColor)
                SetTransparentColor();

            // Update preview window

            if (_previewLayer != null)
                _previewLayer.Dispose();

            Model.TileSetLayer layer = new Model.TileSetLayer(_previewPool.Name, _previewPool);
            _previewLayer = new TileSetLayerPresenter(layer) {
                LevelGeometry = _layerControl.LevelGeometry,
            };

            _rootLayer.Layers.Clear();
            _rootLayer.Layers.Add(_previewLayer);

            // Update stats

            _countTilesHigh.Text = ((_height + (int)_numYSpacing.Value) / ((int)_numTileHeight.Value + (int)_numYSpacing.Value + (int)_numYMargin.Value)).ToString();
            _countTilesWide.Text = ((_width + (int)_numXSpacing.Value) / ((int)_numTileWidth.Value + (int)_numXSpacing.Value + (int)_numXMargin.Value)).ToString();
            _countUniqueTiles.Text = _previewPool.Count.ToString();

            return _previewPool;
        }
Beispiel #15
0
 private void ClearTransparentColor(TextureResource resource)
 {
     resource.Set(_originalResource, Point.Zero);
 }
Beispiel #16
0
 public override void Update (TextureResource textureData)
 {
     Pool.Tiles.SetTileTexture(Uid, textureData);
     base.Update(textureData);
 }
 public void AddResource(TextureResource resource)
 {
     //_textures.Con
 }
Beispiel #18
0
        public TextureResource Crop(Rectangle region)
        {
            Rectangle rect = ClampRectangle(region, Bounds);

            if (Rectangle.IsAreaNegativeOrEmpty(rect))
                return new TextureResource(0, 0);

            TextureResource sub = new TextureResource(rect.Width, rect.Height);

            int priScan = ScanlineSize;
            int subScan = sub.ScanlineSize;

            int sourceOffset = rect.Y * priScan + rect.X * _bytesPerPixel;
            for (int y = 0; y < rect.Height; y++) {
                int sourceIndex = sourceOffset + y * priScan;
                int destIndex = y * subScan;
                Array.Copy(_data, sourceIndex, sub._data, destIndex, subScan);
            }

            return sub;
        }
Beispiel #19
0
        public void SetComposite(TextureResource data, Point location)
        {
            Rectangle rect = ClampRectangle(new Rectangle(location, data.Size), Bounds);

            if (Rectangle.IsAreaNegativeOrEmpty(rect))
                return;

            int dataScan = data.ScanlineSize;
            int clampScan = rect.Width * _bytesPerPixel;

            int sourceOffset = (rect.Y - location.Y) * dataScan + (rect.X - location.X) * _bytesPerPixel;
            int targetOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel;
            for (int y = 0; y < rect.Height; y++) {
                for (int x = 0; x < rect.Width; x++) {
                    int sourceIndex = sourceOffset + y * dataScan + x * _bytesPerPixel;
                    int destIndex = targetOffset + y * ScanlineSize + x * _bytesPerPixel;

                    float alpha = data._data[sourceIndex + 3] / 255f;
                    _data[destIndex + 0] = (byte)(_data[destIndex + 0] * (1f - alpha) + data._data[sourceIndex + 0] * alpha);
                    _data[destIndex + 1] = (byte)(_data[destIndex + 1] * (1f - alpha) + data._data[sourceIndex + 1] * alpha);
                    _data[destIndex + 2] = (byte)(_data[destIndex + 2] * (1f - alpha) + data._data[sourceIndex + 2] * alpha);
                    _data[destIndex + 3] = (byte)Math.Min(255, _data[destIndex + 3] * (1f - alpha) + data._data[sourceIndex + 3]);
                }
            }
        }
Beispiel #20
0
 public ObjectClass(string name, TextureResource image, Rectangle maskBounds, Point origin)
     : this(name, image, maskBounds)
 {
     _origin = origin;
 }
Beispiel #21
0
 public ObjectClass(string name, TextureResource image, Rectangle maskBounds)
     : this(name, image)
 {
     _maskBounds = maskBounds;
 }
Beispiel #22
0
 private void ClearObjectPreiew()
 {
     _sourceImage = null;
 }
Beispiel #23
0
 public virtual void UpdateFromBase (TextureResource textureData)
 {
     TextureResource xform = _transform.Transform(textureData, Pool.TileWidth, Pool.TileHeight);
     Pool.Tiles.SetTileTexture(Uid, xform);
 }
Beispiel #24
0
 public abstract TextureResource Transform(TextureResource data, int width, int height);
Beispiel #25
0
 public override void Update (TextureResource textureData)
 {
     _base.Update(_transform.InverseTransform(textureData, Pool.TileWidth, Pool.TileHeight));
 }
Beispiel #26
0
        public Guid AddResource(TextureResource resource)
        {
            if (resource == null)
                throw new ArgumentNullException("resource");

            Guid uid = Guid.NewGuid();
            _resources.Add(uid, resource);

            OnResourceAdded(new ResourceEventArgs(uid));
            return uid;
        }
Beispiel #27
0
        public static XmlProxy ToXmlProxy(TextureResource tex)
        {
            if (tex == null)
                return null;

            return new XmlProxy()
            {
                Width = tex._width,
                Height = tex._height,
                RawData = tex._data,
            };
        }
Beispiel #28
0
        private void LoadObjectPreview(String path)
        {
            try {
                _sourceImage = TextureResourceBitmapExt.CreateTextureResource(path);

                _originX = 0;
                _originY = 0;
                _maskLeft = 0;
                _maskTop = 0;
                _maskRight = _sourceImage.Width;
                _maskBottom = _sourceImage.Height;

                _sourceFileValid = true;
                UpdateMaskPropertyFields();
            }
            catch (Exception) {
                _sourceFileValid = false;
            }
        }
Beispiel #29
0
        public void Set(TextureResource data, Point location)
        {
            if (data == null)
                return;

            Rectangle rect = ClampRectangle(new Rectangle(location, data.Size), Bounds);

            if (Rectangle.IsAreaNegativeOrEmpty(rect))
                return;

            int dataScan = data.ScanlineSize;
            int clampScan = rect.Width * _bytesPerPixel;

            int sourceOffset = (rect.Y - location.Y) * dataScan + (rect.X - location.X) * _bytesPerPixel;
            int targetOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel;
            for (int y = 0; y < rect.Height; y++) {
                int sourceIndex = sourceOffset + y * dataScan;
                int destIndex = targetOffset + y * ScanlineSize;
                Array.Copy(data._data, sourceIndex, _data, destIndex, clampScan);
            }
        }
Beispiel #30
0
 public override TextureResource InverseTransform(TextureResource data, int width, int height)
 {
     return Transform(data, width, height);
 }
Beispiel #31
0
        public override TextureResource MakePreview()
        {
            if (TilesWide <= 0 || TilesHigh <= 0)
                return null;

            TextureResource resource = new TextureResource(TilesWide * TileWidth, TilesHigh * TileHeight);
            foreach (LocatedTile tile in Tiles) {
                int x = (tile.X - _minX) * TileWidth;
                int y = (tile.Y - _minY) * TileHeight;
                if (tile.Tile != null)
                    resource.SetComposite(tile.Tile.Pool.Tiles.GetTileTexture(tile.Tile.Uid), new Point(x, y));
            }

            return resource;
        }
Beispiel #32
0
        private void ClearObjectPreiew()
        {
            _sourceImage = null;

            //RaisePreviewProperties();
        }