/// <summary>Function called to render the sprite data.</summary> /// <returns>The presentation interval to use when rendering.</returns> protected override int OnRender() { var spriteRegion = SpriteContent.Texture.ToPixel(SpriteContent.TextureCoordinates).ToRectangleF(); var imageRegion = new DX.RectangleF(0, 0, SpriteContent.Texture.Width, SpriteContent.Texture.Height); RenderSpriteTextureWithoutSprite(imageRegion, spriteRegion); SwapChain.RenderTargetView.Clear(BackgroundColor); Renderer.Begin(); if (IsAnimating) { // Draw the pattern layer. Renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, SwapChain.Width, SwapChain.Height), new GorgonColor(GorgonColor.White, (0.5f - TextureAlpha.Min(0.5f).Max(0)) * 2), BackgroundPattern, new DX.RectangleF(0, 0, SwapChain.Width / BackgroundPattern.Width, SwapChain.Height / BackgroundPattern.Height)); RenderRect(imageRegion, new GorgonColor(GorgonColor.White, TextureAlpha * 2), BackgroundPattern, new DX.RectangleF(0, 0, (imageRegion.Width * ZoomScaleValue) / BackgroundPattern.Width, (imageRegion.Height * ZoomScaleValue) / BackgroundPattern.Height)); RenderRect(spriteRegion, GorgonColor.White, BackgroundPattern, new DX.RectangleF(0, 0, (spriteRegion.Width * ZoomScaleValue) / BackgroundPattern.Width, (spriteRegion.Height * ZoomScaleValue) / BackgroundPattern.Height)); } else { // Draw the pattern layer. RenderRect(imageRegion, GorgonColor.White, BackgroundPattern, new DX.RectangleF(0, 0, (imageRegion.Width * ZoomScaleValue) / BackgroundPattern.Width, (imageRegion.Height * ZoomScaleValue) / BackgroundPattern.Height)); } // Draw the image buffer layer. Renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, SwapChain.Width, SwapChain.Height), new GorgonColor(GorgonColor.White, TextureAlpha), ImageBufferTexture, new DX.RectangleF(0, 0, 1, 1)); // Draw the sprite layer. Renderer.DrawSprite(_workingSprite); // Draw an indicator for the anchor. DX.Vector2 anchorPos = ToClient(new DX.Vector2(SpriteContent.Anchor.X * spriteRegion.Width + spriteRegion.Left, SpriteContent.Anchor.Y * spriteRegion.Height + spriteRegion.Top)).Truncate(); Renderer.DrawEllipse(new DX.RectangleF(anchorPos.X - 4, anchorPos.Y - 4, 8, 8), GorgonColor.Black); Renderer.DrawEllipse(new DX.RectangleF(anchorPos.X - 3, anchorPos.Y - 3, 6, 6), GorgonColor.White); // We convert to integer first so we can clip the decimal places. _marchAnts.Draw(Renderer.MeasureSprite(_workingSprite).Truncate()); Renderer.End(); return(1); }
/// <summary>Function called to render the sprite data.</summary> /// <returns>The presentation interval to use when rendering.</returns> protected override int OnRender() { DX.RectangleF spriteRegion = _picker.Rectangle; var imageRegion = new DX.RectangleF(0, 0, SpriteContent.Texture.Width, SpriteContent.Texture.Height); RenderSpriteTextureWithoutSprite(imageRegion, spriteRegion); SwapChain.RenderTargetView.Clear(BackgroundColor); Renderer.Begin(); // Draw the pattern layer. RenderRect(imageRegion, GorgonColor.White, BackgroundPattern, new DX.RectangleF(0, 0, (imageRegion.Width * ZoomScaleValue) / BackgroundPattern.Width, (imageRegion.Height * ZoomScaleValue) / BackgroundPattern.Height)); // Draw the image buffer layer. Renderer.DrawFilledRectangle(new DX.RectangleF(0, 0, SwapChain.Width, SwapChain.Height), new GorgonColor(GorgonColor.White, 0.5f), ImageBufferTexture, new DX.RectangleF(0, 0, 1, 1)); // Draw the sprite layer. RenderRect(spriteRegion, GorgonColor.White, SpriteContent.Texture, SpriteContent.Texture.ToTexel(spriteRegion.ToRectangle()), TextureArrayIndex, GorgonSamplerState.PointFiltering); _marchAnts.Draw(ToClient(spriteRegion)); Renderer.End(); return(1); }
/// <summary>Function to draw the texture.</summary> /// <param name="renderer">The renderer used to draw the texture.</param> /// <param name="image">The image being rendered.</param> /// <param name="batchState">The currently active batch render state.</param> protected override void OnDrawTexture(Gorgon2D renderer, IImageContent image, Gorgon2DBatchState batchState) { renderer.End(); float imageWidth = TextureBounds.Width / 4; float imageHeight = TextureBounds.Height / 3; float centerCanvasX = TextureBounds.Width / 2.0f + TextureBounds.Left; float centerCanvasY = TextureBounds.Height / 2.0f + TextureBounds.Top; float imageX = centerCanvasX - imageWidth; float imageY = centerCanvasY - (imageHeight / 2.0f); var bounds = new DX.RectangleF(imageX, imageY, imageWidth, imageHeight); int cubeGroup = image.CurrentArrayIndex / 6; _cubeImageBounds[0] = new DX.RectangleF(bounds.Left + bounds.Width, bounds.Top, bounds.Width, bounds.Height); _cubeImageBounds[1] = new DX.RectangleF(bounds.Left - bounds.Width, bounds.Top, bounds.Width, bounds.Height); _cubeImageBounds[2] = new DX.RectangleF(bounds.Left, bounds.Top - bounds.Height, bounds.Width, bounds.Height); _cubeImageBounds[3] = new DX.RectangleF(bounds.Left, bounds.Top + bounds.Height, bounds.Width, bounds.Height); _cubeImageBounds[4] = bounds; _cubeImageBounds[5] = new DX.RectangleF(bounds.Left + (bounds.Width * 2), bounds.Top, bounds.Width, bounds.Height); int selectedImage = image.CurrentArrayIndex % 6; renderer.Begin(batchState); for (int i = 0; i < 6; ++i) { renderer.DrawFilledRectangle(_cubeImageBounds[i], new GorgonColor(GorgonColor.White, Alpha), _textureView, new DX.RectangleF(0, 0, 1, 1), (cubeGroup * 6) + i, textureSampler: GorgonSamplerState.PointFiltering); } renderer.End(); renderer.Begin(); for (int i = 0; i < _cubeImageBounds.Length; ++i) { renderer.DrawRectangle(_cubeImageBounds[i], new GorgonColor(GorgonColor.Black, 0.88f), 1); } _selectionRect.Draw(_cubeImageBounds[selectedImage]); var offset = new DX.Vector2(0, _axisFont.MeasureLine("+X", true).Height); renderer.DrawString("+X", _cubeImageBounds[0].BottomLeft - offset, _axisFont, GorgonColor.White); renderer.DrawString("-X", _cubeImageBounds[1].BottomLeft - offset, _axisFont, GorgonColor.White); renderer.DrawString("+Y", _cubeImageBounds[2].BottomLeft - offset, _axisFont, GorgonColor.White); renderer.DrawString("-Y", _cubeImageBounds[3].BottomLeft - offset, _axisFont, GorgonColor.White); renderer.DrawString("+Z", _cubeImageBounds[4].BottomLeft - offset, _axisFont, GorgonColor.White); renderer.DrawString("-Z", _cubeImageBounds[5].BottomLeft - offset, _axisFont, GorgonColor.White); renderer.End(); }