HslColor and Color Utilities (#989)
* Refactor HslColor: Improve implementation, documentation, and API - Added explicit memory layout to prepare for particle update. - Restructured fields as private with readonly property accessors. Struct is meant to be immutable, but the CopyTo method makes it mutable, so this is a trade off - Added nullability annotations and explicit argument validations. - Added Deconstruct method to match MonoGame terminology and marked Destruct as obsolete. - Marked the implicit string conversion as obsolete. Users should use the Parse method as it's more explicity as to what's happening. - Restructure the FromRgb method for better readability and future maintenance. * Deprecate ColorExtensions.ToHsl method in favor of HslColor.FromRgb The ColorExtensions.ToHsl and HslColor.FromRgb methods provide the same functionality but with different implementations. HslColor.FromRgb is more accurate and handles edge cases correctly, so it should be preferred. * Mark ColorExtensions.FromHex as obsolete This just calls ColorHelper.FromHex, which is where the call site should be anyway as this isn't an extension method of Color. * Move FromAbgr to ColorHelper. This is not an extension method. Mark other as obsolete. * Add a const value for machine epsilon * Move ToRgb as a static method of HslColor struct - ColorExtensions.ToRgb has been marked obsolete * Mark ColorExtensions.ToRgb as obsolete * Move ToHex from ColorHelper to ColorExtensions and make it an extension method. Marked ColorHelper.ToHex as obsolete * Mark ColorHelper.FromHsl as obsolete * Clean up namespaces * Add FromHex overload that uses ReadOnlySpan<char> which increases performance and reduces memory allocations * Update documentation of FromAbgr since it was moved to ColorHelper * Fix <c> tag in documentation * Per coding guidelines, fields at top of class declaration * Per coding guidelines, prefix static fields with `s_` * Document the FromName method * Adhere to coding guidelines - If statement, even single line, uses brackets - Inline `Color` definition * Documentat ColorHelper class * Remove extra whitespace line * Clean up unused namespaces * Correct test case * Move to root namespace * Rename to HslColorTests * Add tests for ColorExtensions.ToHex * Use facts not theorys * Add tests for ColorHelper.FromHex
MonoGame.Extended
MonoGame.Extended is a set of utilities (in the form of libraries/tools) to MonoGame that makes it easier to make games. Choose what you want, the rest stays out of your way. It makes MonoGame more awesome.
Getting started
Code is distributed as NuGet packages in the form of libraries (.dll files). You can easily install the NuGet packages into your existing MonoGame project using the NuGet Package Manager UI in Visual Studio or by using the command line interface (CLI) in a terminal.
dotnet add package MonoGame.Extended --version 4.0.2
Using the Content Pipeline Extensions
To use the content pipeline extension, please refer to the Setup MGCB Edtior documentation.
Where to next?
- Check out the samples
- Join our live Discord
- Read the Documentation
- Submit an issue on GitHub
- Ask a question on gamedev stack overflow
- Post on our MonoGame community forum
- Follow development on Patreon
Patreon Supporters
The patreon has been removed. If you would like to support the maintainers of this project, please consider using the GitHub sponsors link for one of the maintainers.
As a special thanks to those that supported this project through Patreon in the past, their websites were linked in this readme and have been preserved below:
Special Thanks
- Matthew-Davey for letting us use the Mercury Particle Engine.
- John McDonald for 2D XNA Primitives
- LibGDX for a whole lot of inspiration.
- @prime31 for
Nez. BothMonoGame.ExtendedandNezare in communication with each other to share ideas.
And a special thinks to all contributors!
License
MonoGame.Extended is released under the MIT License (MIT). Please refer to the LICENSE file for full license text.
