Move extension methods to Extensions.cs
Add IsInRange function
This commit is contained in:
1 parent
db4096d57f
commit
cc7d8058e2
4 files changed
+62
-58
No files matched your search
@@ -413,7 +413,7 @@ namespace Vocaluxe.Screens
|
||||
_SongMenu.Active = !_PlaylistActive;
|
||||
_ToggleSongOptions(ESongOptionsView.None);
|
||||
}
|
||||
else if (CHelper.IsInBounds(_SongMenu.Rect, mouseEvent.X, mouseEvent.Y))
|
||||
else if (CHelper.IsInBounds(_SongMenu.Rect, mouseEvent))
|
||||
{
|
||||
_PlaylistActive = false;
|
||||
_Playlist.Selected = _PlaylistActive;
|
||||
|
||||
+6
-56
@@ -17,7 +17,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@@ -63,46 +62,6 @@ namespace VocaluxeLib
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes sure val is between min and max
|
||||
/// Asserts that min<=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>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>
|
||||
/// Concat strings into one string with ", " as separator.
|
||||
/// </summary>
|
||||
@@ -121,17 +80,8 @@ namespace VocaluxeLib
|
||||
|
||||
public static void SetRect(SRectF bounds, out SRectF rect, float aspectRatio, EAspect aspect)
|
||||
{
|
||||
var bounds2 = new RectangleF(bounds.X, bounds.Y, bounds.W, bounds.H);
|
||||
RectangleF rect2;
|
||||
SetRect(bounds2, out rect2, aspectRatio, aspect);
|
||||
|
||||
rect = new SRectF(rect2.X, rect2.Y, rect2.Width, rect2.Height, bounds.Z);
|
||||
}
|
||||
|
||||
public static void SetRect(RectangleF bounds, out RectangleF rect, float aspectRatio, EAspect aspect)
|
||||
{
|
||||
float boundsW = bounds.Width;
|
||||
float boundsH = bounds.Height;
|
||||
float boundsW = bounds.W;
|
||||
float boundsH = bounds.H;
|
||||
float boundsAspectRatio = boundsW / boundsH;
|
||||
|
||||
float scaledWidth;
|
||||
@@ -169,10 +119,10 @@ namespace VocaluxeLib
|
||||
break;
|
||||
}
|
||||
|
||||
float left = (boundsW - scaledWidth) / 2 + bounds.Left;
|
||||
float upper = (boundsH - scaledHeight) / 2 + bounds.Top;
|
||||
float left = (boundsW - scaledWidth) / 2 + bounds.X;
|
||||
float upper = (boundsH - scaledHeight) / 2 + bounds.Y;
|
||||
|
||||
rect = new RectangleF(left, upper, scaledWidth, scaledHeight);
|
||||
rect = new SRectF(left, upper, scaledWidth, scaledHeight, bounds.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -276,7 +226,7 @@ namespace VocaluxeLib
|
||||
|
||||
public static bool IsInBounds(SRectF bounds, int x, int y)
|
||||
{
|
||||
return (bounds.X <= x) && (bounds.X + bounds.W >= x) && (bounds.Y <= y) && (bounds.Y + bounds.H >= y);
|
||||
return ((float)x).IsInRange(bounds.X, bounds.X + bounds.W) && ((float)y).IsInRange(bounds.Y, bounds.Y + bounds.H);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Globalization;
|
||||
@@ -26,6 +27,59 @@ namespace VocaluxeLib
|
||||
{
|
||||
public static class CExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Makes sure val is between min and max
|
||||
/// Asserts that min<=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>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>
|
||||
{
|
||||
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>
|
||||
|
||||
@@ -440,7 +440,7 @@ namespace VocaluxeLib.Menu
|
||||
|
||||
public bool IsMouseOver(SMouseEvent mouseEvent)
|
||||
{
|
||||
return CHelper.IsInBounds(CompleteRect, mouseEvent.X, mouseEvent.Y) || _Interactions.IsMouseOver(mouseEvent);
|
||||
return CHelper.IsInBounds(CompleteRect, mouseEvent) || _Interactions.IsMouseOver(mouseEvent);
|
||||
}
|
||||
|
||||
public void UnloadTextures()
|
||||
|
||||
Reference in new issue
Block a user