WhatsThis update
[mussa.git] / alg / glsequence.cpp
index 54a13fad5af915e8dd28190ceae135147e43b9ca..6cb1b578fc211c59bcd39c68f721b816116c27fc 100644 (file)
@@ -46,9 +46,9 @@ GlSequence &GlSequence::operator=(const GlSequence & s)
   return *this;
 }
 
-const Sequence& GlSequence::sequence() const
+boost::shared_ptr<Sequence> GlSequence::sequence()
 {
-  return *seq;
+  return seq;
 }
 
 void GlSequence::setX(GLfloat value)
@@ -63,7 +63,7 @@ GLfloat GlSequence::x() const
 
 GLfloat GlSequence::right() const
 {
-  return length()+seq_x;
+  return size()+seq_x;
 }
 
 void GlSequence::setY(GLfloat value)
@@ -81,7 +81,7 @@ GLfloat GlSequence::height() const
   return seq_height;
 }
 
-GLfloat GlSequence::length() const
+GLfloat GlSequence::size() const
 {
   return seq->size();
 }
@@ -149,7 +149,6 @@ Color GlSequence::color()
   return drawColor;
 }
 
-
 int GlSequence::get_viewport_width_in_pixels()
 {
   GLint viewport[4];
@@ -236,7 +235,7 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
        ++annot_itor)
   {
     glColor3f(0.0, 0.8, 0.0);
-    draw_box(left, right, seq_x+annot_itor->start, seq_x+annot_itor->end, 
+    draw_box(left, right, seq_x+annot_itor->begin, seq_x+annot_itor->end, 
              seq_height, annotation_z);
   }
   // if motifs?
@@ -245,12 +244,13 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
        ++motifs_itor)
   {
     glColor3fv(color_mapper->lookup("motif", motifs_itor->sequence).get());
-    draw_box(left, right, seq_x+motifs_itor->start, seq_x+motifs_itor->end, 
+    draw_box(left, right, seq_x+motifs_itor->begin, seq_x+motifs_itor->end, 
              seq_height, annotation_z+1.0);
   }
 
 }
 
+// this way of drawing characters, came from the red open gl book
 const int PT = 1;
 const int STROKE = 2;
 const int END =3;
@@ -283,6 +283,9 @@ CP Cdata[] = {
 CP Xdata[] = {{ 0, 5, PT}, {5, -5,STROKE},{0,-5,PT},{5, 5, END}};
 CP Ndata[] = {{ 0, -5, PT}, {0, 5, PT}, {5, -5, PT}, {5, 5, END}};
 
+//! the maximum width used for a charcter glyph
+const int max_glyph_width = 5; // unit ( glyph_coord )
+
 static void drawLetter(CP *l, GLfloat z)
 {
   glBegin(GL_LINE_STRIP);
@@ -318,14 +321,19 @@ void GlSequence::draw_sequence(GLfloat left, GLfloat right) const
   Sequence::const_iterator seq_itor = sequence_begin(left, right);
   Sequence::const_iterator seq_end = sequence_end(left, right);
   Sequence::size_type basepair = 0;
+  const float bp_per_world = 1.0; //( world coord )
+  const float glyph_x_scale = 0.125; // unit = ( world coord / glyph coord )
+  // compute how much space there should be to either size of a letter
+  const float glyph_margin = (bp_per_world - glyph_x_scale * max_glyph_width) 
+                           / 2.0;  
 
   assert(seq_end - seq_itor >= 0);
   while(seq_itor != seq_end)
   {
     assert ( basepair < seq->size() );
     glPushMatrix();
-    glTranslatef( seq_x+leftbase(left) + basepair, seq_y, 1.0 );
-    glScalef(0.1, 1.0, 1.0);
+    glTranslatef( seq_x+leftbase(left) + basepair + glyph_margin, seq_y, 1.0 );
+    glScalef(glyph_x_scale, 1.0, 1.0);
     switch (*seq_itor) {
       case 'A': case 'a':
         drawLetter(Adata, z);