OSDN Git Service

[UI][Qt] Add save screen "Capture Screen" feature.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 22 Nov 2015 04:11:09 +0000 (13:11 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 22 Nov 2015 04:11:09 +0000 (13:11 +0900)
source/src/common.h
source/src/qt/common/draw_thread.cpp
source/src/qt/common/qt_gldraw.cpp
source/src/qt/common/qt_gldraw.h
source/src/qt/common/qt_glevents.cpp
source/src/qt/common/qt_glutil.cpp
source/src/qt/common/qt_main.cpp

index d2344fe..99f7b22 100644 (file)
@@ -209,8 +209,8 @@ typedef uint16 scrntype;
 #  define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8))
 typedef uint32 scrntype;
 # elif defined(_RGBA888)
-//#   define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
-#   define RGB_COLOR(r, g, b) (((uint32)(b) << 24) | ((uint32)(g) << 16) | ((uint32)(r) << 8)) | ((uint32)0xff << 0)
+#   define RGB_COLOR(r, g, b) (((uint32)(r) << 24) | ((uint32)(g) << 16) | ((uint32)(b) << 8)) | ((uint32)0xff << 0)
+//#   define RGB_COLOR(r, g, b) (((uint32)(b) << 24) | ((uint32)(g) << 16) | ((uint32)(r) << 8)) | ((uint32)0xff << 0)
 typedef uint32 scrntype;
 # endif
 
@@ -226,8 +226,8 @@ typedef uint16 scrntype;
 #  define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0))
 typedef uint32 scrntype;
 # elif defined(_RGBA888)
-//#   define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
-#   define RGB_COLOR(r, g, b) (((uint32)(b) << 16) | ((uint32)(g) << 8) | ((uint32)(r) << 0)) | ((uint32)0xff << 24)
+#   define RGB_COLOR(r, g, b) (((uint32)(r) << 16) | ((uint32)(g) << 8) | ((uint32)(b) << 0)) | ((uint32)0xff << 24)
+//#   define RGB_COLOR(r, g, b) (((uint32)(b) << 16) | ((uint32)(g) << 8) | ((uint32)(r) << 0)) | ((uint32)0xff << 24)
 typedef uint32 scrntype;
 # endif
 
index 4f5a1d1..fbc5072 100644 (file)
@@ -46,3 +46,6 @@ void DrawThreadClass::doExit(void)
 void DrawThreadClass::doWork(const QString &param)
 {
 }
+
+
+
index ec69d8b..7d4c6df 100644 (file)
@@ -344,7 +344,7 @@ void GLDrawClass::drawUpdateTexture(QImage *p)
                        extfunc->glTexSubImage2D(GL_TEXTURE_2D, 0,
                                                 0, 0,
                                                 p->width(), p->height(),
-                                                GL_RGBA, GL_UNSIGNED_BYTE, p->constBits());
+                                                GL_BGRA, GL_UNSIGNED_BYTE, p->constBits());
                        extfunc->glBindTexture(GL_TEXTURE_2D, 0);
                        //this->deleteTexture(uVramTextureID);
                } else {
@@ -553,6 +553,8 @@ void GLDrawClass::paintGL(void)
                drawUpdateTexture(imgptr);
                crt_flag = false;
        }
+       SaveToPixmap(); // If save requested, then Save to Pixmap.
+       
        extfunc->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        extfunc->glEnable(GL_DEPTH_TEST);
        extfunc->glDisable(GL_BLEND);
@@ -571,6 +573,7 @@ void GLDrawClass::paintGL(void)
        extfunc->glDisable(GL_BLEND);
        drawGrids();
        extfunc->glFlush();
+
 }
 
 #ifndef GL_MULTISAMPLE
