Refactor Rendering of Objects (prepare for CPU rendering)
[ipdf/code.git] / src / ipdf.h
1 #ifndef _IPDF_H
2 #define _IPDF_H
3
4 #include "common.h"
5 #include "real.h"
6
7 #define C_RED Colour(1,0,0,1)
8 #define C_GREEN Colour(0,1,0,1)
9 #define C_BLUE Colour(0,0,1,1)
10
11 namespace IPDF
12 {
13
14         inline Real Random(Real max=1, Real min=0)
15         {
16                 return min + (max-min) * (Real(rand() % (int)1e6) / Real(1e6));
17         }
18
19         typedef unsigned ObjectID;
20         /** Type of object
21      * NOTE: Extra entry in the enum so we can use this as an array index
22          */
23         typedef enum 
24         {
25                 RECT_FILLED = 0,
26                 RECT_OUTLINE,
27                 CIRCLE_FILLED, 
28                 NUMBER_OF_OBJECT_TYPES
29         } ObjectType;
30
31         enum DocChunkTypes
32         {
33                 CT_NUMOBJS,
34                 CT_OBJTYPES,
35                 CT_OBJBOUNDS,
36         };
37
38         struct Rect
39         {
40                 Real x; Real y; Real w; Real h;
41                 Rect() = default; // Needed so we can fread/fwrite this struct
42                 Rect(Real _x, Real _y, Real _w, Real _h) : x(_x), y(_y), w(_w), h(_h) {}
43                 std::string Str() const
44                 {
45                         std::stringstream s;
46                         // float conversion needed because it is fucking impossible to get ostreams working with template classes
47                         s << "{" << Float(x) << ", " << Float(y) << ", " << Float(w) << ", " << Float(h) << "}";
48                         return s.str();
49                 }
50         };
51
52         struct Colour
53         {
54                 float r; float g; float b; float a;
55                 Colour() = default;
56                 Colour(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) {}
57         };
58
59         struct Objects
60         {
61                 std::vector<ObjectType> types;          
62                 std::vector<Rect> bounds;
63         };
64
65         class View;
66 }
67
68
69 #endif //_IPDF_H

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