119 int i = 0; |
119 int i = 0; |
120 |
120 |
121 for (CameraIcon& info : m_cameraIcons) |
121 for (CameraIcon& info : m_cameraIcons) |
122 { |
122 { |
123 // MATH |
123 // MATH |
124 int x1 = (m_width - (info.camera != FreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1; |
124 int x1 = (width() - (info.camera != FreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1; |
125 int y1 = ((i / 3) * 16) + 1; |
125 int y1 = ((i / 3) * 16) + 1; |
126 |
126 |
127 info.sourceRect = QRect (0, 0, 16, 16); |
127 info.sourceRect = QRect (0, 0, 16, 16); |
128 info.targetRect = QRect (x1, y1, 16, 16); |
128 info.targetRect = QRect (x1, y1, 16, 16); |
129 info.hitRect = QRect ( |
129 info.hitRect = QRect ( |
337 } |
337 } |
338 } |
338 } |
339 |
339 |
340 // ============================================================================= |
340 // ============================================================================= |
341 // |
341 // |
342 void GLRenderer::resizeGL (int w, int h) |
342 void GLRenderer::resizeGL (int width, int height) |
343 { |
343 { |
344 m_width = w; |
|
345 m_height = h; |
|
346 calcCameraIcons(); |
344 calcCameraIcons(); |
347 glViewport (0, 0, w, h); |
345 glViewport (0, 0, width, height); |
348 glMatrixMode (GL_PROJECTION); |
346 glMatrixMode (GL_PROJECTION); |
349 glLoadIdentity(); |
347 glLoadIdentity(); |
350 gluPerspective (45.0f, (double) w / (double) h, 1.0f, 10000.0f); |
348 gluPerspective (45.0f, (double) width / (double) height, 1.0f, 10000.0f); |
351 glMatrixMode (GL_MODELVIEW); |
349 glMatrixMode (GL_MODELVIEW); |
352 } |
350 } |
353 |
351 |
354 // ============================================================================= |
352 // ============================================================================= |
355 // |
353 // |
360 m_needZoomToFit = false; |
358 m_needZoomToFit = false; |
361 zoomAllToFit(); |
359 zoomAllToFit(); |
362 } |
360 } |
363 |
361 |
364 m_virtualWidth = zoom(); |
362 m_virtualWidth = zoom(); |
365 m_virtualHeight = (m_height * m_virtualWidth) / m_width; |
363 m_virtualHeight = (height() * m_virtualWidth) / width(); |
366 |
364 |
367 if (m_config->drawWireframe() and not m_isDrawingSelectionScene) |
365 if (m_config->drawWireframe() and not m_isDrawingSelectionScene) |
368 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
366 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |
369 |
367 |
370 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
368 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
703 int y1 = y0 + range.height(); |
701 int y1 = y0 + range.height(); |
704 |
702 |
705 // Clamp the values to ensure they're within bounds |
703 // Clamp the values to ensure they're within bounds |
706 x0 = qMax (0, x0); |
704 x0 = qMax (0, x0); |
707 y0 = qMax (0, y0); |
705 y0 = qMax (0, y0); |
708 x1 = qMin (x1, m_width); |
706 x1 = qMin (x1, width()); |
709 y1 = qMin (y1, m_height); |
707 y1 = qMin (y1, height()); |
710 const int areawidth = (x1 - x0); |
708 const int areawidth = (x1 - x0); |
711 const int areaheight = (y1 - y0); |
709 const int areaheight = (y1 - y0); |
712 const qint32 numpixels = areawidth * areaheight; |
710 const qint32 numpixels = areawidth * areaheight; |
713 |
711 |
714 // Allocate space for the pixel data. |
712 // Allocate space for the pixel data. |
715 QVector<unsigned char> pixelData; |
713 QVector<unsigned char> pixelData; |
716 pixelData.resize(4 * numpixels); |
714 pixelData.resize(4 * numpixels); |
717 |
715 |
718 // Read pixels from the color buffer. |
716 // Read pixels from the color buffer. |
719 glReadPixels(x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data()); |
717 glReadPixels(x0, height() - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data()); |
720 |
718 |
721 QSet<int32_t> indices; |
719 QSet<int32_t> indices; |
722 |
720 |
723 // Go through each pixel read and add them to the selection. |
721 // Go through each pixel read and add them to the selection. |
724 // Each pixel maps to an LDObject index injectively. |
722 // Each pixel maps to an LDObject index injectively. |
753 { |
751 { |
754 unsigned char pixel[4]; |
752 unsigned char pixel[4]; |
755 makeCurrent(); |
753 makeCurrent(); |
756 setPicking(true); |
754 setPicking(true); |
757 drawGLScene(); |
755 drawGLScene(); |
758 glReadPixels(mouseX, m_height - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
756 glReadPixels(mouseX, height() - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
759 LDObject* object = LDObject::fromID(pixel[0] * 0x10000 + pixel[1] * 0x100 + pixel[2]); |
757 LDObject* object = LDObject::fromID(pixel[0] * 0x10000 + pixel[1] * 0x100 + pixel[2]); |
760 setPicking(false); |
758 setPicking(false); |
761 repaint(); |
759 repaint(); |
762 return object; |
760 return object; |
763 } |
761 } |
900 zoom() = 30.0; |
898 zoom() = 30.0; |
901 break; |
899 break; |
902 } |
900 } |
903 |
901 |
904 zoomNotch (inward); |
902 zoomNotch (inward); |
905 QVector<unsigned char> capture (4 * m_width * m_height); |
903 QVector<unsigned char> capture (4 * width() * height()); |
906 drawGLScene(); |
904 drawGLScene(); |
907 glReadPixels (0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, capture.data()); |
905 glReadPixels (0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, capture.data()); |
908 QImage image (capture.constData(), m_width, m_height, QImage::Format_ARGB32); |
906 QImage image (capture.constData(), width(), height(), QImage::Format_ARGB32); |
909 bool filled = false; |
907 bool filled = false; |
910 |
908 |
911 // Check the top and bottom rows |
909 // Check the top and bottom rows |
912 for (int i = 0; i < image.width(); ++i) |
910 for (int i = 0; i < image.width(); ++i) |
913 { |
911 { |
914 if (image.pixel (i, 0) != black or image.pixel (i, m_height - 1) != black) |
912 if (image.pixel (i, 0) != black or image.pixel (i, height() - 1) != black) |
915 { |
913 { |
916 filled = true; |
914 filled = true; |
917 break; |
915 break; |
918 } |
916 } |
919 } |
917 } |
990 setPicking (true); |
988 setPicking (true); |
991 drawGLScene(); |
989 drawGLScene(); |
992 setPicking (false); |
990 setPicking (false); |
993 |
991 |
994 unsigned char pixel[4]; |
992 unsigned char pixel[4]; |
995 glReadPixels (m_mousePosition.x(), m_height - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); |
993 glReadPixels (m_mousePosition.x(), height() - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]); |
996 newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2]; |
994 newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2]; |
997 } |
995 } |
998 |
996 |
999 if (newIndex != (oldObject ? oldObject->id() : 0)) |
997 if (newIndex != (oldObject ? oldObject->id() : 0)) |
1000 { |
998 { |