dont draw sequence box when we can see sequence text
[mussa.git] / alg / glsequence.hpp
index 3916687cee56c0272c3476b4c4a12681642322b3..a2b5704a66024f0e6b61f7749d6126b4e9e8fffe 100644 (file)
 #ifndef _GL_SEQUENCE_H_
 #define _GL_SEQUENCE_H_
 
+#include <boost/shared_ptr.hpp>
+
 #include "alg/annotation_colors.hpp"
 #include "alg/sequence.hpp"
 #include "alg/color.hpp"
+// isn't it lovely how the header file can live in different places?
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#else
 #include <GL/gl.h>
+#endif
+
+class GlSequence;
+typedef boost::shared_ptr<GlSequence> GlSequenceRef;
+
 //! 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
  */
-class GlSequence
+class GlSequence : public Sequence
 {
 public: 
-  GlSequence(const Sequence & s, AnnotationColors &cm);
+  GlSequence(const Sequence & s,
+             boost::shared_ptr<AnnotationColors> cm);
   GlSequence(const GlSequence & s);
+  GlSequence(const GlSequence *);
+  //! Make a new GlSequence, using a copy of SeqSpan
+  GlSequence(const GlSequenceRef);
+  
   GlSequence &operator=(const GlSequence &s);
 
-  //! draw a track 
-  /*! left and right are the edges of the current viewport
+  static DrawableRef default_drawable();
+  static DrawableRef copy_drawable(DrawableRef s);
+  
+  //! search through sequence and add an annotation highlighting all the non AGCT characters
+  void add_annotations_for_defined_sequence(Drawable::draw_func_ptr draw=0);
+  /**!search through our annotations and set the draw function for a particular "type"
+   * this is really a temporary solution to configuring annotation display styles
    */
-  void draw(GLfloat left, GLfloat right) const;
-
-  const Sequence& sequence() const;
+  void update_annotation_draw_function(
+         std::string type, 
+         Drawable::draw_func_ptr draw, 
+         ColorRef color
+       );
   //! set our starting x (horizontal) coordinate
-  void setX(GLfloat);
+  void setX(float x);
   //! get our starting x (horizontal) coordinate
-  GLfloat x() const;
+  float x() const;
   //! set our current y (vertical) position
-  void setY(GLfloat);
+  void setY(float y);
   //! get our current y (vertical) position
-  GLfloat y() const;
+  float y() const;
+  //! get our current z (depth) position
+  float z() const;
   //! how thick (high) the track we're drawing is
-  GLfloat height() const;
+  float height() const;
+
+  //! set our default draw color
+  void setColor(ColorRef &c );
+  //! return our draw color
+  const ColorRef color() const;
+  //! return our draw color
+  ColorRef color();
+  //! return default gene color
+  static ColorRef default_gene_color();
+  //! return default track color
+  static ColorRef default_track_color();
+  
+  //! return our annotation color mapper
+  AnnotationColorsRef colorMapper() { return color_mapper; }
+
+  //! draw a from left to right +/- height/2
+  static
+  void draw_box(GLfloat world_left, GLfloat world_right, 
+                GLfloat left, GLfloat right, GLfloat height,
+                GLfloat y, GLfloat z,
+                GLint primitive=GL_QUADS);
+  //! draw a track 
+  /*! left and right are the edges of the current viewport
+   */
+  void draw(GLfloat left, GLfloat right) const;
+
+  //! get our right (horizontal) coordinate (size-x)
+  float right() const;
   //! how long is our sequence track? (computed from the sequence)
-  GLfloat length() const;
+  GLfloat size() const;
  
   //! return the left (lowest) base index that is fully visible
-  Sequence::size_type GlSequence::leftbase(GLfloat left) const;
+  Sequence::size_type 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;
+  //! done mostly so all the iterator logic continues to work correctly.
+  Sequence::size_type 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;
+  Sequence::const_iterator region_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;
+  Sequence::const_iterator region_end(GLfloat left, GLfloat right) const;
 
-  //! set track color 
-  void setColor(Color &);
-  Color color();
+  //! return a subsequence as a GlSequence (instead of a Sequence subsequence)
+  GlSequence subseq(size_type start, size_type count) const;
+  
+  //! Return the pixel width of the opengl viewport.
+  static int get_viewport_width_in_pixels();
+  //! how big is a pixel in world coordinats
+  static GLfloat pixelWidth(GLfloat, GLfloat);
+  //! how big is a pixel in world coordinats (specifying viewport size)
+  static GLfloat pixelWidth(GLfloat, GLfloat, int);
 
+  //! are we close enough that it would make sense to view the base pairs?
+  static bool is_sequence_renderable(GLfloat left, GLfloat right);
   //! 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 
@@ -64,26 +120,21 @@ public:
    *             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;
+  static bool is_sequence_renderable(GLfloat, GLfloat, int);
 
   friend bool operator==(const GlSequence &left, const GlSequence &right);
 
 protected:
-  const Sequence& seq;
-  GLfloat seq_x;
-  GLfloat seq_y;
-  GLfloat seq_z;
-  GLfloat seq_height;
-  AnnotationColors& color_mapper;
-  Color drawColor;
-  const GLfloat char_pix_per_world_unit;
+  AnnotationColorsRef color_mapper;
+
+  //! initalize a SeqSpanRef covering start, count
+  SeqSpanRef make_drawable_annotation(
+    Drawable::draw_func_ptr draw,
+    std::string name,
+    size_type start,
+    size_type count,
+    ColorRef color);
 
-  //! Return the pixel width of the opengl viewport.
-  static int get_viewport_pixel_width();
-  //! draw a from left to right +/- height/2
-  void draw_box(GLfloat left, GLfloat right, GLfloat height, GLfloat z) const;
   //! draw sequence as a bar
   void draw_track(GLfloat, GLfloat) const;
   void draw_annotations(GLfloat, GLfloat) const;
@@ -92,4 +143,9 @@ protected:
    */
   void draw_sequence(GLfloat, GLfloat) const;
 };
+
+//! draw sequence track when we're far enough out not to see the AGCTs. 
+void draw_summarized_track(SeqSpanRef ref, float left, float right);
+//! draw a 1/4 width centered track 
+void draw_narrow_track(SeqSpanRef ref, float left, float right);
 #endif