public ObjectClass(string name, TextureResource image) : this(name) { _image = image; _imageBounds = image.Bounds; _maskBounds = image.Bounds; }
public SnappingManager(Point subjectOrigin, Rectangle subjectBounds, Size gridSize) { _gridX = gridSize.Width; _gridY = gridSize.Height; _origin = subjectOrigin; _bounds = subjectBounds; }
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)); } }
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); } }
private bool TestMaskBoundsPartial(Rectangle region, ObjectInstance instance) { Rectangle bounds = instance.MaskBounds; return bounds.Right > region.Left && bounds.Left < region.Right && bounds.Bottom > region.Top && bounds.Top < region.Bottom; }
public ObjectClass(string name, TextureResource image, Rectangle maskBounds) : this(name, image) { _maskBounds = maskBounds; }
public void RemoveTiles(Rectangle tileRegion) { for (int y = tileRegion.Top; y < tileRegion.Bottom; y++) { for (int x = tileRegion.Left; x < tileRegion.Right; x++) { _tiles.Remove(new TileCoord(x, y)); _tileAnnot.RemoveTileLocation(new TileCoord(x, y)); } } }
public bool Equals(Rectangle other) { return this.X == other.X && this.Y == other.Y && this.Width == other.Width && this.Height == other.Height; }
public static bool IsAreaNegative(Rectangle rect) { return IsAreaNegativeOrEmpty(rect) && !IsAreaEmpty(rect); }
private Rectangle ClampRectangle(Rectangle rect, Rectangle bounds) { if (rect.X < bounds.X) { rect.Width += rect.X; rect.X = bounds.X; } if (rect.Y < bounds.Y) { rect.Height += rect.Y; rect.Y = bounds.Y; } if (rect.X + rect.Width > bounds.X + bounds.Width) rect.Width = bounds.X + bounds.Width - rect.X; if (rect.Y + rect.Height > bounds.Y + bounds.Height) rect.Height = bounds.Y + bounds.Height - rect.Y; return rect; }
public void Clear(Rectangle region) { Apply(c => { return Colors.Transparent; }, region); }
private void UpdateBounds() { _classVersion = _class.Version; _imageRotatedBounds = CalculateRectangleBounds(new Rectangle( _class.ImageBounds.Left - _class.Origin.X, _class.ImageBounds.Top - _class.Origin.Y, _class.ImageBounds.Width, _class.ImageBounds.Height), _rotation); _maskRotatedBounds = CalculateRectangleBounds(new Rectangle( _class.MaskBounds.Left - _class.Origin.X, _class.MaskBounds.Top - _class.Origin.Y, _class.MaskBounds.Width, _class.MaskBounds.Height), _rotation); }
private static Rectangle CalculateRectangleBounds(Rectangle rect, float angle) { float st = (float)Math.Sin(angle); float ct = (float)Math.Cos(angle); float x1 = rect.Left * ct - rect.Top * st; float y1 = rect.Left * st + rect.Top * ct; float x2 = rect.Right * ct - rect.Top * st; float y2 = rect.Right * st + rect.Top * ct; float x3 = rect.Left * ct - rect.Bottom * st; float y3 = rect.Left * st + rect.Bottom * ct; float x4 = rect.Right * ct - rect.Bottom * st; float y4 = rect.Right * st + rect.Bottom * ct; int xmin = (int)Math.Floor(Math.Min(x1, Math.Min(x2, Math.Min(x3, x4)))); int xmax = (int)Math.Ceiling(Math.Max(x1, Math.Max(x2, Math.Max(x3, x4)))); int ymin = (int)Math.Floor(Math.Min(y1, Math.Min(y2, Math.Min(y3, y4)))); int ymax = (int)Math.Ceiling(Math.Max(y1, Math.Max(y2, Math.Max(y3, y4)))); return new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin); }
public static Xna.Rectangle ToXnaRectangle(this TF.Rectangle rect) { return(new Xna.Rectangle(rect.X, rect.Y, rect.Width, rect.Height)); }
public IEnumerable<LocatedTileStack> TileStacksAt(Rectangle region) { int xs = Math.Max(region.X, TileOriginX); int ys = Math.Max(region.Y, TileOriginY); int w = Math.Min(region.Width, TilesWide - region.X); int h = Math.Min(region.Height, TilesHigh - region.Y); for (int y = ys; y < ys + h; y++) { for (int x = xs; x < xs + w; x++) { int xi = XIndex(x); int yi = YIndex(y); if (_tiles[yi, xi] != null) { yield return new LocatedTileStack(_tiles[yi, xi], x, y); } } } }
public override IEnumerable<LocatedTile> TilesAt(Rectangle region) { int xs = Math.Max(region.X, TileOriginX); int ys = Math.Max(region.Y, TileOriginY); int xe = Math.Min(region.X + region.Width, TilesWide + TileOriginX); int ye = Math.Min(region.Y + region.Height, TilesHigh + TileOriginY); for (int y = ys; y < ye; y++) { for (int x = xs; x < xe; x++) { int xi = XIndex(x); int yi = YIndex(y); if (_tiles[yi, xi] == null) { continue; } foreach (Tile tile in _tiles[yi, xi]) { yield return new LocatedTile(tile, x, y); } } } }
public ObjectClass(string name, TextureResource image, Rectangle maskBounds, Point origin) : this(name, image, maskBounds) { _origin = origin; }
private bool TestOrigin(Rectangle region, ObjectInstance instance) { return instance.X >= region.Left && instance.X <= region.Right && instance.Y >= region.Top && instance.Y <= region.Bottom; }
private List<ObjectInstance> ObjectsInArea(Rectangle area) { List<ObjectInstance> list = new List<ObjectInstance>(); foreach (ObjectInstance inst in Layer.ObjectsInRegion(area, ObjectRegionTest.Image)) { list.Add(inst); } return list; }
public void Apply(PixelFunctionXY pixelFunc, Rectangle region) { Rectangle rect = ClampRectangle(region, Bounds); if (Rectangle.IsAreaNegativeOrEmpty(rect)) return; int sourceOffset = rect.Y * ScanlineSize + rect.X * _bytesPerPixel; for (int y = 0; y < rect.Height; y++) { int lineIndex = sourceOffset + y * ScanlineSize; for (int x = 0; x < rect.Width; x++) { int index = lineIndex + x * _bytesPerPixel; Color result = pixelFunc(new Color( _data[index + 0], _data[index + 1], _data[index + 2], _data[index + 3]), rect.X + x, rect.Y + y); _data[index + 0] = result.R; _data[index + 1] = result.G; _data[index + 2] = result.B; _data[index + 3] = result.A; } } }
public Rectangle SelectionBounds(ObjectRegionTest test) { int minX = int.MaxValue; int minY = int.MaxValue; int maxX = int.MinValue; int maxY = int.MinValue; foreach (SelectedObjectRecord record in _selectedObjects) { Rectangle reference = Rectangle.Empty; switch (test) { case ObjectRegionTest.Image: reference = record.Instance.ImageBounds; break; case ObjectRegionTest.Mask: reference = record.Instance.MaskBounds; break; case ObjectRegionTest.Origin: reference = new Rectangle(record.Instance.X, record.Instance.Y, 0, 0); break; case ObjectRegionTest.PartialImage: reference = record.Instance.ImageBounds; break; case ObjectRegionTest.PartialMask: reference = record.Instance.MaskBounds; break; } minX = Math.Min(minX, reference.Left); minY = Math.Min(minY, reference.Top); maxX = Math.Max(maxX, reference.Right); maxY = Math.Max(maxY, reference.Bottom); } return new Rectangle(minX, minY, maxX - minX, maxY - minY); }
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; }
private Rectangle ClampSelection(Rectangle rect) { int x = Math.Max(rect.X, Layer.TileOriginX); int y = Math.Max(rect.Y, Layer.TileOriginY); return new Rectangle(x, y, Math.Min(rect.Width, Layer.TilesWide - x), Math.Min(rect.Height, Layer.TilesHigh - y) ); }
public static bool IsAreaEmpty(Rectangle rect) { return rect.Width == 0 || rect.Height == 0; }
public void SizeToBound(Rectangle bound) { Center = bound.Center; Radius = (float)Math.Sqrt(bound.Width * bound.Width + bound.Height * bound.Height) / 2; }
public static bool IsAreaNegativeOrEmpty(Rectangle rect) { return rect.Width <= 0 || rect.Height <= 0; }
public IEnumerable<ObjectInstance> ObjectsInRegion(Rectangle region, ObjectRegionTest test) { Func<Rectangle, ObjectInstance, bool> testFunc = null; switch (test) { case ObjectRegionTest.Image: testFunc = TestImageBounds; break; case ObjectRegionTest.PartialImage: testFunc = TestImageBoundsPartial; break; case ObjectRegionTest.Mask: testFunc = TestMaskBounds; break; case ObjectRegionTest.PartialMask: testFunc = TestMaskBoundsPartial; break; case ObjectRegionTest.Origin: testFunc = TestOrigin; break; } foreach (ObjectInstance inst in _objects) { if (testFunc(region, inst)) yield return inst; } }
public void AddTiles(MultiTileGridLayer layer, Rectangle tileRegion) { for (int y = tileRegion.Top; y < tileRegion.Bottom; y++) { for (int x = tileRegion.Left; x < tileRegion.Right; x++) { AddTile(layer, new TileCoord(x, y)); } } }
private bool TestMaskBounds(Rectangle region, ObjectInstance instance) { Rectangle bounds = instance.MaskBounds; return bounds.Left >= region.Left && bounds.Right <= region.Right && bounds.Top >= region.Top && bounds.Bottom <= region.Bottom; }
private IEnumerable<TileCoord> TileCoordsFromRegion(Rectangle region) { for (int y = region.Top; y < region.Bottom; y++) for (int x = region.Left; x < region.Right; x++) yield return new TileCoord(x, y); }
public abstract IEnumerable<LocatedTile> TilesAt(Rectangle region);