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>
/// <param name="texturePath">Full path to the image file</param>
/// <returns>Reference to texture</returns>
public static CTextureRef EnqueueTexture(String texturePath)
public static CTextureRef EnqueueTexture(String texturePath)
{
return _Draw.EnqueueTexture(texturePath);
}
@@ -399,13 +399,25 @@ namespace Vocaluxe.Base
/// <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>
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)
return;
SRectF rect;
CHelper.SetRect(bounds, out rect, textureRef.OrigAspect, aspect);
DrawTexture(textureRef, rect);
DrawTexture(textureRef, rect, color);
}
/// <summary>
+17 -2
View File
@@ -423,6 +423,16 @@ namespace Vocaluxe.Base
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)
{
CDraw.DrawTextureReflection(texture, rect, color, reflectionSpace, reflectionHeight);
@@ -438,12 +448,17 @@ namespace Vocaluxe.Base
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);
}
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);
}
+1 -4
View File
@@ -62,11 +62,8 @@ namespace Vocaluxe.Base
}
if (_VideoTexture == null)
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()
+3 -2
View File
@@ -660,8 +660,9 @@ namespace Vocaluxe.Lib.Draw
{
lock (_TextureQueue)
{
CTextureRef textureRef = _GetTextureReference(w, h, _CreateTexture(new Size(-1, -1)));
_TextureQueue.Enqueue(new STextureQueue(textureRef, EQueueAction.Add, new Size(w, h), data));
TTextureType texture = _CreateTexture(new Size(-1, -1));
CTextureRef textureRef = _GetTextureReference(w, h, texture);
_TextureQueue.Enqueue(new STextureQueue(texture, EQueueAction.Add, new Size(w, h), data));
return textureRef;
}
}
+1 -3
View File
@@ -467,9 +467,7 @@ namespace Vocaluxe.Screens
if (background != null)
{
var bounds = new SRectF(0, 0, CSettings.RenderW, CSettings.RenderH, 0);
SRectF rect;
CHelper.SetRect(bounds, out rect, background.OrigAspect, aspect);
CDraw.DrawTexture(background, rect, background.Color);
CDraw.DrawTexture(background, bounds, aspect, background.Color);
}
else if (_SlideShow != null)
_SlideShow.Draw();
+5 -2
View File
@@ -143,13 +143,16 @@ namespace VocaluxeLib
void DrawTexture(CTextureRef texture, SRectF rect);
void DrawTexture(CTextureRef texture, SRectF rect, SColorF color);
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);
CTextureRef AddTexture(string fileName);
void RemoveTexture(ref CTextureRef texture);
void DrawColor(SColorF color, SRectF rect);
void DrawColorReflection(SColorF color, SRectF rect, float space, float height);
void DrawRect(SColorF color, SRectF rect);
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
+30 -49
View File
@@ -16,7 +16,6 @@
#endregion
using System;
using System.Drawing;
using System.Xml;
using System.Diagnostics;
using System.Collections.Generic;
@@ -172,36 +171,31 @@ namespace VocaluxeLib.Menu
CBase.Theme.SkinVideoPause(_Theme.VideoName, _PartyModeID);
}
public bool Draw()
public void Draw()
{
bool ok = false;
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())
if (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON)
{
Pause();
ok = _DrawBackgroundMusicVideo();
if (CBase.Config.GetVideosToBackground() == EOffOn.TR_CONFIG_ON && CBase.BackgroundMusic.IsPlaying() && CBase.BackgroundMusic.SongHasVideo() &&
CBase.BackgroundMusic.VideoEnabled())
{
Pause();
ok = _DrawBackgroundMusicVideo();
}
else
{
Resume();
ok = _DrawVideo();
}
}
else if (_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_ON)
{
Resume();
ok = _DrawVideo();
}
if (_Theme.Type == EBackgroundTypes.SlideShow && _Theme.SlideShowTextures.Count > 0)
else if (_Theme.Type == EBackgroundTypes.SlideShow && _Theme.SlideShowTextures.Count > 0)
ok = _DrawSlideShow();
if (!String.IsNullOrEmpty(_Theme.TextureName) &&
(_Theme.Type == EBackgroundTypes.Texture ||
(_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF)))
if (!String.IsNullOrEmpty(_Theme.TextureName) && (_Theme.Type == EBackgroundTypes.Texture || !ok))
ok = _DrawTexture();
if (_Theme.Type == EBackgroundTypes.Color || _Theme.Type == EBackgroundTypes.Texture && !ok ||
(_Theme.Type == EBackgroundTypes.Video && CBase.Config.GetVideoBackgrounds() == EOffOn.TR_CONFIG_OFF && !ok))
if (_Theme.Type == EBackgroundTypes.Color || !ok)
_DrawColor();
return true;
}
public void UnloadTextures()
@@ -247,11 +241,14 @@ namespace VocaluxeLib.Menu
#endregion public
#region internal
private static SRectF _GetDrawRect()
{
return new SRectF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), CBase.Settings.GetZFar() / 4);
}
private void _DrawColor()
{
var bounds = new SRectF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH(), CBase.Settings.GetZFar() / 4);
CBase.Drawing.DrawColor(Color, bounds);
CBase.Drawing.DrawRect(Color, _GetDrawRect());
}
private bool _DrawTexture()
@@ -259,11 +256,7 @@ namespace VocaluxeLib.Menu
CTextureRef texture = CBase.Theme.GetSkinTexture(_Theme.TextureName, _PartyModeID);
if (texture != null)
{
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH());
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));
CBase.Drawing.DrawTexture(texture, _GetDrawRect(), EAspect.Crop);
return true;
}
return false;
@@ -284,7 +277,7 @@ namespace VocaluxeLib.Menu
_SlideShowTimer.Restart();
if (_SlideShowCurrent + 1 < _SlideShowTextures.Count)
_SlideShowCurrent++;
else if (_SlideShowCurrent != 0)
else
_SlideShowCurrent = 0;
}
@@ -293,11 +286,7 @@ namespace VocaluxeLib.Menu
if (texture == null)
return false;
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH());
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));
CBase.Drawing.DrawTexture(texture, _GetDrawRect(), EAspect.Crop);
if (_SlideShowTimer.ElapsedMilliseconds >= CBase.Settings.GetSlideShowImageTime())
{
@@ -310,9 +299,9 @@ namespace VocaluxeLib.Menu
if (texture != null)
{
float alpha = (_SlideShowTimer.ElapsedMilliseconds - CBase.Settings.GetSlideShowImageTime()) / CBase.Settings.GetSlideShowFadeTime();
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) - 1), new SColorF(1, 1, 1, alpha));
SColorF color = texture.Color;
color.A = (_SlideShowTimer.ElapsedMilliseconds - CBase.Settings.GetSlideShowImageTime()) / CBase.Settings.GetSlideShowFadeTime();
CBase.Drawing.DrawTexture(texture, _GetDrawRect(), EAspect.Crop, color);
}
}
@@ -326,11 +315,7 @@ namespace VocaluxeLib.Menu
CTextureRef videoTexture = CBase.Theme.GetSkinVideoTexture(_Theme.VideoName, _PartyModeID);
if (videoTexture != null)
{
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH());
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));
CBase.Drawing.DrawTexture(videoTexture, _GetDrawRect(), EAspect.Crop);
return true;
}
return false;
@@ -341,11 +326,7 @@ namespace VocaluxeLib.Menu
CTextureRef videoTexture = CBase.BackgroundMusic.GetVideoTexture();
if (videoTexture != null)
{
var bounds = new RectangleF(0f, 0f, CBase.Settings.GetRenderW(), CBase.Settings.GetRenderH());
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));
CBase.Drawing.DrawTexture(videoTexture, _GetDrawRect(), EAspect.Crop);
return true;
}
return false;
+2 -2
View File
@@ -275,10 +275,10 @@ namespace VocaluxeLib.Menu
if (i == _MaxBar)
color = MaxColor;
CBase.Drawing.DrawColor(color, bar);
CBase.Drawing.DrawRect(color, bar);
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);
}
else
CBase.Drawing.DrawColor(color, rect);
CBase.Drawing.DrawRect(color, rect);
}
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() {}
+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);
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)
@@ -494,7 +494,7 @@ namespace VocaluxeLib.Menu
}
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)