Welcome to mirror list, hosted at ThFree Co, Russian Federation.

color.hpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9c0dd81f71e54e72881d48ef1e39a76b7ea4417b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once

#include "std/cstdint.hpp"
#include "std/string.hpp"
#include "std/sstream.hpp"

namespace graphics
{

struct Color
{
  uint8_t r;
  uint8_t g;
  uint8_t b;
  uint8_t a;

  /// alpha 255 means non-transparent and 0 means fully transparent
  Color(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t a1);
  Color();
  Color(Color const & p);
  Color const & operator=(Color const & p);

  static Color const fromARGB(uint32_t _c);
  static Color const fromXRGB(uint32_t _c, uint8_t _a = 0);

  Color const & operator /= (unsigned k);

  static Color Black();
  static Color White();
  static Color Red();
  static Color Green();
  static Color Blue();
};

bool operator < (Color const & l, Color const & r);
bool operator > (Color const & l, Color const & r);
bool operator !=(Color const & l, Color const & r);
bool operator ==(Color const & l, Color const & r);

inline int redFromARGB(uint32_t c)   {return (c >> 16) & 0xFF;}
inline int greenFromARGB(uint32_t c) {return (c >> 8) & 0xFF; }
inline int blueFromARGB(uint32_t c)  {return (c & 0xFF);      }
inline int alphaFromARGB(uint32_t c) {return (c >> 24) & 0xFF;}

inline string DebugPrint(Color const & c)
{
  ostringstream os;
  os << "r: " << (int)c.r << " ";
  os << "g: " << (int)c.g << " ";
  os << "b: " << (int)c.b << " ";
  os << "alpha: " << (int)c.a;
  return os.str();
}

}