Move same methods to base class

This commit is contained in:
Flamefire committed 2014-09-27 16:56:37 +02:00
1 parent 158117ce31
commit 94d3bed471
3 files changed
+104 -198

No files matched your search

+1 -102
View File
@@ -15,7 +15,6 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System.Diagnostics;
using SlimDX;
using SlimDX.Direct3D9;
using System;
@@ -428,7 +427,7 @@ namespace Vocaluxe.Lib.Draw
/// <param name="dc">Coordinates to draw on</param>
/// <param name="color">Color to use</param>
/// <param name="isReflection">If true, then color is faded out in y direction</param>
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
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
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);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
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);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="begin">A Value ranging from 0 to 1 containing the beginning of the texture</param>
/// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
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);
}
/// <summary>
/// Draws a reflection of a texture
/// </summary>
/// <param name="textureRef">The texture of which a reflection should be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="space">The space between the texture and the reflection</param>
/// <param name="height">The height of the reflection</param>
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)
+102 -1
View File
@@ -212,7 +212,7 @@ namespace Vocaluxe.Lib.Draw
#region Textures
#region private/protected
#region drawing
/// <summary>
/// Struct that contains texture and world coordinates for drawing
/// </summary>
@@ -229,6 +229,15 @@ namespace Vocaluxe.Lib.Draw
public float Rotation;
}
/// <summary>
/// Adds a texture to the vertext buffer
/// </summary>
/// <param name="texture">Texture to draw</param>
/// <param name="dc">Coordinates to draw on</param>
/// <param name="color">Color to use</param>
/// <param name="isReflection">If true, then color is faded out in y direction</param>
protected abstract void _DrawTexture(TTextureType texture, SDrawCoords dc, SColorF color, bool isReflection = false);
/// <summary>
/// Calculates the texture and world coordinates for drawing the texture in the rect cropping at the the bounds
/// </summary>
@@ -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);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
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);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="begin">A Value ranging from 0 to 1 containing the beginning of the texture</param>
/// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
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);
}
/// <summary>
/// Draws a reflection of a texture
/// </summary>
/// <param name="textureRef">The texture of which a reflection should be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="space">The space between the texture and the reflection</param>
/// <param name="height">The height of the reflection</param>
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
/// <summary>
/// Returns the maximum area allowed for a texture based on the current quality
/// </summary>
+1 -95
View File
@@ -15,7 +15,6 @@
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#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);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="mirrored">True if the texture should be mirrored</param>
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);
}
/// <summary>
/// Draws a texture
/// </summary>
/// <param name="textureRef">The texture to be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="begin">A Value ranging from 0 to 1 containing the beginning of the texture</param>
/// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
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);
}
/// <summary>
/// Draws a reflection of a texture
/// </summary>
/// <param name="textureRef">The texture of which a reflection should be drawn</param>
/// <param name="rect">A SRectF struct containing the destination coordinates</param>
/// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
/// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
/// <param name="space">The space between the texture and the reflection</param>
/// <param name="height">The height of the reflection</param>
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