Add loadsvg script command, fix ParanoidNumber size limiting*
[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 #define USE_SHADING !(USE_GPU_RENDERING) && true
12
13 #define TRANSFORM_OBJECTS_NOT_VIEW
14
15 namespace IPDF
16 {
17         class Screen;
18         /**
19          * The View class manages a rectangular view into the document.
20          * It is responsible for coordinate transforms and rendering the document.
21          * ObjectRenderer's for each type of Object should be created in the constructor.
22          */
23         class View
24         {
25                 public:
26                         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));
27                         virtual ~View();
28
29                         void Render(int width = 0, int height = 0);
30                         
31                         void Translate(Real x, Real y);
32                         void ScaleAroundPoint(Real x, Real y, Real scale_amount);
33                         void SetBounds(const Rect & new_bounds);
34                         
35                         Rect TransformToViewCoords(const Rect& inp) const;
36                         
37                         const Rect& GetBounds() const { return m_bounds; }
38                         
39                         
40                         const bool UsingGPUTransform() const { return m_use_gpu_transform; } // whether view transform calculated on CPU or GPU
41                         const bool UsingGPURendering() const { return m_use_gpu_rendering; } // whether GPU shaders are used or CPU rendering
42                         void ToggleGPUTransform() { m_use_gpu_transform = (!m_use_gpu_transform); m_bounds_dirty = true; m_buffer_dirty = true; }
43                         void ToggleGPURendering() { m_use_gpu_rendering = (!m_use_gpu_rendering); m_bounds_dirty = true; m_buffer_dirty = true; }
44                         void SetGPUTransform(bool state) {m_use_gpu_transform = state; m_bounds_dirty = true; m_buffer_dirty = true;}
45                         
46                         void SetGPURendering(bool state) {m_use_gpu_rendering = state; m_bounds_dirty = true; m_buffer_dirty = true;}
47
48                         bool ShowingBezierBounds() const {return m_show_bezier_bounds;} // render bounds rectangles
49                         void ShowBezierBounds(bool state) {m_show_bezier_bounds = state; m_bounds_dirty = true; m_buffer_dirty = true;}
50                         bool ShowingBezierType() const {return m_show_bezier_type;}
51                         void ShowBezierType(bool state) {m_show_bezier_type = state; m_bounds_dirty = true; m_buffer_dirty = true;}
52                         bool ShowingFillPoints() const {return m_show_fill_points;}
53                         void ShowFillPoints(bool state) {m_show_fill_points = state; m_bounds_dirty = true; m_buffer_dirty = true;}
54                         bool ShowingFillBounds() const {return m_show_fill_bounds;}
55                         void ShowFillBounds(bool state) {m_show_fill_bounds = true;}
56                         
57                         bool PerformingShading() const {return m_perform_shading;}
58                         void PerformShading(bool state) {m_perform_shading = state; m_bounds_dirty = true; m_buffer_dirty = true;}
59
60                         void ForceBoundsDirty() {m_bounds_dirty = true;}                
61                         void ForceBufferDirty() {m_buffer_dirty = true;}                
62                         void ForceRenderDirty() {m_render_dirty = true;}
63                         
64                         void SetLazyRendering(bool state = true) {m_lazy_rendering = state;}
65                         bool UsingLazyRendering() const {return m_lazy_rendering;}
66                         
67                         void SaveBMP(const char * filename) {if (UsingGPURendering()) SaveGPUBMP(filename); else SaveCPUBMP(filename);}
68                         
69                         void SaveCPUBMP(const char * filename);
70                         void SaveGPUBMP(const char * filename);
71
72                         Document & Doc() {return m_document;}
73
74                 private:
75                         struct GPUObjBounds
76                         {
77                                 float x0, y0;
78                                 float x1, y1;
79                         } __attribute__((packed));
80
81                         void PrepareRender(); // call when m_render_dirty is true
82                         void UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj); // call when m_buffer_dirty is true
83
84                         void RenderRange(int width, int height, unsigned first_obj, unsigned last_obj);
85
86                         bool m_use_gpu_transform;
87                         bool m_use_gpu_rendering;
88                         bool m_bounds_dirty; // the view bounds has changed (occurs when changing view)
89                         bool m_buffer_dirty; // the object bounds have changed (also occurs when changing view, but only when not using GPU transforms)
90                         bool m_render_dirty; // the document has changed (occurs when document first loaded)
91                         Document & m_document;
92                         Screen & m_screen;
93                         FrameBuffer m_cached_display;
94                         Rect m_bounds;
95                         Colour m_colour;
96
97                         // Stores the view bounds.
98                         GraphicsBuffer m_bounds_ubo; //bounds_dirty means this one has changed
99                         // Stores the bounds for _all_ objects.
100                         GraphicsBuffer m_objbounds_vbo; //buffer_dirty means this one has changed
101
102                         // ObjectRenderers to be initialised in constructor
103                         // Trust me it will be easier to generalise things this way. Even though there are pointers.
104                         std::vector<ObjectRenderer*> m_object_renderers; 
105                         uint8_t * m_cpu_rendering_pixels; // pixels to be used for CPU rendering
106
107                         
108                         // shading
109                         bool m_perform_shading;
110                         
111                         // Debug rendering
112                         bool m_show_bezier_bounds;
113                         bool m_show_bezier_type;
114                         bool m_show_fill_points;
115                         bool m_show_fill_bounds;
116                         
117                         bool m_lazy_rendering;// don't redraw frames unless we need to
118
119
120 #ifndef QUADTREE_DISABLED
121                         QuadTreeIndex m_current_quadtree_node;  // The highest node we will traverse.
122                         int m_quadtree_max_depth;               // The maximum quadtree depth.
123                         void RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int remaining_depth);
124
125 #endif
126         };
127 }
128
129 #endif //_VIEW_H

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