PropertyParserColour.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUI_CORE_PROPERTYPARSERCOLOUR_H
  29. #define RMLUI_CORE_PROPERTYPARSERCOLOUR_H
  30. #include "../../Include/RmlUi/Core/PropertyParser.h"
  31. #include "../../Include/RmlUi/Core/Types.h"
  32. #include "ControlledLifetimeResource.h"
  33. namespace Rml {
  34. /**
  35. A property parser that parses a colour value.
  36. @author Peter Curry
  37. */
  38. class PropertyParserColour : public PropertyParser {
  39. public:
  40. PropertyParserColour();
  41. virtual ~PropertyParserColour();
  42. /// Called to parse a RCSS colour declaration.
  43. /// @param[out] property The property to set the parsed value on.
  44. /// @param[in] value The raw value defined for this property.
  45. /// @param[in] parameters The parameters defined for this property; not used for this parser.
  46. /// @return True if the value was parsed successfully, false otherwise.
  47. bool ParseValue(Property& property, const String& value, const ParameterMap& parameters) const override;
  48. /// Parse a colour directly.
  49. static bool ParseColour(Colourb& colour, const String& value);
  50. static void Initialize();
  51. static void Shutdown();
  52. private:
  53. static ControlledLifetimeResource<struct PropertyParserColourData> parser_data;
  54. // Parse a colour in hex-code form (e.g. #FF00FF or #00FF00FF).
  55. static bool ParseHexColour(Colourb& colour, const String& value);
  56. // Parse a colour in RGB form (e.g. rgb(255, 0, 255) or rgba(0, 255, 0, 255)).
  57. static bool ParseRGBColour(Colourb& colour, const String& value);
  58. // Parse a colour in HSL form (e.g. hsl(0, 100%, 50%) or hsla(0, 100%, 50%, 1.0)).
  59. static bool ParseHSLColour(Colourb& colour, const String& value);
  60. // Parse a colour in CIELAB form (e.g. lab(100.0 0.0 0.0) or lab(50.0 -60.0 60.0 / 0.5)
  61. // or CIELCh form (e.g. lch(100.0 0.0 30) or lch(100.0 0.0 60 / 0.5)).
  62. static bool ParseCIELABColour(Colourb& colour, const String& value);
  63. // Parse a colour in Oklab form (e.g. oklab(1.0 0.0 0.0) or oklab(0.5 -0.2 0.2 / 0.5))
  64. // or Oklch form (e.g. oklch(1.0 0.0 30) or oklch(1.0 0.0 60 / 0.5)).
  65. static bool ParseOklabColour(Colourb& colour, const String& value);
  66. static bool GetColourFunctionValues(StringList& values, const String& value, bool is_comma_separated);
  67. };
  68. } // namespace Rml
  69. #endif