Sat, 27 Apr 2013 02:17:03 +0300
Added screencapping
gldraw.cpp | file | annotate | diff | comparison | revisions | |
gldraw.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui_actions.cpp | file | annotate | diff | comparison | revisions | |
icons/screencap.png | file | annotate | diff | comparison | revisions |
--- a/gldraw.cpp Fri Apr 26 22:53:21 2013 +0300 +++ b/gldraw.cpp Sat Apr 27 02:17:03 2013 +0300 @@ -722,4 +722,20 @@ paintGL (); swapBuffers (); +} + +// ============================================================================= +uchar* GLRenderer::screencap (ushort& w, ushort& h) { + w = width; + h = height; + uchar* cap = new uchar[4 * w * h]; + paintGL (); + + // Capture the pixels + glReadPixels (0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, cap); + + // Restore the background + setBackground (); + + return cap; } \ No newline at end of file
--- a/gldraw.h Fri Apr 26 22:53:21 2013 +0300 +++ b/gldraw.h Sat Apr 27 02:17:03 2013 +0300 @@ -45,6 +45,7 @@ void refresh (); void updateSelFlash (); void resetAngles (); + uchar* screencap (ushort& w, ushort& h); double rotX, rotY, rotZ; double panX, panY;
--- a/gui.cpp Fri Apr 26 22:53:21 2013 +0300 +++ b/gui.cpp Sat Apr 27 02:17:03 2013 +0300 @@ -86,6 +86,7 @@ EXTERN_ACTION (resetView) EXTERN_ACTION (insertFrom) EXTERN_ACTION (insertRaw) +EXTERN_ACTION (screencap) #ifndef RELEASE EXTERN_ACTION (addTestQuad) @@ -197,11 +198,13 @@ // View menu qViewMenu = menuBar ()->addMenu (tr ("&View")); - qViewMenu->addAction (ACTION (resetView)); + qViewMenu->addAction (ACTION (resetView)); // Reset View + qViewMenu->addSeparator (); // ----- + qViewMenu->addAction (ACTION (screencap)); // Screencap Part // Insert menu qInsertMenu = menuBar ()->addMenu (tr ("&Insert")); - qInsertMenu->addAction (ACTION (insertFrom)); // Insert from File + qInsertMenu->addAction (ACTION (insertFrom)); // Insert from File qInsertMenu->addAction (ACTION (insertRaw)); // Insert Raw qInsertMenu->addSeparator (); // ------- qInsertMenu->addAction (ACTION (newSubfile)); // New Subfile @@ -392,6 +395,7 @@ g_CurrentToolBar->addAction (ACTION (makeBorders)); g_CurrentToolBar->addAction (ACTION (makeCornerVerts)); g_CurrentToolBar->addAction (ACTION (roundCoords)); + g_CurrentToolBar->addAction (ACTION (screencap)); updateToolBars (); }
--- a/gui_actions.cpp Fri Apr 26 22:53:21 2013 +0300 +++ b/gui_actions.cpp Sat Apr 27 02:17:03 2013 +0300 @@ -304,6 +304,7 @@ layout->addWidget (te_edit); layout->addWidget (bbx_buttons); dlg->setLayout (layout); + dlg->setWindowTitle (APPNAME_DISPLAY ": Insert Raw"); dlg->connect (bbx_buttons, SIGNAL (accepted ()), dlg, SLOT (accept ())); dlg->connect (bbx_buttons, SIGNAL (rejected ()), dlg, SLOT (reject ())); @@ -332,6 +333,23 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= +MAKE_ACTION (screencap, "Screencap Part", "screencap", "Save a picture of the model", (0)) { + ushort w, h; + uchar* imagedata = g_ForgeWindow->R->screencap (w, h); + + // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. + QImage img = QImage (imagedata, w, h, QImage::Format_ARGB32).rgbSwapped ().mirrored (); + + str fname = QFileDialog::getSaveFileName (); + if (~fname > 0 && !img.save (fname)) + critical (format ("Couldn't open %s for saving screencap: %s", fname.chars(), strerror (errno))); + + delete[] imagedata; +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= // Debug things #ifndef RELEASE MAKE_ACTION (addTestQuad, "Add Test Quad", "add-quad", "Adds a test quad.", (0)) {