Rename SetRect to something more appropriate and tune it

This commit is contained in:
Flamefire committed 2014-09-25 12:15:18 +02:00
1 parent 2ba5f9ee7f
commit 879176a87f
4 files changed
+31 -27

No files matched your search

+1 -2
View File
@@ -381,8 +381,7 @@ namespace Vocaluxe.Base
if (textureRef == null) if (textureRef == null)
return; return;
SRectF rect; SRectF rect = CHelper.FitInBounds(bounds, textureRef.OrigAspect, aspect);
CHelper.SetRect(bounds, out rect, textureRef.OrigAspect, aspect);
DrawTexture(textureRef, rect, color); DrawTexture(textureRef, rect, color);
} }
+28 -21
View File
@@ -78,51 +78,58 @@ namespace VocaluxeLib
return result; return result;
} }
public static void SetRect(SRectF bounds, out SRectF rect, float aspectRatio, EAspect aspect) /// <summary>
/// Places a rect within the bounds maintaining the aspectRatio and using the given aspect
/// </summary>
/// <param name="bounds">Bounds to fit the rect in</param>
/// <param name="aspectRatio">The original aspectRatio of the rect/image/...</param>
/// <param name="aspect">
/// Crop: Fit fully in bounds cutting off overhanging parts (same on both sides)<br />
/// LetterBox: Fit the long side possibly leaving some space on the other (rect will be centered)<br />
/// StretcH: Just fit the rect in the bounds (rect=bounds)
/// </param>
public static SRectF FitInBounds(SRectF bounds, float aspectRatio, EAspect aspect)
{ {
float boundsW = bounds.W; if (aspect == EAspect.Stretch)
float boundsH = bounds.H; return bounds;
float boundsAspectRatio = boundsW / boundsH;
float scaledWidth; float boundsAspectRatio = bounds.W / bounds.H;
float scaledHeight;
float scaledWidth, scaledHeight;
switch (aspect) switch (aspect)
{ {
case EAspect.Crop: case EAspect.Crop:
if (boundsAspectRatio >= aspectRatio) if (boundsAspectRatio >= aspectRatio)
{ {
scaledWidth = boundsW; scaledWidth = bounds.W;
scaledHeight = boundsW / aspectRatio; scaledHeight = bounds.W / aspectRatio;
} }
else else
{ {
scaledHeight = boundsH; scaledHeight = bounds.H;
scaledWidth = boundsH * aspectRatio; scaledWidth = bounds.H * aspectRatio;
} }
break; break;
case EAspect.LetterBox: case EAspect.LetterBox:
if (boundsAspectRatio <= aspectRatio) if (boundsAspectRatio <= aspectRatio)
{ {
scaledWidth = boundsW; scaledWidth = bounds.W;
scaledHeight = boundsW / aspectRatio; scaledHeight = bounds.W / aspectRatio;
} }
else else
{ {
scaledHeight = boundsH; scaledHeight = bounds.H;
scaledWidth = boundsH * aspectRatio; scaledWidth = bounds.H * aspectRatio;
} }
break; break;
default: default:
scaledWidth = boundsW; return bounds;
scaledHeight = boundsH;
break;
} }
float left = (bounds.W - scaledWidth) / 2 + bounds.X;
float top = (bounds.H - scaledHeight) / 2 + bounds.Y;
float left = (boundsW - scaledWidth) / 2 + bounds.X; return new SRectF(left, top, scaledWidth, scaledHeight, bounds.Z);
float upper = (boundsH - scaledHeight) / 2 + bounds.Y;
rect = new SRectF(left, upper, scaledWidth, scaledHeight, bounds.Z);
} }
/// <summary> /// <summary>
+1 -1
View File
@@ -196,7 +196,7 @@ namespace VocaluxeLib.Menu
SRectF rect = Rect.Scale(scale); SRectF rect = Rect.Scale(scale);
rect.Z += zModify; rect.Z += zModify;
if (texture != null) if (texture != null)
CHelper.SetRect(rect, out rect, texture.OrigAspect, aspect); rect = CHelper.FitInBounds(rect, texture.OrigAspect, aspect);
var color = new SColorF(Color.R, Color.G, Color.B, Color.A * Alpha); var color = new SColorF(Color.R, Color.G, Color.B, Color.A * Alpha);
if (Visible || forceDraw || (CBase.Settings.GetProgramState() == EProgramState.EditTheme)) if (Visible || forceDraw || (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
@@ -17,7 +17,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using VocaluxeLib.Draw; using VocaluxeLib.Draw;
@@ -473,8 +472,7 @@ namespace VocaluxeLib.Menu.SongMenu
{ {
if (vidtex.Color.A < 1) if (vidtex.Color.A < 1)
_CoverBig.Draw(EAspect.Crop); _CoverBig.Draw(EAspect.Crop);
SRectF rect; SRectF rect = CHelper.FitInBounds(_CoverBig.Rect, vidtex.OrigAspect, EAspect.Crop);
CHelper.SetRect(_CoverBig.Rect, out rect, vidtex.OrigAspect, EAspect.Crop);
CBase.Drawing.DrawTexture(vidtex, rect); CBase.Drawing.DrawTexture(vidtex, rect);
CBase.Drawing.DrawTextureReflection(vidtex, rect, vidtex.Color, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight); CBase.Drawing.DrawTextureReflection(vidtex, rect, vidtex.Color, _CoverBig.ReflectionSpace, _CoverBig.ReflectionHeight);