| 1 |
/*************************************************************************** |
| 2 |
couleur.cpp - description |
| 3 |
------------------- |
| 4 |
begin : Mon Jun 4 2001 |
| 5 |
copyright : (C) 2001 by Olivier Langella |
| 6 |
email : [email protected] |
| 7 |
***************************************************************************/ |
| 8 |
|
| 9 |
/*************************************************************************** |
| 10 |
* * |
| 11 |
* This program is free software; you can redistribute it and/or modify * |
| 12 |
* it under the terms of the GNU General Public License as published by * |
| 13 |
* the Free Software Foundation; either version 2 of the License, or * |
| 14 |
* (at your option) any later version. * |
| 15 |
* * |
| 16 |
***************************************************************************/ |
| 17 |
|
| 18 |
#include "couleur.h" |
| 19 |
|
| 20 |
vector<string> Couleur::_tab_couleurs; |
| 21 |
unsigned int Couleur::_pos_tab_couleurs(0); |
| 22 |
|
| 23 |
Couleur::Couleur(unsigned long rouge, unsigned long vert, unsigned long bleu) { |
| 24 |
_boolrgb = true; |
| 25 |
_boolnom = false; |
| 26 |
|
| 27 |
_rouge = rouge; |
| 28 |
_vert= vert; |
| 29 |
_bleu = bleu; |
| 30 |
} |
| 31 |
|
| 32 |
Couleur::Couleur(const biolib::vecteurs::ChaineCar & couleur){ |
| 33 |
//couleur peut contenir 3 chiffres (rgb) ou un nom de couleur en Anglais |
| 34 |
biolib::vecteurs::ChaineCar mot, lacouleur(couleur); |
| 35 |
|
| 36 |
_boolrgb = false; |
| 37 |
_boolnom = false; |
| 38 |
|
| 39 |
if (lacouleur == "") lacouleur.assign(get_couleur_diff()); |
| 40 |
|
| 41 |
if (lacouleur.GetNbMots() == 3) { |
| 42 |
_boolrgb = true; |
| 43 |
lacouleur.GetMot(1, mot); |
| 44 |
if (mot.EstUnChiffre()) { |
| 45 |
_rouge = (int) mot; |
| 46 |
_rouge *= 256; |
| 47 |
} |
| 48 |
else _boolrgb = false; |
| 49 |
lacouleur.GetMot(2, mot); |
| 50 |
if ((_boolrgb) && (mot.EstUnChiffre())) { |
| 51 |
_vert = (int) mot; |
| 52 |
_vert *= 256; |
| 53 |
} |
| 54 |
else _boolrgb = false; |
| 55 |
lacouleur.GetMot(3, mot); |
| 56 |
if ((_boolrgb) && (mot.EstUnChiffre())) { |
| 57 |
_bleu = (int) mot; |
| 58 |
_bleu *= 256; |
| 59 |
} |
| 60 |
else _boolrgb = false; |
| 61 |
|
| 62 |
} |
| 63 |
if (_boolrgb == false) {//nom de couleur en Anglais |
| 64 |
_boolnom = true; |
| 65 |
_nom.assign(lacouleur); |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
Couleur::~Couleur(){ |
| 71 |
} |
| 72 |
|
| 73 |
bool Couleur::operator== (const Couleur &rval) const { |
| 74 |
if ((_boolrgb) && (rval._boolrgb) && (_rouge == rval._rouge) && (_vert == rval._vert) && (_bleu == rval._bleu)) return true; |
| 75 |
|
| 76 |
if ((_boolnom) && (rval._boolnom) && (_nom == rval._nom)) return true; |
| 77 |
|
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
const string & Couleur::get_couleur_diff() { |
| 82 |
unsigned int i; |
| 83 |
|
| 84 |
if ( Couleur::_tab_couleurs.size() == 0 ) Couleur::f_rempli_tab_couleurs(); |
| 85 |
i = Couleur::_pos_tab_couleurs; |
| 86 |
Couleur::_pos_tab_couleurs++; |
| 87 |
if (Couleur::_pos_tab_couleurs == Couleur::_tab_couleurs.size()) Couleur::_pos_tab_couleurs = 0; |
| 88 |
|
| 89 |
return (Couleur::_tab_couleurs[i]); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
void Couleur::f_rempli_tab_couleurs() { |
| 94 |
|
| 95 |
_tab_couleurs.push_back("red"); |
| 96 |
_tab_couleurs.push_back("green"); |
| 97 |
_tab_couleurs.push_back("blue"); |
| 98 |
_tab_couleurs.push_back("turquoise"); |
| 99 |
_tab_couleurs.push_back("pink"); |
| 100 |
_tab_couleurs.push_back("yellow"); |
| 101 |
_tab_couleurs.push_back("brown"); |
| 102 |
_tab_couleurs.push_back("purple"); |
| 103 |
_tab_couleurs.push_back("sea green"); |
| 104 |
_tab_couleurs.push_back("salmon"); |
| 105 |
_tab_couleurs.push_back("sky blue"); |
| 106 |
_tab_couleurs.push_back("yellow green"); |
| 107 |
_tab_couleurs.push_back("brown1"); |
| 108 |
_tab_couleurs.push_back("aquamarine"); |
| 109 |
_tab_couleurs.push_back("orange"); |
| 110 |
_tab_couleurs.push_back("brown2"); |
| 111 |
_tab_couleurs.push_back("navy blue"); |
| 112 |
_tab_couleurs.push_back("goldenrod"); |
| 113 |
_tab_couleurs.push_back("tomato"); |
| 114 |
_tab_couleurs.push_back("violet"); |
| 115 |
_tab_couleurs.push_back("gold"); |
| 116 |
|
| 117 |
} |