<commit_before>﻿using System;
using Microsoft.Xna.Framework;
using Terraria;


namespace HamstarHelpers.Helpers.UI {
	/// <summary>
	/// Assorted static "helper" functions pertaining to the in-game UI zoom and positions.
	/// </summary>
	public class UIZoomHelpers {
		/// <summary>
		/// Gets the current screen size according to the given scales.
		/// </summary>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static (float Width, float Height) GetScreenSize( bool? uiZoomState, bool? gameZoomState ) {
			float width = UIZoomHelpers.ApplyZoom( Main.screenWidth, uiZoomState, gameZoomState );
			float height = UIZoomHelpers.ApplyZoom( Main.screenHeight, uiZoomState, gameZoomState );

			return (width, height);
		}

		/// <summary>
		/// Gets the world position and range of the screen, according to the given zoom parameters.
		/// </summary>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static Rectangle GetWorldFrameOfScreen( bool? uiZoomState, bool? gameZoomState ) {
			float width = UIZoomHelpers.ApplyZoom( Main.screenWidth, uiZoomState, gameZoomState );
			float height = UIZoomHelpers.ApplyZoom( Main.screenHeight, uiZoomState, gameZoomState );

			int scrX = (int)Main.screenPosition.X;
			scrX += (int)( ( (float)Main.screenWidth - width ) * 0.5f );
			int scrY = (int)Main.screenPosition.Y;
			scrY += (int)( ( (float)Main.screenHeight - height ) * 0.5f );

			return new Rectangle( scrX, scrY, (int)width, (int)height );
		}


		////////////////

		/// <summary>
		/// Applies the given zoom parameters to the given float.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static float ApplyZoom( float value, bool? uiZoomState, bool? gameZoomState ) {
			if( uiZoomState.HasValue ) {
				if( uiZoomState.Value ) {
					value /= Main.UIScale;
				} else {
					value *= Main.UIScale;
				}
			}
			if( gameZoomState.HasValue ) {
				if( gameZoomState.Value ) {
					value /= Main.GameZoomTarget;
				} else {
					value *= Main.GameZoomTarget;
				}
			}

			return value;
		}

		/// <summary>
		/// Applies the given zoom parameters to the given Vector2.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static Vector2 ApplyZoom(
					Vector2 value,
					bool? uiZoomState,
					bool? gameZoomState ) {
			if( uiZoomState.HasValue ) {
				if( uiZoomState.Value ) {
					value /= Main.UIScale;
				} else {
					value *= Main.UIScale;
				}
			}
			if( gameZoomState.HasValue ) {
				if( gameZoomState.Value ) {
					value /= Main.GameZoomTarget;
				} else {
					value *= Main.GameZoomTarget;
				}
			}

			return value;
		}

		/// <summary>
		/// Applies the given zoom parameters to the given Vector2.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="uiZoomStateForCenterOffset">Applies zoom effects relative to the center of the screen.</param>
		/// <returns></returns>
		public static Vector2 ApplyZoomFromScreenCenter(
					Vector2 value,
					bool? uiZoomState,
					bool? gameZoomState,
					bool? uiZoomStateForCenterOffset,
					bool? gameZoomStateForCenterOffset ) {
			var scrMid = new Vector2( Main.screenWidth, Main.screenHeight ) * 0.5f;
			value -= UIZoomHelpers.ApplyZoom( scrMid, uiZoomStateForCenterOffset, gameZoomStateForCenterOffset );

			if( uiZoomState.HasValue ) {
				if( uiZoomState.Value ) {
					value /= Main.UIScale;
				} else {
					value *= Main.UIScale;
				}
			}
			if( gameZoomState.HasValue ) {
				if( gameZoomState.Value ) {
					value /= Main.GameZoomTarget;
				} else {
					value *= Main.GameZoomTarget;
				}
			}

			value += scrMid;

			return value;
		}
	}
}
<commit_msg>v5.8.1 - Condensed some code<commit_after>﻿using System;
using Microsoft.Xna.Framework;
using Terraria;


