80f49861b116db216258cf96e9349370704460eb
[ipdf/code.git] / src / view.cpp
1 #include "view.h"
2
3 #include "SDL_opengl.h"
4
5 using namespace IPDF;
6 using namespace std;
7
8 void View::Translate(Real x, Real y)
9 {
10         x *= m_bounds.w;
11         y *= m_bounds.h;
12         m_bounds.x += x;
13         m_bounds.y += y;
14 }
15
16 void View::ScaleAroundPoint(Real x, Real y, Real scaleAmt)
17 {
18         // Convert to local coords.
19         x *= m_bounds.w;
20         y *= m_bounds.h;
21         x += m_bounds.x;
22         y += m_bounds.y;
23         
24         Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt));
25         
26         Real top = y - m_bounds.y;
27         Real left = x - m_bounds.x;
28         
29         top *= scaleAmt;
30         left *= scaleAmt;
31         
32         m_bounds.x = x - left;
33         m_bounds.y = y - top;
34         m_bounds.w *= scaleAmt;
35         m_bounds.h *= scaleAmt;
36 }
37
38 void View::Render()
39 {
40         static bool debug_output_done = false;
41         if (!debug_output_done)
42         {
43                 m_document.DebugDumpObjects();
44                 debug_output_done = true;
45         }
46
47         glClearColor(1.f,1.f,1.f,1.f);
48         glClear(GL_COLOR_BUFFER_BIT);
49
50         glMatrixMode(GL_PROJECTION);
51         glLoadIdentity();
52         glOrtho(Float(m_bounds.x), Float(m_bounds.x)+Float(m_bounds.w), Float(m_bounds.y) + Float(m_bounds.h), Float(m_bounds.y), -1.f, 1.f);
53         glMatrixMode(GL_MODELVIEW);
54         glLoadIdentity();
55
56         glColor4f(0.f,0.f,0.f,1.f);
57         glBegin(GL_QUADS);
58         for (unsigned id = 0; id < m_document.ObjectCount(); ++id)
59         {
60                 if (m_document.m_objects.types[id] == RECT_FILLED)
61                         continue;
62                 Rect obj_bounds = m_document.m_objects.bounds[id];
63                 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y));
64                 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y));
65                 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y) + Float(obj_bounds.h));
66                 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y) + Float(obj_bounds.h));
67         }
68         glEnd();
69
70         for (unsigned id = 0; id < m_document.ObjectCount(); ++id)
71         {
72                 if (m_document.m_objects.types[id] == RECT_OUTLINE)
73                         continue;
74                 Rect obj_bounds = m_document.m_objects.bounds[id];
75                 glBegin(GL_LINE_LOOP);
76                 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y));
77                 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y));
78                 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y) + Float(obj_bounds.h));
79                 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y) + Float(obj_bounds.h));
80                 glEnd();
81         }
82
83 }

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