_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

color.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2012 by Joris Dauphin
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef COLOR_H
31 #define COLOR_H
32 
34 
35 #include <stdint.h>
36 
37 typedef uint32_t IntColor; // Uint32 in SDL
38 
39 struct SDL_Color;
40 struct lua_State;
41 
43 class CColor
44 {
45 public:
46  CColor() : R(0), G(0), B(0), A(0) {}
47  CColor(unsigned char r, unsigned char g, unsigned char b,
48  unsigned char a = 0) : R(r), G(g), B(b), A(a) {}
49  CColor(const CColor &color) : R(color.R), G(color.G), B(color.B), A(color.A) {}
50 
51  void Parse(lua_State *l, int index = -1);
52 
54  operator SDL_Color() const;
55 
57  operator IntColor() const;
58 
59 public:
60  unsigned char R;
61  unsigned char G;
62  unsigned char B;
63  unsigned char A;
64 };
65 
66 
67 #include <vector>
68 
70 {
71 public:
73 
74  void Clear();
75 
76  void Set(std::vector<CColor> &colors);
77 
78 private:
79  std::vector<CColor> Colors;
80 };
81 
82 
94 {
95 public:
96  PaletteSwap(unsigned int variable, unsigned char colorStart, unsigned char colorCount, unsigned char steps, unsigned char alternatives, std::vector<CColor> &colors);
97  ~PaletteSwap();
98 
99  SDL_Color *GetColorsForPercentAndAlternative(unsigned int value, unsigned int max, unsigned int alt);
100 
101  unsigned int GetUnitVariableIndex() { return UnitVariableIndex; }
102  unsigned int GetColorIndexStart() { return ColorIndexStart; }
103  unsigned int GetColorCount() { return ColorCount; }
104 
105 private:
106  unsigned int UnitVariableIndex;
107  unsigned char ColorIndexStart;
108  unsigned char ColorCount;
109  unsigned char Steps;
110  unsigned char AlternativesCount;
111  SDL_Color *Colors = nullptr;
112 };
113 
123 IntColor InterpolateColor(IntColor color1, IntColor color2, float fraction);
124 
126 
127 #endif
CColor::CColor
CColor()
Definition: color.h:46
PaletteSwap::~PaletteSwap
~PaletteSwap()
Definition: color.cpp:94
PaletteSwap
A class to encode unit-variable dependent palette swaps.
Definition: color.h:93
CColor::CColor
CColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=0)
Definition: color.h:47
PaletteSwap::GetColorCount
unsigned int GetColorCount()
Definition: color.h:103
CColor::G
unsigned char G
Red.
Definition: color.h:61
IntColor
uint32_t IntColor
Definition: color.h:37
PaletteSwap::GetColorIndexStart
unsigned int GetColorIndexStart()
Definition: color.h:102
CUnitColors::Set
void Set(std::vector< CColor > &colors)
Definition: color.cpp:75
CUnitColors::Clear
void Clear()
Definition: color.cpp:70
CColor
A platform independent color.
Definition: color.h:43
CColor::R
unsigned char R
Definition: color.h:60
CColor::A
unsigned char A
Blue.
Definition: color.h:63
PaletteSwap::GetColorsForPercentAndAlternative
SDL_Color * GetColorsForPercentAndAlternative(unsigned int value, unsigned int max, unsigned int alt)
Definition: color.cpp:101
CColor::Parse
void Parse(lua_State *l, int index=-1)
Definition: color.cpp:50
PaletteSwap::GetUnitVariableIndex
unsigned int GetUnitVariableIndex()
Definition: color.h:101
CColor::CColor
CColor(const CColor &color)
Definition: color.h:49
InterpolateColor
IntColor InterpolateColor(IntColor color1, IntColor color2, float fraction)
Definition: color.cpp:112
CUnitColors
Definition: color.h:69
CColor::B
unsigned char B
Green.
Definition: color.h:62
CUnitColors::CUnitColors
CUnitColors()
Definition: color.h:72
PaletteSwap::PaletteSwap
PaletteSwap(unsigned int variable, unsigned char colorStart, unsigned char colorCount, unsigned char steps, unsigned char alternatives, std::vector< CColor > &colors)
Definition: color.cpp:80
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.