Ejemplo n.º 1
0
        /// <summary>
        /// Intra-layer drawing event handler for rendering wind-swept leaves
        /// </summary>
        /// <param name="layerEventArgs"></param>
        private void OnBeforeLayerDraw(object sender, LayerEventArgs layerEventArgs)
        {
            SpriteBatch spriteBatch = m_xnaDisplayDevice.SpriteBatchAlpha;

            foreach (Vector2 vecLeaf in m_vecLeafPositions)
            {
                float fRotation = ((vecLeaf.X + vecLeaf.Y) * 0.01f) % MathHelper.TwoPi;
                spriteBatch.Draw(m_textureLeaf, vecLeaf, null, Color.White, fRotation, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);
            }
        }
Ejemplo n.º 2
0
        private void OnBeforeLayerDraw(object sender, LayerEventArgs layerEventArgs)
        {
            m_graphics.PixelOffsetMode = PixelOffsetMode.Half;

            if (layerEventArgs.Layer != m_selectedLayer)
                return;

            if (m_layerCompositing == LayerCompositing.DimUnselected)
            {
                // set translucency for current layer
                m_colorMatrix.Matrix33 = 1.0f;
                m_imageAttributes.SetColorMatrix(m_colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            }
        }
Ejemplo n.º 3
0
        private void OnBeforeLayerDraw(object sender, LayerEventArgs layerEventArgs)
        {
            SpriteBatch spriteBatch = m_xnaDisplayDevice.SpriteBatchAlpha;

            Vector2 vet = new Vector2(_player.BoundingBox.X,_player.BoundingBox.Y);
            spriteBatch.Draw(_player.Texture, vet, _player.SourceRect, Color.White, 0f, _player.Origin, 1.0f, SpriteEffects.None, 0.0f);
        }
Ejemplo n.º 4
0
        private void OnAfterLayerDraw(object sender, LayerEventArgs layerEventArgs)
        {
            if (layerEventArgs.Layer != m_selectedLayer)
                return;

            // alignment data
            Layer layer = layerEventArgs.Layer;
            xTile.Dimensions.Rectangle viewport = layerEventArgs.Viewport;
            xTile.Dimensions.Size tileSize = layer.TileSize;
            xTile.Dimensions.Location layerViewportLocation
                = m_selectedLayer.ConvertMapToLayerLocation(viewport.Location, m_viewport.Size);

            // tile guide
            if (m_tileGuides)
            {
                int offsetX = layerViewportLocation.X % tileSize.Width;
                int offsetY = layerViewportLocation.Y % tileSize.Height;
                for (int guideY = -offsetY; guideY < viewport.Size.Height; guideY += tileSize.Height)
                    m_graphics.DrawLine(m_tileGuidePen, 0, guideY, m_viewport.Size.Width, guideY);

                m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                for (int guideX = -offsetX; guideX < viewport.Size.Width; guideX += tileSize.Width)
                    m_graphics.DrawLine(m_tileGuidePen, guideX, 0, guideX, m_viewport.Size.Height);
            }

            // tile selections
            if (!m_tileSelection.IsEmpty())
            {
                Location tileViewportLocation = new Location(
                    layerViewportLocation.X / tileSize.Width, layerViewportLocation.Y / tileSize.Height);
                xTile.Dimensions.Size tileViewportSize = viewport.Size;
                tileViewportSize.Width /= tileSize.Width;
                tileViewportSize.Height /= tileSize.Height;
                tileViewportSize.Width++;
                tileViewportSize.Height++;

                m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                Location tileLocation = tileViewportLocation;
                for (;  tileLocation.Y <= tileViewportLocation.Y + tileViewportSize.Height; tileLocation.Y++)
                    for (tileLocation.X = tileViewportLocation.X;
                        tileLocation.X <= tileViewportLocation.X + tileViewportSize.Width; tileLocation.X++)
                    {
                        if (m_tileSelection.Contains(tileLocation))
                        {
                            xTile.Dimensions.Rectangle tileRectangle = m_selectedLayer.GetTileDisplayRectangle(viewport, tileLocation);
                            int x1 = tileRectangle.Location.X;
                            int y1 = tileRectangle.Location.Y;
                            int width = tileRectangle.Size.Width;
                            int height = tileRectangle.Size.Height;
                            int x2 = x1 + width;
                            int y2 = y1 + height;

                            m_graphics.FillRectangle(m_tileSelectionBrush, x1, y1 , width, height);

                            // selection borders
                            TileSelectionBorder tileSelectionBorder = m_tileSelection.GetTileSelectionBorder(tileLocation);
                            if (tileSelectionBorder.Left)
                                m_graphics.DrawLine(Pens.DarkCyan, x1, y1, x1, y2);

                            if (tileSelectionBorder.Right)
                                m_graphics.DrawLine(Pens.DarkCyan, x2, y1, x2, y2);

                            if (tileSelectionBorder.Above)
                                m_graphics.DrawLine(Pens.DarkCyan, x1, y1, x2, y1);

                            if (tileSelectionBorder.Below)
                                m_graphics.DrawLine(Pens.DarkCyan, x1, y2, x2, y2);
                        }
                    }
            }

            // highlight tile under mouse cursor
            if (m_mouseInside)
            {
                xTile.Dimensions.Rectangle tileDisplayRectangle
                    = m_selectedLayer.GetTileDisplayRectangle(m_viewport, m_tileLayerLocation);
                xTile.Dimensions.Location tileDisplayLocation = tileDisplayRectangle.Location;

                if (m_bMouseDown && (m_editTool == EditTool.Select || m_editTool == EditTool.TileBlock) )
                {
                    xTile.Dimensions.Rectangle tileDragRectangle
                        = m_selectedLayer.GetTileDisplayRectangle(m_viewport, m_dragTileStart);
                    xTile.Dimensions.Location tileDragLocation = tileDragRectangle.Location;

                    int minX = Math.Min(tileDragLocation.X, tileDisplayLocation.X);
                    int minY = Math.Min(tileDragLocation.Y, tileDisplayLocation.Y);
                    int maxX = Math.Max(tileDragLocation.X, tileDisplayLocation.X);
                    int maxY = Math.Max(tileDragLocation.Y, tileDisplayLocation.Y);

                    if (m_editTool == EditTool.TileBlock
                        && m_selectedTileSheet != null && m_selectedTileIndex >= 0)
                    {
                        m_graphics.PixelOffsetMode = PixelOffsetMode.Half;

                        Bitmap tileBitmap = TileImageCache.Instance.GetTileBitmap(m_selectedTileSheet, m_selectedTileIndex);
                        for (int tileY = minY; tileY <= maxY; tileY += tileSize.Height)
                            for (int tileX = minX; tileX <= maxX; tileX += tileSize.Width)
                                m_graphics.DrawImage(tileBitmap, tileX, tileY, tileSize.Width, tileSize.Height);
                    }

                    m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                    int selectionWidth = maxX + tileSize.Width - minX;
                    int selectionHeight = maxY + tileSize.Height - minY;
                    m_graphics.FillRectangle(m_tileSelectionBrush, minX, minY, selectionWidth, selectionHeight);
                    m_graphics.DrawRectangle(m_tileSelectionPen, minX, minY, selectionWidth, selectionHeight);
                }
                else if (m_editTool == EditTool.TileBrush)
                {
                    if (m_selectedTileBrush != null)
                    {
                        xTile.Dimensions.Location location = tileDisplayRectangle.Location;
                        xTile.Dimensions.Size brushSize = m_selectedTileBrush.BrushSize;
                        xTile.Dimensions.Size displaySize = m_selectedTileBrush.DisplaySize;

                        location.X -= (brushSize.Width / 2) * tileSize.Width;
                        location.Y -= (brushSize.Height / 2) * tileSize.Height;

                        m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                        m_colorMatrix.Matrix33 = 0.5f;
                        m_imageAttributes.SetColorMatrix(m_colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                        System.Drawing.Rectangle destRect
                            = new System.Drawing.Rectangle(location.X, location.Y,
                                displaySize.Width, displaySize.Height);
                        m_graphics.DrawImage(m_selectedTileBrush.ImageRepresentation, destRect,
                            0, 0, displaySize.Width, displaySize.Height, GraphicsUnit.Pixel, m_imageAttributes);
                    }
                }
                else
                {
                    xTile.Dimensions.Location location = tileDisplayRectangle.Location;
                    xTile.Dimensions.Size size = tileDisplayRectangle.Size;

                    m_graphics.PixelOffsetMode = PixelOffsetMode.None;

                    m_graphics.FillRectangle(m_tileSelectionBrush,
                        location.X, location.Y, size.Width, size.Height);
                    m_graphics.DrawRectangle(m_tileSelectionPen,
                        location.X, location.Y, size.Width, size.Height);
                }
            }

            if (m_layerCompositing == LayerCompositing.DimUnselected)
            {
                // set translucency for upper layers
                m_colorMatrix.Matrix33 = 0.25f;
                m_imageAttributes.SetColorMatrix(m_colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            }
        }
Ejemplo n.º 5
0
 private void MapCharacterDraw(object sender, LayerEventArgs layerEventArgs)
 {
     SpriteBatch spriteBatch = mapDisplayDevice.SpriteBatchAlpha;
     foreach (MapCharacter i in mapCharacter)
         if (i.Visible == true) { i.Draw(spriteBatch, viewportOffset); }
 }