factor out viewport to display scaling functions
[mussa.git] / alg / glseqbrowser.hpp
index ba33704bb481f492b116385841889b01c20ffdf8..f88caf5e7e5bb57e4dea0b1ff56f20d4f8c21408 100644 (file)
@@ -28,6 +28,8 @@ public:
 
   //! select a region (using canvas coordinates)
   void selectRegion(int top, int left, int bottom, int right);
+  //! turn off selection
+  void clearSelection();
 
   //! border size
   float border() const;
@@ -36,6 +38,8 @@ public:
   float left() const;
   //! max world right coordinate
   float right() const;
+  // return how wide is a pixel in world coordinates?
+  float get_pixel_width() const;
 
   void setViewportCenter(float x);
   //! return world coordinate of the left side of the viewport
@@ -48,6 +52,16 @@ public:
   float viewportHeight() const;
   //! return width of the viewport in world coordinates
   float viewportWidth() const;
+  
+  //! return viewport height in pixels
+  int viewportPixelHeight() const;
+  //! return viewport width in pixels
+  int viewportPixelWidth() const;
+  
+  //! convert x axis from display to world coordinates
+  float viewportXtoWorldX(int x);
+  //! convert y axis from display to world coordinates
+  float viewportYtoWorldY(int y);
 
   //! zoom out far enough to show the full size of the sequence
   double zoomOut();
@@ -62,7 +76,7 @@ public:
   void centerOnPath(const std::vector<int>&);
 
   void setColorMapper(boost::shared_ptr<AnnotationColors> cm);
-  const AnnotationColors& colorMapper();
+  const AnnotationColorsRef colorMapper();
 
   //! clear our tracks and connections
   void clear();
@@ -97,19 +111,23 @@ public:
 
   //! copy sequence from selected track using formating function
   template<class Item>
-  void copySelectedTracks(std::list<Item>& result, 
-             Item (*format_track)(boost::shared_ptr<Sequence> s,
-                                  int left, 
-                                  int right));
+  size_t copySelectedTracks(std::list<Item>& result, 
+             Item (*format_track)(const Sequence& s, int left, int right));
   //! copy sequence from selected tracks as FASTA sequences
-  void copySelectedTracksAsFasta(std::string& copy_buffer);
+  /*! \return number of base pairs copied
+   */
+  size_t copySelectedTracksAsFasta(std::string& copy_buffer);
   //! copy sequence from selected tracks as a list of sequences
-  void copySelectedTracksAsSequences(std::list<Sequence>& result);
+  /*! \return number of base pairs copied
+   */
+  size_t copySelectedTracksAsSequences(std::list<Sequence>& result);
   //! copy sequence from selected tracks as plain sequences
-  void copySelectedTracksAsString(std::string& copy_buffer);
+  /*! \return number of base pairs copied
+   */
+  size_t copySelectedTracksAsString(std::string& copy_buffer);
 
   //! copy tracks as a sequence and its coordinates
-  void copySelectedTracksAsSeqLocation(std::list<SequenceLocation>& result);
+  size_t copySelectedTracksAsSeqLocation(std::list<SequenceLocation>& result);
   
   
   //! Provide a logical name for a type discriminator for our glName stack
@@ -142,11 +160,13 @@ public:
     point<float> start;
     point<float> end;
     bool reversed;
+    int length;
+    // each integer represents an index into our list of paths
     std::set<int> path_ids;
 
-    Segment() : start(0.0, 0.0), end(0.0, 0.0) {}
-    Segment(float x1, float y1, float x2, float y2, bool isRC) 
-      : start(x1, y1), end(x2, y2), reversed(isRC) {}
+    Segment() : start(0.0, 0.0), end(0.0, 0.0), reversed(false), length(0) {}
+    Segment(float x1, float y1, float x2, float y2, bool isRC, int length_
+      : start(x1, y1), end(x2, y2), reversed(isRC), length(length_) {}
   };
 
   //! data structure holding our line segments
@@ -154,7 +174,7 @@ public:
    *  it's indexed by the pair x1, x2 (the two x coordinates between
    *  the two tracks
    */
-  typedef std::pair<int, int> segment_key;
+  typedef std::pair<int, int> segment_key;  
   typedef std::map<segment_key, Segment> pair_segment_map;
   typedef std::vector<pair_segment_map> path_segment_map_vector;
   path_segment_map_vector path_segments;
@@ -195,13 +215,13 @@ private:
   //! the center of our current viewport (world coord) (used for scrollbar)
   float viewport_center;
   double zoom_level;
-  boost::shared_ptr<AnnotationColors> color_mapper;
-  //! container of all the GlSequences loaded into our scene
-  std::vector<boost::shared_ptr<GlSequence> > track_container;
+  AnnotationColorsRef color_mapper;
   //! counter for each path added to us via connect
   int pathid;
 
 protected:
+  //! container of all the GlSequences loaded into our scene
+  std::vector<GlSequenceRef > track_container;
   //! where to draw our box (world coordinates)
   rect<float> selectedRegion;
   //! true if we have a selection
@@ -212,4 +232,15 @@ protected:
   std::list<TrackRegion> selected_tracks;
   typedef std::list<TrackRegion>::iterator selected_track_iterator;
 };
+
+inline float GlSeqBrowser::viewportXtoWorldX(int x) {
+  GLfloat x_scale = cur_ortho.width()/((float)viewport_size.x);
+  return (cur_ortho.left + (x * x_scale));
+}
+
+inline float GlSeqBrowser::viewportYtoWorldY(int y) {
+  GLfloat y_scale = cur_ortho.height()/((float)viewport_size.y);
+  return cur_ortho.top-(y * y_scale);
+}
+
 #endif