File: color.h

package info (click to toggle)
warmux 1%3A11.04.1%2Brepack2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 126,388 kB
  • sloc: cpp: 186,040; xml: 8,909; sh: 3,358; makefile: 1,052; ansic: 713
file content (75 lines) | stat: -rw-r--r-- 2,476 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/******************************************************************************
 *  Warmux is a convivial mass murder game.
 *  Copyright (C) 2001-2011 Warmux Team.
 *
 *  This program 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; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 ******************************************************************************
 * Color
 *****************************************************************************/

#ifndef COLOR_H
#define COLOR_H

#include <SDL.h>

class Color
{
  union
  {
    struct
    {
      Uint8 red   : 8;
      Uint8 green : 8;
      Uint8 blue  : 8;
      Uint8 alpha : 8;
    } components;
    Uint32 color;
  } value;

public:
  Color()
    { SetColor(200, 50, 50, 130); }
  Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 130)
    { SetColor(r, g, b, a); }
  Color(Uint8 grey, Uint8 a = SDL_ALPHA_OPAQUE)
    { SetColor(grey, grey, grey, a); }
  Color(const Color& other) { value.color = other.value.color; }

  bool operator==(const Color &c) const { return value.color == c.value.color; }
  bool operator!=(const Color &c) const { return value.color != c.value.color; }

  void SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
  {
    value.components.red   = r;
    value.components.green = g;
    value.components.blue  = b;
    value.components.alpha = a;
  }

  void SetRed(Uint8 r)   { value.components.red   = r; }
  void SetGreen(Uint8 g) { value.components.green = g; }
  void SetBlue(Uint8 b)  { value.components.blue  = b; }
  void SetAlpha(Uint8 a) { value.components.alpha = a; }

  Uint8 GetRed() const   { return value.components.red;   }
  Uint8 GetGreen() const { return value.components.green; }
  Uint8 GetBlue() const  { return value.components.blue;  }
  Uint8 GetAlpha() const { return value.components.alpha; }
  Uint32 GetColor() const;

  SDL_Color GetSDLColor() const;
};

#endif