make annotations big enough to show up
[mussa.git] / alg / glsequence.cpp
index e38da9d417e40999d0e20df04996c61cc7456094..893e6fcfc8ace6df612a32581066baafcf617a24 100644 (file)
@@ -149,21 +149,33 @@ Color GlSequence::color()
 }
 
 
-int GlSequence::get_viewport_pixel_width()
+int GlSequence::get_viewport_width_in_pixels()
 {
   GLint viewport[4];
   glGetIntegerv(GL_VIEWPORT, viewport);
   return viewport[3]; // grab the viewport width
 }
 
+GLfloat GlSequence::get_pixel_width(GLfloat left, GLfloat right) const
+{
+  return get_pixel_width(left, right, get_viewport_width_in_pixels());
+}
+
+GLfloat
+GlSequence::get_pixel_width(GLfloat left, GLfloat right, int vp_width) const
+{
+  return round((right-left)/vp_width);
+}
+
+bool GlSequence::is_sequence_renderable(GLfloat left, GLfloat right) const
+{
+  return is_sequence_renderable(left, right, get_viewport_width_in_pixels());
+}
+
 bool GlSequence::is_sequence_renderable(GLfloat left, 
                                         GLfloat right, 
                                         int viewport_width) const
 {
-  // if called with default argument, go get the viewable width
-  if (viewport_width == -1) {
-    viewport_width = get_viewport_pixel_width();
-  }
   GLfloat world_width = right - left;
   GLfloat pixels_needed = (char_pix_per_world_unit * world_width);
 
@@ -184,13 +196,19 @@ void GlSequence::draw(GLfloat left, GLfloat right) const
   draw_annotations(left, right);
 }
 
-void GlSequence::draw_box(GLfloat left, GLfloat right, 
+void GlSequence::draw_box(GLfloat world_left, GLfloat world_right,
+                          GLfloat left, GLfloat right, 
                           GLfloat height, GLfloat z) const
 {
+  GLfloat pixel_width = get_pixel_width(world_left, world_right);
   GLfloat offset = height/2.0;
   GLfloat top = seq_y + offset;
   GLfloat bottom = seq_y - offset;
-    
+  
+  // make our box be at least 1 pixel
+  if ((right-left) < pixel_width) {
+    right = left + pixel_width;
+  }
   glBegin(GL_QUADS);
     glVertex3f(left,  top,    z);
     glVertex3f(left,  bottom, z);
@@ -199,34 +217,34 @@ void GlSequence::draw_box(GLfloat left, GLfloat right,
   glEnd();
 }
 
-void GlSequence::draw_track(GLfloat , GLfloat ) const
+void GlSequence::draw_track(GLfloat left, GLfloat right) const
 {
   glColor3fv(drawColor.get());
   // draw main sequence track
-  draw_box(seq_x, seq_x+seq.size(), seq_height, 0.0);
+  draw_box(left, right, seq_x, seq_x+seq.size(), seq_height, 0.0);
 }
 
-void GlSequence::draw_annotations(GLfloat , GLfloat ) const
+void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
 {
   // draw annotations
-  GLfloat annotation_z = seq_z + 1.0;
+  GLfloat annotation_z = seq_z + 10.0;
   const std::list<annot>& annots = seq.annotations();
   const std::list<motif>& motifs = seq.motifs();
   for (std::list<annot>::const_iterator annot_itor = annots.begin();
        annot_itor != annots.end();
-       ++annot_itor, ++annotation_z)
+       ++annot_itor)
   {
-    glColor3f(0.0, 0.5, 0.0);
-    draw_box(seq_x+annot_itor->start, seq_x+annot_itor->end, 
+    glColor3f(0.0, 0.8, 0.0);
+    draw_box(left, right, seq_x+annot_itor->start, seq_x+annot_itor->end, 
              seq_height, annotation_z);
   }
   // if motifs?
   for (std::list<motif>::const_iterator motifs_itor = motifs.begin();
        motifs_itor != motifs.end();
-       ++motifs_itor, ++annotation_z)
+       ++motifs_itor)
   {
     glColor3fv(color_mapper.lookup("motif", motifs_itor->sequence).get());
-    draw_box(seq_x+motifs_itor->start, seq_x+motifs_itor->end, 
+    draw_box(left, right, seq_x+motifs_itor->start, seq_x+motifs_itor->end, 
              seq_height, annotation_z);
   }