show where the Ns are
[mussa.git] / alg / glsequence.cpp
index 89150d3a0068aba3cf1d169cf6b322ab4c88bacf..62f8b7a83e6ac1d9a0254d97a2cca5a1d1264b60 100644 (file)
@@ -6,6 +6,8 @@
 #include <stdexcept>
 using namespace std;
 
+static const float default_height = 12.0;
+
 GlSequence::GlSequence(const Sequence &s, 
                        boost::shared_ptr<AnnotationColors> cm) 
   : Sequence(s),
@@ -53,7 +55,7 @@ GlSequence &GlSequence::operator=(const GlSequence & s)
 DrawableRef GlSequence::default_drawable()
 {
   ColorRef c(new Color(0.0, 0.0, 0.0));
-  DrawableRef d(new Drawable(0.0, 0.0, 1.0, 12.0, c));
+  DrawableRef d(new Drawable(0.0, 0.0, 1.0, default_height, c));
   return d;
 }
 
@@ -90,7 +92,6 @@ void GlSequence::add_annotations_for_undefined_sequence(Drawable::draw_func_ptr
   Sequence::const_iterator end_i = end();
   
   Sequence::const_iterator start_block_i = end();
-  
   for(; seq_i != end_i; ++seq_i)
   {
     // need a better set of characters to serch for
@@ -237,13 +238,13 @@ int GlSequence::get_viewport_width_in_pixels()
   return viewport[3]; // grab the viewport width
 }
 
-GLfloat GlSequence::pixelWidth(GLfloat left, GLfloat right) const
+GLfloat GlSequence::pixelWidth(GLfloat left, GLfloat right)
 {
   return pixelWidth(left, right, get_viewport_width_in_pixels());
 }
 
 GLfloat
-GlSequence::pixelWidth(GLfloat left, GLfloat right, int vp_width) const
+GlSequence::pixelWidth(GLfloat left, GLfloat right, int vp_width)
 {
   return round((right-left)/vp_width);
 }
@@ -279,12 +280,12 @@ void GlSequence::draw(GLfloat left, GLfloat right) const
 
 void GlSequence::draw_box(GLfloat world_left, GLfloat world_right,
                           GLfloat left, GLfloat right, 
-                          GLfloat height, GLfloat z) const
+                          GLfloat height, GLfloat y, GLfloat z)
 {
   GLfloat pixel_width = pixelWidth(world_left, world_right);
   GLfloat offset = height/2.0;
-  GLfloat top = y() + offset;
-  GLfloat bottom = y() - offset;
+  GLfloat top = y + offset;
+  GLfloat bottom = y - offset;
   
   // make our box be at least 1 pixel
   if ((right-left) < pixel_width) {
@@ -302,7 +303,7 @@ void GlSequence::draw_track(GLfloat left, GLfloat right) const
 {
   glColor3fv(color()->get());
   // draw main sequence track
-  draw_box(left, right, x(), x()+Sequence::size(), height(), 0.0);
+  draw_box(left, right, x(), x()+Sequence::size(), height(), y(), 0.0);
 }
 
 void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
@@ -315,9 +316,15 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
        annot_itor != annots.end();
        ++annot_itor)
   {
-    glColor3f(0.0, 0.8, 0.0);
-    draw_box(left, right, x()+(*annot_itor)->start(), x()+(*annot_itor)->stop(), 
-             height(), annotation_z);
+    DrawableRef drawable((*annot_itor)->drawable());
+    if (drawable and drawable->drawFunction()) {
+      assert((*annot_itor)->parent() == seq);
+      drawable->drawFunction()((*annot_itor), left, right); 
+    } else {
+      glColor3f(0.0, 0.8, 0.0);
+      draw_box(left, right, x()+(*annot_itor)->start(), x()+(*annot_itor)->stop(), 
+               height(), y(), annotation_z);
+    }
   }
   // if motifs?
   for (MotifList::const_iterator motifs_itor = motifs.begin();
@@ -326,7 +333,7 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
   {
     glColor3fv(color_mapper->lookup("motif", motifs_itor->sequence).get());
     draw_box(left, right, x()+motifs_itor->begin, x()+motifs_itor->end, 
-             height(), annotation_z+1.0);
+             height(), y(), annotation_z+1.0);
   }
 }
 
@@ -449,3 +456,22 @@ bool operator==(const GlSequence &left, const GlSequence &right)
            (left.color() == right.color()));
 }
 
+void draw_narrow_track(SeqSpanRef s, float left, float right)
+{
+  SeqSpanRef parent(s->parent());
+  DrawableRef parent_draw(parent->drawable());
+  float x( (parent_draw) ? parent_draw->x() : 0);
+  float y( (parent_draw) ? parent_draw->y() : 0);
+  float z( (parent_draw) ? parent_draw->z() : 10 );
+  float height( (parent_draw) ? parent_draw->height() : default_height ); 
+
+  glColor3f(1.0, 1.0, 1.0);
+  // offset to middle of the top (+) or bottom (-) quarter 
+  float yoffset = height * 5.0/8.0; //(1/2 + 1/8)
+  // height of a quarter
+  float hsmall = height * 1.0/4.0;
+  GlSequence::draw_box(left, right, x+s->start(), x+s->stop(), 
+                       hsmall, y, z+10);
+  //GlSequence::draw_box(left, right, x+s->start(), x+s->stop(), 
+  //                     hsmall, y-yoffset, z+10);
+}
\ No newline at end of file