diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs
index ace7503d..62f17bd2 100644
--- a/Vocaluxe/Screens/CScreenSong.cs
+++ b/Vocaluxe/Screens/CScreenSong.cs
@@ -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;
diff --git a/VocaluxeLib/CHelper.cs b/VocaluxeLib/CHelper.cs
index ea314518..e14f363b 100644
--- a/VocaluxeLib/CHelper.cs
+++ b/VocaluxeLib/CHelper.cs
@@ -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;
}
- ///
- /// Makes sure val is between min and max
- /// Asserts that min<=max
- ///
- ///
- ///
- ///
- ///
- /// Clamped value
- public static T Clamp(this T val, T min, T max) where T : IComparable
- {
- Debug.Assert(min.CompareTo(max) <= 0);
- if (val.CompareTo(min) < 0)
- return min;
- if (val.CompareTo(max) > 0)
- return max;
- return val;
- }
-
- ///
- /// Makes sure val is between min and max but also handles the case where min>max
- ///
- ///
- ///
- ///
- ///
- ///
- /// Clamped value
- public static T Clamp(this T val, T min, T max, bool preferMin) where T : IComparable
- {
- if (min.CompareTo(max) > 0)
- {
- if (preferMin)
- max = min;
- else
- min = max;
- }
- return Clamp(val, min, max);
- }
-
///
/// Concat strings into one string with ", " as separator.
///
@@ -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);
}
///
@@ -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);
}
///
diff --git a/VocaluxeLib/Extensions.cs b/VocaluxeLib/Extensions.cs
index 3716cbb5..fd359b67 100644
--- a/VocaluxeLib/Extensions.cs
+++ b/VocaluxeLib/Extensions.cs
@@ -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
{
+ ///
+ /// Makes sure val is between min and max
+ /// Asserts that min<=max
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Clamped value
+ public static T Clamp(this T val, T min, T max) where T : IComparable
+ {
+ Debug.Assert(min.CompareTo(max) <= 0);
+ if (val.CompareTo(min) < 0)
+ return min;
+ if (val.CompareTo(max) > 0)
+ return max;
+ return val;
+ }
+
+ ///
+ /// Makes sure val is between min and max but also handles the case where min>max
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Clamped value
+ public static T Clamp(this T val, T min, T max, bool preferMin) where T : IComparable
+ {
+ if (min.CompareTo(max) > 0)
+ {
+ if (preferMin)
+ max = min;
+ else
+ min = max;
+ }
+ return Clamp(val, min, max);
+ }
+
+ ///
+ /// Checks if the value is in the specified range
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool IsInRange(this T val, T min, T max) where T : IComparable
+ {
+ return min.CompareTo(val) <= 0 && max.CompareTo(val) >= 0;
+ }
+
///
/// Resizes the given list to the given size. Removes elements or adds default values
///
diff --git a/VocaluxeLib/Menu/CPlaylist.cs b/VocaluxeLib/Menu/CPlaylist.cs
index 428955d0..5364d78f 100644
--- a/VocaluxeLib/Menu/CPlaylist.cs
+++ b/VocaluxeLib/Menu/CPlaylist.cs
@@ -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()