@@ -585,6 +588,9 @@ GLDrawClass::GLDrawClass(QWidget *parent)
 #endif
 {
        
+       save_pixmap_req = false;
+       filename_screen_pixmap.clear();
+       
 #if defined(_USE_GLAPI_QT5_4)   
        uVramTextureID = new QOpenGLTexture(QOpenGLTexture::Target2D);
 #else
index b3dad35..dbb16a2 100644 (file)
@@ -220,6 +220,9 @@ class GLDrawClass: public QGLWidget
 # ifdef USE_BITMAP
        void drawBitmapTexture(void);
 #endif
+       QString filename_screen_pixmap;
+       bool save_pixmap_req;
+       void SaveToPixmap(void);
        
 public:
        GLDrawClass(QWidget *parent = 0);
@@ -236,7 +239,6 @@ public:
        void SetBrightRGB(float r, float g, float b);
        void InitFBO(void);
        void closeEvent(QCloseEvent *event);
-       
 public slots:
        void initKeyCode(void);
        void releaseKeyCode(void);
@@ -262,7 +264,8 @@ public slots:
        void setEmuPtr(EMU *p);
        void enterEvent(QEvent *);
        void leaveEvent(QEvent *);
-   
+       void do_save_frame_screen(void);
+       
 signals:
        void update_screenChanged(int tick);
        void do_notify_move_mouse(int x, int y);
index 1bd39d9..321cc5a 100644 (file)
@@ -21,6 +21,7 @@
 #include <GL/glu.h>
 #include "qt_gldraw.h"
 #include <QEvent>
+#include <QDateTime>
 
 void GLDrawClass::enterEvent(QEvent *event)
 {
@@ -127,3 +128,17 @@ void GLDrawClass::closeEvent(QCloseEvent *event)
 {
        //emit sig_finished();
 }
+
+void GLDrawClass::do_save_frame_screen(void)
+{
+       if(!save_pixmap_req) {
+               save_pixmap_req = true;
+               QDateTime nowTime = QDateTime::currentDateTime();
+               QString tmps = QString::fromUtf8("Screen_Save_emu");
+               tmps = tmps + QString::fromUtf8(CONFIG_NAME);
+               tmps = tmps + QString::fromUtf8("_");
+               tmps = tmps + nowTime.toString(QString::fromUtf8("yyyy-MM-dd_hh-mm-ss.zzz"));
+               tmps = tmps + QString::fromUtf8(".png");
+               filename_screen_pixmap = QString::fromUtf8(p_emu->bios_path(tmps.toUtf8().constData()));
+       }
+}
index 17770e6..825261a 100644 (file)
@@ -14,6 +14,7 @@
 #include <omp.h>
 #endif //_OPENMP
 #include <QGLContext>
+#include <QImage>
 
 //extern const char *cl_render;
 
@@ -474,3 +475,15 @@ void GLDrawClass::InitFBO(void)
        }
        bGL_PIXEL_UNPACK_BUFFER_BINDING = false;
 }
+
+void GLDrawClass::SaveToPixmap(void)
+{
+       if(save_pixmap_req) {
+               if(!filename_screen_pixmap.isEmpty()) {
+                       QImage snapshot = this->grabFrameBuffer();
+                       snapshot.save(filename_screen_pixmap);
+               }
+               save_pixmap_req = false;
+               filename_screen_pixmap.clear();
+       }
+}
index ee48e42..64093cf 100644 (file)
@@ -281,7 +281,8 @@ void Ui_MainWindow::LaunchEmuThread(void)
        connect(hDrawEmu, SIGNAL(sig_draw_frames(int)), hRunEmu, SLOT(print_framerate(int)));
        connect(hDrawEmu, SIGNAL(message_changed(QString)), this, SLOT(message_status_bar(QString)));
        connect(hDrawEmu, SIGNAL(sig_update_screen(QImage *)), glv, SLOT(update_screen(QImage *)), Qt::QueuedConnection);
-       
+       connect(actionCapture_Screen, SIGNAL(triggered()), glv, SLOT(do_save_frame_screen()));
+               
        connect(hRunEmu, SIGNAL(sig_draw_thread()), hDrawEmu, SLOT(doDraw()));
        //connect(hRunEmu, SIGNAL(quit_draw_thread()), hDrawEmu, SLOT(doExit()));
        connect(this, SIGNAL(quit_draw_thread()), hDrawEmu, SLOT(doExit()));