示例#1
0
        public IBitmap ApplyArea(IArea area)
        {
            //todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
            //This will require to change the rendering as well to offset the location
            byte    zero = (byte)0;
            UIImage output;

            using (FastBitmap inBmp = new FastBitmap(_cgImage))
            {
                using (FastBitmap outBmp = new FastBitmap(Width, Height))
                {
                    for (int y = 0; y < Height; y++)
                    {
                        int bitmapY = Height - y - 1;
                        for (int x = 0; x < Width; x++)
                        {
                            var  color = inBmp.GetPixel(x, bitmapY);
                            byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
                            outBmp.SetPixel(x, bitmapY, Color.FromRgba(color.R, color.G, color.B, alpha));
                        }
                    }
                    output = outBmp.GetImage();
                }
            }

            return(new IOSBitmap(output, _graphics));
        }
示例#2
0
        public IBitmap ApplyArea(IArea area)
        {
            //todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
            //This will require to change the rendering as well to offset the location
            byte   zero   = (byte)0;
            Bitmap output = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            using (FastBitmap inBmp = new FastBitmap(_bitmap, ImageLockMode.ReadOnly))
            {
                using (FastBitmap outBmp = new FastBitmap(output, ImageLockMode.WriteOnly, true))
                {
                    for (int y = 0; y < Height; y++)
                    {
                        int bitmapY = Height - y - 1;
                        for (int x = 0; x < Width; x++)
                        {
                            System.Drawing.Color color = inBmp.GetPixel(x, bitmapY);
                            byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
                            outBmp.SetPixel(x, bitmapY, System.Drawing.Color.FromArgb(alpha, color));
                        }
                    }
                }
            }

            return(new DesktopBitmap(output, _graphics));
        }
示例#3
0
        public IBitmap ApplyArea(IArea area)
        {
            //todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
            //This will require to change the rendering as well to offset the location
            byte   zero   = (byte)0;
            Bitmap output = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888);

            using (FastBitmap inBmp = new FastBitmap(_bitmap))
            {
                using (FastBitmap outBmp = new FastBitmap(output, true))
                {
                    for (int y = 0; y < Height; y++)
                    {
                        int bitmapY = Height - y - 1;
                        for (int x = 0; x < Width; x++)
                        {
                            global::Android.Graphics.Color color = inBmp.GetPixel(x, bitmapY);
                            byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
                            outBmp.SetPixel(x, bitmapY, new global::Android.Graphics.Color(color.R, color.G, color.B, alpha));
                        }
                    }
                }
            }

            return(new AndroidBitmap(output, _graphics));
        }
示例#4
0
		public IBitmap ApplyArea(IArea area)
		{
			//todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
			//This will require to change the rendering as well to offset the location
			byte zero = (byte)0;
			Bitmap output = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888);
			using (FastBitmap inBmp = new FastBitmap (_bitmap))
			{
				using (FastBitmap outBmp = new FastBitmap (output, true))
				{
					for (int y = 0; y < Height; y++)
					{
						int bitmapY = Height - y - 1;
						for (int x = 0; x < Width; x++)
						{
							global::Android.Graphics.Color color = inBmp.GetPixel(x, bitmapY);
							byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
							outBmp.SetPixel(x, bitmapY, new global::Android.Graphics.Color(color.R, color.G, color.B, alpha));
						}
					}
				}
			}

            return new AndroidBitmap(output, _graphics);
		}
示例#5
0
        public bool CollidesWith(float x, float y)
        {
            ISquare boundingBox = BoundingBox;

            if (boundingBox == null)
            {
                return(false);
            }
            IArea pixelPerfect = _pixelPerfect.PixelPerfectHitTestArea;

            if (_drawableInfo.IgnoreViewport && _state != null)
            {
                var viewport = _state.Room.Viewport;
                //todo: Support viewport rotation (+ ignore scaling areas = false?)
                x = (x - viewport.X) * viewport.ScaleX;
                y = (y - viewport.Y) * viewport.ScaleY;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (boundingBox.Contains(new PointF(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, _scale.ScaleX * _obj.Animation.Sprite.ScaleX,
                                          _scale.ScaleY * _obj.Animation.Sprite.ScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#6
0
		public IBitmap ApplyArea(IArea area)
		{
			//todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
			//This will require to change the rendering as well to offset the location
			byte zero = (byte)0;
			Bitmap output = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
			using (FastBitmap inBmp = new FastBitmap (_bitmap, ImageLockMode.ReadOnly))
			{
				using (FastBitmap outBmp = new FastBitmap (output, ImageLockMode.WriteOnly, true))
				{
					for (int y = 0; y < Height; y++)
					{
						int bitmapY = Height - y - 1;
						for (int x = 0; x < Width; x++)
						{
							System.Drawing.Color color = inBmp.GetPixel(x, bitmapY);
							byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
							outBmp.SetPixel(x, bitmapY, System.Drawing.Color.FromArgb(alpha, color));
						}
					}
				}
			}

            return new DesktopBitmap(output, _graphics);
		}
示例#7
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            if (_crop?.IsGuaranteedToFullyCrop() ?? false)
            {
                //This should not be needed as the bounding box should be cropped anyway.
                //However, for a performance optimization if an entity is guaranteed to be fully cropped (like items in the bottom of a long listbox) the bounding box is not calculated, so we need to take it into account here.
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxesComponent.WorldBoundingBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null || !pixelPerfectComponent.IsPixelPerfect ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            var drawable = _drawableInfo;

            if (drawable != null && !drawable.IgnoreViewport)
            {
                var matrix = viewport.GetMatrix(drawable.RenderLayer);
                matrix.Invert();
                Vector3 xyz = new Vector3(x, y, 0f);
                Vector3.Transform(ref xyz, ref matrix, out xyz);
                //todo: (support ignore scaling areas = false?)
                x = xyz.X;
                y = xyz.Y;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.CurrentSprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.CurrentSprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#8
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            var boundingBoxes = boundingBoxesComponent.GetBoundingBoxes(viewport);

            if (boundingBoxes == null)
            {
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxes.HitTestBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            if (_drawableInfo?.IgnoreViewport ?? false)
            {
                //todo: Support viewport rotation (+ ignore scaling areas = false?)
                x = (x - viewport.X) * viewport.ScaleX;
                y = (y - viewport.Y) * viewport.ScaleY;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.Animation.Sprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.Animation.Sprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#9
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxesComponent.WorldBoundingBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null || !pixelPerfectComponent.IsPixelPerfect ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            if (!(_drawableInfo?.IgnoreViewport ?? false))
            {
                var matrix = viewport.GetMatrix(_drawableInfo.RenderLayer);
                matrix.Invert();
                Vector3 xyz = new Vector3(x, y, 0f);
                Vector3.Transform(ref xyz, ref matrix, out xyz);
                //todo: (support ignore scaling areas = false?)
                x = xyz.X;
                y = xyz.Y;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.CurrentSprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.CurrentSprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }