public static void DrawFilledRectangle(int layer, Vector2 position, Vector2 size, Color color, DrawingBlendingType blendingType) { DrawRequest drawRequest = new DrawRequest(_pixelTexture, position, null, 0, size, Vector2.Zero, false, color, false, false, null); DrawOnLayer(drawRequest, layer, blendingType); }
public static void DrawLine(int layer, Vector2 start, Vector2 end, float size, Color color) { Vector2 vector = end - start; float lenght = vector.Length(); Vector2 scale = new Vector2(lenght, size); float angle = vector.Angle(); DrawRequest drawRequest = new DrawRequest(_pixelTexture, start, null, angle, scale, new Vector2(0f, 0.5f), false, color, false, false, null); DrawOnLayer(drawRequest, layer, DrawingBlendingType.Alpha); }
public void Draw(DrawRequest drawRequest) { _drawRequestCollection.Add(drawRequest); }
public Particle() { this._isActive = false; this._initialColorFloatValues = new Vector4(); this._drawRequest = default(DrawRequest); }
/// <summary> /// Draws the control. /// </summary> protected override void Draw() { ParentEditor.ZoomBox.Camera.Update(1 / 60f); if (particleEffect.Position != updatedPosition) { particleEffect.Position = updatedPosition; } particleEffect.Update(1 / 60f); _parent = Parent as ParticleEffectEditor; // if the animation was paused externally, pause it in the GUI if (particleEffect.Emitter.IsPaused == true && _parent.toolStripButtonPause.Enabled == true) { _parent.toolStripButtonPause_Click(null, EventArgs.Empty); } // if the animation was stopped externally, stop it in the GUI if (particleEffect.Emitter.IsStopped == true && _parent.toolStripButtonStop.Enabled == true) { _parent.toolStripButtonStop_Click(null, EventArgs.Empty); } if (background != null) { DrawRequest backgroundRequest = new DrawRequest(background, Vector2.Zero, false, null, 0, Vector2.One, new Vector2(0.5f), true, Color.White, false, false, null); DrawingManager.DrawOnLayer(backgroundRequest, 10, DrawingBlendingType.Alpha); } particleEffect.Draw(1f); GraphicsDevice.Clear(backgroundColor); DrawingManager.ViewPortSize = new Point(this.Width, this.Height); MilkshakeForm.SwapCameraAndRenderScene(ParentEditor.ZoomBox.Camera); ParentEditor.Update(1 / 60f); }
/// <summary> /// Draw a DrawRequest on the specified blending sub layer /// </summary> /// <param name="drawRequest"></param> /// <param name="blendingType"></param> public void Draw(DrawRequest drawRequest, DrawingBlendingType blendingType) { // Forward the request to the correct layer _components[(int)blendingType].Draw(drawRequest); }
/// <summary> /// Main rendering method. Renders all the requests of the current blending type /// </summary> /// <param name="device">The GraphicsDevice to render on</param> /// <param name="transformMatrix">The camera transform matrix</param> /// <returns>True if any drawing was performed on that layer, false otherwise</returns> public bool RenderLayerComponent(GraphicsDevice graphicsDevice, Matrix transformMatrix) { // only draw if there is pending requests bool drawNeeded = (_drawRequestCollection.Count > 0); if (drawNeeded) { // if the layer is a refraction one, we need to stop the spritebatch no matter what if (_useRefraction == true) { #if !XNATOUCH if (DrawingManager.DrawingLayerTypeInUse != null) { // stop the current batch DrawingManager.SpriteBatch.End(); } // resolve the current buffer to a texture DrawingManager.RenderTargetManager.ResolveToTexture(RenderTargetInstance.BackBuffer); // switch the temporary render target to draw the normal maps DrawingManager.RenderTargetManager.SwitchTo(RenderTargetInstance.A); graphicsDevice.Clear(new Color(0.5f, 0.5f, 0.0f, 0.0f)); // restart the spritebatch using Additive mode DrawingManager.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, transformMatrix); #endif } // smart check to see if we need to end the current spritebatch else { // Check if the spritebatch needs to be ended if (DrawingManager.DrawingLayerTypeInUse != null && DrawingManager.LastTransformMatrix.HasValue && (_type != DrawingManager.DrawingLayerTypeInUse.Value || DrawingManager.LastTransformMatrix.Value != transformMatrix)) { DrawingManager.DrawingLayerTypeInUse = null; DrawingManager.SpriteBatch.End(); } // If we need to begin the effect, use .Begin() first if (DrawingManager.DrawingLayerTypeInUse == null) { DrawingManager.LastTransformMatrix = transformMatrix; // Alpha types blending uses the AlphaBlend mode if (_type == DrawingLayerType.Alpha) { #if XNATOUCH DrawingManager.SpriteBatch.Begin(SpriteBlendMode.PreMultiplied, SpriteSortMode.Immediate, SaveStateMode.None, transformMatrix); #else DrawingManager.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, transformMatrix); #endif } // Additives and Subtractives types use Additive mode as the base else { DrawingManager.SpriteBatch.Begin(SpriteBlendMode.Additive, SpriteSortMode.Immediate, SaveStateMode.None, transformMatrix); if (_type == DrawingLayerType.Subtractive) { #if !XNATOUCH graphicsDevice.RenderState.BlendFunction = BlendFunction.ReverseSubtract; #endif } } } } // Use the current type as the one in use DrawingManager.DrawingLayerTypeInUse = _type; // Render all the requests for (int i = 0; i < _drawRequestCollection.Count; i++) { DrawRequest drawRequest = _drawRequestCollection[i]; if (drawRequest.isPivotRelative == true) { if (drawRequest.isFont == false) { // if the pivot is relative (instead of absolute pixel values) // multiply it by the texture or rect's size if (drawRequest.sourceRectangle.HasValue == true) { drawRequest.pivot = new Vector2(drawRequest.pivot.X * drawRequest.sourceRectangle.Value.Width, drawRequest.pivot.Y * drawRequest.sourceRectangle.Value.Height); } else { drawRequest.pivot = new Vector2(drawRequest.pivot.X * drawRequest.texture.Width, drawRequest.pivot.Y * drawRequest.texture.Height); } } else { drawRequest.pivot = new Vector2(drawRequest.pivot.X * drawRequest.textSize.X, drawRequest.pivot.Y * drawRequest.textSize.Y); } } Vector2 drawPosition = drawRequest.position; Vector2 drawScale = drawRequest.scaleRatio; if (drawRequest.IgnoreCamera) { // TO-DO: FIX THIS FOR MULTI CAM SUPPORT //drawPosition += SceneManager.ActiveScene.ActiveCameras[0].Position; Vector2 pos = drawPosition; pos = Vector2.Transform( pos, Matrix.CreateTranslation(new Vector3(SceneManager.GlobalDataHolder.NativeResolution.X, SceneManager.GlobalDataHolder.NativeResolution.Y, 0)) * Matrix.Invert(SceneManager.ActiveScene.ActiveCameras[0].Matrix)); drawPosition = pos; drawScale /= SceneManager.ActiveScene.ActiveCameras[0].Zoom.X; } if (drawRequest.texture != null) { DrawingManager.SpriteBatch.Draw( drawRequest.texture, drawPosition, drawRequest.sourceRectangle, drawRequest.tint, drawRequest.rotation, drawRequest.pivot, drawScale, (drawRequest.hFlip ? SpriteEffects.FlipHorizontally : SpriteEffects.None) | (drawRequest.vFlip ? SpriteEffects.FlipVertically : SpriteEffects.None), 0); } else if (drawRequest.font != null) { DrawingManager.SpriteBatch.DrawString(drawRequest.font, drawRequest.text, drawPosition, drawRequest.tint, drawRequest.rotation, drawRequest.pivot, drawScale, (drawRequest.hFlip ? SpriteEffects.FlipHorizontally : SpriteEffects.None) | (drawRequest.vFlip ? SpriteEffects.FlipVertically : SpriteEffects.None), 0); } } if (_useRefraction == true) { #if !XNATOUCH DrawingManager.SpriteBatch.End(); DrawingManager.RenderTargetManager.SwitchTo(RenderTargetInstance.BackBuffer); graphicsDevice.Clear(Color.TransparentWhite); DrawingManager.RenderTargetManager.ResolveToTexture(RenderTargetInstance.A); graphicsDevice.Textures[1] = DrawingManager.RenderTargetManager.GetTexture(RenderTargetInstance.A); //DrawingManager.RenderTargetManager.GetTexture(RenderTargetInstance.A).Save("E:/buffer.png", ImageFileFormat.Png); DrawingManager.SpriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None); DrawingManager.RefractionLayerEffect.Begin(); DrawingManager.RefractionLayerEffect.CurrentTechnique.Passes[0].Begin(); // only render the viewport part DrawingManager.SpriteBatch.Draw(DrawingManager.RenderTargetManager. GetTexture(RenderTargetInstance.BackBuffer), new Rectangle(0, 0, DrawingManager.ViewPortSize.X, DrawingManager.ViewPortSize.Y), new Rectangle(0, 0, DrawingManager.ViewPortSize.X, DrawingManager.ViewPortSize.Y), Color.White); DrawingManager.RefractionLayerEffect.CurrentTechnique.Passes[0].End(); DrawingManager.RefractionLayerEffect.End(); DrawingManager.SpriteBatch.End(); // force the next layer to restart a spritebatch DrawingManager.DrawingLayerTypeInUse = null; #endif } } return(drawNeeded); }
public void LoadTexture(string path) { _texture = Texture2D.FromStream(GraphicsDevice, System.IO.File.OpenRead(path)); _drawRequest = new DrawRequest(_texture, Vector2.Zero, null, 0, Vector2.One, Vector2.Zero, false, Color.White, false, false, null); }
public override void Draw(float elapsed) { if (!this.Visible) { return; } // Draw in reverse order from the list for (int i = TileLayers.Count - 1; i >= 0; i--) { TileLayer layer = TileLayers[i]; if (!layer.Visible) { continue; } for (int y = _visibleTiles.Top; y < _visibleTiles.Bottom; y++) { for (int x = _visibleTiles.Left; x < _visibleTiles.Right; x++) { Tile tile = layer.Tiles[x][y]; if (tile.Index != -1) { Vector2 drawPos = _scaledTilePivot; drawPos.X += (float)x * _scaledTileSize.X; drawPos.Y += (float)y * _scaledTileSize.Y; if (this.Rotation != 0) { drawPos = Vector2.Transform(drawPos, _rotationMatrix); } drawPos -= _scaledPivot; DrawRequest _drawRequest = new DrawRequest(); _drawRequest.texture = this.Material.Texture; _drawRequest.position = this.Position + drawPos; _drawRequest.rotation = tile.Rotation * MathHelper.PiOver2 + this.Rotation; _drawRequest.pivot = _tilePivot; _drawRequest.isPivotRelative = false; _drawRequest.hFlip = tile.HFlip; _drawRequest.vFlip = tile.VFlip; _drawRequest.sourceRectangle = GetSourceRectOfTile(tile.Index); if (tile.Rotation == 1 || tile.Rotation == 3) { _drawRequest.scaleRatio = _rotatedScale; } else { _drawRequest.scaleRatio = Scale; } _drawRequest.tint = this.Tint; DrawingManager.DrawOnLayer(_drawRequest, this.Layer, this.BlendingType); } } } } }
/// <summary> /// Draw on the requested layer /// </summary> /// <param name="drawRequest">The drawRequest to render</param> /// <param name="layer">The desired layer</param> public static void DrawOnLayer(DrawRequest drawRequest, int layer, DrawingBlendingType blendingType) { _layers[layer - 1].Draw(drawRequest, blendingType); }
/// <summary> /// Draw a DrawRequest on the alpha sublayer of that layer /// </summary> public void Draw(DrawRequest drawRequest) { _components[2].Draw(drawRequest); }
/// <summary> /// Draws the control. /// </summary> protected override void Draw() { GraphicsDevice.Clear(Color.Black); if (_background != null) { float scaledWidth = this.Width / (float)_background.Width; float scaledHeight = this.Height / (float)_background.Height; DrawRequest backgroundRequest = new DrawRequest(_background, Vector2.Zero,false, null, 0, new Vector2(scaledWidth, scaledHeight), Vector2.Zero, false, Color.White, false, false, null); DrawingManager.DrawOnLayer(backgroundRequest, 10, DrawingBlendingType.Alpha); } _ppAnim.Update(1 / 60f); _parent = Parent as PostProcessAnimationEditor; // if the animation was paused externally, pause it in the GUI if (_ppAnim.IsPaused == true && _parent.toolStripButtonPause.Enabled == true) { _parent.toolStripButtonPause_Click(null, EventArgs.Empty); } // if the animation was stopped externally, stop it in the GUI if (_ppAnim.IsStopped == true && _parent.toolStripButtonStop.Enabled == true) { _parent.toolStripButtonStop_Click(null, EventArgs.Empty); } int oldLayer = _ppAnim.Layer; _ppAnim.Draw(1 / 60f); _ppAnim.Layer = oldLayer; DrawingManager.ViewPortSize = new Point(this.Width, this.Height); MilkshakeForm.SwapCameraAndRenderScene(ParentEditor.ZoomBox.Camera); ((PostProcessAnimationEditor)this.Parent).Update(1/60f); }
public Sprite() : base() { _blendingType = DrawingBlendingType.Alpha; _drawRequest = default(DrawRequest); _drawRequest.tint = Color.White; _drawRequest.scaleRatio = Vector2.One; this.MaterialArea = ""; _useTilingSafeBorders = false; this.AutoScroll = false; this.AutoScrollSpeed = 0; this.AutoScrollArea = 0; this.AutoScrollVertical = false; this.AutoScrollMirroring = false; }
public static void DrawFilledRectangle(int layer, Vector2 position, Vector2 size, Color color, DrawingBlendingType blendingType) { DrawRequest drawRequest = new DrawRequest(_pixelTexture, position,false, null, 0, size, Vector2.Zero, false, color, false, false, null); DrawOnLayer(drawRequest, layer, blendingType); }
public void Draw(float elapsed) { if (this.Parent.Material == null) { return; } DrawRequest _drawRequest = new DrawRequest(); _drawRequest.texture = this.Parent.Material.Texture; _drawRequest.position = this.Parent.Position; _drawRequest.rotation = this.Parent.Rotation; _drawRequest.scaleRatio = this.Parent.Scale; if (this.AnimationFrames != null && this.AnimationFrames.Count > _currentFrameIndex && this.Parent.Material.Areas.ContainsKey(this.AnimationFrames[_currentFrameIndex].Area)) { _drawRequest.sourceRectangle = this.Parent.Material. Areas[this.AnimationFrames[_currentFrameIndex].Area]; } else { _drawRequest.sourceRectangle = null; } _drawRequest.pivot = this.Parent.Pivot; _drawRequest.isPivotRelative = this.Parent.IsPivotRelative; _drawRequest.tint = this.Parent.Tint; _drawRequest.hFlip = this.Parent.FlipHorizontal; _drawRequest.vFlip = this.Parent.FlipVertical; DrawingManager.DrawOnLayer(_drawRequest, this.Parent.Layer, this.Parent.BlendingType); }
public void LoadTexture(string path) { _texture = Texture2D.FromFile(GraphicsDevice, path); _drawRequest = new DrawRequest(_texture, Vector2.Zero,false, null, 0, Vector2.One, Vector2.Zero, false, Color.White, false, false, null); }
public override void Draw(float elapsed) { if (!this.Visible) { return; } if (this.Shadow == true) { DrawRequest _drawRequestShadow = new DrawRequest(); //_drawRequest.font = this.Material.Texture; _drawRequestShadow.position = this.Position + new Vector2(3, 2); _drawRequestShadow.rotation = this.Rotation; _drawRequestShadow.scaleRatio = this.Scale; Color shadowColor = Color.Black; shadowColor.A = _opacity; _drawRequestShadow.tint = shadowColor; _drawRequestShadow.font = _font.Font; _drawRequestShadow.text = Text; _drawRequestShadow.isFont = true; _drawRequestShadow.textSize = this.BoundingRectSize; _drawRequestShadow.pivot = Pivot; _drawRequestShadow.isPivotRelative = this.IsPivotRelative; _drawRequestShadow.IgnoreCamera = IgnoreCameraPosition; DrawingManager.DrawOnLayer(_drawRequestShadow, this.Layer, _blendingType); } //_drawRequest.font = this.Material.Texture; _drawRequest.position = this.Position; _drawRequest.rotation = this.Rotation; _drawRequest.scaleRatio = this.Scale; _drawRequest.font = _font.Font; _drawRequest.isFont = true; _drawRequest.textSize = this.BoundingRectSize; _drawRequest.text = this.Text; _drawRequest.isPivotRelative = this.IsPivotRelative; _drawRequest.pivot = this.Pivot; _drawRequest.IgnoreCamera = this.IgnoreCameraPosition; DrawingManager.DrawOnLayer(_drawRequest, this.Layer, _blendingType); base.Draw(elapsed); }