示例#1
0
            public override void RenderContent(RenderLayer renderContext, SpriteBatch spriteBatch)
            {
                Dictionary <string, Texture2D> brushClassOverlays = _form._brushClassOverlays;
                DynamicTileBrush brush = _form._brush;

                if (!brushClassOverlays.ContainsKey(brush.BrushClass.ClassName))
                {
                    System.Drawing.Bitmap overlayBitmap = null;
                    if (brush.BrushClass.ClassName == "Basic")
                    {
                        overlayBitmap = Properties.Resources.DynBrushBasic;
                    }
                    else if (brush.BrushClass.ClassName == "Extended")
                    {
                        overlayBitmap = Properties.Resources.DynBrushExtended;
                    }
                    else
                    {
                        return;
                    }

                    TextureResource overlayResource = TextureResourceBitmapExt.CreateTextureResource(overlayBitmap);
                    brushClassOverlays.Add(brush.BrushClass.ClassName, overlayResource.CreateTexture(spriteBatch.GraphicsDevice));
                }

                Texture2D overlay = brushClassOverlays[brush.BrushClass.ClassName];

                int width  = (int)(overlay.Width * renderContext.LevelGeometry.ZoomFactor * (brush.TileWidth / 16.0));
                int height = (int)(overlay.Height * renderContext.LevelGeometry.ZoomFactor * (brush.TileHeight / 16.0));

                Microsoft.Xna.Framework.Rectangle dstRect = new Microsoft.Xna.Framework.Rectangle(0, 0, width, height);
                spriteBatch.Draw(overlay, dstRect, new Microsoft.Xna.Framework.Color(1f, 1f, 1f, .5f));
            }
示例#2
0
        public Texture2D Resolve(Guid textureId)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("TextureCache");
            }

            if (_device == null || _sourcePool == null)
            {
                return(null);
            }

            Texture2D tex;

            if (_cache.TryGetValue(textureId, out tex) && tex != null)
            {
                return(tex);
            }

            TextureResource resource = _sourcePool.GetResource(textureId);

            if (resource != null)
            {
                tex = resource.CreateTexture(_device);
                _cache.Add(textureId, tex);
            }

            return(tex);
        }
示例#3
0
        private void DrawObjectAction(DrawBatch drawBatch)
        {
            if (_sourceImage == null)
            {
                return;
            }

            drawBatch.GraphicsDevice.ScissorRectangle = Xna.Rectangle.Empty;

            if (_objectBrush == null)
            {
                _objectBrush = new TextureBrush(_sourceImage.CreateTexture(_drawControl.GraphicsDevice))
                {
                    OwnsTexture = true
                }
            }
            ;
            if (_maskPen == null)
            {
                _maskPen = new Pen(new CheckerBrush(_drawControl.GraphicsDevice, Xna.Color.Black, Xna.Color.White, 4, .75f), true);
            }

            int originX = (_drawControl.Width - _sourceImage.Width) / 2;
            int originY = (_drawControl.Height - _sourceImage.Height) / 2;

            _objectBrush.Transform = Xna.Matrix.CreateTranslation(-(float)originX / _sourceImage.Width, -(float)originY / _sourceImage.Height, 0);

            drawBatch.Begin();

            drawBatch.FillRectangle(_objectBrush, new Xna.Rectangle(originX, originY, _sourceImage.Width, _sourceImage.Height));
            drawBatch.DrawRectangle(_maskPen, new Microsoft.Xna.Framework.Rectangle(
                                        originX - 1 + (_maskLeft ?? 0) + (_originX ?? 0),
                                        originY - 1 + (_maskTop ?? 0) + (_originY ?? 0),
                                        1 + (_maskRight - _maskLeft) ?? 0,
                                        1 + (_maskBottom - _maskTop) ?? 0));

            drawBatch.FillCircle(Brush.White, new Xna.Vector2(originX + _originX ?? 0, originY + _originY ?? 0), 4, 12);
            drawBatch.FillCircle(Brush.Black, new Xna.Vector2(originX + _originX ?? 0, originY + _originY ?? 0), 3, 12);

            drawBatch.End();
        }