--- /dev/null
+#ifndef DRAWABLE_HPP_
+#define DRAWABLE_HPP_
+
+#include <boost/shared_ptr.hpp>
+
+#include "color.hpp"
+
+class Drawable;
+typedef boost::shared_ptr<Drawable> DrawableRef;
+
+/**
+ * \brief Store the information needed to draw a sequence on some canvas
+ */
+class Drawable {
+public:
+ Drawable() :
+ draw_x(0), draw_y(0), draw_z(0), draw_height(0), draw_color(new Color) {}
+ Drawable(float x, float y, float z, float h, ColorRef c) :
+ draw_x(x), draw_y(y), draw_z(z), draw_height(h), draw_color(c) {}
+ Drawable(const DrawableRef d) :
+ draw_x(d->draw_x), draw_y(d->draw_y), draw_z(d->draw_z),
+ draw_height(d->draw_height),
+ draw_color(new Color(d->draw_color))
+ {}
+
+ //! set our starting x (horizontal) coordinate
+ void setX(float x) { draw_x = x; }
+ //! get our starting x (horizontal) coordinate
+ float x() const { return draw_x; }
+ //! set our current y (vertical) position
+ void setY(float y) { draw_y = y; }
+ //! get our current y (vertical) position
+ float y() const { return draw_y; }
+ //! set our current z (depth) position
+ void setZ(float z) { draw_z = z; }
+ //! get our current z (depth) position
+ float z() const { return draw_z; }
+
+ //! set how tall our rectangle should be
+ float setHeight(float h) { draw_height = h; }
+ //! how thick (high) the track we're drawing is
+ float height() const { return draw_height; }
+
+ //! set our default draw color
+ void setColor(ColorRef c) { draw_color = c; }
+ //! return our draw color
+ ColorRef color() { return draw_color; }
+
+protected:
+ float draw_x;
+ float draw_y;
+ float draw_z;
+ float draw_height;
+ ColorRef draw_color;
+};
+#endif /*DRAWABLE_HPP_*/
--- /dev/null
+#define BOOST_AUTO_TEST_MAIN
+#include <boost/test/auto_unit_test.hpp>
+
+#include <boost/shared_ptr.hpp>
+
+#include "drawable.hpp"
+
+BOOST_AUTO_TEST_CASE( drawable_empty_constructors )
+{
+ Drawable a;
+ BOOST_CHECK_EQUAL(a.x(), 0);
+ BOOST_CHECK_EQUAL(a.y(), 0);
+ BOOST_CHECK_EQUAL(a.z(), 0);
+ BOOST_CHECK_EQUAL(a.height(), 0);
+
+ DrawableRef asp(new Drawable);
+ BOOST_CHECK_EQUAL(asp->x(), 0);
+ BOOST_CHECK_EQUAL(asp->y(), 0);
+ BOOST_CHECK_EQUAL(asp->z(), 0);
+ BOOST_CHECK_EQUAL(asp->height(), 0);
+}
+
+BOOST_AUTO_TEST_CASE( drawable_filled_constructors )
+{
+ ColorRef white(new Color(1.0, 1.0, 1.0));
+
+ Drawable a(1.0,2.0,3.0,4.0, white);
+ BOOST_CHECK_EQUAL(a.x(), 1.0);
+ BOOST_CHECK_EQUAL(a.y(), 2.0);
+ BOOST_CHECK_EQUAL(a.z(), 3.0);
+ BOOST_CHECK_EQUAL(a.height(), 4.0);
+ BOOST_CHECK_EQUAL(*(a.color()), *white);
+
+ DrawableRef asp(new Drawable(1.0,2.0,3.0,4.0, white));
+ BOOST_CHECK_EQUAL(asp->x(), 1.0);
+ BOOST_CHECK_EQUAL(asp->y(), 2.0);
+ BOOST_CHECK_EQUAL(asp->z(), 3.0);
+ BOOST_CHECK_EQUAL(asp->height(), 4.0);
+ BOOST_CHECK_EQUAL(*(asp->color()), *white);
+}
+
+BOOST_AUTO_TEST_CASE( drawable_copyref_constructor )
+{
+ ColorRef white(new Color(1.0, 1.0, 1.0));
+ ColorRef grey(new Color(0.5, 0.5, 0.5));
+ ColorRef black(new Color(0.0, 0.0, 0.0));
+
+ DrawableRef asp(new Drawable(1.0,1.0,1.0,1.0, white));
+ DrawableRef bsp(asp);
+ DrawableRef csp(new Drawable(asp));
+
+ bsp->setX(2.0);
+ bsp->setColor(grey);
+ BOOST_CHECK_EQUAL(asp->x(), bsp->x());
+ BOOST_CHECK_EQUAL(asp->x(), 2.0);
+ BOOST_CHECK_EQUAL(*asp->color(), grey);
+
+ // csp shouldn't have changed
+ BOOST_CHECK_EQUAL(csp->x(), 1.0);
+ BOOST_CHECK_EQUAL(*csp->color(), white);
+
+ // changes to csp should only affect csp
+ csp->setColor(black);
+ BOOST_CHECK_EQUAL(*asp->color(), *grey);
+ BOOST_CHECK_EQUAL(*bsp->color(), *grey);
+ BOOST_CHECK_EQUAL(*csp->color(), *black);
+}
\ No newline at end of file