add draw function pointer to drawable
[mussa.git] / alg / drawable.hpp
1 #ifndef DRAWABLE_HPP_
2 #define DRAWABLE_HPP_
3
4 #include <boost/shared_ptr.hpp>
5
6 #include "color.hpp"
7
8 // Nooo!!!! I'm repeating myself. 
9 // Should all the'se ref typedefs go somewhere else?
10 // *sigh* mutters about recursive #includes
11 class SeqSpan;
12 typedef boost::shared_ptr<SeqSpan> SeqSpanRef;
13
14 class Drawable;
15 typedef boost::shared_ptr<Drawable> DrawableRef;
16
17 /** 
18  * \brief Store the information needed to draw a sequence on some canvas 
19  */ 
20 class Drawable {
21 public:
22   typedef void (*draw_func_ptr)(SeqSpanRef, void *);
23   
24   Drawable() : 
25     draw_x(0), draw_y(0), draw_z(0), draw_height(0), draw_color(new Color), draw_func(0) {}
26   Drawable(float x, float y, float z, float h, ColorRef c, draw_func_ptr draw=0) :
27     draw_x(x), draw_y(y), draw_z(z), draw_height(h), draw_color(c), draw_func(draw) {}
28   Drawable(const DrawableRef d) :
29     draw_x(d->draw_x), draw_y(d->draw_y), draw_z(d->draw_z), 
30     draw_height(d->draw_height),
31     draw_color(new Color(d->draw_color)),
32     draw_func(d->draw_func)
33   {}
34     
35   //! set our starting x (horizontal) coordinate
36   void setX(float x) { draw_x = x; }
37   //! get our starting x (horizontal) coordinate
38   float x() const { return draw_x; }
39   //! set our current y (vertical) position
40   void setY(float y) { draw_y = y; }
41   //! get our current y (vertical) position
42   float y() const { return draw_y; }
43   //! set our current z (depth) position
44   void setZ(float z) { draw_z = z; }
45   //! get our current z (depth) position
46   float z() const { return draw_z; }
47   
48   //! set how tall our rectangle should be
49   float setHeight(float h) { draw_height = h; }
50   //! how thick (high) the track we're drawing is
51   float height() const { return draw_height; }
52
53   //! set our default draw color
54   void setColor(ColorRef c) { draw_color = c; }
55   //! return our draw color
56   ColorRef color() { return draw_color; }
57   
58   void setDrawFunction(draw_func_ptr d) { draw_func = d; }
59   draw_func_ptr drawFunction() const { return draw_func; }
60
61 protected:
62   float draw_x;
63   float draw_y;
64   float draw_z;
65   float draw_height;
66   ColorRef draw_color;
67   draw_func_ptr draw_func;
68
69 };
70 #endif /*DRAWABLE_HPP_*/