Example #1
0
        private void DrawInternal(DeviceContext pContext, BitmapResource pBitmap, Vector2 pPosition, Size pSize)
        {
            _effects[0].SetInput(0, pBitmap.DirectXBitmap, false);

            float widthFactor;
            float heightFactor;

            if (_useTiledScaling)
            {
                widthFactor  = Game.ActiveCamera.Zoom;
                heightFactor = Game.ActiveCamera.Zoom;
            }
            else
            {
                widthFactor  = pSize.Width / pBitmap.Width;
                heightFactor = pSize.Height / pBitmap.Height;
            }

            var scale = new SharpDX.Direct2D1.Effect(_context, Scale);

            scale.SetValue(0, new RawVector2(widthFactor, heightFactor));
            scale.SetInput(0, _effects[_effects.Count - 1].Output, false);

            if (pBitmap.Source.HasValue)
            {
                var r      = pBitmap.Source.Value;
                var source = new RawRectangleF(r.Left, r.Top, r.Left + pSize.Width, r.Top + pSize.Height);
                pContext.DrawImage(scale.Output, pPosition, source, InterpolationMode.Linear, CompositeMode.SourceOver);
            }
            else
            {
                pContext.DrawImage(_effects[_effects.Count - 1].Output, pPosition);
            }
        }
Example #2
0
        public Effect AddTile(BitmapResource pResource)
        {
            var e = new SharpDX.Direct2D1.Effect(_context, Tile);

            var rect = pResource.Source.HasValue ? pResource.Source.Value : new Rectangle(0, 0, pResource.Width, pResource.Height);

            e.SetValue(0, rect);
            _effects.Add(e);
            _useTiledScaling = true;
            return(this);
        }
Example #3
0
        public void DrawBitmap(BitmapResource pBitmap, float pOpacity, Vector2 pPosition, Size pScale)
        {
            var x = pPosition.X;
            var y = pPosition.Y;

            Context.DrawBitmap(pBitmap.DirectXBitmap,
                               new RawRectangleF(x, y, x + pScale.Width, y + pScale.Height),
                               pOpacity,
                               BitmapInterpolationMode.NearestNeighbor,
                               pBitmap.Source);
        }
Example #4
0
        public BitmapResource TileBitmap(BitmapResource pBitmap, int pTileWidth, int pTileHeight, int pXCount, int pYCount)
        {
            Bitmap b = new Bitmap(Context,
                                  new Size2(pXCount * pTileWidth, pYCount * pTileHeight),
                                  new BitmapProperties(pBitmap.DirectXBitmap.PixelFormat));

            for (int x = 0; x < pXCount; x++)
            {
                for (int y = 0; y < pYCount; y++)
                {
                    var posX = x * pTileWidth;
                    var posY = y * pTileHeight;
                    b.CopyFromBitmap(pBitmap.DirectXBitmap, new RawPoint(posX, posY), pBitmap.Source.Value);
                }
            }

            return(new BitmapResource()
            {
                DirectXBitmap = b
            });
        }
Example #5
0
        public BitmapResource ApplyTo(BitmapResource pBitmap, Size pScale)
        {
            var b = new Bitmap1(_context,
                                new SharpDX.Size2((int)pScale.Width, (int)pScale.Height),
                                new BitmapProperties1()
            {
                PixelFormat   = pBitmap.DirectXBitmap.PixelFormat,
                BitmapOptions = BitmapOptions.Target
            });

            var t = _context.Target;

            _context.Target = b;
            _context.BeginDraw();
            DrawInternal(_context, pBitmap, Vector2.Zero, pScale);
            _context.EndDraw();
            _context.Target = t;

            return(new BitmapResource()
            {
                DirectXBitmap = b
            });
        }
Example #6
0
 public SpriteStrip(BitmapResource pBitmap, Size pSize)
 {
     Bitmap    = pBitmap;
     FrameSize = pSize;
 }
Example #7
0
 public RenderComponent(BitmapResource pResource, int pZIndex) : this()
 {
     Bitmap = pResource;
     ZIndex = pZIndex;
 }
Example #8
0
 public void Draw(BitmapResource pBitmap, float pOpacity, Vector2 pPosition, Size pScale)
 {
     DrawInternal(((DirectXAdapter)Game.Graphics).Context, pBitmap, pPosition, pScale);
 }