protected void DrawTiles() { if (_highlightedTile > -1) { Point pos = GetPosOfTile(_highlightedTile); int halfPadding = _padding / 2; pos.X -= halfPadding - this.AutoScrollPosition.X; pos.Y -= halfPadding - this.AutoScrollPosition.Y; DrawingManager.DrawFilledRectangle(ParentGrid.Layer, new Vector2(pos.X, pos.Y), new Vector2(ParentGrid.TileSize.X + _padding, ParentGrid.TileSize.Y + _padding), Color.DarkGray, ParentGrid.BlendingType); } if (TileGridEditor.Instance.SelectedBrushTile > -1) { Point pos = GetPosOfTile(TileGridEditor.Instance.SelectedBrushTile); int halfPadding = _padding / 2; pos.X -= halfPadding - this.AutoScrollPosition.X; pos.Y -= halfPadding - this.AutoScrollPosition.Y; DrawingManager.DrawFilledRectangle(ParentGrid.Layer, new Vector2(pos.X, pos.Y), new Vector2(ParentGrid.TileSize.X + _padding, ParentGrid.TileSize.Y + _padding), Color.White, ParentGrid.BlendingType); } for (int i = 0; i < _rowsCountOnTexture * ParentGrid.ColumnsCountOnTexture; i++) { DrawRequest drawRequest = default(DrawRequest); drawRequest.scaleRatio = Vector2.One; drawRequest.tint = Color.White; drawRequest.texture = ParentGrid.Material.Texture; Point pos = GetPosOfTile(i); drawRequest.position.X = pos.X + this.AutoScrollPosition.X; drawRequest.position.Y = pos.Y + this.AutoScrollPosition.Y; drawRequest.sourceRectangle = ParentGrid.GetSourceRectOfTile(i); DrawingManager.DrawOnLayer(drawRequest, 1, DrawingBlendingType.Alpha); } }
protected void DrawTileSelection(int tileX, int tileY) { Color fillColor = new Color(80, 100, 150, 150); Vector2 pos = new Vector2(tileX * TileGrid.TileSize.X * TileGrid.Scale.X, tileY * TileGrid.TileSize.Y * TileGrid.Scale.Y); Vector2 size = new Vector2(TileGrid.TileSize.X * TileGrid.Scale.X, TileGrid.TileSize.Y * TileGrid.Scale.Y); DrawingManager.DrawFilledRectangle(TileGrid.Layer, pos, size, fillColor, TileGrid.BlendingType); DebugShapes.DrawRectangle(new Rectangle((int)(pos.X + 1), (int)(pos.Y + 1), (int)size.X - 2, (int)size.Y - 2), Color.Aquamarine); }
protected void DrawBrushTileHighlight(Color color) { if (_brushStartPoint.X > -1 && _brushStartPoint.Y > -1) { Point clampedSize = _brushSize; clampedSize.X = IceMath.Clamp(_brushStartPoint.X + clampedSize.X, 0, TileGrid.TileCols) - _brushStartPoint.X; clampedSize.Y = IceMath.Clamp(_brushStartPoint.Y + clampedSize.Y, 0, TileGrid.TileRows) - _brushStartPoint.Y; Vector2 pos = new Vector2(_brushStartPoint.X * TileGrid.TileSize.X * TileGrid.Scale.X, _brushStartPoint.Y * TileGrid.TileSize.Y * TileGrid.Scale.Y); Vector2 size = new Vector2(clampedSize.X * TileGrid.TileSize.X * TileGrid.Scale.X, clampedSize.Y * TileGrid.TileSize.Y * TileGrid.Scale.Y); DrawingManager.DrawFilledRectangle(TileGrid.Layer, pos, size, color, TileGrid.BlendingType); } }
protected void DrawPastingSelection(int tileX, int tileY) { if (tileX == -1 || tileY == -1) { return; } Color fillColor = new Color(200, 0, 0, 128); foreach (TileCopy tileCopy in _clipboardTiles) { Point tilePos = new Point(); tilePos.X = tileX + tileCopy.Displacement.X; tilePos.Y = tileY + tileCopy.Displacement.Y; if (tilePos.X < TileGrid.TileCols && tilePos.Y < TileGrid.TileRows) { Vector2 pos = new Vector2(tilePos.X * TileGrid.TileSize.X * TileGrid.Scale.X, tilePos.Y * TileGrid.TileSize.Y * TileGrid.Scale.Y); Vector2 size = new Vector2(TileGrid.TileSize.X * TileGrid.Scale.X, TileGrid.TileSize.Y * TileGrid.Scale.Y); DrawingManager.DrawFilledRectangle(TileGrid.Layer, pos, size, fillColor, TileGrid.BlendingType); } } }
/// <summary> /// Draws the control, using SpriteBatch and SpriteFont. /// </summary> protected override void Draw() { ParentEditor.ZoomBox.Camera.Update(1 / 60f); GraphicsDevice.Clear(Color.RoyalBlue); // Use SpriteSortMode.Immediate, so we can apply custom renderstates. _spriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.LinearWrap, null, null); // Set the texture addressing mode to wrap, so we can repeat // many copies of our tiled checkerboard texture. _sprite.Pivot = Vector2.Zero; _sprite.Position = Vector2.Zero; Rectangle fullRect = new Rectangle(0, 0, this.Width, this.Height); Rectangle spriteRect = new Rectangle(0, 0, _sprite.Material.Texture.Width, _sprite.Material.Texture.Height);; Point textureSize = new Point(_sprite.Material.Texture.Width, _sprite.Material.Texture.Height); if (!ShowWholeImage) { if (_sprite.SourceRectangle != null) { Rectangle rect = _sprite.SourceRectangle.Value; spriteRect = new Rectangle(0, 0, rect.Width, rect.Height); textureSize = new Point(rect.Width, rect.Height); } } ParentEditor.ZoomBox.Camera.Position = new Vector2(-this.AutoScrollPosition.X, -this.AutoScrollPosition.Y); // Draw a tiled checkerboard pattern in the background. _spriteBatch.Draw(_crossTexture, fullRect, fullRect, Color.White); _spriteBatch.Draw(_checkerTexture, new Rectangle(0, 0, (int)(spriteRect.Width * _sprite.Scale.X * ParentEditor.ZoomBox.ZoomFactor), (int)(spriteRect.Height * _sprite.Scale.Y * ParentEditor.ZoomBox.ZoomFactor)), new Rectangle(0, 0, (int)(spriteRect.Width * _sprite.Scale.X * ParentEditor.ZoomBox.ZoomFactor), (int)(spriteRect.Height * _sprite.Scale.Y * ParentEditor.ZoomBox.ZoomFactor)), Color.White); _spriteBatch.End(); this.AutoScrollMinSize = new System.Drawing.Size((int)(textureSize.X * _sprite.Scale.X * ParentEditor.ZoomBox.ZoomFactor), (int)(textureSize.Y * _sprite.Scale.Y * ParentEditor.ZoomBox.ZoomFactor)); if (ShowWholeImage) { Rectangle?_srcRectangle = _sprite.SourceRectangle; _sprite.SourceRectangle = null; _sprite.Draw(1f); _sprite.SourceRectangle = _srcRectangle; if (_sprite.SourceRectangle.HasValue) { SquidEngine.Drawing.DebugShapes.DrawRectangle(_sprite.SourceRectangle.Value, Color.Yellow); } } else { _sprite.Draw(1f); } // if selection a rectangle, draw a fading selection if (_selectionMode == SpriteEditorSelectionMode.SelectingTile) { Rectangle hRect = _spriteRectangles[_selectedRectangle]; Color rectColor = new Color(255, 255, 255, (byte)_alphaCounter); Color highlightRectColor = new Color(155, 225, 255, (byte)_alphaCounter); foreach (var rect in this.Sprite.Material.Areas) { Color color = rectColor; if (rect.Key == _selectedRectangle) { color = highlightRectColor; } DrawingManager.DrawFilledRectangle(1, new Vector2(rect.Value.X, rect.Value.Y), new Vector2(rect.Value.Width, rect.Value.Height), color, DrawingBlendingType.Alpha); } if (_alphaGoingUp) { _alphaCounter += 8; if (_alphaCounter > 190) { _alphaCounter = 190; _alphaGoingUp = false; } } else { _alphaCounter -= 8; if (_alphaCounter < 40) { _alphaCounter = 40; _alphaGoingUp = true; } } } DrawingManager.ViewPortSize = new Point(this.Width, this.Height); SquidEditorForm.SwapCameraAndRenderScene(ParentEditor.ZoomBox.Camera); _parent.Update(1 / 60f); }
protected override void Draw() { DrawingManager.ViewPortSize = new Point(this.Width, this.Height); ParentEditor.ZoomBox.Camera.Update(1 / 60f); GraphicsDevice.Clear(Color.CornflowerBlue); // Use SpriteSortMode.Immediate, so we can apply custom renderstates. _spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState); // Set the texture addressing mode to wrap, so we can repeat // many copies of our tiled checkerboard texture. GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap; GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap; Rectangle fullRect = new Rectangle(0, 0, this.Width, this.Height); // Draw a tiled checkerboard pattern in the background. _spriteBatch.Draw(_checkerTexture, fullRect, fullRect, new Color(64, 64, 92)); if (CompositeEntity == null) { _spriteBatch.End(); } else { _spriteBatch.End(); float gridSize = 100000; DrawingManager.DrawFilledRectangle(10, new Vector2(-gridSize, 0), new Vector2(gridSize * 2, 1), new Color(128, 128, 128, 40), DrawingBlendingType.Alpha); DrawingManager.DrawFilledRectangle(10, new Vector2(0, -gridSize), new Vector2(1, gridSize * 2), new Color(128, 128, 128, 40), DrawingBlendingType.Alpha); DrawingManager.DrawFilledRectangle(10, new Vector2(-gridSize, 213), new Vector2(gridSize * 2, 1), new Color(255, 0, 255, 0), DrawingBlendingType.Alpha); CompositeEntity.Position = new Vector2(0); if (ParentEditor.SelectedCompositeKeyFrame != null) { DrawKeyFrame(ParentEditor.SelectedCompositeKeyFrame); if (String.IsNullOrEmpty(this.HighlightedBone) == false) { DrawBoneSceneItemBoundingRect(this.HighlightedBone, Color.Gray); } foreach (String boneTransformRef in this.SelectedBones) { DrawBoneSceneItemBoundingRect(boneTransformRef, Color.Blue); } if (_refreshSceneItemProperties == true) { ParentEditor.propertyGridCompositeBoneTransform.SelectedObject = this.ParentEditor.SelectedCompositeBoneTransform; _refreshSceneItemProperties = false; } } MilkshakeForm.SwapCameraAndRenderScene(ParentEditor.ZoomBox.Camera); // draw Pivot if (String.IsNullOrEmpty(this.HighlightedBone) != true) { _spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None); Vector2 offset = new Vector2(this.Width / 2f, this.Height / 2f); CompositeBoneTransform boneTransform = ParentEditor.SelectedCompositeKeyFrame.GetBoneTransformFromKeyFrame( ParentEditor.SelectedCompositeKeyFrame, this.HighlightedBone); SceneItem boneTransformSceneItem = boneTransform.GetSceneItem(); if (boneTransform.IsVisible == true && boneTransformSceneItem != null) { Rectangle boundingRect = boneTransformSceneItem.BoundingRect; Vector2 pivotPos = offset + boneTransformSceneItem.GetAbsolutePivot(true) + new Vector2(boundingRect.X, boundingRect.Y); _spriteBatch.Draw(_pivotTexture, pivotPos, null, Color.White, 0, new Vector2(6.5f), Vector2.One, SpriteEffects.None, 1); } _spriteBatch.End(); } } if (ParentEditor.UpdatePreview == true) { ParentEditor.UpdatePreview = false; ParentEditor.PreviewAnimation(); } ParentEditor.Update(1 / 60f); }
protected override void Draw() { DrawingManager.ViewPortSize = new Point(this.Width, this.Height); Update(1 / 60f); ParentEditor.ZoomBox.Camera.Position = new Vector2(-this.AutoScrollPosition.X, -this.AutoScrollPosition.Y); ParentEditor.ZoomBox.Camera.Update(1 / 60f); Vector2 sizeRatio = new Vector2( (float)this.Size.Width / ((float)this.Size.Width * ParentEditor.ZoomBox.Camera.Zoom.X), (float)this.Size.Height / ((float)this.Size.Height * ParentEditor.ZoomBox.Camera.Zoom.Y)); GraphicsDevice.Clear(Color.White); // Use SpriteSortMode.Immediate, so we can apply custom renderstates. _spriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.LinearWrap, null, null); // Set the texture addressing mode to wrap, so we can repeat // many copies of our tiled checkerboard texture. Rectangle fullRect = new Rectangle(0, 0, this.Width, this.Height); // Draw a tiled crossed pattern in the background. _spriteBatch.Draw(_crossTexture, fullRect, fullRect, Color.White); _spriteBatch.Draw(_checkerTexture, new Rectangle(0, 0, (int)(_tileGrid.BoundingRect.Width * ParentEditor.ZoomBox.Camera.Zoom.X), (int)(_tileGrid.BoundingRect.Height * ParentEditor.ZoomBox.Camera.Zoom.Y)), new Rectangle(0, 0, (int)(_tileGrid.BoundingRect.Width * ParentEditor.ZoomBox.Camera.Zoom.X), (int)(_tileGrid.BoundingRect.Height * ParentEditor.ZoomBox.Camera.Zoom.Y)), Color.White); _spriteBatch.End(); this.AutoScrollMinSize = new System.Drawing.Size((int)(_tileGrid.BoundingRect.Width * ParentEditor.ZoomBox.Camera.Zoom.X), (int)(_tileGrid.BoundingRect.Height * ParentEditor.ZoomBox.Camera.Zoom.Y)); Vector2 pos = _tileGrid.Position; _tileGrid.Position = Vector2.Zero; _tileGrid.Pivot = Vector2.Zero; _tileGrid.Draw(1 / 60f); _tileGrid.Position = pos; //_camera.Position += _tileGrid.Position; if (PaintMode == TileGridPaintMode.Brush) { DrawBrushTileHighlight(new Color(25, 255, 100, 150)); } else if (PaintMode == TileGridPaintMode.Bucket) { DrawBrushTileHighlight(new Color(25, 100, 255, 150)); _brushSize = new Point(1, 1); } else if (PaintMode == TileGridPaintMode.Eraser) { DrawBrushTileHighlight(new Color(255, 0, 0, 150)); } else if (PaintMode == TileGridPaintMode.Edit) { foreach (Point tile in _selectedTiles) { DrawTileSelection(tile.X, tile.Y); } if (_isPastingTiles) { DrawPastingSelection(_drawPosPastingSelection.X, _drawPosPastingSelection.Y); } } else if (PaintMode == TileGridPaintMode.Passage) { for (int y = 0; y < _tileGrid.TileRows; ++y) { for (int x = 0; x < _tileGrid.TileCols; ++x) { Color fillColor; if (TileGrid.TileLayers[0].Tiles[x][y].Passable) { fillColor = new Color(80, 100, 150, 150); } else { fillColor = new Color(80, 0, 15, 150); } Vector2 position = new Vector2(x * TileGrid.TileSize.X * TileGrid.Scale.X, y * TileGrid.TileSize.Y * TileGrid.Scale.Y); Vector2 size = new Vector2(TileGrid.TileSize.X * TileGrid.Scale.X, TileGrid.TileSize.Y * TileGrid.Scale.Y); DrawingManager.DrawFilledRectangle(TileGrid.Layer, position, size, fillColor, TileGrid.BlendingType); } } } if (_drawGrid == true) { DrawGridLines(); } SquidEditorForm.SwapCameraAndRenderScene(ParentEditor.ZoomBox.Camera); _parent.Update(1 / 60f); }