|
5 | 5 | namespace libscratchcpp |
6 | 6 | { |
7 | 7 |
|
| 8 | +/*! A typedef for unsigned int. Holds the RGBA values. */ |
| 9 | +using Rgb = unsigned int; |
| 10 | + |
| 11 | +/*! Returns the red component of the quadruplet rgb. */ |
| 12 | +inline constexpr int red(Rgb rgb) |
| 13 | +{ |
| 14 | + return ((rgb >> 16) & 0xff); |
| 15 | +} |
| 16 | + |
| 17 | +/*! Returns the green component of the quadruplet rgb. */ |
| 18 | +inline constexpr int green(Rgb rgb) |
| 19 | +{ |
| 20 | + return ((rgb >> 8) & 0xff); |
| 21 | +} |
| 22 | + |
| 23 | +/*! Returns the blue component of the quadruplet rgb. */ |
| 24 | +inline constexpr int blue(Rgb rgb) |
| 25 | +{ |
| 26 | + return (rgb & 0xff); |
| 27 | +} |
| 28 | + |
| 29 | +/*! Returns the alpha component of the quadruplet rgb. */ |
| 30 | +inline constexpr int alpha(Rgb rgb) |
| 31 | +{ |
| 32 | + return rgb >> 24; |
| 33 | +} |
| 34 | + |
| 35 | +/*! Creates an RGB triplet from the given color components. */ |
| 36 | +inline constexpr Rgb rgb(int r, int g, int b) |
| 37 | +{ |
| 38 | + return (0xffu << 24) | ((r & 0xffu) << 16) | ((g & 0xffu) << 8) | (b & 0xffu); |
| 39 | +} |
| 40 | + |
| 41 | +/*! Creates an RGBA quadruplet from the given color components. */ |
| 42 | +inline constexpr Rgb rgba(int r, int g, int b, int a) |
| 43 | +{ |
| 44 | + return ((a & 0xffu) << 24) | ((r & 0xffu) << 16) | ((g & 0xffu) << 8) | (b & 0xffu); |
| 45 | +} |
| 46 | + |
8 | 47 | extern "C" |
9 | 48 | { |
10 | 49 | LIBSCRATCHCPP_EXPORT void value_free(ValueData *v); |
@@ -33,6 +72,7 @@ extern "C" |
33 | 72 | LIBSCRATCHCPP_EXPORT void value_toString(const ValueData *v, std::string *dst); |
34 | 73 | LIBSCRATCHCPP_EXPORT char *value_toCString(const ValueData *v); |
35 | 74 | LIBSCRATCHCPP_EXPORT void value_toUtf16(const ValueData *v, std::u16string *dst); |
| 75 | + LIBSCRATCHCPP_EXPORT Rgb value_toRgba(const ValueData *v); |
36 | 76 |
|
37 | 77 | LIBSCRATCHCPP_EXPORT bool value_doubleIsInt(double v); |
38 | 78 |
|
|
0 commit comments