namespace HamstarHelpers.Helpers.UI {
	/// <summary>
	/// Assorted static "helper" functions pertaining to the in-game UI zoom and positions.
	/// </summary>
	public class UIZoomHelpers {
		/// <summary>
		/// Gets the current screen size according to the given scales.
		/// </summary>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static (float Width, float Height) GetScreenSize( bool? uiZoomState, bool? gameZoomState ) {
			float width = UIZoomHelpers.ApplyZoom( Main.screenWidth, uiZoomState, gameZoomState );
			float height = UIZoomHelpers.ApplyZoom( Main.screenHeight, uiZoomState, gameZoomState );

			return (width, height);
		}

		/// <summary>
		/// Gets the world position and range of the screen, according to the given zoom parameters.
		/// </summary>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static Rectangle GetWorldFrameOfScreen( bool? uiZoomState, bool? gameZoomState ) {
			float width = UIZoomHelpers.ApplyZoom( Main.screenWidth, uiZoomState, gameZoomState );
			float height = UIZoomHelpers.ApplyZoom( Main.screenHeight, uiZoomState, gameZoomState );

			int scrX = (int)Main.screenPosition.X;
			scrX += (int)( ( (float)Main.screenWidth - width ) * 0.5f );
			int scrY = (int)Main.screenPosition.Y;
			scrY += (int)( ( (float)Main.screenHeight - height ) * 0.5f );

			return new Rectangle( scrX, scrY, (int)width, (int)height );
		}


		////////////////

		/// <summary>
		/// Applies the given zoom parameters to the given float.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static float ApplyZoom( float value, bool? uiZoomState, bool? gameZoomState ) {
			if( uiZoomState.HasValue ) {
				if( uiZoomState.Value ) {
					value /= Main.UIScale;
				} else {
					value *= Main.UIScale;
				}
			}
			if( gameZoomState.HasValue ) {
				if( gameZoomState.Value ) {
					value /= Main.GameZoomTarget;
				} else {
					value *= Main.GameZoomTarget;
				}
			}

			return value;
		}

		/// <summary>
		/// Applies the given zoom parameters to the given Vector2.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <returns></returns>
		public static Vector2 ApplyZoom(
					Vector2 value,
					bool? uiZoomState,
					bool? gameZoomState ) {
			if( uiZoomState.HasValue ) {
				if( uiZoomState.Value ) {
					value /= Main.UIScale;
				} else {
					value *= Main.UIScale;
				}
			}
			if( gameZoomState.HasValue ) {
				if( gameZoomState.Value ) {
					value /= Main.GameZoomTarget;
				} else {
					value *= Main.GameZoomTarget;
				}
			}

			return value;
		}

		/// <summary>
		/// Applies the given zoom parameters to the given Vector2.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
		/// removed, and applies it.</param>
		/// <param name="uiZoomStateForCenterOffset"></param>
		/// <param name="gameZoomStateForCenterOffset"></param>
		/// <returns></returns>
		public static Vector2 ApplyZoomFromScreenCenter(
					Vector2 value,
					bool? uiZoomState,
					bool? gameZoomState,
					bool? uiZoomStateForCenterOffset,
					bool? gameZoomStateForCenterOffset ) {
			var scrMid = new Vector2( Main.screenWidth, Main.screenHeight ) * 0.5f;
			value -= UIZoomHelpers.ApplyZoom( scrMid, uiZoomStateForCenterOffset, gameZoomStateForCenterOffset );
			value = UIZoomHelpers.ApplyZoom( value, uiZoomState, gameZoomState );
			value += scrMid;

			return value;
		}
	}
}

{'fraction_non_alphanumeric': 0.1403857625770531, 'fraction_numerical': 0.0028832769934380594, 'mean_word_length': 3.0495169082125604, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1432817', 'n_tokens_mistral': 3558, 'n_tokens_neox': 3036, 'n_words': 935}