Esempio n. 1
0
        public TextureBrush(Stream stream, bool loadAsync = false)
        {
            IsAsync = loadAsync;
            disposeTexture = true;
            texture = new Texture(stream, loadAsync);

            Color = Color4.White;
            InterpolationMode = InterpolationMode.Default;
        }
Esempio n. 2
0
        public TextureBrush(Texture texture)
        {
            IsAsync = texture.IsAsync;
            disposeTexture = false;
            this.texture = texture;

            Color = Color4.White;
            InterpolationMode = InterpolationMode.Default;
        }
Esempio n. 3
0
        unsafe void SetTexture(Texture texture, Color4 color, float opacity)
        {
            SetTextureInner(texture.ResourceView);

            var buffer = new Brush.BrushBuffer() { Type = 4, Opacity = opacity};
            buffer.GradientColors[0] = color.R;
            buffer.GradientColors[1] = color.G;
            buffer.GradientColors[2] = color.B;
            buffer.GradientColors[3] = color.A;
            deviceContext.UpdateSubresource(brushBuffer, 0, null, (IntPtr)(&buffer), 0, 0);
            deviceContext.PixelShader.SetConstantBuffer(1, brushBuffer);
        }
Esempio n. 4
0
        /// <summary>
        /// Draws a colored texture.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="color">The color of the texture.</param>
        /// <param name="destinationRectangle">The rectangle the texture will be displayed in.</param>
        /// <param name="sourceRectangle">The rectangle defining the part of the texture that will be displayed.</param>
        /// <param name="opacity">The opacity of the drawn texture.</param>
        /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">The source rectangle lies not inside the textures bounds.</exception>
        public void DrawTexture(Texture texture, Color4 color, Rectangle destinationRectangle, Rectangle sourceRectangle, float opacity = 1f, InterpolationMode interpolationMode = InterpolationMode.Default)
        {
            if (sourceRectangle.Left < 0 || sourceRectangle.Top < 0 ||
                sourceRectangle.Right > texture.Width || sourceRectangle.Bottom > texture.Height)
                throw new ArgumentOutOfRangeException(nameof(sourceRectangle));

            SetTexture(texture, color, opacity);
            SetSamplerState(currentWrapMode, interpolationMode == InterpolationMode.Default ? defaultInterpolationMode : interpolationMode);

            float textCoordLeft = sourceRectangle.Left / texture.Width;
            float textCoordRight = sourceRectangle.Right / texture.Width;
            float textCoordTop = sourceRectangle.Top / texture.Height;
            float textCoordBottom = sourceRectangle.Bottom / texture.Height;

            Vertex[] vertices = new[]
            {
                new Vertex(destinationRectangle.Left, destinationRectangle.Top, textCoordLeft, textCoordTop),
                new Vertex(destinationRectangle.Right, destinationRectangle.Top, textCoordRight, textCoordTop),
                new Vertex(destinationRectangle.Left, destinationRectangle.Bottom, textCoordLeft, textCoordBottom),
                new Vertex(destinationRectangle.Right, destinationRectangle.Bottom, textCoordRight, textCoordBottom),
            };
            int[] indices = { 0, 1, 2, 1, 2, 3 };

            DrawVertices(indices, vertices, 0);
        }
Esempio n. 5
0
 /// <summary>
 /// Draws a texture.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="location">The loction the texture will be displayed at.</param>
 /// <param name="opacity">The opacity of the drawn texture.</param>
 /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param>
 public void DrawTexture(Texture texture, Vector2 location, float opacity = 1, InterpolationMode interpolationMode = InterpolationMode.Default)
 {
     DrawTexture(texture, Color4.White, new Rectangle(location.X, location.Y, texture.Width, texture.Height), opacity, interpolationMode);
 }
Esempio n. 6
0
 /// <summary>
 /// Draws a texture.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="destinationRectangle">The rectangle the texture will be displayed in.</param>
 /// <param name="opacity">The opacity of the drawn texture.</param>
 /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param>
 public void DrawTexture(Texture texture, Rectangle destinationRectangle, float opacity = 1f, InterpolationMode interpolationMode = InterpolationMode.Default)
 {
     DrawTexture(texture, Color4.White, destinationRectangle, opacity, interpolationMode);
 }
Esempio n. 7
0
        /// <summary>
        /// Draws a colored texture.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="color">The color of the texture.</param>
        /// <param name="destinationRectangle">The rectangle the texture will be displayed in.</param>
        /// <param name="opacity">The opacity of the drawn texture.</param>
        /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param>
        public void DrawTexture(Texture texture, Color4 color, Rectangle destinationRectangle, float opacity = 1f, InterpolationMode interpolationMode = InterpolationMode.Default)
        {
            SetTexture(texture, color, opacity);
            SetSamplerState(currentWrapMode, interpolationMode == InterpolationMode.Default ? defaultInterpolationMode : interpolationMode);

            Vertex[] vertices = new[]
            {
                new Vertex(destinationRectangle.Left, destinationRectangle.Top, 0, 0),
                new Vertex(destinationRectangle.Right, destinationRectangle.Top, 1, 0),
                new Vertex(destinationRectangle.Left, destinationRectangle.Bottom, 0, 1),
                new Vertex(destinationRectangle.Right, destinationRectangle.Bottom, 1, 1),
            };
            int[] indices = { 0, 1, 2, 1, 2, 3 };

            DrawVertices(indices, vertices, 0);
        }