1 // colour.h - Colour Structures
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #ifndef __COMMON_COLOUR_H__
20 #define __COMMON_COLOUR_H__
35 Colour& operator= (string const &arg){
37 // Check if the size of the string is 9.
46 // Check if the first character has a hash in.
49 if (arg.substr(0,1) != "#"){
55 // Check each character (1-8) and make sure
56 // it is a number or a letter between A and F.
58 for (int characterSeek = 1; characterSeek < 9; characterSeek++){
60 int characterASCII = 0;
62 characterASCII = arg[characterSeek];
64 if ((characterASCII < 48 && characterASCII > 57) || (characterASCII < 65 && characterASCII > 70)){
70 istringstream hexNumber;
74 hexNumber.str(arg.substr(1,2));
75 hexNumber >> hex >> this->red;
77 // Set the green value.
80 hexNumber.str(arg.substr(3,2));
81 hexNumber >> hex >> this->green;
83 // Set the blue value.
86 hexNumber.str(arg.substr(5,2));
87 hexNumber >> hex >> this->blue;
89 // Set the alpha value.
92 hexNumber.str(arg.substr(7,2));
93 hexNumber >> hex >> this->alpha;
106 // Convert the red value.
110 } else if (red < 0) {
113 IntToHex(&red, &ColourOutHex, 2);
114 ColourOut += ColourOutHex;
117 // Convert the green value.
121 } else if (green < 0){
124 IntToHex(&green, &ColourOutHex, 2);
125 ColourOut += ColourOutHex;
128 // Convert the blue value.
132 } else if (blue < 0) {
135 IntToHex(&blue, &ColourOutHex, 2);
136 ColourOut += ColourOutHex;
139 // Convert the alpha value.
143 } else if (alpha < 0){
146 IntToHex(&alpha, &ColourOutHex, 2);
147 ColourOut += ColourOutHex;