948 uchar* pixelptr = &pixeldata[0]; |
948 uchar* pixelptr = &pixeldata[0]; |
949 |
949 |
950 // Read pixels from the color buffer. |
950 // Read pixels from the color buffer. |
951 glReadPixels (x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); |
951 glReadPixels (x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata); |
952 |
952 |
953 LDObjectPtr removedObj; |
953 LDObject* removedObj; |
954 QList<qint32> indices; |
954 QList<qint32> indices; |
955 |
955 |
956 // Go through each pixel read and add them to the selection. |
956 // Go through each pixel read and add them to the selection. |
957 // Note: black is background, those indices are skipped. |
957 // Note: black is background, those indices are skipped. |
958 for (qint32 i = 0; i < numpixels; ++i) |
958 for (qint32 i = 0; i < numpixels; ++i) |
969 |
969 |
970 RemoveDuplicates (indices); |
970 RemoveDuplicates (indices); |
971 |
971 |
972 for (qint32 idx : indices) |
972 for (qint32 idx : indices) |
973 { |
973 { |
974 LDObjectPtr obj = LDObject::fromID (idx); |
974 LDObject* obj = LDObject::fromID (idx); |
975 assert (obj != null); |
975 assert (obj != null); |
976 |
976 |
977 // If this is an additive single pick and the object is currently selected, |
977 // If this is an additive single pick and the object is currently selected, |
978 // we remove it from selection instead. |
978 // we remove it from selection instead. |
979 if (additive) |
979 if (additive) |
993 |
993 |
994 // Update everything now. |
994 // Update everything now. |
995 g_win->updateSelection(); |
995 g_win->updateSelection(); |
996 |
996 |
997 // Recompile the objects now to update their color |
997 // Recompile the objects now to update their color |
998 for (LDObjectPtr obj : Selection()) |
998 for (LDObject* obj : Selection()) |
999 compileObject (obj); |
999 compileObject (obj); |
1000 |
1000 |
1001 if (removedObj) |
1001 if (removedObj) |
1002 compileObject (removedObj); |
1002 compileObject (removedObj); |
1003 |
1003 |
1006 } |
1006 } |
1007 |
1007 |
1008 // |
1008 // |
1009 // Simpler version of GLRenderer::pick which simply picks whatever object on the screen |
1009 // Simpler version of GLRenderer::pick which simply picks whatever object on the screen |
1010 // |
1010 // |
1011 LDObjectPtr GLRenderer::pickOneObject (int mouseX, int mouseY) |
1011 LDObject* GLRenderer::pickOneObject (int mouseX, int mouseY) |
1012 { |
1012 { |
1013 uchar pixel[4]; |
1013 uchar pixel[4]; |
1014 doMakeCurrent(); |
1014 doMakeCurrent(); |
1015 setPicking (true); |
1015 setPicking (true); |
1016 drawGLScene(); |
1016 drawGLScene(); |
1017 glReadPixels (mouseX, m_height - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
1017 glReadPixels (mouseX, m_height - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
1018 LDObjectPtr obj = LDObject::fromID ((pixel[0] * 0x10000) + (pixel[1] * 0x100) + pixel[2]); |
1018 LDObject* obj = LDObject::fromID ((pixel[0] * 0x10000) + (pixel[1] * 0x100) + pixel[2]); |
1019 setPicking (false); |
1019 setPicking (false); |
1020 repaint(); |
1020 repaint(); |
1021 return obj; |
1021 return obj; |
1022 } |
1022 } |
1023 |
1023 |
1106 return (Axis) (3 - cam->axisX - cam->axisY); |
1106 return (Axis) (3 - cam->axisX - cam->axisY); |
1107 } |
1107 } |
1108 |
1108 |
1109 // ============================================================================= |
1109 // ============================================================================= |
1110 // |
1110 // |
1111 static QList<Vertex> GetVerticesOf (LDObjectPtr obj) |
1111 static QList<Vertex> GetVerticesOf (LDObject* obj) |
1112 { |
1112 { |
1113 QList<Vertex> verts; |
1113 QList<Vertex> verts; |
1114 |
1114 |
1115 if (obj->numVertices() >= 2) |
1115 if (obj->numVertices() >= 2) |
1116 { |
1116 { |
1117 for (int i = 0; i < obj->numVertices(); ++i) |
1117 for (int i = 0; i < obj->numVertices(); ++i) |
1118 verts << obj->vertex (i); |
1118 verts << obj->vertex (i); |
1119 } |
1119 } |
1120 elif (obj->type() == OBJ_Subfile) |
1120 else if (obj->type() == OBJ_Subfile) |
1121 { |
1121 { |
1122 LDSubfilePtr ref = obj.staticCast<LDSubfile>(); |
1122 for (LDObject* obj : static_cast<LDSubfile*> (obj)->inlineContents (true, false)) |
1123 LDObjectList objs = ref->inlineContents (true, false); |
|
1124 |
|
1125 for (LDObjectPtr obj : objs) |
|
1126 { |
1123 { |
1127 verts << GetVerticesOf (obj); |
1124 verts << GetVerticesOf (obj); |
1128 obj->destroy(); |
1125 obj->destroy(); |
1129 } |
1126 } |
1130 } |
1127 } |
1132 return verts; |
1129 return verts; |
1133 } |
1130 } |
1134 |
1131 |
1135 // ============================================================================= |
1132 // ============================================================================= |
1136 // |
1133 // |
1137 void GLRenderer::compileObject (LDObjectPtr obj) |
1134 void GLRenderer::compileObject (LDObject* obj) |
1138 { |
1135 { |
1139 compiler()->stageForCompilation (obj); |
1136 compiler()->stageForCompilation (obj); |
1140 } |
1137 } |
1141 |
1138 |
1142 // ============================================================================= |
1139 // ============================================================================= |
1143 // |
1140 // |
1144 void GLRenderer::forgetObject (LDObjectPtr obj) |
1141 void GLRenderer::forgetObject (LDObject* obj) |
1145 { |
1142 { |
1146 if (compiler() != null) |
1143 if (compiler() != null) |
1147 compiler()->dropObject (obj); |
1144 compiler()->dropObject (obj); |
1148 } |
1145 } |
1149 |
1146 |
1406 |
1403 |
1407 // ============================================================================= |
1404 // ============================================================================= |
1408 // |
1405 // |
1409 LDOverlayPtr GLRenderer::findOverlayObject (ECamera cam) |
1406 LDOverlayPtr GLRenderer::findOverlayObject (ECamera cam) |
1410 { |
1407 { |
1411 for (LDObjectPtr obj : document()->objects()) |
1408 for (LDObject* obj : document()->objects()) |
1412 { |
1409 { |
1413 LDOverlayPtr ovlobj = obj.dynamicCast<LDOverlay>(); |
1410 LDOverlayPtr overlay = dynamic_cast<LDOverlay*> (obj); |
1414 |
1411 |
1415 if (ovlobj != null and obj.staticCast<LDOverlay>()->camera() == cam) |
1412 if (overlay and overlay->camera() == cam) |
1416 return ovlobj; |
1413 return overlay; |
1417 } |
1414 } |
1418 |
1415 |
1419 return LDOverlayPtr(); |
1416 return nullptr; |
1420 } |
1417 } |
1421 |
1418 |
1422 // ============================================================================= |
1419 // ============================================================================= |
1423 // |
1420 // |
1424 // Read in overlays from the current file and update overlay info accordingly. |
1421 // Read in overlays from the current file and update overlay info accordingly. |
1461 LDOverlayPtr ovlobj = findOverlayObject (cam); |
1458 LDOverlayPtr ovlobj = findOverlayObject (cam); |
1462 |
1459 |
1463 if (meta.img == null and ovlobj != null) |
1460 if (meta.img == null and ovlobj != null) |
1464 { |
1461 { |
1465 // If this is the last overlay image, we need to remove the empty space after it as well. |
1462 // If this is the last overlay image, we need to remove the empty space after it as well. |
1466 LDObjectPtr nextobj = ovlobj->next(); |
1463 LDObject* nextobj = ovlobj->next(); |
1467 |
1464 |
1468 if (nextobj and nextobj->type() == OBJ_Empty) |
1465 if (nextobj and nextobj->type() == OBJ_Empty) |
1469 nextobj->destroy(); |
1466 nextobj->destroy(); |
1470 |
1467 |
1471 // If the overlay object was there and the overlay itself is |
1468 // If the overlay object was there and the overlay itself is |