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