Private
Public Access
Documented Value
This commit is contained in:
1 parent
bbccecf82c
commit
8bb4f9b148
1 file changed
+53
-2
@@ -6,28 +6,71 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs {
|
||||
/// <summary>
|
||||
/// This class contains a large amount of useful conversions
|
||||
/// </summary>
|
||||
public class Value {
|
||||
/// <summary>
|
||||
/// Converts string to int (if possible)
|
||||
/// </summary>
|
||||
/// <param name="text">String to be converted to int</param>
|
||||
/// <returns>Integer representation of string</returns>
|
||||
public static int ConvertToInt(string text) {
|
||||
text = SettingsAndHelperFunctions.Strip(text);
|
||||
return int.Parse(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts string to double (if possible)
|
||||
/// </summary>
|
||||
/// <param name="text">String to be converted to double</param>
|
||||
/// <returns>Double representation of string</returns>
|
||||
public static double ConvertToDouble(string text) {
|
||||
text = SettingsAndHelperFunctions.Strip(text);
|
||||
return double.Parse(text);
|
||||
}
|
||||
|
||||
//TODO: Make unit tests for this function
|
||||
/// <summary>
|
||||
/// Converts two strings to a point object.
|
||||
/// </summary>
|
||||
/// <param name="text1">X parameter</param>
|
||||
/// <param name="text2">Y parameter</param>
|
||||
/// <returns>A Point object</returns>
|
||||
/// <todo>Make unit tests for this function</todo>
|
||||
public static Point ConvertToPoint(string text1, string text2) {
|
||||
return new Point(ConvertToInt(text1), ConvertToInt(text2));
|
||||
}
|
||||
|
||||
//TODO: Make unit tests for this function
|
||||
/// <summary>
|
||||
/// This function convers text to Color.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It can parse several different types of strings.
|
||||
/// Types of string accepted:
|
||||
/// - A string that is the name of a predefined color. See <see cref="Color"/> class for full list.
|
||||
/// - A string that represents a Hex Triplet (<code>#rrggbb</code>). See <see href="https://en.wikipedia.org/wiki/Web_colors#Hex_triplet"/>.
|
||||
/// - A string that represents a Hex Quadruplet (<code>#rrggbbaa</code>, where <code>aa</code> represents alpha).
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Color tmp = TextToColor("red");
|
||||
/// Console.WriteLine("Name: " + tmp.toString()) //=> "red"
|
||||
///
|
||||
/// tmp = TextToColor("deadbe");
|
||||
/// Console.WriteLine("Name: " + tmp.toString()) //=> "00deadbe"
|
||||
///
|
||||
/// //It's important to remember that C# doesn't work like HTML colors, putting alpha first, rather than last.
|
||||
///
|
||||
/// tmp = TextToColor("deadbeef");
|
||||
/// Console.WriteLine("Name: " + tmp.toString()) //=> "efdeadbe"
|
||||
/// </example>
|
||||
///
|
||||
/// <param name="text">a string with a valid name or format</param>
|
||||
/// <returns>color of the string</returns>
|
||||
public static Color TextToColor(string text) {
|
||||
Color color = Color.FromName(text);
|
||||
if (color.IsKnownColor) return color;
|
||||
|
||||
|
||||
if (text.StartsWith("#"))
|
||||
text = text.Substring(1);
|
||||
|
||||
@@ -51,6 +94,14 @@ namespace Advanced_Software_Engineering.Verbs {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a color from RGB(A) int values
|
||||
/// </summary>
|
||||
/// <param name="r">Red</param>
|
||||
/// <param name="g">Green</param>
|
||||
/// <param name="b">Blue</param>
|
||||
/// <param name="a">Optional: Alpha/Transparancy (default is 0)</param>
|
||||
/// <returns></returns>
|
||||
public static Color IntsToColor(int r, int g, int b, int a = 0) {
|
||||
return Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user