make annotations big enough to show up
[mussa.git] / alg / glsequence.hpp
1 #ifndef _GL_SEQUENCE_H_
2 #define _GL_SEQUENCE_H_
3
4 #include "alg/annotation_colors.hpp"
5 #include "alg/sequence.hpp"
6 #include "alg/color.hpp"
7 #include <gl.h>
8 //! Manage rendering a mussa sequence track
9 /*! The idea is this will keep track of the location of where the sequence
10  *  is being rendered, and handle displaying annotations on that track
11  */
12 class GlSequence
13 {
14 public: 
15   GlSequence(const Sequence & s, AnnotationColors &cm);
16   GlSequence(const GlSequence & s);
17   GlSequence &operator=(const GlSequence &s);
18
19   //! draw a track 
20   /*! left and right are the edges of the current viewport
21    */
22   void draw(GLfloat left, GLfloat right) const;
23
24   const Sequence& sequence() const;
25   //! set our starting x (horizontal) coordinate
26   void setX(GLfloat);
27   //! get our starting x (horizontal) coordinate
28   GLfloat x() const;
29   //! get our right (horizontal) coordinate (length-x)
30   GLfloat right() const;
31   //! set our current y (vertical) position
32   void setY(GLfloat);
33   //! get our current y (vertical) position
34   GLfloat y() const;
35   //! how thick (high) the track we're drawing is
36   GLfloat height() const;
37   //! how long is our sequence track? (computed from the sequence)
38   GLfloat length() const;
39  
40   //! return the left (lowest) base index that is fully visible
41   Sequence::size_type GlSequence::leftbase(GLfloat left) const;
42   //! return one past rightmost (highest ) base index that is fully visible
43   /*! done mostly so all the iterator logic continues to work correctly.
44    */
45   Sequence::size_type GlSequence::rightbase(GLfloat right) const;
46
47   //! return iterator to the start of the stored sequence
48   Sequence::const_iterator sequence_begin() const;
49   //! return iterator to the end of the stored sequence
50   Sequence::const_iterator sequence_end() const;
51   //! provide an iterator to the sequence starting at world coordinate left
52   Sequence::const_iterator sequence_begin(GLfloat left, GLfloat right) const;
53   //! provide an iterator to the sequence ending at world coordinate right
54   Sequence::const_iterator sequence_end(GLfloat left, GLfloat right) const;
55
56   //! set track color 
57   void setColor(Color &);
58   Color color();
59
60   //! how big is a pixel in world coordinats
61   GLfloat get_pixel_width(GLfloat, GLfloat) const;
62   //! how big is a pixel in world coordinats (specifying viewport size)
63   GLfloat get_pixel_width(GLfloat, GLfloat, int) const;
64
65   //! are we close enough that it would make sense to view the base pairs?
66   bool is_sequence_renderable(GLfloat left, GLfloat right) const;
67   //! are we close enough that it would make sense to view the base pairs?
68   /*! though we don't actually check to see if there's sequence in our
69    *  view, just that there's enough pixels to render something if 
70    *  there were.
71    *  \param[in] left the left edge of the viewable region in world coordinates
72    *  \param[in] right the right edge of the viewable region in world 
73    *             coordinates
74    *  \param[in] pixel_width allow setting the current viewport pixel width
75    */
76   bool is_sequence_renderable(GLfloat, GLfloat, int) const;
77
78   friend bool operator==(const GlSequence &left, const GlSequence &right);
79
80 protected:
81   const Sequence& seq;
82   GLfloat seq_x;
83   GLfloat seq_y;
84   GLfloat seq_z;
85   GLfloat seq_height;
86   AnnotationColors& color_mapper;
87   Color drawColor;
88   const GLfloat char_pix_per_world_unit;
89
90   //! Return the pixel width of the opengl viewport.
91   static int get_viewport_width_in_pixels();
92   //! draw a from left to right +/- height/2
93   void draw_box(GLfloat world_left, GLfloat world_right, GLfloat left, GLfloat right, GLfloat height, GLfloat z) const;
94   //! draw sequence as a bar
95   void draw_track(GLfloat, GLfloat) const;
96   void draw_annotations(GLfloat, GLfloat) const;
97   //! render a sequence as ATGC
98   /*! left and right are the current edges of the viewable world
99    */
100   void draw_sequence(GLfloat, GLfloat) const;
101 };
102 #endif