public void Draw(IResourceImage resource, int layer, MegaMan.Common.Geometry.Point position, MegaRect? sourceRect = null, bool flipHorizontal = false, bool flipVertical = false)
        {
            if (!IsLayerEnabled(layer)) return;

            var texture = _loadedTextures[resource.ResourceId];
            var batch = _spriteBatchLayers[layer];

            if (resource.PaletteName != null)
            {
                var palette = PaletteSystem.Get(resource.PaletteName);
                if (palette != null)
                {
                    VerifyPaletteSwaps(palette, resource.ResourceId, texture);
                    texture = this._paletteSwaps[resource.ResourceId][palette.CurrentIndex];
                }
            }

            var destination = new Vector2(position.X, position.Y);

            XnaRect? source = null;
            if (sourceRect != null)
                source = new XnaRect(sourceRect.Value.X, sourceRect.Value.Y, sourceRect.Value.Width, sourceRect.Value.Height);

            SpriteEffects effect = SpriteEffects.None;
            if (flipHorizontal) effect = SpriteEffects.FlipHorizontally;
            if (flipVertical) effect |= SpriteEffects.FlipVertically;

            batch.Draw(texture,
                destination, source,
                _opacityColor, 0,
                Vector2.Zero, 1, effect, 0);
        }
        public bool CollidesWidth(ConnectedScreenSegment otherSegment)
        {
            var myRect = new Rectangle(Location.X, Location.Y, Width, Height);
            var otherRect = new Rectangle(otherSegment.Location.X, otherSegment.Location.Y, otherSegment.Width, otherSegment.Height);

            if (Rectangle.Intersect(myRect, otherRect) == Rectangle.Empty)
            {
                return false;
            }

            return _screens.Any(s => otherSegment._screens.Any(o => Rectangle.Intersect(s.GetLocation(this.Location), o.GetLocation(otherSegment.Location)) != Rectangle.Empty));
        }
        public static WriteableBitmap GetOrLoadFrameGrayscale(string imagePath, Rectangle srcRect)
        {
            var tuple = Tuple.Create(srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height);

            if (!croppedImagesGrayscale.ContainsKey(imagePath))
            {
                croppedImagesGrayscale[imagePath] = new Dictionary<Tuple<int, int, int, int>, WriteableBitmap>();
            }

            if (!croppedImagesGrayscale[imagePath].ContainsKey(tuple))
            {
                var grayscale = GetOrLoadImageGrayscale(imagePath);
                var frame = CropFrame(ref srcRect, grayscale);

                croppedImagesGrayscale[imagePath][tuple] = frame;
            }

            return croppedImagesGrayscale[imagePath][tuple];
        }
Esempio n. 4
0
 public void Intersect(Rectangle rect)
 {
     Rectangle rectangle = Rectangle.Intersect(rect, this);
     this.X = rectangle.X;
     this.Y = rectangle.Y;
     this.Width = rectangle.Width;
     this.Height = rectangle.Height;
 }
Esempio n. 5
0
 public bool Contains(Rectangle rect)
 {
     return this.X <= rect.X && rect.X + rect.Width <= this.X + this.Width && this.Y <= rect.Y && rect.Y + rect.Height <= this.Y + this.Height;
 }
Esempio n. 6
0
 public static Rectangle Union(Rectangle a, Rectangle b)
 {
     int num = Math.Min(a.X, b.X);
     int num2 = Math.Max(a.X + a.Width, b.X + b.Width);
     int num3 = Math.Min(a.Y, b.Y);
     int num4 = Math.Max(a.Y + a.Height, b.Y + b.Height);
     return new Rectangle(num, num3, num2 - num, num4 - num3);
 }
Esempio n. 7
0
 public static Rectangle Intersect(Rectangle a, Rectangle b)
 {
     int num = Math.Max(a.X, b.X);
     int num2 = Math.Min(a.X + a.Width, b.X + b.Width);
     int num3 = Math.Max(a.Y, b.Y);
     int num4 = Math.Min(a.Y + a.Height, b.Y + b.Height);
     if (num2 >= num && num4 >= num3)
     {
         return new Rectangle(num, num3, num2 - num, num4 - num3);
     }
     return Rectangle.Empty;
 }
        private static WriteableBitmap CropFrame(ref Rectangle srcRect, BitmapSource source)
        {
            var x = Math.Min(srcRect.X, source.PixelWidth - 1);
            var y = Math.Min(srcRect.Y, source.PixelHeight - 1);
            x = Math.Max(x, 0);
            y = Math.Max(y, 0);

            var right = srcRect.X + srcRect.Width;
            right = Math.Min(right, source.PixelWidth);
            right = Math.Max(right, 0);

            var bottom = srcRect.Y + srcRect.Height;
            bottom = Math.Min(bottom, source.PixelHeight);
            bottom = Math.Max(bottom, 0);

            var crop = new CroppedBitmap(source, new Int32Rect(x, y, right - x, bottom - y));
            crop.Freeze();

            var bmp = BitmapFactory.ConvertToPbgra32Format(crop);
            return bmp;
        }
Esempio n. 9
0
        public void SetSelection(int tx, int ty, int width, int height)
        {
            if (width != 0 && height != 0)
            {
                if (tx < 0)
                {
                    width += tx;
                    tx = 0;
                }
                if (ty < 0)
                {
                    height += ty;
                    ty = 0;
                }

                if (width + tx > Width) width = Width - tx;
                if (height + ty > Height) height = Height - ty;

                // all in tile sizes
                Selection = new Rectangle(tx, ty, width, height);
            }
            else
            {
                Selection = null;
            }

            if (SelectionChanged != null)
            {
                SelectionChanged(Selection);
            }

            ViewModelMediator.Current.GetEvent<SelectionChangedEventArgs>().Raise(this, new SelectionChangedEventArgs() { Screen = this, Selection = Selection });
        }
 private void UpdateSelection(Rectangle? bounds)
 {
     _selectionBounds = bounds;
 }