diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 4856a4d9..81a69d89 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -15,7 +15,6 @@ // along with Vocaluxe. If not, see . #endregion -using System.Diagnostics; using SlimDX; using SlimDX.Direct3D9; using System; @@ -428,7 +427,7 @@ namespace Vocaluxe.Lib.Draw /// Coordinates to draw on /// Color to use /// If true, then color is faded out in y direction - private void _DrawTexture(CD3DTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false) + protected override void _DrawTexture(CD3DTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false) { //Align the pixels because Direct3D expects the pixels to be the left top corner dc.Wx1 -= 0.5f; @@ -617,106 +616,6 @@ namespace Vocaluxe.Lib.Draw } texture.D3DTexture.UnlockRectangle(0); } - - #region drawing - /// - /// Draws a texture - /// - /// The texture to be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// True if the texture should be mirrored - public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, bool mirrored = false) - { - if (Math.Abs(color.A) < 0.01) - return; - SDrawCoords dc; - CD3DTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, out dc, mirrored)) - return; - - _DrawTexture(texture, dc, color); - } - - /// - /// Draws a texture - /// - /// The texture to be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// A SRectF struct containing which part of the texture should be drawn - /// True if the texture should be mirrored - public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) - { - if (Math.Abs(color.A) < 0.01) - return; - SDrawCoords dc; - CD3DTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, bounds, out dc)) - return; - - _DrawTexture(texture, dc, color); - } - - /// - /// Draws a texture - /// - /// The texture to be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// A Value ranging from 0 to 1 containing the beginning of the texture - /// A Value ranging from 0 to 1 containing the ending of the texture - public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, float begin, float end) - { - if (Math.Abs(color.A) < 0.01) - return; - SDrawCoords dc; - CD3DTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, out dc, false, begin, end)) - return; - - _DrawTexture(texture, dc, color); - } - - /// - /// Draws a reflection of a texture - /// - /// The texture of which a reflection should be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// A SRectF struct containing which part of the texture should be drawn - /// The space between the texture and the reflection - /// The height of the reflection - public void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, float space, float height) - { - Debug.Assert(height >= 0); - - if (Math.Abs(color.A) < 0.01 || height < 1) - return; - SDrawCoords dc; - CD3DTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, bounds, out dc, true)) - return; - - if (height > rect.H) - height = rect.H; - - dc.Wy1 += rect.H + space; // Move from start of rect to end of rect with spacing - dc.Wy2 += space + height; // Move from end of rect - dc.Ty2 += (rect.H - height) / rect.H; // Adjust so not all of the start of the texture is drawn (mirrored--> Ty1>Ty2) - if (dc.Ty2 < dc.Ty1) // Make sure we actually draw something - _DrawTexture(texture, dc, color, true); - } - #endregion drawing - #endregion Textures private static Matrix _CalculateRotationMatrix(float rot, float rx1, float rx2, float ry1, float ry2) diff --git a/Vocaluxe/Lib/Draw/CDrawBase.cs b/Vocaluxe/Lib/Draw/CDrawBase.cs index c5688320..d44322be 100644 --- a/Vocaluxe/Lib/Draw/CDrawBase.cs +++ b/Vocaluxe/Lib/Draw/CDrawBase.cs @@ -212,7 +212,7 @@ namespace Vocaluxe.Lib.Draw #region Textures - #region private/protected + #region drawing /// /// Struct that contains texture and world coordinates for drawing /// @@ -229,6 +229,15 @@ namespace Vocaluxe.Lib.Draw public float Rotation; } + /// + /// Adds a texture to the vertext buffer + /// + /// Texture to draw + /// Coordinates to draw on + /// Color to use + /// If true, then color is faded out in y direction + protected abstract void _DrawTexture(TTextureType texture, SDrawCoords dc, SColorF color, bool isReflection = false); + /// /// Calculates the texture and world coordinates for drawing the texture in the rect cropping at the the bounds /// @@ -316,6 +325,98 @@ namespace Vocaluxe.Lib.Draw return true; } + public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, bool mirrored = false) + { + if (Math.Abs(color.A) < 0.01) + return; + SDrawCoords dc; + TTextureType texture; + if (!_GetTexture(textureRef, out texture)) + return; + if (!_CalcDrawCoords(texture, rect, out dc, mirrored)) + return; + + _DrawTexture(texture, dc, color); + } + + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A SRectF struct containing which part of the texture should be drawn + /// True if the texture should be mirrored + public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) + { + if (Math.Abs(color.A) < 0.01) + return; + SDrawCoords dc; + TTextureType texture; + if (!_GetTexture(textureRef, out texture)) + return; + if (!_CalcDrawCoords(texture, rect, bounds, out dc)) + return; + + _DrawTexture(texture, dc, color); + } + + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A Value ranging from 0 to 1 containing the beginning of the texture + /// A Value ranging from 0 to 1 containing the ending of the texture + public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, float begin, float end) + { + if (Math.Abs(color.A) < 0.01) + return; + SDrawCoords dc; + TTextureType texture; + if (!_GetTexture(textureRef, out texture)) + return; + if (!_CalcDrawCoords(texture, rect, out dc, false, begin, end)) + return; + + _DrawTexture(texture, dc, color); + } + + /// + /// Draws a reflection of a texture + /// + /// The texture of which a reflection should be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A SRectF struct containing which part of the texture should be drawn + /// The space between the texture and the reflection + /// The height of the reflection + public void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, float space, float height) + { + Debug.Assert(height >= 0); + + if (Math.Abs(color.A) < 0.01 || height < 1) + return; + SDrawCoords dc; + TTextureType texture; + if (!_GetTexture(textureRef, out texture)) + return; + if (!_CalcDrawCoords(texture, rect, bounds, out dc, true)) + return; + + if (height > rect.H) + height = rect.H; + + dc.Wy1 += rect.H + space; // Move from start of rect to end of rect with spacing + dc.Wy2 += space + height; // Move from end of rect + dc.Ty2 += (rect.H - height) / rect.H; // Adjust so not all of the start of the texture is drawn (mirrored--> Ty1>Ty2) + if (dc.Ty2 < dc.Ty1) // Make sure we actually draw something + _DrawTexture(texture, dc, color, true); + } + #endregion drawing + + #region private/protected /// /// Returns the maximum area allowed for a texture based on the current quality /// diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 6617466c..1981f2f7 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -15,7 +15,6 @@ // along with Vocaluxe. If not, see . #endregion -using System.Diagnostics; using System.Drawing.Imaging; using OpenTK; using OpenTK.Graphics; @@ -437,8 +436,7 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, 0); } - #region drawing - private static void _DrawTexture(COGLTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false) + protected override void _DrawTexture(COGLTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false) { // Align textures to full pixels to reduce artefacts dc.Wx1 = (float)Math.Round(dc.Wx1); @@ -486,98 +484,6 @@ namespace Vocaluxe.Lib.Draw GL.Disable(EnableCap.Blend); GL.BindTexture(TextureTarget.Texture2D, 0); } - - public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, bool mirrored = false) - { - if (Math.Abs(color.A) < 0.01) - return; - SDrawCoords dc; - COGLTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, out dc, mirrored)) - return; - - _DrawTexture(texture, dc, color); - } - - /// - /// Draws a texture - /// - /// The texture to be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// A SRectF struct containing which part of the texture should be drawn - /// True if the texture should be mirrored - public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false) - { - if (Math.Abs(color.A) < 0.01) - return; - SDrawCoords dc; - COGLTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, bounds, out dc)) - return; - - _DrawTexture(texture, dc, color); - } - - /// - /// Draws a texture - /// - /// The texture to be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// A Value ranging from 0 to 1 containing the beginning of the texture - /// A Value ranging from 0 to 1 containing the ending of the texture - public void DrawTexture(CTextureRef textureRef, SRectF rect, SColorF color, float begin, float end) - { - if (Math.Abs(color.A) < 0.01) - return; - SDrawCoords dc; - COGLTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, out dc, false, begin, end)) - return; - - _DrawTexture(texture, dc, color); - } - - /// - /// Draws a reflection of a texture - /// - /// The texture of which a reflection should be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// A SRectF struct containing which part of the texture should be drawn - /// The space between the texture and the reflection - /// The height of the reflection - public void DrawTextureReflection(CTextureRef textureRef, SRectF rect, SColorF color, SRectF bounds, float space, float height) - { - Debug.Assert(height >= 0); - - if (Math.Abs(color.A) < 0.01 || height < 1) - return; - SDrawCoords dc; - COGLTexture texture; - if (!_GetTexture(textureRef, out texture)) - return; - if (!_CalcDrawCoords(texture, rect, bounds, out dc, true)) - return; - - if (height > rect.H) - height = rect.H; - - dc.Wy1 += rect.H + space; // Move from start of rect to end of rect with spacing - dc.Wy2 += space + height; // Move from end of rect - dc.Ty2 += (rect.H - height) / rect.H; // Adjust so not all of the start of the texture is drawn (mirrored--> Ty1>Ty2) - if (dc.Ty2 < dc.Ty1) // Make sure we actually draw something - _DrawTexture(texture, dc, color, true); - } - #endregion drawing - #endregion Textures #endregion implementation