3 #include "SDL_opengl.h"
8 void View::Translate(Real x, Real y)
14 Debug("View Bounds => %s", m_bounds.Str().c_str());
17 void View::ScaleAroundPoint(Real x, Real y, Real scaleAmt)
19 // x and y are coordinates in the window
20 // Convert to local coords.
26 //Debug("Mouse wheel event %f %f %f\n", Float(x), Float(y), Float(scaleAmt));
28 Real top = y - m_bounds.y;
29 Real left = x - m_bounds.x;
34 m_bounds.x = x - left;
36 m_bounds.w *= scaleAmt;
37 m_bounds.h *= scaleAmt;
38 Debug("View Bounds => %s", m_bounds.Str().c_str());
41 Rect View::TransformToViewCoords(const Rect& inp) const
44 out.x = (inp.x - m_bounds.x) / m_bounds.w;
45 out.y = (inp.y - m_bounds.y) / m_bounds.h;
47 out.w = inp.w / m_bounds.w;
48 out.h = inp.h / m_bounds.h;
54 // Draw some grid lines at fixed pixel positions
55 glMatrixMode(GL_PROJECTION);
57 glOrtho(0.0, 1.0, 1.0, 0.0, -1.f, 1.f);
58 glMatrixMode(GL_MODELVIEW);
61 glColor4f(0.9,0.9,0.9,0.1);
62 const float num_lines = 50.0;
63 for (float i = 0; i < num_lines; ++i)
66 glVertex2f(i*(1.0/num_lines), 0.0);
67 glVertex2f(i*(1.0/num_lines), 1.0);
70 glVertex2f(0.0,i*(1.0/num_lines));
71 glVertex2f(1.0,i*(1.0/num_lines));
79 static bool debug_output_done = false;
80 if (!debug_output_done)
82 m_document.DebugDumpObjects();
83 debug_output_done = true;
87 //DrawGrid(); // Draw the gridlines
89 glMatrixMode(GL_PROJECTION);
91 if (m_use_gpu_transform)
93 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);
97 glOrtho(0,1,1,0,-1,1);
99 glMatrixMode(GL_MODELVIEW);
102 if (m_colour.a < 1.0f)
105 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
107 glColor4f(m_colour.r, m_colour.g, m_colour.b, m_colour.a);
109 for (unsigned id = 0; id < m_document.ObjectCount(); ++id)
111 if (m_document.m_objects.types[id] != RECT_FILLED)
114 if (m_use_gpu_transform)
116 obj_bounds = m_document.m_objects.bounds[id];
120 obj_bounds = TransformToViewCoords(m_document.m_objects.bounds[id]);
122 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y));
123 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y));
124 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y) + Float(obj_bounds.h));
125 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y) + Float(obj_bounds.h));
130 for (unsigned id = 0; id < m_document.ObjectCount(); ++id)
132 if (m_document.m_objects.types[id] != RECT_OUTLINE)
135 if (m_use_gpu_transform)
137 obj_bounds = m_document.m_objects.bounds[id];
141 obj_bounds = TransformToViewCoords(m_document.m_objects.bounds[id]);
143 glBegin(GL_LINE_LOOP);
144 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y));
145 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y));
146 glVertex2f(Float(obj_bounds.x) + Float(obj_bounds.w), Float(obj_bounds.y) + Float(obj_bounds.h));
147 glVertex2f(Float(obj_bounds.x), Float(obj_bounds.y) + Float(obj_bounds.h));
151 if (m_colour.a < 1.0f)