src/canvas.cpp

changeset 1178
3a88e7a60b63
parent 1177
8661b9237ed5
child 1181
ca6d0ef9aadb
equal deleted inserted replaced
1177:8661b9237ed5 1178:3a88e7a60b63
88 y += metrics.height(); 88 y += metrics.height();
89 } 89 }
90 } 90 }
91 } 91 }
92 92
93 /*
94 * Assuming we're currently viewing from a fixed camera, draw a backdrop into it. Currently this means drawing the grid.
95 */
96 void Canvas::drawFixedCameraBackdrop()
97 {
98 // Find the top left corner of the grid
99 Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0}));
100 Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()}));
101 qreal gridSize = grid()->coordinateSnap();
102 qreal x0 = sign(topLeft.x()) * (fabs(topLeft.x()) - fmod(fabs(topLeft.x()), gridSize));
103 qreal y0 = sign(topLeft.y()) * (fabs(topLeft.y()) - fmod(fabs(topLeft.y()), gridSize));
104 glEnable(GL_LINE_STIPPLE);
105 glBegin(GL_LINES);
106
107 static const auto prepareGridLine = [](qreal value) -> bool
108 {
109 if (not isZero(value))
110 {
111 if (isZero(fmod(value, 10.0)))
112 glColor4f(0, 0, 0, 0.6);
113 else
114 glColor4f(0, 0, 0, 0.25);
115
116 return true;
117 }
118 else
119 {
120 return false;
121 }
122 };
123
124 for (qreal x = x0; x < bottomRight.x(); x += gridSize)
125 {
126 if (prepareGridLine(x))
127 {
128 glVertex(currentCamera().realize({x, -10000, 999}));
129 glVertex(currentCamera().realize({x, 10000, 999}));
130 }
131 }
132
133 for (qreal y = y0; y < bottomRight.y(); y += gridSize)
134 {
135 if (prepareGridLine(y))
136 {
137 glVertex(currentCamera().realize({-10000, y, 999}));
138 glVertex(currentCamera().realize({10000, y, 999}));
139 }
140 }
141
142 glEnd();
143 glDisable(GL_LINE_STIPPLE);
144 }
145
93 bool Canvas::freeCameraAllowed() const 146 bool Canvas::freeCameraAllowed() const
94 { 147 {
95 return m_currentEditMode->allowFreeCamera(); 148 return m_currentEditMode->allowFreeCamera();
96 } 149 }
97 150

mercurial