UGDK
|
00001 #ifndef HORUSEYE_FRAMEWORK_DRAWABLE_H_ 00002 #define HORUSEYE_FRAMEWORK_DRAWABLE_H_ 00003 00004 #include <ugdk/math/vector2D.h> 00005 00006 namespace ugdk { 00007 namespace graphic { 00008 00009 class Drawable { 00010 public: 00011 enum HookPoint { 00012 TOP_LEFT, TOP, TOP_RIGHT, 00013 LEFT, CENTER, RIGHT, 00014 BOTTOM_LEFT, BOTTOM, BOTTOM_RIGHT 00015 }; 00016 virtual ~Drawable() {}; 00017 00018 virtual void Update(double dt) = 0; 00019 virtual void Draw() const = 0; 00020 virtual const Vector2D& size() const = 0; 00021 00022 void set_hotspot(const Vector2D& hotspot) { hotspot_ = hotspot; } 00023 void set_hotspot(const HookPoint& hook) { 00024 switch(hook) { 00025 case TOP_LEFT : hotspot_ = Vector2D( 0.0, 0.0); break; 00026 case TOP : hotspot_ = Vector2D(size().x * 0.5, 0.0); break; 00027 case TOP_RIGHT : hotspot_ = Vector2D( size().x, 0.0); break; 00028 case LEFT : hotspot_ = Vector2D( 0.0, size().y * 0.5); break; 00029 case CENTER : hotspot_ = size() * 0.5; break; 00030 case RIGHT : hotspot_ = Vector2D( size().x, size().y * 0.5); break; 00031 case BOTTOM_LEFT : hotspot_ = Vector2D( 0.0, size().y); break; 00032 case BOTTOM : hotspot_ = Vector2D(size().x * 0.5, size().y); break; 00033 case BOTTOM_RIGHT: hotspot_ = size(); break; 00034 } 00035 } 00036 00037 const double width() const { return size().x; } 00038 const double height() const { return size().y; } 00039 const Vector2D& hotspot() const { return hotspot_; } 00040 00041 protected: 00042 Drawable() {} 00043 00044 ugdk::Vector2D hotspot_; 00045 }; 00046 00047 } // namespace graphic 00048 } // namespace ugdk 00049 00050 #endif