implement zoom in terms of base pairs per pixel
[mussa.git] / alg / glseqbrowser.cpp
index 96496a2fd751102532a32e616ba846006e90a87e..386b5f6f5d4d4fd04c4da49002a8604dc2823a71 100644 (file)
@@ -19,7 +19,6 @@ GlSeqBrowser::GlSeqBrowser()
 
 GlSeqBrowser::GlSeqBrowser(const GlSeqBrowser& gt)
   : border_width(gt.border_width),
-    max_ortho(gt.max_ortho),
     cur_ortho(gt.cur_ortho),
     viewport_size(gt.viewport_size),
     viewport_center(gt.viewport_center),
@@ -244,6 +243,20 @@ float GlSeqBrowser::viewportWidth() const
   return cur_ortho.right - cur_ortho.left;
 }
 
+int GlSeqBrowser::zoomOut()
+{
+
+  if (right() - left() > 0) {
+    cur_ortho.left = left();
+    cur_ortho.right = right();
+    zoom_level = (int)(( (right() - left()) / viewport_size.x) * 100);
+    return zoom_level;
+  } else {
+    // made up number representing 50 bp / pixel
+    return 5000;
+  }
+}
+
 void GlSeqBrowser::setZoom(int new_zoom)
 {
   update_viewport(viewport_center, new_zoom);
@@ -305,7 +318,7 @@ void GlSeqBrowser::clear_links()
 }
 
 void 
-GlSeqBrowser::link(const vector<int>& path, const vector<bool>& rc, int length)
+GlSeqBrowser::link(const vector<int>& path, const vector<bool>& rc, int )
 {
   if (path.size() < 2) {
     // should i throw an error instead?
@@ -366,14 +379,13 @@ void GlSeqBrowser::centerOnPath(const vector<int>& paths)
 
 void GlSeqBrowser::update_viewport(float center, int new_zoom)
 {
-  float max_width = max_ortho.width();
-  // division by zero is a major bummer
+  // limit how close we can get
   if (new_zoom < 1) {
     new_zoom = 1;
   }
-  float new_max_width = max_width / new_zoom;
-  cur_ortho.left = center-new_max_width;
-  cur_ortho.right = center+new_max_width;
+  float new_width = (((float)new_zoom / 100.0) * (float)viewport_size.x);
+  cur_ortho.left = center-new_width/2.0;
+  cur_ortho.right = center+new_width/2.0;
 }
 
 void GlSeqBrowser::update_layout()
@@ -406,12 +418,12 @@ void GlSeqBrowser::update_layout()
     // nothing to do as we're empty
     return;
   }
-  max_ortho.right = max_base_pairs + border_width;
-  max_ortho.left = -border_width;
-  max_ortho.top = viewport_size.x;
-  max_ortho.bottom = 0;
-  cur_ortho = max_ortho;
+  cur_ortho.right = max_base_pairs + border_width;
+  cur_ortho.left = -border_width;
+  cur_ortho.top = viewport_size.x;
+  cur_ortho.bottom = 0;
   viewport_center = (cur_ortho.width()/2) + cur_ortho.left;
+  zoomOut();
 }
 
 void GlSeqBrowser::draw() const