Mana
Loading...
Searching...
No Matches
palette.h
Go to the documentation of this file.
1/*
2 * Configurable text colors
3 * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
4 * Copyright (C) 2009 The Mana World Development Team
5 * Copyright (C) 2009-2012 The Mana Developers
6 *
7 * This file is part of The Mana Client.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#pragma once
24
25#include "utils/time.h"
26
27#include <guichan/color.hpp>
28
29#include <cstdlib>
30#include <optional>
31#include <set>
32#include <string>
33#include <vector>
34
35// Default Gradient Delay
36constexpr int GRADIENT_DELAY = 40;
37
42{
43 public:
44 Palette(int size);
45 Palette(const Palette &) = delete;
46 Palette(Palette &&);
47 ~Palette();
48
49 Palette &operator=(const Palette &) = delete;
51
59
60 void setColor(int type,
61 const gcn::Color &color,
62 const std::optional<gcn::Color> &outlineColor,
63 GradientType grad,
64 int delay);
65
72 const gcn::Color &getColor(int type) const
73 {
74 return mColors[type].color;
75 }
76
83 const std::optional<gcn::Color> &getOutlineColor(int type) const
84 {
85 return mColors[type].outlineColor;
86 }
87
95 {
96 return mColors[type].grad;
97 }
98
105 int getGradientDelay(int type) const
106 { return mColors[type].delay; }
107
111 static void advanceGradients();
112
113 protected:
115 static const gcn::Color RAINBOW_COLORS[];
116 static const int RAINBOW_COLOR_COUNT;
117
120
121 using Palettes = std::set<Palette *>;
123
124 void advanceGradient(int advance);
125
127 {
128 int type;
129 gcn::Color color;
130 gcn::Color testColor;
131 gcn::Color committedColor;
132 std::optional<gcn::Color> outlineColor;
133 std::string text;
137 int delay;
139
149
150 int getRGB() const
151 {
152 return (committedColor.r << 16) | (committedColor.g << 8) |
154 }
155 };
157 std::vector<ColorElem> mColors;
158 std::vector<ColorElem*> mGradVector;
159};
Class controlling the game's color palette.
Definition palette.h:42
static const gcn::Color RAINBOW_COLORS[]
Colors used for the rainbow gradient.
Definition palette.h:31
void advanceGradient(int advance)
Definition palette.cpp:94
GradientType getGradientType(int type) const
Gets the GradientType associated with the specified type.
Definition palette.h:94
Palette(const Palette &)=delete
~Palette()
Definition palette.cpp:56
static const int RAINBOW_COLOR_COUNT
Number of Elemets of RAINBOW_COLORS.
Definition palette.h:116
std::set< Palette * > Palettes
Definition palette.h:121
static Palettes mInstances
Definition palette.h:122
static void advanceGradients()
Updates all colors, that are non-static.
Definition palette.cpp:82
const gcn::Color & getColor(int type) const
Gets the color associated with the type.
Definition palette.h:72
void setColor(int type, const gcn::Color &color, const std::optional< gcn::Color > &outlineColor, GradientType grad, int delay)
Definition palette.cpp:71
Palette & operator=(const Palette &)=delete
std::vector< ColorElem * > mGradVector
Definition palette.h:158
std::vector< ColorElem > mColors
Vector containing the colors.
Definition palette.h:157
const std::optional< gcn::Color > & getOutlineColor(int type) const
Gets the optional outline color associated with the type.
Definition palette.h:83
GradientType
Colors can be static or can alter over time.
Definition palette.h:53
@ SPECTRUM
Definition palette.h:56
@ STATIC
Definition palette.h:54
@ PULSE
Definition palette.h:55
@ RAINBOW
Definition palette.h:57
static Timer mRainbowTimer
Timer used when updating gradient-type colors.
Definition palette.h:119
int getGradientDelay(int type) const
Gets the gradient delay for the specified type.
Definition palette.h:105
Simple timer that can be used to check if a certain amount of time has passed.
Definition time.h:62
constexpr int GRADIENT_DELAY
Definition palette.h:36
GradientType grad
Definition palette.h:134
std::string text
Definition palette.h:133
GradientType committedGrad
Definition palette.h:135
std::optional< gcn::Color > outlineColor
Definition palette.h:132
gcn::Color testColor
Definition palette.h:130
gcn::Color committedColor
Definition palette.h:131
gcn::Color color
Definition palette.h:129
void set(int type, const gcn::Color &color, GradientType grad, int delay)
Definition palette.h:140
int getRGB() const
Definition palette.h:150