X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fcommon%2Fcolour.h;h=cf858b16fd6f2f88c9cf9f85953726d333ef3f3d;hb=cba151c4b833a26c63984769f921bab5e755decd;hp=93d42a686c6a31f07fe6cf10e9f0bc65b7490994;hpb=88dd6a205052fbf1d53083eb7e4733a7cf251db1;p=xestiacalendar%2F.git diff --git a/source/common/colour.h b/source/common/colour.h index 93d42a6..cf858b1 100644 --- a/source/common/colour.h +++ b/source/common/colour.h @@ -1,6 +1,6 @@ // colour.h - Colour Structures // -// (c) 2016 Xestia Software Development. +// (c) 2016-2017 Xestia Software Development. // // This file is part of Xestia Calendar. // @@ -17,6 +17,7 @@ // with Xestia Calendar. If not, see #include +#include #include "text.h" #ifndef __COMMON_COLOUR_H__ @@ -31,6 +32,70 @@ struct Colour{ int green = 0; int alpha = 255; + Colour& operator= (string const &arg){ + + // Check if the size of the string is 9. + // Return if not. + + if (arg.size() != 9){ + + return *this; + + } + + // Check if the first character has a hash in. + // Return if not. + + if (arg.substr(0,1) != "#"){ + + return *this; + + } + + // Check each character (1-8) and make sure + // it is a number or a letter between A and F. + + for (int characterSeek = 1; characterSeek < 9; characterSeek++){ + + int characterASCII = 0; + + characterASCII = arg[characterSeek]; + + if ((characterASCII < 48 && characterASCII > 57) || (characterASCII < 65 && characterASCII > 70)){ + return *this; + } + + } + + istringstream hexNumber; + + // Set the red value. + + hexNumber.str(arg.substr(1,2)); + hexNumber >> hex >> this->red; + + // Set the green value. + + hexNumber.clear(); + hexNumber.str(arg.substr(3,2)); + hexNumber >> hex >> this->green; + + // Set the blue value. + + hexNumber.clear(); + hexNumber.str(arg.substr(5,2)); + hexNumber >> hex >> this->blue; + + // Set the alpha value. + + hexNumber.clear(); + hexNumber.str(arg.substr(7,2)); + hexNumber >> hex >> this->alpha; + + return *this; + + } + operator string() { string ColourOut;