create class to hold drawing information
authorDiane Trout <diane@caltech.edu>
Fri, 30 Mar 2007 18:35:17 +0000 (18:35 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 30 Mar 2007 18:35:17 +0000 (18:35 +0000)
this will be added to SeqSpan to add information needed to draw
stuff on the screen--only if a particular SeqSpan is being rendered.

alg/drawable.hpp [new file with mode: 0644]
alg/test/CMakeLists.txt
alg/test/test_drawable.cpp [new file with mode: 0644]

diff --git a/alg/drawable.hpp b/alg/drawable.hpp
new file mode 100644 (file)
index 0000000..ca6610f
--- /dev/null
@@ -0,0 +1,56 @@
+#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_*/
index b766624de61642759f42f57905b474034b7a38e3..be8dbea5e12dae46f830e9a6cc29e255aa7dd4e7 100644 (file)
@@ -47,6 +47,7 @@ MAKE_ALG_UNITTEST( test_annotations )
 MAKE_ALG_UNITTEST( test_annotation_color )
 MAKE_ALG_UNITTEST( test_color )
 MAKE_ALG_UNITTEST( test_conserved_path )
 MAKE_ALG_UNITTEST( test_annotation_color )
 MAKE_ALG_UNITTEST( test_color )
 MAKE_ALG_UNITTEST( test_conserved_path )
+MAKE_ALG_UNITTEST( test_drawable )
 MAKE_ALG_UNITTEST( test_flp )
 MAKE_ALG_UNITTEST( test_glseqbrowser )
 MAKE_ALG_UNITTEST( test_glsequence )
 MAKE_ALG_UNITTEST( test_flp )
 MAKE_ALG_UNITTEST( test_glseqbrowser )
 MAKE_ALG_UNITTEST( test_glsequence )
diff --git a/alg/test/test_drawable.cpp b/alg/test/test_drawable.cpp
new file mode 100644 (file)
index 0000000..e3afd70
--- /dev/null
@@ -0,0 +1,67 @@
+#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