| 1 |
#ifndef _melder_colour_h_ |
| 2 |
#define _melder_colour_h_ |
| 3 |
/* melder_colour.h |
| 4 |
* |
| 5 |
* Copyright (C) 2019 Paul Boersma |
| 6 |
* |
| 7 |
* This code is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 10 |
* your option) any later version. |
| 11 |
* |
| 12 |
* This code is distributed in the hope that it will be useful, but |
| 13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 |
* See the GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
struct MelderColour { |
| 22 |
double red, green, blue, transparency; |
| 23 |
explicit MelderColour () : |
| 24 |
red (0.0), green (0.0), blue (0.0), transparency (0.0) {} |
| 25 |
explicit MelderColour (double greyValue) : |
| 26 |
red (Melder_clipped (0.0, greyValue, 1.0)), green (red), blue (red), transparency (0.0) {} |
| 27 |
explicit MelderColour (double initialRed, double initialGreen, double initialBlue) : |
| 28 |
red (initialRed), green (initialGreen), blue (initialBlue), transparency (0.0) {} |
| 29 |
explicit MelderColour (double initialRed, double initialGreen, double initialBlue, double initialTransparency) : |
| 30 |
red (initialRed), green (initialGreen), blue (initialBlue), transparency (initialTransparency) {} |
| 31 |
explicit MelderColour (constVEC const& vec); |
| 32 |
bool valid () const { |
| 33 |
return isdefined (our red); |
| 34 |
} |
| 35 |
bool isGrey () const { |
| 36 |
return our red == our green && our green == our blue; |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
extern MelderColour Melder_BLACK, Melder_WHITE, Melder_RED, Melder_GREEN, Melder_BLUE, |
| 41 |
Melder_CYAN, Melder_MAGENTA, Melder_YELLOW, Melder_MAROON, Melder_LIME, Melder_NAVY, Melder_TEAL, |
| 42 |
Melder_PURPLE, Melder_OLIVE, Melder_PINK, Melder_SILVER, Melder_GREY; |
| 43 |
|
| 44 |
MelderColour MelderColour_fromColourName (conststring32 colourName); |
| 45 |
/* |
| 46 |
If `colourName` is one of the 16 standard names (case-insensitively), |
| 47 |
then return that colour. If not, then result.valid() will return false. |
| 48 |
*/ |
| 49 |
|
| 50 |
MelderColour MelderColour_fromNumberString (conststring32 numberString); |
| 51 |
|
| 52 |
MelderColour MelderColour_fromRGBString (conststring32 rgbString); |
| 53 |
|
| 54 |
MelderColour MelderColour_fromColourNameOrNumberStringOrRGBString (conststring32 string); |
| 55 |
|
| 56 |
MelderColour MelderColour_fromColourNameOrRGBString (conststring32 string); |
| 57 |
|
| 58 |
conststring32 MelderColour_nameRGB (MelderColour colour); |
| 59 |
conststring32 MelderColour_namePrettyOrNull (MelderColour colour); |
| 60 |
conststring32 MelderColour_name (MelderColour colour); |
| 61 |
|
| 62 |
static inline bool MelderColour_equal (MelderColour colour1, MelderColour colour2) { |
| 63 |
return |
| 64 |
colour1. red == colour2. red && |
| 65 |
colour1. green == colour2. green && |
| 66 |
colour1. blue == colour2. blue && |
| 67 |
colour1. transparency == colour2. transparency; |
| 68 |
} |
| 69 |
MelderColour Melder_cyclingBackgroundColour (integer category); |
| 70 |
MelderColour Melder_cyclingTextColour (integer category); |
| 71 |
|
| 72 |
static inline MelderColour operator* (double multiplier, MelderColour me) { |
| 73 |
return |
| 74 |
multiplier <= 1.0 ? |
| 75 |
MelderColour (me.red * multiplier, me.green * multiplier, me.blue * multiplier, me.transparency) |
| 76 |
: |
| 77 |
MelderColour ( |
| 78 |
1.0 - (1.0 - me.red) / multiplier, |
| 79 |
1.0 - (1.0 - me.green) / multiplier, |
| 80 |
1.0 - (1.0 - me.blue) / multiplier, |
| 81 |
me.transparency |
| 82 |
) |
| 83 |
; |
| 84 |
} |
| 85 |
|
| 86 |
/* End of file melder_colour.h */ |
| 87 |
#endif |