X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;ds=sidebyside;f=source%2Fcommon%2Fcolour.h;h=c9acc08970f67b5f51d08e6edf68340a07d4dea0;hb=b00724231971de7bc52e5cd7f11f0d4669e9aafd;hp=dc3dedfc8dba94ea4bbb73652391f2ebe893d6d8;hpb=e239336903d4625067eb7afda590fa5496cebbf4;p=xestiacalendar%2F.git
diff --git a/source/common/colour.h b/source/common/colour.h
index dc3dedf..c9acc08 100644
--- a/source/common/colour.h
+++ b/source/common/colour.h
@@ -1,14 +1,14 @@
// colour.h - Colour Structures
//
-// (c) 2016 Xestia Software Development.
+// (c) 2016-2017 Xestia Software Development.
//
// This file is part of Xestia Calendar.
//
-// Xestia Address Book is free software: you can redistribute it and/or modify
+// Xestia Calendar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
-// Xestia Address Book is distributed in the hope that it will be useful,
+// Xestia Calendar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
@@ -16,18 +16,86 @@
// You should have received a copy of the GNU General Public License along
// with Xestia Calendar. If not, see
+#ifndef __COMMON_COLOUR_H__
+#define __COMMON_COLOUR_H__
+
#include
+#include
#include "text.h"
using namespace std;
struct Colour{
- int red;
- int blue;
- int green;
- int alpha;
+ int red = 0;
+ int blue = 0;
+ 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;
@@ -83,4 +151,6 @@ struct Colour{
}
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file