refactor glsequence to be more testable
[mussa.git] / alg / glsequence.h
index 343f9ff29a76aad96127a21e1e8c409ae626c4a0..319517b98dfedf45bce505191dce9095a83bb28d 100644 (file)
@@ -2,8 +2,8 @@
 #define _GL_SEQUENCE_H_
 
 #include "alg/sequence.hh"
+#include "alg/color.h"
 #include <GL/gl.h>
-
 //! Manage rendering a mussa sequence track
 /*! The idea is this will keep track of the location of where the sequence
  *  is being rendered, and handle displaying annotations on that track
@@ -16,26 +16,70 @@ public:
   GlSequence &operator=(const GlSequence &s);
 
   //! draw a track 
-  /*! left and right are the current edges of the viewable world
+  /*! left and right are the edges of the current viewport
    */
   void draw(GLfloat left, GLfloat right) const;
 
   const Sequence& sequence() const;
+  //! set our starting x (horizontal) coordinate
   void setX(GLfloat);
+  //! get our starting x (horizontal) coordinate
   GLfloat x() const;
+  //! set our current y (vertical) position
   void setY(GLfloat);
+  //! get our current y (vertical) position
   GLfloat y() const;
-  void setWidth(GLfloat);
-  GLfloat width() const;
+  //! how long is our sequence track? (computed from the sequence)
+  GLfloat length() const;
+  //! return the left (lowest) base index that is fully visible
+  Sequence::size_type GlSequence::leftbase(GLfloat left) const;
+  //! return one past rightmost (highest ) base index that is fully visible
+  /*! done mostly so all the iterator logic continues to work correctly.
+   */
+  Sequence::size_type GlSequence::rightbase(GLfloat right) const;
+
+  //! return iterator to the start of the stored sequence
+  Sequence::const_iterator sequence_begin() const;
+  //! return iterator to the end of the stored sequence
+  Sequence::const_iterator sequence_end() const;
+  //! provide an iterator to the sequence starting at world coordinate left
+  Sequence::const_iterator sequence_begin(GLfloat left, GLfloat right) const;
+  //! provide an iterator to the sequence ending at world coordinate right
+  Sequence::const_iterator sequence_end(GLfloat left, GLfloat right) const;
+
+  //! set track color 
+  void setColor(Color &);
+  Color color();
+
+  //! are we close enough that it would make sense to view the base pairs?
+  /*! though we don't actually check to see if there's sequence in our
+   *  view, just that there's enough pixels to render something if 
+   *  there were.
+   *  \param[in] left the left edge of the viewable region in world coordinates
+   *  \param[in] right the right edge of the viewable region in world 
+   *             coordinates
+   *  \param[in] pixel_width allow setting the current viewport pixel width
+   */
+  bool is_sequence_renderable(GLfloat left, 
+                              GLfloat right, 
+                              int pixel_width=-1) const;
+
+  friend bool operator==(const GlSequence &left, const GlSequence &right);
 
 protected:
   const Sequence& seq;
   GLfloat seq_x;
   GLfloat seq_y;
   GLfloat seq_z;
-  GLfloat seq_width;
   GLfloat seq_height;
+  Color drawColor;
+  const GLfloat char_pix_per_world_unit;
 
+  //! Return the pixel width of the opengl viewport.
+  static int get_viewport_pixel_width();
+  void draw_bar(GLfloat, GLfloat) const;
+  void draw_annotations(GLfloat, GLfloat) const;
   //! render a sequence (if we have enough space
   /*! left and right are the current edges of the viewable world
    */
@@ -43,5 +87,4 @@ protected:
 };
 
 const float gl_track_height = 10.0;
-
 #endif