MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
colourvalue.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _colourvalue_cpp
41 #define _colourvalue_cpp
42 
43 #include "colourvalue.h"
44 #include "stringtool.h"
45 #include "serialization.h"
46 #include "exception.h"
47 
48 #include <Ogre.h>
49 
50 #include <memory>
51 namespace Mezzanine
52 {
53  ColourValue::ColourValue(Real Red, Real Green, Real Blue, Real Alpha)
54  {
55  this->RedChannel = Red;
56  this->GreenChannel = Green;
57  this->BlueChannel = Blue;
58  this->AlphaChannel = Alpha;
59  }
60 
61  ColourValue::ColourValue(const Ogre::ColourValue& OgreValues)
62  {
63  this->RedChannel = OgreValues.r;
64  this->GreenChannel = OgreValues.g;
65  this->BlueChannel = OgreValues.b;
66  this->AlphaChannel = OgreValues.a;
67  }
68 
70  {
71  this->RedChannel = OtherColour.RedChannel;
72  this->GreenChannel = OtherColour.GreenChannel;
73  this->BlueChannel = OtherColour.BlueChannel;
74  this->AlphaChannel = OtherColour.AlphaChannel;
75  }
76 
78  { this->ProtoDeSerialize(OneNode); }
79 
81  { }
82 
83  ///////////////////////////////////////////////////////////////////////////////
84  // Conversion Methods
85 
86  Ogre::ColourValue ColourValue::GetOgreColourValue() const
87  {
88  Ogre::ColourValue OgreColour;
89  OgreColour.r = this->RedChannel;
90  OgreColour.g = this->GreenChannel;
91  OgreColour.b = this->BlueChannel;
92  OgreColour.a = this->AlphaChannel;
93  return OgreColour;
94  }
95 
96  ///////////////////////////////////////////////////////////////////////////////
97  // Utility
98 
100  { RedChannel = Red; }
101 
103  { return RedChannel; }
104 
106  { GreenChannel = Green; }
107 
109  { return GreenChannel; }
110 
112  { BlueChannel = Blue; }
113 
115  { return BlueChannel; }
116 
118  { AlphaChannel = Alpha; }
119 
121  { return AlphaChannel; }
122 
124  {
125  return ColourValue( (this->RedChannel+OtherColor.RedChannel) * 0.5,
126  (this->GreenChannel+OtherColor.GreenChannel) * 0.5,
127  (this->BlueChannel+OtherColor.BlueChannel) * 0.5,
128  (this->AlphaChannel+OtherColor.AlphaChannel) * 0.5 );
129  }
130 
131  ///////////////////////////////////////////////////////////////////////////////
132  // Overloaded Operators
133 
134  bool ColourValue::operator==(const ColourValue &Colour) const
135  { return ( Colour.RedChannel == this->RedChannel && Colour.GreenChannel == this->GreenChannel && Colour.BlueChannel == this->BlueChannel && Colour.AlphaChannel == this->AlphaChannel ); }
136 
137  bool ColourValue::operator!=(const ColourValue &Colour) const
138  { return ( Colour.RedChannel != this->RedChannel || Colour.GreenChannel != this->GreenChannel || Colour.BlueChannel != this->BlueChannel || Colour.AlphaChannel != this->AlphaChannel ); }
139 
140  void ColourValue::operator=(const ColourValue &OtherColour)
141  {
142  this->RedChannel = OtherColour.RedChannel;
143  this->GreenChannel = OtherColour.GreenChannel;
144  this->BlueChannel = OtherColour.BlueChannel;
145  this->AlphaChannel = OtherColour.AlphaChannel;
146  }
147 
148  ///////////////////////////////////////////////////////////////////////////////
149  // Prefab Colour fetchers
150 
152  { return ColourValue(0.0,0.0,0.0,0.0); }
153 
154  ///////////////////////////////////////////////////////////////////////////////
155  // X11 Colour Prefabs
156 
158  { return ColourValue(0.941176,0.972549,1.0,1.0); }
159 
161  { return ColourValue(0.980392,0.921568,0.843137,1.0); }
162 
164  { return ColourValue(0.0,1.0,1.0,1.0); }
165 
167  { return ColourValue(0.498039,1.0,0.831372,1.0); }
168 
170  { return ColourValue(0.941176,1.0,1.0,1.0); }
171 
173  { return ColourValue(0.960784,0.960784,0.862745,1.0); }
174 
176  { return ColourValue(1.0,0.894117,0.768627,1.0); }
177 
179  { return ColourValue(0.0,0.0,0.0,1.0); }
180 
182  { return ColourValue(1.0,0.921568,0.803921,1.0); }
183 
185  { return ColourValue(0.0,0.0,1.0,1.0); }
186 
188  { return ColourValue(0.541176,0.168627,0.886274,1.0); }
189 
191  { return ColourValue(0.647058,0.164705,0.164705,1.0); }
192 
194  { return ColourValue(0.870588,0.721568,0.529411,1.0); }
195 
197  { return ColourValue(0.372549,0.619607,0.627450,1.0); }
198 
200  { return ColourValue(0.498039,1.0,0.0,1.0); }
201 
203  { return ColourValue(0.823529,0.411764,0.117647,1.0); }
204 
206  { return ColourValue(1.0,0.498039,0.313725,1.0); }
207 
209  { return ColourValue(0.392116,0.584313,0.929411,1.0); }
210 
212  { return ColourValue(1.0,0.972549,0.862745,1.0); }
213 
215  { return ColourValue(0.862745,0.078431,0.235294,1.0); }
216 
218  { return ColourValue(0.0,1.0,1.0,1.0); }
219 
221  { return ColourValue(0.0,0.0,0.545098,1.0); }
222 
224  { return ColourValue(0.0,0.545098,0.545098,1.0); }
225 
227  { return ColourValue(0.721568,0.525490,0.043137,1.0); }
228 
230  { return ColourValue(0.662745,0.662745,0.662745,1.0); }
231 
233  { return ColourValue(0.0,0.392116,0.0,1.0); }
234 
236  { return ColourValue(0.741176,0.717647,0.419607,1.0); }
237 
239  { return ColourValue(0.545098,0.0,0.545098,1.0); }
240 
242  { return ColourValue(0.333333,0.419607,0.184313,1.0); }
243 
245  { return ColourValue(1.0,0.549019,0.0,1.0); }
246 
248  { return ColourValue(0.6,0.196078,0.8,1.0); }
249 
251  { return ColourValue(0.545098,0.0,0.0,1.0); }
252 
254  { return ColourValue(0.913725,0.588235,0.478431,1.0); }
255 
257  { return ColourValue(0.560784,0.737254,0.560784,1.0); }
258 
260  { return ColourValue(0.282352,0.239215,0.545098,1.0); }
261 
263  { return ColourValue(0.184313,0.309803,0.309803,1.0); }
264 
266  { return ColourValue(0.0,0.807843,0.819607,1.0); }
267 
269  { return ColourValue(0.580392,0.0,0.827450,1.0); }
270 
272  { return ColourValue(1.0,0.078431,0.576470,1.0); }
273 
275  { return ColourValue(0.0,0.749019,1.0,1.0); }
276 
278  { return ColourValue(0.411764,0.411764,0.411764,1.0); }
279 
281  { return ColourValue(0.117647,0.564705,1.0,1.0); }
282 
284  { return ColourValue(0.698039,0.133333,0.133333,1.0); }
285 
287  { return ColourValue(1.0,0.980392,0.941176,1.0); }
288 
290  { return ColourValue(0.133333,0.545098,0.133333,1.0); }
291 
293  { return ColourValue(1.0,0.0,1.0,1.0); }
294 
296  { return ColourValue(0.862745,0.862745,0.862745,1.0); }
297 
299  { return ColourValue(0.972549,0.972549,1.0,1.0); }
300 
302  { return ColourValue(1.0,0.843137,0.0,1.0); }
303 
305  { return ColourValue(0.854901,0.647058,0.125490,1.0); }
306 
308  { return ColourValue(0.501960,0.501960,0.501960,1.0); }
309 
311  { return ColourValue(0.0,0.501960,0.0,1.0); }
312 
314  { return ColourValue(0.678431,1.0,0.184313,1.0); }
315 
317  { return ColourValue(0.941176,1.0,0.941176,1.0); }
318 
320  { return ColourValue(1.0,0.411764,0.705882,1.0); }
321 
323  { return ColourValue(0.803921,0.360784,0.360784,1.0); }
324 
326  { return ColourValue(0.294117,0.0,0.509803,1.0); }
327 
329  { return ColourValue(1.0,1.0,0.941176,1.0); }
330 
332  { return ColourValue(0.941176,0.901960,0.549019,1.0); }
333 
335  { return ColourValue(0.901960,0.901960,0.980392,1.0); }
336 
338  { return ColourValue(1.0,0.941176,0.960784,1.0); }
339 
341  { return ColourValue(0.486274,0.988235,0.0,1.0); }
342 
344  { return ColourValue(1.0,0.980392,0.803921,1.0); }
345 
347  { return ColourValue(0.678431,0.847058,0.901960,1.0); }
348 
350  { return ColourValue(0.941176,0.501960,0.501960,1.0); }
351 
353  { return ColourValue(0.878431,1.0,1.0,1.0); }
354 
356  { return ColourValue(0.980392,0.980392,0.823529,1.0); }
357 
359  { return ColourValue(0.827450,0.827450,0.827450,1.0); }
360 
362  { return ColourValue(0.564705,0.933333,0.564705,1.0); }
363 
365  { return ColourValue(1.0,0.713725,0.756862,1.0); }
366 
368  { return ColourValue(1.0,0.627450,0.478431,1.0); }
369 
371  { return ColourValue(0.125490,0.698039,0.666666,1.0); }
372 
374  { return ColourValue(0.529411,0.807843,0.980392,1.0); }
375 
377  { return ColourValue(0.466666,0.533333,0.6,1.0); }
378 
380  { return ColourValue(0.690196,0.768627,0.870588,1.0); }
381 
383  { return ColourValue(1.0,1.0,0.878431,1.0); }
384 
386  { return ColourValue(0.0,1.0,0.0,1.0); }
387 
389  { return ColourValue(0.196078,0.803921,0.196078,1.0); }
390 
392  { return ColourValue(0.980392,0.941176,0.901960,1.0); }
393 
395  { return ColourValue(1.0,0.0,1.0,1.0); }
396 
398  { return ColourValue(0.501960,0.0,0.0,1.0); }
399 
401  { return ColourValue(0.4,0.803921,0.666666,1.0); }
402 
404  { return ColourValue(0.0,0.0,0.803921,1.0); }
405 
407  { return ColourValue(0.729411,0.333333,0.827450,1.0); }
408 
410  { return ColourValue(0.576470,0.439215,0.858823,1.0); }
411 
413  { return ColourValue(0.235294,0.701960,0.443137,1.0); }
414 
416  { return ColourValue(0.482352,0.407843,0.933333,1.0); }
417 
419  { return ColourValue(0.0,0.980392,0.603921,1.0); }
420 
422  { return ColourValue(0.282352,0.819607,0.8,1.0); }
423 
425  { return ColourValue(0.780392,0.082352,0.521568,1.0); }
426 
428  { return ColourValue(0.098039,0.098039,0.439215,1.0); }
429 
431  { return ColourValue(0.960784,1.0,0.980392,1.0); }
432 
434  { return ColourValue(1.0,0.894117,0.882352,1.0); }
435 
437  { return ColourValue(1.0,0.894117,0.709803,1.0); }
438 
440  { return ColourValue(1.0,0.870588,0.678431,1.0); }
441 
443  { return ColourValue(0.0,0.0,0.501960,1.0); }
444 
446  { return ColourValue(0.992156,0.960784,0.901960,1.0); }
447 
449  { return ColourValue(0.501960,0.501960,0.0,1.0); }
450 
452  { return ColourValue(0.419607,0.556862,0.137254,1.0); }
453 
455  { return ColourValue(1.0,0.647058,0.0,1.0); }
456 
458  { return ColourValue(1.0,0.270588,0.0,1.0); }
459 
461  { return ColourValue(0.854901,0.439215,0.839215,1.0); }
462 
464  { return ColourValue(0.933333,0.909803,0.666666,1.0); }
465 
467  { return ColourValue(0.596078,0.984313,0.596078,1.0); }
468 
470  { return ColourValue(0.686274,0.933333,0.933333,1.0); }
471 
473  { return ColourValue(0.858823,0.439215,0.576470,1.0); }
474 
476  { return ColourValue(1.0,0.937254,0.835294,1.0); }
477 
479  { return ColourValue(1.0,0.854901,0.725490,1.0); }
480 
482  { return ColourValue(0.803921,0.521568,0.247058,1.0); }
483 
485  { return ColourValue(1.0,0.752941,0.796078,1.0); }
486 
488  { return ColourValue(0.866666,0.627450,0.866666,1.0); }
489 
491  { return ColourValue(0.690196,0.878431,0.901960,1.0); }
492 
494  { return ColourValue(0.501960,0.0,0.501960,1.0); }
495 
497  { return ColourValue(1.0,0.0,0.0,1.0); }
498 
500  { return ColourValue(0.737254,0.560784,0.560784,1.0); }
501 
503  { return ColourValue(0.254901,0.411764,0.882352,1.0); }
504 
506  { return ColourValue(0.545098,0.270588,0.074509,1.0); }
507 
509  { return ColourValue(0.980392,0.501960,0.447058,1.0); }
510 
512  { return ColourValue(0.956862,0.643137,0.376470,1.0); }
513 
515  { return ColourValue(0.180392,0.545098,0.341176,1.0); }
516 
518  { return ColourValue(1.0,0.960784,0.933333,1.0); }
519 
521  { return ColourValue(0.627450,0.311568,0.176470,1.0); }
522 
524  { return ColourValue(0.752941,0.752941,0.752941,1.0); }
525 
527  { return ColourValue(0.529411,0.807843,0.921568,1.0); }
528 
530  { return ColourValue(0.415686,0.352941,0.803921,1.0); }
531 
533  { return ColourValue(0.439215,0.501960,0.564705,1.0); }
534 
536  { return ColourValue(1.0,0.980392,0.980392,1.0); }
537 
539  { return ColourValue(0.0,1.0,0.498039,1.0); }
540 
542  { return ColourValue(0.274509,0.509803,0.705882,1.0); }
543 
545  { return ColourValue(0.823529,0.705882,0.549019,1.0); }
546 
548  { return ColourValue(0.0,0.501960,0.501960,1.0); }
549 
551  { return ColourValue(0.847058,0.749019,0.847058,1.0); }
552 
554  { return ColourValue(1.0,0.388235,0.278431,1.0); }
555 
557  { return ColourValue(0.250980,0.878431,0.815686,1.0); }
558 
560  { return ColourValue(0.933333,0.509803,0.933333,1.0); }
561 
563  { return ColourValue(0.960784,0.870588,0.701960,1.0); }
564 
566  { return ColourValue(1.0,1.0,1.0,1.0); }
567 
569  { return ColourValue(0.960784,0.960784,0.960784,1.0); }
570 
572  { return ColourValue(1.0,1.0,0.0,1.0); }
573 
575  { return ColourValue(0.603921,0.803921,0.196078,1.0); }
576 
577  ///////////////////////////////////////////////////////////////////////////////
578  // Serialization
579 
580  void ColourValue::ProtoSerialize(XML::Node& CurrentRoot) const
581  {
582  Mezzanine::XML::Node VecNode = CurrentRoot.AppendChild(this->ColourValue::SerializableName());
583  VecNode.SetName(this->ColourValue::SerializableName());
584 
585  Mezzanine::XML::Attribute VersionAttr = VecNode.AppendAttribute("Version");
586  Mezzanine::XML::Attribute RAttr = VecNode.AppendAttribute("Red");
587  Mezzanine::XML::Attribute GAttr = VecNode.AppendAttribute("Green");
588  Mezzanine::XML::Attribute BAttr = VecNode.AppendAttribute("Blue");
589  Mezzanine::XML::Attribute AAttr = VecNode.AppendAttribute("Alpha");
590  if( VersionAttr && RAttr && BAttr && GAttr && AAttr)
591  {
592  if( VersionAttr.SetValue("1") && RAttr.SetValue(this->RedChannel) && BAttr.SetValue(this->BlueChannel) && GAttr.SetValue(this->GreenChannel) && AAttr.SetValue(this->AlphaChannel))
593  {
594  return;
595  }else{
596  SerializeError("Create XML Attribute Values", this->ColourValue::SerializableName(),true);
597  }
598  }else{
599  SerializeError("Create XML Attributes", this->ColourValue::SerializableName(),true);
600  }
601  }
602 
603  // DeSerializable
605  {
606  if( Mezzanine::String(OneNode.Name())==this->ColourValue::SerializableName() )
607  {
608  if(OneNode.GetAttribute("Version").AsInt() == 1)
609  {
610  this->RedChannel=OneNode.GetAttribute("Red").AsReal();
611  this->GreenChannel=OneNode.GetAttribute("Green").AsReal();
612  this->BlueChannel=OneNode.GetAttribute("Blue").AsReal();
613  this->AlphaChannel=OneNode.GetAttribute("Alpha").AsReal();
614  }else{
615  MEZZ_EXCEPTION(Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (this->ColourValue::SerializableName()) + ": Not Version 1");
616  }
617  }else{
618  MEZZ_EXCEPTION(Exception::II_IDENTITY_INVALID_EXCEPTION,"Attempting to deserialize a " + (this->ColourValue::SerializableName()) + ", found a " + OneNode.Name());
619  }
620  }
621 
623  { return String("ColourValue"); }
624 }//Mezzanine
625 
626 ///////////////////////////////////////////////////////////////////////////////
627 // Class External << Operators for streaming or assignment
628 std::ostream& operator << (std::ostream& stream, const Mezzanine::ColourValue& Ev)
629 {
630  Serialize(stream,Ev);
631  return stream;
632 }
633 
634 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::ColourValue& Ev)
635  { return DeSerialize(stream, Ev); }
636 
637 void operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::ColourValue& Ev)
638  { Ev.ProtoDeSerialize(OneNode); }
639 
640 
641 #endif