diff --git a/dgl/Color.hpp b/dgl/Color.hpp index 0b8aaede..ce3c6fc4 100644 --- a/dgl/Color.hpp +++ b/dgl/Color.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2022 Filipe Coelho + * Copyright (C) 2012-2025 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -115,6 +115,17 @@ struct Color { */ static Color fromHTML(const char* rgb, float alpha = 1.0f) noexcept; + /** + Create a color from a RGB unsigned integer. + Basically doing: + ``` + uint8_t red = (color >> 24) & 0xff; + uint8_t green = (color >> 16) & 0xff; + uint8_t blue = (color >> 8) & 0xff; + ``` + */ + static Color fromRGB(uint color, float alpha = 1.0f) noexcept; + /** Linearly interpolate this color against another. */ diff --git a/dgl/src/Color.cpp b/dgl/src/Color.cpp index 525c651f..109910b0 100644 --- a/dgl/src/Color.cpp +++ b/dgl/src/Color.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho + * Copyright (C) 2012-2025 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -242,6 +242,14 @@ Color Color::fromHTML(const char* rgb, const float alpha) noexcept return Color(r, g, b, alpha); } +Color Color::fromRGB(const uint color, const float alpha) noexcept +{ + return Color(static_cast(color >> 24) & 0xff, + static_cast(color >> 16) & 0xff, + static_cast(color >> 8) & 0xff, + alpha); +} + void Color::interpolate(const Color& other, float u) noexcept { fixRange(u); diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp index ca412578..77418403 100644 --- a/distrho/DistrhoUI.hpp +++ b/distrho/DistrhoUI.hpp @@ -106,10 +106,11 @@ public: The following example code can be use to extract individual colors: ``` - const int red = (bgColor >> 24) & 0xff; - const int green = (bgColor >> 16) & 0xff; - const int blue = (bgColor >> 8) & 0xff; + int red = (bgColor >> 24) & 0xff; + int green = (bgColor >> 16) & 0xff; + int blue = (bgColor >> 8) & 0xff; ``` + @see Color::fromRGB */ uint getBackgroundColor() const noexcept; @@ -119,10 +120,11 @@ public: The following example code can be use to extract individual colors: ``` - const int red = (fgColor >> 24) & 0xff; - const int green = (fgColor >> 16) & 0xff; - const int blue = (fgColor >> 8) & 0xff; + int red = (fgColor >> 24) & 0xff; + int green = (fgColor >> 16) & 0xff; + int blue = (fgColor >> 8) & 0xff; ``` + @see Color::fromRGB */ uint getForegroundColor() const noexcept;