UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
modifier.h
Go to the documentation of this file.
1 #ifndef UGDK_GRAPHIC_MODIFIER_H_
2 #define UGDK_GRAPHIC_MODIFIER_H_
3 
4 #include <vector>
5 #include <cstddef>
6 #include <ugdk/math/vector2D.h>
7 #include <ugdk/base/types.h>
8 
9 namespace ugdk {
10 namespace graphic {
11 
12 class Modifier {
13  public:
14  enum Flags {
15  NOTHING = 0,
17  HAS_COLOR = 2,
19  };
20 
22  Modifier();
23 
25 
36  Modifier(const Vector2D& _offset, const Vector2D _scale = Vector2D(1.0, 1.0),
37  double _rotation = 0.0, Mirror _mirror = MIRROR_NONE, const Color _color = WHITE, bool _visible = true) :
38 
39  offset_(_offset), scale_(_scale), rotation_(_rotation), mirror_(_mirror),
40  color_(_color), visible_(_visible), flags_(HAS_TRANSFORMATION | HAS_COLOR) {}
41 
42  // Destructor
43  ~Modifier() {}
44 
45  // Getters.
49  const Vector2D& offset() const { return offset_; }
50  const Vector2D& scale() const { return scale_; }
51  double rotation() const { return rotation_; }
52  const Mirror& mirror() const { return mirror_; }
53  const Color& color() const { return color_; }
54  uint16 flags() const { return flags_; }
55  bool visible() const { return visible_; }
56 
57  // Setters.
58  void set_offset(const Vector2D& _offset) { offset_ = _offset; flags_ |= HAS_TRANSFORMATION; }
59  void set_scale(const Vector2D& _scale) { scale_ = _scale; flags_ |= HAS_TRANSFORMATION; }
61  void set_rotation(const double rotation);
63  void set_mirror(const Mirror mirror);
65  void set_color(const Color& color);
66  void set_visible(const bool _visible) { visible_ = _visible; }
72  void ComposeOffset(const Vector2D& _offset) { offset_ += _offset; flags_ |= HAS_TRANSFORMATION;}
73  void ComposeScale(const Vector2D& _scale) { scale_.x *= _scale.x;
74  scale_.y *= _scale.y;
75  flags_ |= HAS_TRANSFORMATION; }
76 
77  void ToggleFlag(uint16 flag) { flags_ ^= flag; }
79  void ComposeRotation(const double rotation);
81  void ComposeMirror(const Mirror& mirror);
83  void ComposeColor(const Color& color);
84  void ComposeVisible(bool _visible) { visible_ = visible_ && _visible; }
85 
86  void ComposeOffset( const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeOffset( mod2->offset_ ); }
87  void ComposeScale( const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeScale( mod2->scale_ ); }
88  void ComposeRotation( const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeRotation( mod2->rotation_ ); }
89  void ComposeMirror( const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeMirror( mod2->mirror_ ); }
90  void ComposeColor( const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeColor( mod2->color_ ); }
91  void ComposeVisible( const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeVisible( mod2->visible_ ); }
92 
94  void Compose(const Modifier* mod2);
96  static Modifier* Compose(const Modifier* mod1, const Modifier* mod2);
99 
100  static Modifier* Copy(const Modifier* mod2);
101 
102  private:
103  // Attributes
104  Vector2D offset_,
105  scale_;
106  double rotation_;
107  Mirror mirror_;
108  Color color_; //TODO: Modifier's "color_" is actually a light filter.
109  bool visible_;
110  uint16 flags_;
111 };
112 
113 } // namespace graphic
114 } // namespace ugdk
115 
116 #endif /* UGDK_GRAPHIC_MODIFIER_H_ */