Merge branch 'Better_Graphics_Handling' into Automatic_Covers

Conflicts:
	Vocaluxe/Base/CCover.cs
	Vocaluxe/Base/CGraphics.cs
	Vocaluxe/Base/Fonts/CFontStyle.cs
	Vocaluxe/Base/Fonts/CGlyph.cs
	VocaluxeLib/Menu/CText.cs
	VocaluxeLib/Structs.cs
This commit is contained in:
Flamefire committed 2014-09-25 19:43:21 +02:00
commit dd1231ad34
603 files changed
+25356 -25970

No files matched your search

+99
View File
@@ -17,6 +17,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
@@ -25,6 +28,60 @@ namespace VocaluxeLib
{
public static class CExtensions
{
/// <summary>
/// Makes sure val is between min and max
/// Asserts that min&lt;=max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
if (val.CompareTo(min) < 0)
return min;
if (val.CompareTo(max) > 0)
return max;
return val;
}
/// <summary>
/// Makes sure val is between min and max but also handles the case where min&gt;max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <param name="preferMin"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max, bool preferMin) where T : IComparable<T>
{
if (min.CompareTo(max) > 0)
{
if (preferMin)
max = min;
else
min = max;
}
return Clamp(val, min, max);
}
/// <summary>
/// Checks if the value is in the specified range
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
public static bool IsInRange<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
return min.CompareTo(val) <= 0 && max.CompareTo(val) >= 0;
}
/// <summary>
/// Resizes the given list to the given size. Removes elements or adds default values
/// </summary>
@@ -120,5 +177,47 @@ namespace VocaluxeLib
rect.H + 2 * rect.H * (scale - 1f),
rect.Z);
}
public static Size GetSize(this Bitmap bmp)
{
return new Size(bmp.Width, bmp.Height);
}
public static Rectangle GetRect(this Bitmap bmp)
{
return Rectangle.Round(new Rectangle(0, 0, bmp.Width, bmp.Height));
}
/// <summary>
/// Resizes the bitmap to the given size creating a copy of it
/// </summary>
/// <param name="bmp"></param>
/// <param name="newSize"></param>
/// <returns>Resized bitmap or null on error</returns>
public static Bitmap Resize(this Bitmap bmp, Size newSize)
{
Bitmap result = null;
try
{
//Create a new Bitmap with the new sizes
result = new Bitmap(newSize.Width, newSize.Height);
//Scale the texture
using (Graphics g = Graphics.FromImage(result))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawImage(bmp, result.GetRect());
}
}
catch (Exception)
{
if (result != null)
{
result.Dispose();
result = null;
}
}
return result;
}
}
}