Browse Source

Add Color::fromRGB()

Signed-off-by: falkTX <falktx@falktx.com>
pull/506/head
falkTX 5 months ago
parent
commit
3821cb0b2c
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 29 additions and 8 deletions
  1. +12
    -1
      dgl/Color.hpp
  2. +9
    -1
      dgl/src/Color.cpp
  3. +8
    -6
      distrho/DistrhoUI.hpp

+ 12
- 1
dgl/Color.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
*
* 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.
*/


+ 9
- 1
dgl/src/Color.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
*
* 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<int>(color >> 24) & 0xff,
static_cast<int>(color >> 16) & 0xff,
static_cast<int>(color >> 8) & 0xff,
alpha);
}

void Color::interpolate(const Color& other, float u) noexcept
{
fixRange(u);


+ 8
- 6
distrho/DistrhoUI.hpp View File

@@ -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;



Loading…
Cancel
Save