OSDN Git Service

[Qt][UI][MOUSE] Make pointer-diff at OSD_BASE:: . Not at EMC_THREAD::.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 10 Aug 2021 12:01:20 +0000 (21:01 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 10 Aug 2021 12:01:20 +0000 (21:01 +0900)
source/src/qt/CMakeLists.txt
source/src/qt/avio/CMakeLists.txt
source/src/qt/common/emu_thread_slots.cpp
source/src/qt/gui/CMakeLists.txt
source/src/qt/gui/emu_thread_tmpl.cpp
source/src/qt/gui/emu_thread_tmpl.h
source/src/qt/gui/qt_glevents.cpp
source/src/qt/osd_base.h
source/src/qt/osd_input.cpp
source/src/vm/common_vm/CMakeLists.txt

index b2aad75..b273837 100644 (file)
@@ -1,5 +1,5 @@
 message("* qt/osd")
-SET(THIS_LIB_VERSION 3.7.0)
+SET(THIS_LIB_VERSION 3.8.0)
 
 set(s_qt_osd_headers
        osd_base.h
index f22d882..e804fd8 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/avio")
 
-SET(THIS_LIB_VERSION 3.4.0)
+SET(THIS_LIB_VERSION 3.4.1)
 set(s_qt_avio_headers
          movie_saver.h
          movie_loader.h
index 356f234..d7ca57c 100644 (file)
@@ -861,16 +861,18 @@ void EmuThreadClassBase::set_romakana(bool flag)
 void EmuThreadClassBase::moved_mouse(double x, double y, double globalx, double globaly)
 {
        if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
-               mouse_x = (int)floor(x);
-               mouse_y = (int)floor(y);
+               mouse_x = x;
+               mouse_y = y;
 //             bool flag = p_osd->is_mouse_enabled();
 //             if(!flag) return;
 //             printf("Mouse Moved: %g, %g\n", x, y);
 //             p_osd->set_mouse_pointer(floor(x), floor(y));
        } else if(using_flags->is_use_mouse()) {
-               double factor = (double)(p_config->mouse_sensitivity & ((1 << 16) - 1));
-               mouse_x = (int)(floor((x * factor) / 8192.0));
-               mouse_y = (int)(floor((y * factor) / 8192.0));
+//             double factor = (double)(p_config->mouse_sensitivity & ((1 << 16) - 1));
+//             mouse_x = (int)(floor((globalx * factor) / 8192.0));
+//             mouse_y = (int)(floor((globaly * factor) / 8192.0));
+               mouse_x = globalx;
+               mouse_y = globaly;
                //printf("Moved Mouse %d, %d\n", x, y);
                bool flag = p_osd->is_mouse_enabled();
                if(!flag) return;
index c1b5af5..5575db3 100644 (file)
@@ -1,6 +1,6 @@
 message("* qt/gui")
 
-set(THIS_LIB_VERSION 3.7.0)
+set(THIS_LIB_VERSION 3.8.0)
 
 set(s_qt_gui_headers
          qt_dialogs.h
index af15cc1..074d2d2 100644 (file)
@@ -65,7 +65,8 @@ EmuThreadClassBase::EmuThreadClassBase(Ui_MainWindowBase *rootWindow, USING_FLAG
        vMovieQueue.clear();
        
        drawCond = new QWaitCondition();
-       keyMutex = new QMutex(QMutex::Recursive);
+//     keyMutex = new QMutex(QMutex::Recursive);
+
        mouse_x = 0;
        mouse_y = 0;
        if(using_flags->is_use_tape() && !using_flags->is_tape_binary_only()) {
@@ -83,10 +84,11 @@ EmuThreadClassBase::EmuThreadClassBase(Ui_MainWindowBase *rootWindow, USING_FLAG
                                                                 p_config->sound_volume_l[i]) / 2;
                }
        }
-       keyMutex->lock();
+       QMutexLocker _n(&keyMutex);
+
        key_fifo = new FIFO(512 * 6);
        key_fifo->clear();
-       keyMutex->unlock();
+
 
 };
 
@@ -134,14 +136,16 @@ void EmuThreadClassBase::button_pressed_mouse(Qt::MouseButton button)
                if(using_flags->get_max_button() > 0) {
                        button_desc_t *vm_buttons_d = using_flags->get_vm_buttons();
                        if(vm_buttons_d == NULL) return;
+                       int _x = (int)rint(mouse_x);
+                       int _y = (int)rint(mouse_y);
                        switch(button) {
                        case Qt::LeftButton:
 //                     case Qt::RightButton:
                                for(int i = 0; i < using_flags->get_max_button(); i++) {
-                                       if((mouse_x >= vm_buttons_d[i].x) &&
-                                          (mouse_x < (vm_buttons_d[i].x + vm_buttons_d[i].width))) {
-                                               if((mouse_y >= vm_buttons_d[i].y) &&
-                                                  (mouse_y < (vm_buttons_d[i].y + vm_buttons_d[i].height))) {
+                                       if((_x >= vm_buttons_d[i].x) &&
+                                          (_x < (vm_buttons_d[i].x + vm_buttons_d[i].width))) {
+                                               if((_y >= vm_buttons_d[i].y) &&
+                                                  (_y < (vm_buttons_d[i].y + vm_buttons_d[i].height))) {
                                                        if(vm_buttons_d[i].code != 0x00) {
                                                                key_queue_t sp;
                                                                sp.code = vm_buttons_d[i].code;
@@ -170,15 +174,16 @@ void EmuThreadClassBase::button_released_mouse(Qt::MouseButton button)
                if(using_flags->get_max_button() > 0) {
                        button_desc_t *vm_buttons_d = using_flags->get_vm_buttons();
                        if(vm_buttons_d == NULL) return;
-                       
+                       int _x = (int)rint(mouse_x);
+                       int _y = (int)rint(mouse_y);
                        switch(button) {
                        case Qt::LeftButton:
 //                     case Qt::RightButton:
                                for(int i = 0; i < using_flags->get_max_button(); i++) {
-                                       if((mouse_x >= vm_buttons_d[i].x) &&
-                                          (mouse_x < (vm_buttons_d[i].x + vm_buttons_d[i].width))) {
-                                               if((mouse_y >= vm_buttons_d[i].y) &&
-                                                  (mouse_y < (vm_buttons_d[i].y + vm_buttons_d[i].height))) {
+                                       if((_x >= vm_buttons_d[i].x) &&
+                                          (_x < (vm_buttons_d[i].x + vm_buttons_d[i].width))) {
+                                               if((_y >= vm_buttons_d[i].y) &&
+                                                  (_y < (vm_buttons_d[i].y + vm_buttons_d[i].height))) {
                                                        if(vm_buttons_d[i].code != 0x00) {
                                                                key_queue_t sp;
                                                                sp.code = vm_buttons_d[i].code;
index a7e7090..8a9c24b 100644 (file)
@@ -15,6 +15,8 @@
 #include <QString>
 #include <QStringList>
 #include <QElapsedTimer>
+#include <QRecursiveMutex>
+#include <QMutexLocker>
 
 #include "fifo.h"
 #include "common.h"
@@ -79,7 +81,8 @@ protected:
        config_t *p_config;
        
        QWaitCondition *drawCond;
-       QMutex *keyMutex;
+       QRecursiveMutex keyMutex;
+       QRecursiveMutex mouseMutex;
        
        //class META_MainWindow *MainWindow;
        Ui_MainWindowBase *MainWindow;
@@ -98,7 +101,7 @@ protected:
        QString sStateFile;
        QString lStateFile;
 
-       QMutex uiMutex;
+       QRecursiveMutex uiMutex;
        char dbg_prev_command[MAX_COMMAND_LEN];
        int fd_open_wait_count[8];
        QString fd_reserved_path[8];
@@ -158,23 +161,21 @@ protected:
        virtual void saveState() { }
 
        void enqueue_key_up(key_queue_t s) {
-               keyMutex->lock();
+               QMutexLocker n(&keyMutex);
                key_fifo->write(KEY_QUEUE_UP);
                key_fifo->write(s.code);
                key_fifo->write(s.mod);
                key_fifo->write(s.repeat? 1 : 0);
-               keyMutex->unlock();
        };
        void enqueue_key_down(key_queue_t s) {
-               keyMutex->lock();
+               QMutexLocker n(&keyMutex);
                key_fifo->write(KEY_QUEUE_DOWN);
                key_fifo->write(s.code);
                key_fifo->write(s.mod);
                key_fifo->write(s.repeat? 1 : 0);
-               keyMutex->unlock();
        };
        void dequeue_key(key_queue_t *s) {
-               keyMutex->lock();
+               QMutexLocker n(&keyMutex);
                uint32_t _type = (uint32_t)key_fifo->read();
                if(_type ==     KEY_QUEUE_DOWN) {
                        s->type = _type;
@@ -197,18 +198,15 @@ protected:
                        s->mod = 0;
                        s->repeat = false;
                }
-               keyMutex->unlock();
        };
        bool is_empty_key() {
-               keyMutex->lock();
+               QMutexLocker n(&keyMutex);
                bool f = key_fifo->empty();
-               keyMutex->unlock();
                return f;
        };
        void clear_key_queue() {
-               keyMutex->lock();
+               QMutexLocker n(&keyMutex);
                key_fifo->clear();
-               keyMutex->unlock();
        };
 
 public:
index 359cebb..ac09fda 100644 (file)
@@ -61,16 +61,16 @@ void GLDrawClass::mouseMoveEvent(QMouseEvent *event)
                }
        }
        QPointF pos;
-       if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
+//     if(using_flags->is_use_one_board_computer() || (using_flags->get_max_button() > 0)) {
                pos = event->localPos();
-       } else {
-               pos = event->screenPos();
-       }
+//     } else {
+//             pos = event->screenPos();
+//     }
        double xpos = (double)(pos.x()) / (double)width();
        double ypos = (double)(pos.y()) / (double)height();
        double gxpos = (double)(event->globalPos().x()) / (double)width();
        double gypos = (double)(event->globalPos().y()) / (double)height();
-       //printf("@@ %d %d\n", pos.x(), pos.y());
+
        if(using_flags->is_use_one_board_computer() || using_flags->is_use_mouse() || (using_flags->get_max_button() > 0)) {
                if(!enable_mouse) return;
                //if(QApplication::overrideCursor() == NULL) {
@@ -115,7 +115,7 @@ void GLDrawClass::mouseMoveEvent(QMouseEvent *event)
                gyy = gypos * (double)d_hh;
        }
 
-       //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_GENERAL, "Mouse Move: (%f,%f) -> (%d, %d)\n", xpos, ypos, (int)xx, (int)yy);
+       //csp_logger->debug_log(CSP_LOG_DEBUG, CSP_LOG_TYPE_GENERAL, "Mouse Move: (%f,%f) : (%f,%f) -> (%g, %g)(%g, %g)", pos.x(), pos.y(), xpos, ypos, xx, yy, gxx, gyy);
        emit sig_notify_move_mouse(xx, yy, gxx, gyy);
 
 }
index 03353d8..f68996c 100644 (file)
@@ -217,11 +217,11 @@ protected:
        
        int32_t mouse_status[3];        // x, y, button (b0 = left, b1 = right)
        bool mouse_enabled;
-       int mouse_ptrx;
-       int mouse_ptry;
-       int mouse_button;
-       int mouse_oldx;
-       int mouse_oldy;
+       double mouse_ptrx;
+       double mouse_ptry;
+    int32_t mouse_button;
+       double mouse_oldx;
+       double mouse_oldy;
        //Qt::CursorShape mouse_shape;
        
        QImage background_image;
@@ -458,7 +458,7 @@ public:
        void toggle_mouse();
        bool is_mouse_enabled();
        //QImage *getPseudoVramClass(void) { return pPseudoVram;}
-       void set_mouse_pointer(int x, int y);
+       void set_mouse_pointer(double x, double y);
        void set_mouse_button(int button);
        void modify_key_buffer(int code, uint8_t val);
        uint8_t* get_key_buffer();
index 3c98d77..3656d58 100644 (file)
@@ -65,8 +65,8 @@ void OSD_BASE::initialize_input()
                mouse_enabled = false;
        }
 
-       mouse_ptrx = mouse_oldx = get_screen_width() / 2;
-       mouse_ptry = mouse_oldy = get_screen_height() / 2;
+       mouse_ptrx = mouse_oldx = (double)(get_screen_width() / 2);
+       mouse_ptry = mouse_oldy = (double)(get_screen_height() / 2);
        // initialize keycode convert table
        FILEIO* fio = new FILEIO();
        if(fio->Fopen(bios_path(_T("keycode.cfg")), FILEIO_READ_BINARY)) {
@@ -114,14 +114,18 @@ void OSD_BASE::update_input_mouse()
        memset(mouse_status, 0, sizeof(mouse_status));
        //bool hid = false;
        if(mouse_enabled) {
-               int xx = mouse_ptrx;
-               int yy = mouse_ptry;
-               mouse_status[0] = xx - mouse_oldx;
-               mouse_status[1] = yy - mouse_oldy; 
+               double diffx = mouse_ptrx - mouse_oldx;
+               double diffy = mouse_ptry - mouse_oldy;
+               double factor = (double)(p_config->mouse_sensitivity & ((1 << 16) - 1));
+               diffx = (diffx * factor) / 8192.0;
+               diffy = (diffy * factor) / 8192.0;
+               
+               mouse_status[0] = (int32_t)rint(diffx);
+               mouse_status[1] = (int32_t)rint(diffy); 
                mouse_status[2] = mouse_button;
                //printf("Mouse delta(%d, %d)\n", delta_x, delta_y);
-               mouse_oldx = xx;
-               mouse_oldy = yy;
+               mouse_oldx = mouse_ptrx;
+               mouse_oldy = mouse_ptry;
        }
 
 }
@@ -798,6 +802,7 @@ void OSD_BASE::release_joy_buffer(uint32_t* ptr)
 
 int32_t* OSD_BASE::get_mouse_buffer()
 {
+       QMutexLocker n(mouse_mutex);
        update_input_mouse();
        return mouse_status;
 }
@@ -826,8 +831,8 @@ void OSD_BASE::enable_mouse()
        // enable mouse emulation
        if(!mouse_enabled) {
                QMutexLocker n(mouse_mutex);
-               int xx = get_screen_width() / 2;
-               int yy = get_screen_height() / 2;
+               double xx = (double)(get_screen_width() / 2);
+               double yy = (double)(get_screen_height() / 2);
                
                mouse_oldx = xx;
                mouse_oldy = yy;
@@ -865,17 +870,13 @@ bool OSD_BASE::is_mouse_enabled()
        return mouse_enabled;
 }
 
-void OSD_BASE::set_mouse_pointer(int x, int y)
+void OSD_BASE::set_mouse_pointer(double x, double y)
 {
        if((mouse_enabled)) {
                QMutexLocker n(mouse_mutex);
                
                mouse_ptrx = x;
                mouse_ptry = y;
-               
-//             mouse_oldx = mouse_ptrx;
-//             mouse_oldy = mouse_ptry;
-//             printf("Mouse Moved: (%d, %d)\n", mouse_ptrx, mouse_ptry);
        }
 }
 
index c29d269..bd51ee2 100644 (file)
@@ -1,6 +1,6 @@
 message("* vm/common_vm")
 
-SET(THIS_LIB_VERSION 3.9.0)
+SET(THIS_LIB_VERSION 3.9.1)
 
 #include(cotire)
 set(s_vm_common_vm_srcs