1. André Schnabel
  2. Kosu

Commits

André Schnabel  committed d934692

More mouselock tweaks

  • Participants
  • Parent commits 7a0ffe8
  • Branches default

Comments (0)

Files changed (2)

File Platforms/Desktop/DesktopBasecode.cs

View file
 		private void OnMouseLeave(object sender, EventArgs eventArgs) {
 			if(MouseLock) {
 				Globals.Platform.CenterMouse();
-				mousePos.X = (int)(Globals.ScrW / 2.0f);
-				mousePos.Y = (int)(Globals.ScrH / 2.0f);
+				mousePos.X = (int) (Globals.ScrW/2.0f);
+				mousePos.Y = (int) (Globals.ScrH/2.0f);
 				oldPos = mousePos;
 			}
 		}
 			int mouseX, mouseY;
 			int deltaX, deltaY;
 
+			const int borderMargin = 10;
+			if(MouseLock && mousePos.X > Globals.ScrW - borderMargin || mousePos.X < borderMargin || mousePos.Y < borderMargin || mousePos.Y > Globals.ScrH - borderMargin) {
+				OnMouseLeave(null);
+			}
+
 			// Linux case
 			if(Environment.OSVersion.Platform == PlatformID.Unix && !IsRunningOnMac()) {
 				MouseState mstate = OpenTK.Input.Mouse.GetState();

File Utilities/MathUtils.cs

View file
 		public static float Pow(float b, float e) {
 			return (float) System.Math.Pow(b, e);
 		}
+
+		// TODO: Write tests for ConvertToBase functions.
+
+		/// <summary>
+		/// Convert a base-10 (decimal) integer value to an array of base-radix (param) digits.
+		/// </summary>
+		/// <param name="radix">New base for resulting digits.</param>
+		/// <param name="value">base-10 integer value.</param>
+		/// <returns>Array of digits with base-radix having same quantity as base-10 input. Most significant digit first.</returns>
+		public static int[] ConvertToBase(int radix, int value) {
+			if(value == 0) return new[] {0};
+			var result = new int[(int) System.Math.Round(System.Math.Log(value, radix))];
+			for(int i = result.Length - 1; i >= 0; i--) {
+				result[i] = value%radix;
+				value /= radix;
+			}
+			return result;
+		}
+
+		public static int[] ConvertToBase(int radix, int value, int numDigits) {
+			var result = new int[numDigits];
+			if(value == 0) return result;
+
+			var actualDigits = (int) System.Math.Round(System.Math.Log(value, radix));
+			for(int i = actualDigits - 1; i >= 0; i--) {
+				result[i] = value%radix;
+				value /= radix;
+			}
+
+			return result;
+		}
 		#endregion
 
 		#region Distance measures