add draw function pointer to drawable
authorDiane Trout <diane@caltech.edu>
Mon, 9 Apr 2007 20:00:55 +0000 (20:00 +0000)
committerDiane Trout <diane@caltech.edu>
Mon, 9 Apr 2007 20:00:55 +0000 (20:00 +0000)
alg/drawable.hpp
alg/test/test_drawable.cpp

index ca6610fe06c7fda2589a19fad0520a2029d9e76b..97b01059259587015db5bda8c87ff69dc5d87d9a 100644 (file)
@@ -5,6 +5,12 @@
 
 #include "color.hpp"
 
+// Nooo!!!! I'm repeating myself. 
+// Should all the'se ref typedefs go somewhere else?
+// *sigh* mutters about recursive #includes
+class SeqSpan;
+typedef boost::shared_ptr<SeqSpan> SeqSpanRef;
+
 class Drawable;
 typedef boost::shared_ptr<Drawable> DrawableRef;
 
@@ -13,14 +19,17 @@ typedef boost::shared_ptr<Drawable> DrawableRef;
  */ 
 class Drawable {
 public:
+  typedef void (*draw_func_ptr)(SeqSpanRef, void *);
+  
   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) {}
+    draw_x(0), draw_y(0), draw_z(0), draw_height(0), draw_color(new Color), draw_func(0) {}
+  Drawable(float x, float y, float z, float h, ColorRef c, draw_func_ptr draw=0) :
+    draw_x(x), draw_y(y), draw_z(z), draw_height(h), draw_color(c), draw_func(draw) {}
   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))
+    draw_color(new Color(d->draw_color)),
+    draw_func(d->draw_func)
   {}
     
   //! set our starting x (horizontal) coordinate
@@ -45,6 +54,9 @@ public:
   void setColor(ColorRef c) { draw_color = c; }
   //! return our draw color
   ColorRef color() { return draw_color; }
+  
+  void setDrawFunction(draw_func_ptr d) { draw_func = d; }
+  draw_func_ptr drawFunction() const { return draw_func; }
 
 protected:
   float draw_x;
@@ -52,5 +64,7 @@ protected:
   float draw_z;
   float draw_height;
   ColorRef draw_color;
+  draw_func_ptr draw_func;
+
 };
 #endif /*DRAWABLE_HPP_*/
index e3afd703ed224e3e98227d5fddaa180e70da5b72..63d75efdd8be802dd4aa018886b69496251b750c 100644 (file)
@@ -4,6 +4,7 @@
 #include <boost/shared_ptr.hpp>
 
 #include "drawable.hpp"
+#include "seq_span.hpp"
 
 BOOST_AUTO_TEST_CASE( drawable_empty_constructors )
 {
@@ -64,4 +65,36 @@ BOOST_AUTO_TEST_CASE( drawable_copyref_constructor )
   BOOST_CHECK_EQUAL(*asp->color(), *grey);
   BOOST_CHECK_EQUAL(*bsp->color(), *grey);
   BOOST_CHECK_EQUAL(*csp->color(), *black); 
+}
+
+void test_draw_func_null(SeqSpanRef r, void *p)
+{
+}
+
+BOOST_AUTO_TEST_CASE( drawable_null_draw_func )
+{
+  ColorRef white(new Color(1.0, 1.0, 1.0));  
+  DrawableRef asp(new Drawable(1.0,1.0,1.0,1.0, white, test_draw_func_null));
+  
+  BOOST_CHECK_EQUAL(asp->drawFunction(), test_draw_func_null);
+  
+  DrawableRef bsp(asp);
+  BOOST_CHECK_EQUAL(bsp->drawFunction(), test_draw_func_null);
+}
+
+void test_draw_func_find_drawable(SeqSpanRef r, void *p)
+{
+  BOOST_REQUIRE(r->drawable());
+  BOOST_REQUIRE_EQUAL(r->drawable()->drawFunction(), test_draw_func_find_drawable);
+}
+
+BOOST_AUTO_TEST_CASE( test_drawable_find_drawable )
+{
+  ColorRef white(new Color(1.0, 1.0, 1.0));  
+  DrawableRef drawsp(new Drawable(1.0,1.0,1.0,1.0, white, test_draw_func_find_drawable));
+  SeqSpanRef ssp(new SeqSpan("AAAA"));
+  ssp->setDrawable(drawsp);
+     
+  BOOST_CHECK_EQUAL(drawsp->drawFunction(), test_draw_func_find_drawable);
+  ssp->drawable()->drawFunction();
 }
\ No newline at end of file