UGDK
src/ugdk/graphic/modifier.h
Go to the documentation of this file.
00001 #ifndef UGDK_GRAPHIC_MODIFIER_H_
00002 #define UGDK_GRAPHIC_MODIFIER_H_
00003 
00004 #include <vector>
00005 #include <cstddef>
00006 #include <ugdk/math/vector2D.h>
00007 #include <ugdk/base/types.h>
00008 
00009 namespace ugdk {
00010 namespace graphic {
00011 
00012 class Modifier {
00013   public:
00014     enum Flags {
00015         NOTHING                 =  0,
00016         HAS_TRANSFORMATION      =  1,
00017         HAS_COLOR               =  2,
00018         TRUNCATES_WHEN_APPLIED  = 16
00019     };
00020 
00022     Modifier();
00023 
00025 
00036     Modifier(const Vector2D& _offset, const Vector2D _scale = Vector2D(1.0, 1.0),
00037              double _rotation = 0.0, Mirror _mirror = MIRROR_NONE, const Color _color = WHITE, bool _visible = true) :
00038         
00039         offset_(_offset), scale_(_scale), rotation_(_rotation), mirror_(_mirror), 
00040         color_(_color), visible_(_visible), flags_(HAS_TRANSFORMATION | HAS_COLOR) {}
00041 
00042     // Destructor
00043     ~Modifier() {}
00044 
00045     // Getters.
00049     const Vector2D& offset()    const { return   offset_; }
00050     const Vector2D& scale()     const { return    scale_; }
00051     double          rotation()  const { return rotation_; }
00052     const Mirror&   mirror()    const { return   mirror_; }
00053     const Color&    color()     const { return    color_; }
00054     uint16          flags()     const { return    flags_; }
00055     bool            visible()   const { return  visible_; }
00056 
00057     // Setters.
00058     void set_offset(const Vector2D& _offset) { offset_ = _offset; flags_ |= HAS_TRANSFORMATION; }
00059     void set_scale(const Vector2D& _scale)   { scale_  = _scale;  flags_ |= HAS_TRANSFORMATION; }
00061     void set_rotation(const double rotation);
00063     void set_mirror(const Mirror mirror);
00065     void set_color(const Color& color);
00066     void set_visible(const bool _visible) { visible_ = _visible; }
00072     void ComposeOffset(const Vector2D& _offset) { offset_  += _offset;  flags_ |= HAS_TRANSFORMATION;}
00073     void ComposeScale(const Vector2D& _scale)   { scale_.x *= _scale.x;
00074                                                   scale_.y *= _scale.y; 
00075                                                   flags_ |= HAS_TRANSFORMATION; }
00076 
00077     void ToggleFlag(uint16 flag) { flags_ ^= flag; }
00079     void ComposeRotation(const double rotation);
00081     void ComposeMirror(const Mirror& mirror);
00083     void ComposeColor(const Color& color);
00084     void ComposeVisible(bool _visible) { visible_ = visible_ && _visible; }
00085     
00086     void ComposeOffset(   const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeOffset(   mod2->offset_   ); }
00087     void ComposeScale(    const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeScale(    mod2->scale_    ); }
00088     void ComposeRotation( const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeRotation( mod2->rotation_ ); }
00089     void ComposeMirror(   const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeMirror(   mod2->mirror_   ); }
00090     void ComposeColor(    const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeColor(    mod2->color_    ); }
00091     void ComposeVisible(  const Modifier* mod2 ) { if(mod2 == NULL) return; ComposeVisible(  mod2->visible_  ); }
00092 
00094     void Compose(const Modifier* mod2);
00096     static Modifier* Compose(const Modifier* mod1, const Modifier* mod2);
00099 
00100     static Modifier* Copy(const Modifier* mod2);
00101 
00102   private:
00103     // Attributes
00104     Vector2D        offset_,
00105                     scale_;
00106     double          rotation_;
00107     Mirror          mirror_;
00108     Color           color_; //TODO: Modifier's "color_" is actually a light filter.
00109     bool            visible_;
00110     uint16          flags_;
00111 };
00112 
00113 }  // namespace graphic
00114 }  // namespace ugdk
00115 
00116 #endif /* UGDK_GRAPHIC_MODIFIER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines