Maybe don't use all of the lines. Or maybe do.
[ipdf/code.git] / src / view.h
1 #ifndef _VIEW_H
2 #define _VIEW_H
3
4 #include "ipdf.h"
5 #include "document.h"
6 #include "framebuffer.h"
7 #include "objectrenderer.h"
8
9 #define USE_GPU_TRANSFORM true
10 #define USE_GPU_RENDERING true
11
12 namespace IPDF
13 {
14         class Screen;
15         /**
16          * The View class manages a rectangular view into the document.
17          * It is responsible for coordinate transforms and rendering the document.
18          * ObjectRenderer's for each type of Object should be created in the constructor.
19          */
20         class View
21         {
22                 public:
23                         View(Document & document, Screen & screen, const Rect & bounds = Rect(0,0,1,1), const Colour & colour = Colour(0.f,0.f,0.f,1.f));
24                         virtual ~View();
25
26                         void Render(int width = 0, int height = 0);
27                         
28                         void Translate(Real x, Real y);
29                         void ScaleAroundPoint(Real x, Real y, Real scale_amount);
30                         
31                         Rect TransformToViewCoords(const Rect& inp) const;
32                         
33                         const Rect& GetBounds() const { return m_bounds; }
34                         
35                         const bool UsingGPUTransform() const { return m_use_gpu_transform; } // whether view transform calculated on CPU or GPU
36                         const bool UsingGPURendering() const { return m_use_gpu_rendering; } // whether GPU shaders are used or CPU rendering
37                         void ToggleGPUTransform() { m_use_gpu_transform = (!m_use_gpu_transform); m_bounds_dirty = true; m_buffer_dirty = true; }
38                         void ToggleGPURendering() { m_use_gpu_rendering = (!m_use_gpu_rendering); m_bounds_dirty = true; m_buffer_dirty = true; }
39
40
41                         void ForceBoundsDirty() {m_bounds_dirty = true;}                
42                         void ForceBufferDirty() {m_buffer_dirty = true;}                
43                         void ForceRenderDirty() {m_render_dirty = true;}
44
45
46                 private:
47                         struct GPUObjBounds
48                         {
49                                 float x0, y0;
50                                 float x1, y1;
51                         };
52
53                         void PrepareRender(); // call when m_render_dirty is true
54                         void UpdateObjBoundsVBO(); // call when m_buffer_dirty is true
55
56                         bool m_use_gpu_transform;
57                         bool m_use_gpu_rendering;
58                         bool m_bounds_dirty; // the view bounds has changed (occurs when changing view)
59                         bool m_buffer_dirty; // the object bounds have changed (also occurs when changing view, but only when not using GPU transforms)
60                         bool m_render_dirty; // the document has changed (occurs when document first loaded)
61                         Document & m_document;
62                         Screen & m_screen;
63                         FrameBuffer m_cached_display;
64                         Rect m_bounds;
65                         Colour m_colour;
66
67                         // Stores the view bounds.
68                         GraphicsBuffer m_bounds_ubo; //bounds_dirty means this one has changed
69                         // Stores the bounds for _all_ objects.
70                         GraphicsBuffer m_objbounds_vbo; //buffer_dirty means this one has changed
71
72                         // ObjectRenderers to be initialised in constructor
73                         // Trust me it will be easier to generalise things this way. Even though there are pointers.
74                         std::vector<ObjectRenderer*> m_object_renderers; 
75                         uint8_t * m_cpu_rendering_pixels; // pixels to be used for CPU rendering
76         };
77 }
78
79 #endif //_VIEW_H

UCC git Repository :: git.ucc.asn.au