viewport.h 1.38 KB
Newer Older
Nick Sharp's avatar
Nick Sharp committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef CMU462_VIEWPORT_H
#define CMU462_VIEWPORT_H

#include "CMU462.h"
#include "svg.h"

namespace CMU462 {

class Viewport {
 public:

  Viewport( ) : svg_2_norm( Matrix3x3::identity() ) { }
 
  inline Matrix3x3 get_canvas_to_norm() {
    return svg_2_norm;
  }

  inline void set_canvas_to_norm( Matrix3x3 m ) {
    svg_2_norm = m;
  }

  // set viewbox to look at (x,y) in svg coordinate space. Span defineds 
  // the view radius of the viewbox in number of pixels (the amout of pixels
  // included in the viewbox in both x and y direction).
  virtual void set_viewbox( float x, float y, float span ) = 0;

  // Move the viewbox by (dx,dy) in svg coordinate space. Scale the the view 
  // range by scale.
  virtual void update_viewbox( float dx, float dy, float scale ) = 0;

 protected:

  // current viewbox properties
  float x, y, span;

  // SVG coordinate to normalized display coordinates
  Matrix3x3 svg_2_norm;

}; // class Viewport


class ViewportImp : public Viewport {
 public:
  
  virtual void set_viewbox( float x, float y, float size );
  virtual void update_viewbox( float dx, float dy, float scale );

}; // class ViewportImp


class ViewportRef : public Viewport {
 public:
  
  virtual void set_viewbox( float x, float y, float size );
  virtual void update_viewbox( float dx, float dy, float scale );

}; // class ViewportRef


} // namespace CMU462

#endif // CMU462_VIEWPORT_H