UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
drawable.h
Go to the documentation of this file.
1 #ifndef UGDK_UI_DRAWABLE_H_
2 #define UGDK_UI_DRAWABLE_H_
3 
4 #include <ugdk/graphic.h>
5 #include <ugdk/math/vector2D.h>
6 #include <ugdk/ui/hookpoint.h>
7 
8 #include <functional>
9 
10 namespace ugdk {
11 namespace ui {
12 
13 class Drawable {
14  public:
15  virtual ~Drawable() {}
16 
17  virtual void Draw(graphic::Canvas&) const = 0;
18  virtual const math::Vector2D& size() const = 0;
19 
20  void set_draw_setup_function(const std::function<void (const Drawable*, graphic::Canvas&)> &func) {
21  draw_setup_function_ = func;
22  }
23 
24  void set_hotspot(const ugdk::math::Vector2D& _hotspot) { hotspot_ = _hotspot; }
25  void set_hotspot(const HookPoint& hook) {
26  switch(hook) {
27  case HookPoint::TOP_LEFT: hotspot_ = ugdk::math::Vector2D(0.0, 0.0); break;
28  case HookPoint::TOP: hotspot_ = ugdk::math::Vector2D(size().x * 0.5, 0.0); break;
29  case HookPoint::TOP_RIGHT: hotspot_ = ugdk::math::Vector2D(size().x, 0.0); break;
30  case HookPoint::LEFT: hotspot_ = ugdk::math::Vector2D(0.0, size().y * 0.5); break;
31  case HookPoint::CENTER: hotspot_ = size() * 0.5; break;
32  case HookPoint::RIGHT: hotspot_ = ugdk::math::Vector2D(size().x, size().y * 0.5); break;
34  case HookPoint::BOTTOM: hotspot_ = ugdk::math::Vector2D(size().x * 0.5, size().y); break;
35  default: hotspot_ = size(); /* Matches BOTTOM_RIGHT */ break;
36  }
37  }
38 
39  double width() const { return size().x; }
40  double height() const { return size().y; }
41  const math::Vector2D& hotspot() const { return hotspot_; }
42 
43  protected:
44  Drawable() {}
45 
47  std::function<void (const Drawable*, graphic::Canvas&)> draw_setup_function_;
48 };
49 
50 } // namespace ui
51 } // namespace ugdk
52 
53 #endif // UGDK_UI_DRAWABLE_H_
double width() const
Definition: drawable.h:39
Definition: canvas.h:28
virtual const math::Vector2D & size() const =0
Definition: vector2D.h:18
double x
Definition: vector2D.h:45
double height() const
Definition: drawable.h:40
virtual void Draw(graphic::Canvas &) const =0
Definition: animation.h:11
math::Vector2D hotspot_
Definition: drawable.h:46
void set_hotspot(const HookPoint &hook)
Definition: drawable.h:25
Definition: drawable.h:13
Drawable()
Definition: drawable.h:44
void set_draw_setup_function(const std::function< void(const Drawable *, graphic::Canvas &)> &func)
Definition: drawable.h:20
HookPoint
Definition: hookpoint.h:7
double y
Definition: vector2D.h:45
const math::Vector2D & hotspot() const
Definition: drawable.h:41
virtual ~Drawable()
Definition: drawable.h:15
void set_hotspot(const ugdk::math::Vector2D &_hotspot)
Definition: drawable.h:24
std::function< void(const Drawable *, graphic::Canvas &)> draw_setup_function_
Definition: drawable.h:47