Improve background drawing

Don't convert to RectangleF for rescaling
Add function for colored fitting of a texture in bounds
Add DrawLine in IDrawing
This commit is contained in:
Flamefire committed 2014-09-24 16:36:18 +02:00
1 parent 5f139467ea
commit db4096d57f
10 files changed
+77 -70

No files matched your search

+14 -2
View File
@@ -209,7 +209,7 @@ namespace Vocaluxe.Base
/// </summary> /// </summary>
/// <param name="texturePath">Full path to the image file</param> /// <param name="texturePath">Full path to the image file</param>
/// <returns>Reference to texture</returns> /// <returns>Reference to texture</returns>
public static CTextureRef EnqueueTexture(String texturePath) public static CTextureRef EnqueueTexture(String texturePath)
{ {
return _Draw.EnqueueTexture(texturePath); return _Draw.EnqueueTexture(texturePath);
} }
@@ -399,13 +399,25 @@ namespace Vocaluxe.Base
/// <param name="bounds">Where to draw the texture</param> /// <param name="bounds">Where to draw the texture</param>
/// <param name="aspect">How to fit a texture in the bounds if the size differs</param> /// <param name="aspect">How to fit a texture in the bounds if the size differs</param>
public static void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect) public static void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect)
{
DrawTexture(textureRef, bounds, aspect, textureRef.Color);
}
/// <summary>
/// Draws a texture fitting it within the given color and bounds with the method specified by aspect
/// </summary>
/// <param name="textureRef"></param>
/// <param name="bounds">Where to draw the texture</param>
/// <param name="aspect">How to fit a texture in the bounds if the size differs</param>
/// <param name="color">Color to use</param>
public static void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect, SColorF color)
{ {
if (textureRef == null) if (textureRef == null)
return; return;
SRectF rect; SRectF rect;
CHelper.SetRect(bounds, out rect, textureRef.OrigAspect, aspect); CHelper.SetRect(bounds, out rect, textureRef.OrigAspect, aspect);
DrawTexture(textureRef, rect); DrawTexture(textureRef, rect, color);
} }
/// <summary> /// <summary>
+17 -2
View File
@@ -423,6 +423,16 @@ namespace Vocaluxe.Base
CDraw.DrawTexture(texture, rect, color, bounds, mirrored); CDraw.DrawTexture(texture, rect, color, bounds, mirrored);
} }
public void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect)
{
CDraw.DrawTexture(textureRef, bounds, aspect);
}
public void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect, SColorF color)
{
CDraw.DrawTexture(textureRef, bounds, aspect, color);
}
public void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float reflectionSpace, float reflectionHeight) public void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float reflectionSpace, float reflectionHeight)
{ {
CDraw.DrawTextureReflection(texture, rect, color, reflectionSpace, reflectionHeight); CDraw.DrawTextureReflection(texture, rect, color, reflectionSpace, reflectionHeight);
@@ -438,12 +448,17 @@ namespace Vocaluxe.Base
CDraw.RemoveTexture(ref texture); CDraw.RemoveTexture(ref texture);
} }
public void DrawColor(SColorF color, SRectF rect) public void DrawLine(SColorF color, float w, int x1, int y1, int x2, int y2)
{
CDraw.DrawLine(color, w, x1, y1, x2, y2);
}
public void DrawRect(SColorF color, SRectF rect)
{ {
CDraw.DrawRect(color, rect); CDraw.DrawRect(color, rect);
} }
public void DrawColorReflection(SColorF color, SRectF rect, float space, float height) public void DrawRectReflection(SColorF color, SRectF rect, float space, float height)
{ {
CDraw.DrawRectReflection(color, rect, space, height); CDraw.DrawRectReflection(color, rect, space, height);
} }
+1 -4
View File
@@ -62,11 +62,8 @@ namespace Vocaluxe.Base
} }
if (_VideoTexture == null) if (_VideoTexture == null)
return; return;
var bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH);
RectangleF rect;
CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop);
CDraw.DrawTexture(_VideoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CSettings.ZFar / 4)); CDraw.DrawTexture(_VideoTexture, new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, CSettings.ZFar / 4), EAspect.Crop);
} }
public void PreLoad() public void PreLoad()
+3 -2
View File
@@ -660,8 +660,9 @@ namespace Vocaluxe.Lib.Draw
{ {
lock (_TextureQueue) lock (_TextureQueue)
{ {
CTextureRef textureRef = _GetTextureReference(w, h, _CreateTexture(new Size(-1, -1))); TTextureType texture = _CreateTexture(new Size(-1, -1));
_TextureQueue.Enqueue(new STextureQueue(textureRef, EQueueAction.Add, new Size(w, h), data)); CTextureRef textureRef = _GetTextureReference(w, h, texture);
_TextureQueue.Enqueue(new STextureQueue(texture, EQueueAction.Add, new Size(w, h), data));
return textureRef; return textureRef;
} }
} }
+1 -3
View File
@@ -467,9 +467,7 @@ namespace Vocaluxe.Screens
if (background != null) if (background != null)
{ {
var bounds = new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, 0); var bounds = new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, 0);
SRectF rect; CDraw.DrawTexture(background, bounds, aspect, background.Color);
CHelper.SetRect(bounds, out rect, background.OrigAspect, aspect);
CDraw.DrawTexture(background, rect, background.Color);
} }
else if (_SlideShow != null) else if (_SlideShow != null)
_SlideShow.Draw(); _SlideShow.Draw();
+5 -2
View File
@@ -143,13 +143,16 @@ namespace VocaluxeLib
void DrawTexture(CTextureRef texture, SRectF rect); void DrawTexture(CTextureRef texture, SRectF rect);
void DrawTexture(CTextureRef texture, SRectF rect, SColorF color); void DrawTexture(CTextureRef texture, SRectF rect, SColorF color);
void DrawTexture(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false); void DrawTexture(CTextureRef texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored = false);
void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect);
void DrawTexture(CTextureRef textureRef, SRectF bounds, EAspect aspect, SColorF color);
void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float reflectionSpace, float reflectionHeight); void DrawTextureReflection(CTextureRef texture, SRectF rect, SColorF color, float reflectionSpace, float reflectionHeight);
CTextureRef AddTexture(string fileName); CTextureRef AddTexture(string fileName);
void RemoveTexture(ref CTextureRef texture); void RemoveTexture(ref CTextureRef texture);
void DrawColor(SColorF color, SRectF rect); void DrawRect(SColorF color, SRectF rect);
void DrawColorReflection(SColorF color, SRectF rect, float space, float height); void DrawRectReflection(SColorF color, SRectF rect, float space, float height);
void DrawLine(SColorF color, float w, int x1, int y1, int x2, int y2);
} }
public interface IGraphics public interface IGraphics
+30 -49
View File
@@ -16,7 +16,6 @@
#endregion #endregion
using System; using System;
using System.Drawing;
using System.Xml; using System.Xml;
using System.Diagnostics; using System.Diagnostics;
using System.Collections.Generic; using System.Collections.Generic;
@@ -172,36 +171,31 @@ namespace VocaluxeLib.Menu
CBase.Theme.SkinVideoPause(_Theme.VideoName, _PartyModeID); CBase.Theme.SkinVideoPause(_Theme.VideoName, _PartyModeID);
} }
public bool Draw() public void Draw()
{ {
bool ok = false; bool ok = false;
if (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON && if (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON)
CBase.Config.GetVideosToBackground() == EOffOn.TR_CONFIG_ON && CBase.BackgroundMusic.IsPlaying() && CBase.BackgroundMusic.SongHasVideo() &&
CBase.BackgroundMusic.VideoEnabled() && !CBase.BackgroundMusic.IsDisabled())
{ {
Pause(); if (CBase.Config.GetVideosToBackground() == EOffOn.TR_CONFIG_ON && CBase.BackgroundMusic.IsPlaying() && CBase.BackgroundMusic.SongHasVideo() &&
ok = _DrawBackgroundMusicVideo(); CBase.BackgroundMusic.VideoEnabled())
{
Pause();
ok = _DrawBackgroundMusicVideo();
}
else
{
Resume();
ok = _DrawVideo();
}
} }
else if (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON) else if (_Theme.Type == EBackgroundTypes.SlideShow && _Theme.SlideShowTextures.Count > 0)
{
Resume();
ok = _DrawVideo();
}
if (_Theme.Type == EBackgroundTypes.SlideShow && _Theme.SlideShowTextures.Count > 0)
ok = _DrawSlideShow(); ok = _DrawSlideShow();
if (!String.IsNullOrEmpty(_Theme.TextureName) && if (!String.IsNullOrEmpty(_Theme.TextureName) && (_Theme.Type == EBackgroundTypes.Texture || !ok))
(_Theme.Type == EBackgroundTypes.Texture ||
(_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF)))
ok = _DrawTexture(); ok = _DrawTexture();
if (_Theme.Type == EBackgroundTypes.Color || _Theme.Type == EBackgroundTypes.Texture && !ok || if (_Theme.Type == EBackgroundTypes.Color || !ok)
(_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF && !ok))
_DrawColor(); _DrawColor();
return true;
} }
public void UnloadTextures() public void UnloadTextures()
@@ -247,11 +241,14 @@ namespace VocaluxeLib.Menu
#endregion public #endregion public
#region internal #region internal
private static SRectF _GetDrawRect()
{
return new SRectF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), CBase.Settings.GetZFar() / 4);
}
private void _DrawColor() private void _DrawColor()
{ {
var bounds = new SRectF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), CBase.Settings.GetZFar() / 4); CBase.Drawing.DrawRect(Color, _GetDrawRect());
CBase.Drawing.DrawColor(Color, bounds);
} }
private bool _DrawTexture() private bool _DrawTexture()
@@ -259,11 +256,7 @@ namespace VocaluxeLib.Menu
CTextureRef texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID); CTextureRef texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID);
if (texture != null) if (texture != null)
{ {
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); CBase.Drawing.DrawTexture(texture, _GetDrawRect(), EAspect.Crop);
RectangleF rect;
CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4));
return true; return true;
} }
return false; return false;
@@ -284,7 +277,7 @@ namespace VocaluxeLib.Menu
_SlideShowTimer.Restart(); _SlideShowTimer.Restart();
if (_SlideShowCurrent + 1 < _SlideShowTextures.Count) if (_SlideShowCurrent + 1 < _SlideShowTextures.Count)
_SlideShowCurrent++; _SlideShowCurrent++;
else if (_SlideShowCurrent != 0) else
_SlideShowCurrent = 0; _SlideShowCurrent = 0;
} }
@@ -293,11 +286,7 @@ namespace VocaluxeLib.Menu
if (texture == null) if (texture == null)
return false; return false;
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); CBase.Drawing.DrawTexture(texture, _GetDrawRect(), EAspect.Crop);
RectangleF rect;
CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4));
if (_SlideShowTimer.ElapsedMilliseconds >= CBase.Settings.GetSlideShowImageTime()) if (_SlideShowTimer.ElapsedMilliseconds >= CBase.Settings.GetSlideShowImageTime())
{ {
@@ -310,9 +299,9 @@ namespace VocaluxeLib.Menu
if (texture != null) if (texture != null)
{ {
float alpha = (_SlideShowTimer.ElapsedMilliseconds - CBase.Settings.GetSlideShowImageTime()) / CBase.Settings.GetSlideShowFadeTime(); SColorF color = texture.Color;
CHelper.SetRect(bounds, out rect, texture.OrigAspect, EAspect.Crop); color.A = (_SlideShowTimer.ElapsedMilliseconds - CBase.Settings.GetSlideShowImageTime()) / CBase.Settings.GetSlideShowFadeTime();
CBase.Drawing.DrawTexture(texture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, (CBase.Settings.GetZFar() / 4) - 1), new SColorF(1, 1, 1, alpha)); CBase.Drawing.DrawTexture(texture, _GetDrawRect(), EAspect.Crop, color);
} }
} }
@@ -326,11 +315,7 @@ namespace VocaluxeLib.Menu
CTextureRef videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID); CTextureRef videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID);
if (videoTexture != null) if (videoTexture != null)
{ {
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); CBase.Drawing.DrawTexture(videoTexture, _GetDrawRect(), EAspect.Crop);
RectangleF rect;
CHelper.SetRect(bounds, out rect, videoTexture.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4));
return true; return true;
} }
return false; return false;
@@ -341,11 +326,7 @@ namespace VocaluxeLib.Menu
CTextureRef videoTexture = CBase.BackgroundMusic.GetVideoTexture(); CTextureRef videoTexture = CBase.BackgroundMusic.GetVideoTexture();
if (videoTexture != null) if (videoTexture != null)
{ {
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH()); CBase.Drawing.DrawTexture(videoTexture, _GetDrawRect(), EAspect.Crop);
RectangleF rect;
CHelper.SetRect(bounds, out rect, videoTexture.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(videoTexture, new SRectF(rect.X, rect.Y, rect.Width, rect.Height, CBase.Settings.GetZFar() / 4));
return true; return true;
} }
return false; return false;
+2 -2
View File
@@ -275,10 +275,10 @@ namespace VocaluxeLib.Menu
if (i == _MaxBar) if (i == _MaxBar)
color = MaxColor; color = MaxColor;
CBase.Drawing.DrawColor(color, bar); CBase.Drawing.DrawRect(color, bar);
if (Reflection) if (Reflection)
CBase.Drawing.DrawColorReflection(color, bar, ReflectionSpace, ReflectionHeight); CBase.Drawing.DrawRectReflection(color, bar, ReflectionSpace, ReflectionHeight);
} }
} }
+2 -2
View File
@@ -208,11 +208,11 @@ namespace VocaluxeLib.Menu
CBase.Drawing.DrawTextureReflection(texture, rect, color, ReflectionSpace, ReflectionHeight); CBase.Drawing.DrawTextureReflection(texture, rect, color, ReflectionSpace, ReflectionHeight);
} }
else else
CBase.Drawing.DrawColor(color, rect); CBase.Drawing.DrawRect(color, rect);
} }
if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme)) if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
CBase.Drawing.DrawColor(new SColorF(1f, 1f, 1f, 0.5f), rect); CBase.Drawing.DrawRect(new SColorF(1f, 1f, 1f, 0.5f), rect);
} }
public void UnloadTextures() {} public void UnloadTextures() {}
+2 -2
View File
@@ -475,7 +475,7 @@ namespace VocaluxeLib.Menu
CBase.Fonts.DrawTextReflection(_Text, Rect.H, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight); CBase.Fonts.DrawTextReflection(_Text, Rect.H, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme)) if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
CBase.Drawing.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z)); CBase.Drawing.DrawRect(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z));
} }
public void Draw(float begin, float end) public void Draw(float begin, float end)
@@ -494,7 +494,7 @@ namespace VocaluxeLib.Menu
} }
if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme)) if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
CBase.Drawing.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(X, Y, Rect.W, Rect.H, Z)); CBase.Drawing.DrawRect(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(X, Y, Rect.W, Rect.H, Z));
} }
public void DrawRelative(float rx, float ry, float reflectionHeight = 0f, float reflectionSpace = 0f, float rectHeight = 0f) public void DrawRelative(float rx, float ry, float reflectionHeight = 0f, float reflectionSpace = 0f, float rectHeight = 0f)