--- /dev/null
+/*
+ * Color.h
+ *
+ * Created on: Sep 1, 2012
+ * Author: holy
+ */
+
+#ifndef GRAPHICS_COLOR_H_
+#define GRAPHICS_COLOR_H_
+
+#include <SDL.h>
+
+namespace graphics {
+
+class Color {
+
+public:
+ Color() :r(0), g(0), b(0), a(255) { }
+ Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a = 255) : r(r), g(g), b(b), a(a) { }
+
+public:
+ Uint8 RedChannel() const { return r; }
+ Uint8 GreenChannel() const { return g; }
+ Uint8 BlueChannel() const { return b; }
+ Uint8 AlphaChannel() const { return a; }
+
+ Uint32 MapRGB(SDL_PixelFormat *f) const { return SDL_MapRGB(f, r, g, b); }
+ Uint32 MapRGBA(SDL_PixelFormat *f) const { return SDL_MapRGBA(f, r, g, b, a); }
+
+ void SetRedChannel(Uint8 i) { r = i; }
+ void SetGreenChannel(Uint8 i) { g = i; }
+ void SetBlueChannel(Uint8 i) { b = i; }
+ void SetAlphaChannel(Uint8 i) { a = i; }
+
+private:
+ Uint8 r, g, b, a;
+
+};
+
+}
+
+#endif /* GRAPHICS_COLOR_H_ */
using common::Spell;
using common::TargetingMode;
using graphics::Animation;
+using graphics::Color;
using graphics::Font;
using graphics::Frame;
using graphics::Gauge;
}
}
+const Color &Interpreter::GetColor(const std::string &name) const {
+ map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
+ if (i != parsedDefinitions.end()) {
+ if (i->second.type == COLOR) {
+ return colors[i->second.index];
+ } else {
+ throw Error("cannot cast " + i->second.dfn->TypeName() + " to Color");
+ }
+ } else {
+ throw Error("access to undefined Color " + name);
+ }
+}
+
Font *Interpreter::GetFont(const std::string &name) {
map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
if (i != parsedDefinitions.end()) {
parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, BOOLEAN, booleans.size() - 1)));
break;
case Literal::COLOR:
- throw Error("unhandled literal: color");
+ colors.push_back(Color(dfn.GetLiteral()->GetRed(), dfn.GetLiteral()->GetGreen(), dfn.GetLiteral()->GetBlue(), dfn.GetLiteral()->GetAlpha()));
+ parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COLOR, colors.size() - 1)));
break;
case Literal::NUMBER:
numbers.push_back(dfn.GetLiteral()->GetNumber());
}
}
+Color Interpreter::GetColor(const Value &v) {
+ if (v.IsLiteral()) {
+ return Color(v.GetLiteral().GetRed(), v.GetLiteral().GetGreen(), v.GetLiteral().GetBlue(), v.GetLiteral().GetAlpha());
+ } else {
+ ReadDefinition(source.GetDefinition(v.GetIdentifier()));
+ return GetColor(v.GetIdentifier());
+ }
+}
+
Font *Interpreter::GetFont(const Value &v) {
if (v.IsLiteral()) {
Font *f(new Font);
#define LOADER_INTERPRETER_H_
#include "../geometry/Vector.h"
+#include "../graphics/Color.h"
#include "../graphics/ComplexAnimation.h"
#include <map>
public:
graphics::Animation *GetAnimation(const std::string &name);
bool GetBoolean(const std::string &name) const;
+ const graphics::Color &GetColor(const std::string &name) const;
graphics::Font *GetFont(const std::string &name);
graphics::Frame *GetFrame(const std::string &name);
graphics::Gauge *GetGauge(const std::string &name);
public:
const std::vector<bool> &Booleans() const { return booleans; }
+ const std::vector<graphics::Color> &Colors() const { return colors; }
const std::vector<graphics::ComplexAnimation *> &ComplexAnimations() const { return complexAnimations; }
const std::vector<graphics::Font *> &Fonts() const { return fonts; }
const std::vector<graphics::Frame *> &Frames() const { return frames; }
void ReadObject(const Definition &);
graphics::Animation *GetAnimation(const Value &);
+ graphics::Color GetColor(const Value &);
bool GetBoolean(const Value &);
graphics::Font *GetFont(const Value &);
graphics::Frame *GetFrame(const Value &);
const ParsedSource &source;
enum Type {
BOOLEAN,
+ COLOR,
COMPLEX_ANIMATION,
FONT,
FRAME,
std::map<std::string, SDL_Surface *> imageCache;
std::vector<bool> booleans;
+ std::vector<graphics::Color> colors;
std::vector<graphics::ComplexAnimation *> complexAnimations;
std::vector<graphics::Font *> fonts;
std::vector<graphics::Frame *> frames;
battleRes.activeHeroTagFrame = intp.GetFrame("activeHeroTagFrame");
battleRes.smallHeroTagFrame = intp.GetFrame("smallHeroTagFrame");
battleRes.lastSmallHeroTagFrame = intp.GetFrame("lastSmallHeroTagFrame");
- battleRes.heroesBgColor = SDL_MapRGB(screen.Screen()->format, 0x18, 0x28, 0x31);
+ battleRes.heroesBgColor = intp.GetColor("heroesBgColor").MapRGB(screen.Screen()->format);
battleRes.healthGauge = intp.GetGauge("healthGauge");
battleRes.manaGauge = intp.GetGauge("manaGauge");
border: <8,16>,
offset: <0,33>
}
+export Color heroesBgColor (24, 40, 49)
export Gauge healthGauge {
image: :"gauges.png",