48 {{ -1, 0, 0 }, X, Z, false, true }, |
48 {{ -1, 0, 0 }, X, Z, false, true }, |
49 {{ 0, 0, 0 }, X, Y, true, true }, |
49 {{ 0, 0, 0 }, X, Y, true, true }, |
50 {{ 0, -1, 0 }, Z, Y, false, true }, |
50 {{ 0, -1, 0 }, Z, Y, false, true }, |
51 }; |
51 }; |
52 |
52 |
|
53 static const matrix g_circleDrawTransforms[3] = { |
|
54 { 2, 0, 0, 0, 1, 0, 0, 0, 2 }, |
|
55 { 2, 0, 0, 0, 0, 2, 0, 1, 0 }, |
|
56 { 0, 1, 0, 2, 0, 0, 0, 0, 2 }, |
|
57 }; |
|
58 |
53 cfg (String, gl_bgcolor, "#CCCCD9"); |
59 cfg (String, gl_bgcolor, "#CCCCD9"); |
54 cfg (String, gl_maincolor, "#707078"); |
60 cfg (String, gl_maincolor, "#707078"); |
55 cfg (Float, gl_maincolor_alpha, 1.0); |
61 cfg (Float, gl_maincolor_alpha, 1.0); |
56 cfg (Int, gl_linethickness, 2); |
62 cfg (Int, gl_linethickness, 2); |
57 cfg (Bool, gl_colorbfc, false); |
63 cfg (Bool, gl_colorbfc, false); |
577 paint.setPen (pen); |
582 paint.setPen (pen); |
578 paint.setBrush (QColor (64, 192, 0, 128)); |
583 paint.setBrush (QColor (64, 192, 0, 128)); |
579 paint.drawPolygon (poly, numverts); |
584 paint.drawPolygon (poly, numverts); |
580 |
585 |
581 // Draw vertex blips |
586 // Draw vertex blips |
582 pen = m_thinBorderPen; |
587 for (int i = 0; i < numverts; ++i) { |
583 pen.setWidth (1); |
|
584 paint.setPen (pen); |
|
585 paint.setBrush (QColor (64, 192, 0)); |
|
586 |
|
587 for (ushort i = 0; i < numverts; ++i) { |
|
588 QPoint& blip = poly[i]; |
588 QPoint& blip = poly[i]; |
589 paint.drawEllipse (blip.x() - blipsize / 2, blip.y() - blipsize / 2, |
589 drawBlip (paint, blip); |
590 blipsize, blipsize); |
590 |
591 |
|
592 // Draw their coordinates |
591 // Draw their coordinates |
593 paint.drawText (blip.x(), blip.y() - 8, polyverts[i].stringRep (true)); |
592 paint.drawText (blip.x(), blip.y() - 8, polyverts[i].stringRep (true)); |
594 } |
593 } |
|
594 } |
|
595 } |
|
596 elif (editMode() == CircleMode) |
|
597 { // If we have not specified the center point of the circle yet, preview it on the screen. |
|
598 if (m_drawedVerts.size() == 0) |
|
599 drawBlip (paint, coordconv3_2 (m_hoverpos)); |
|
600 else |
|
601 { QVector<vertex> verts; |
|
602 const double dist = circleDrawDist(); |
|
603 const int segs = lores; |
|
604 const double angleUnit = (2 * pi) / segs; |
|
605 Axis relX, relY; |
|
606 getRelativeAxes (relX, relY); |
|
607 |
|
608 for (int i = 0; i < segs; ++i) |
|
609 { vertex v = g_origin; |
|
610 v[relX] = m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist); |
|
611 v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist); |
|
612 verts << v; |
|
613 } |
|
614 |
|
615 QVector<QPoint> points; |
|
616 for (const vertex& v : verts) |
|
617 { QPoint point = coordconv3_2 (v); |
|
618 drawBlip (paint, point); |
|
619 points << point; |
|
620 } |
|
621 |
|
622 QPen pen = m_thinBorderPen; |
|
623 pen.setWidth (2); |
|
624 pen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); |
|
625 paint.setPen (pen); |
|
626 paint.setBrush (Qt::NoBrush); |
|
627 paint.drawPolygon (QPolygon (points)); |
595 } |
628 } |
596 } |
629 } |
597 } |
630 } |
598 |
631 |
599 // Camera icons |
632 // Camera icons |
662 |
695 |
663 paint.setPen (m_thickBorderPen); |
696 paint.setPen (m_thickBorderPen); |
664 paint.setBrush (QBrush (fillColor)); |
697 paint.setBrush (QBrush (fillColor)); |
665 paint.drawRect (rect); |
698 paint.drawRect (rect); |
666 } |
699 } |
|
700 } |
|
701 |
|
702 // ============================================================================= |
|
703 // ----------------------------------------------------------------------------- |
|
704 void GLRenderer::drawBlip (QPainter& paint, QPoint pos) const |
|
705 { QPen pen = m_thinBorderPen; |
|
706 const int blipsize = 8; |
|
707 pen.setWidth (1); |
|
708 paint.setPen (pen); |
|
709 paint.setBrush (QColor (64, 192, 0)); |
|
710 paint.drawEllipse (pos.x() - blipsize / 2, pos.y() - blipsize / 2, blipsize, blipsize); |
667 } |
711 } |
668 |
712 |
669 // ============================================================================= |
713 // ============================================================================= |
670 // ----------------------------------------------------------------------------- |
714 // ----------------------------------------------------------------------------- |
671 QColor GLRenderer::getTextPen () const { |
715 QColor GLRenderer::getTextPen () const { |
1220 (void) accept; |
1274 (void) accept; |
1221 |
1275 |
1222 // Clean the selection and create the object |
1276 // Clean the selection and create the object |
1223 List<vertex>& verts = m_drawedVerts; |
1277 List<vertex>& verts = m_drawedVerts; |
1224 LDObject* obj = null; |
1278 LDObject* obj = null; |
1225 |
1279 |
1226 if (m_rectdraw) { |
1280 switch (editMode()) |
1227 LDQuad* quad = new LDQuad; |
1281 { case Draw: |
1228 |
1282 if (m_rectdraw) { |
1229 // Copy the vertices from m_rectverts |
1283 LDQuad* quad = new LDQuad; |
1230 updateRectVerts(); |
1284 |
1231 |
1285 // Copy the vertices from m_rectverts |
1232 for (int i = 0; i < quad->vertices(); ++i) |
1286 updateRectVerts(); |
1233 quad->setVertex (i, m_rectverts[i]); |
1287 |
1234 |
1288 for (int i = 0; i < quad->vertices(); ++i) |
1235 quad->setColor (maincolor); |
1289 quad->setVertex (i, m_rectverts[i]); |
1236 obj = quad; |
1290 |
1237 } else { |
1291 quad->setColor (maincolor); |
1238 switch (verts.size()) { |
1292 obj = quad; |
1239 case 1: |
1293 } else { |
1240 // 1 vertex - add a vertex object |
1294 switch (verts.size()) { |
1241 obj = new LDVertex; |
1295 case 1: |
1242 static_cast<LDVertex*> (obj)->pos = verts[0]; |
1296 // 1 vertex - add a vertex object |
1243 obj->setColor (maincolor); |
1297 obj = new LDVertex; |
1244 break; |
1298 static_cast<LDVertex*> (obj)->pos = verts[0]; |
1245 |
1299 obj->setColor (maincolor); |
1246 case 2: |
1300 break; |
1247 // 2 verts - make a line |
1301 |
1248 obj = new LDLine (verts[0], verts[1]); |
1302 case 2: |
1249 obj->setColor (edgecolor); |
1303 // 2 verts - make a line |
1250 break; |
1304 obj = new LDLine (verts[0], verts[1]); |
1251 |
1305 obj->setColor (edgecolor); |
1252 case 3: |
1306 break; |
1253 case 4: |
1307 |
1254 obj = (verts.size() == 3) ? |
1308 case 3: |
1255 static_cast<LDObject*> (new LDTriangle) : |
1309 case 4: |
1256 static_cast<LDObject*> (new LDQuad); |
1310 obj = (verts.size() == 3) ? |
1257 |
1311 static_cast<LDObject*> (new LDTriangle) : |
1258 obj->setColor (maincolor); |
1312 static_cast<LDObject*> (new LDQuad); |
1259 for (ushort i = 0; i < obj->vertices(); ++i) |
1313 |
1260 obj->setVertex (i, verts[i]); |
1314 obj->setColor (maincolor); |
1261 break; |
1315 for (ushort i = 0; i < obj->vertices(); ++i) |
1262 } |
1316 obj->setVertex (i, verts[i]); |
1263 } |
1317 break; |
1264 |
1318 } |
|
1319 } |
|
1320 break; |
|
1321 |
|
1322 case CircleMode: |
|
1323 { const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
|
1324 const double dist = circleDrawDist(); |
|
1325 |
|
1326 matrix transform = g_circleDrawTransforms[camera() % 3]; |
|
1327 for (int i = 0; i < 9; ++i) |
|
1328 { if (transform[i] == 2) |
|
1329 transform[i] = dist; |
|
1330 elif (transform[i] == 1 && camera() >= 3) |
|
1331 transform[i] = -1; |
|
1332 } |
|
1333 |
|
1334 LDSubfile* ref = new LDSubfile; |
|
1335 ref->setFileInfo (findLoadedFile ("4-4edge.dat")); |
|
1336 ref->setTransform (transform); |
|
1337 ref->setPosition (m_drawedVerts[0]); |
|
1338 ref->setColor (maincolor); |
|
1339 obj = ref; |
|
1340 } |
|
1341 break; |
|
1342 |
|
1343 case Select: |
|
1344 assert (false); |
|
1345 return; |
|
1346 } |
|
1347 |
1265 if (obj) { |
1348 if (obj) { |
1266 g_win->beginAction (null); |
1349 g_win->beginAction (null); |
1267 file()->addObject (obj); |
1350 file()->addObject (obj); |
1268 compileObject (obj); |
1351 compileObject (obj); |
1269 g_win->fullRefresh(); |
1352 g_win->fullRefresh(); |
1270 g_win->endAction(); |
1353 g_win->endAction(); |
1271 } |
1354 } |
1272 |
1355 |
1273 m_drawedVerts.clear(); |
1356 m_drawedVerts.clear(); |
1274 m_rectdraw = false; |
1357 m_rectdraw = false; |
|
1358 } |
|
1359 |
|
1360 // ============================================================================= |
|
1361 // ----------------------------------------------------------------------------- |
|
1362 double GLRenderer::circleDrawDist() const |
|
1363 { assert (m_drawedVerts.size() >= 1); |
|
1364 const vertex& v1 = (m_drawedVerts.size() == 2) ? m_drawedVerts[1] : m_hoverpos; |
|
1365 Axis relX, relY; |
|
1366 getRelativeAxes (relX, relY); |
|
1367 |
|
1368 const double dx = m_drawedVerts[0][relX] - v1[relX]; |
|
1369 const double dy = m_drawedVerts[0][relY] - v1[relY]; |
|
1370 return sqrt ((dx * dx) + (dy * dy)); |
|
1371 } |
|
1372 |
|
1373 // ============================================================================= |
|
1374 // ----------------------------------------------------------------------------- |
|
1375 void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const |
|
1376 { const staticCameraMeta* cam = &g_staticCameras[m_camera]; |
|
1377 relX = cam->axisX; |
|
1378 relY = cam->axisY; |
1275 } |
1379 } |
1276 |
1380 |
1277 // ============================================================================= |
1381 // ============================================================================= |
1278 // ----------------------------------------------------------------------------- |
1382 // ----------------------------------------------------------------------------- |
1279 static List<vertex> getVertices (LDObject* obj) { |
1383 static List<vertex> getVertices (LDObject* obj) { |