OSDN Git Service

[Qt][Win32] Fix compilation errors with msys2, still not working.
[csp-qt/common_source_project-fm7.git] / source / src / qt / common / emu_input.cpp
index 8758b32..f097cef 100644 (file)
@@ -115,7 +115,7 @@ void EMU::update_input()
                        vm->key_up(VK_SHIFT);
 # endif
                        // check l/r shift
-# if defined(Q_OS_WIN32)                       // 
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)                 // 
                        if(!(GetAsyncKeyState(VK_LSHIFT) & 0x8000)) key_status[VK_LSHIFT] &= 0x7f;
                        if(!(GetAsyncKeyState(VK_RSHIFT) & 0x8000)) key_status[VK_RSHIFT] &= 0x7f;
 # else            
@@ -130,7 +130,7 @@ void EMU::update_input()
                        vm->key_up(VK_LSHIFT);
 # endif
                        // check l/r shift
-# if defined(Q_OS_WIN32)                       // 
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)                 // 
                        if(!(GetAsyncKeyState(VK_LSHIFT) & 0x8000)) key_status[VK_LSHIFT] &= 0x7f;
 # else            
                        if(!(GetAsyncKeyState(VK_LSHIFT, modkey_status) & 0x8000)) key_status[VK_LSHIFT] &= 0x7f;
@@ -143,7 +143,7 @@ void EMU::update_input()
                        vm->key_up(VK_RSHIFT);
 # endif
                        // check l/r shift
-# if defined(Q_OS_WIN32)                       // 
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)                 // 
                        if(!(GetAsyncKeyState(VK_RSHIFT) & 0x8000)) key_status[VK_RSHIFT] &= 0x7f;
 # else            
                        if(!(GetAsyncKeyState(VK_RSHIFT, modkey_status) & 0x8000)) key_status[VK_RSHIFT] &= 0x7f;
@@ -354,7 +354,7 @@ void EMU::key_down(int sym, bool repeat)
        uint8 code = sym;
        if(code == VK_SHIFT){
 #ifndef USE_SHIFT_NUMPAD_KEY
-# if defined(Q_OS_WIN32)                       // 
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)                 // 
                if(GetAsyncKeyState(VK_SHIFT) & 0x8000) {
 # else            
                if(GetAsyncKeyState(VK_SHIFT, modkey_status) & 0x8000) {
@@ -366,7 +366,7 @@ void EMU::key_down(int sym, bool repeat)
 #endif
        } else if(code == VK_LSHIFT){
 #ifndef USE_SHIFT_NUMPAD_KEY
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(GetAsyncKeyState(VK_LSHIFT) & 0x8000) key_status[VK_LSHIFT] = 0x80;
 # else
                if(GetAsyncKeyState(VK_LSHIFT, modkey_status) & 0x8000) key_status[VK_LSHIFT] = 0x80;
@@ -374,14 +374,14 @@ void EMU::key_down(int sym, bool repeat)
 #endif
        } else if(code == VK_RSHIFT){
 #ifndef USE_SHIFT_NUMPAD_KEY
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(GetAsyncKeyState(VK_RSHIFT) & 0x8000) key_status[VK_RSHIFT] = 0x80;
 # else
                if(GetAsyncKeyState(VK_RSHIFT, modkey_status) & 0x8000) key_status[VK_RSHIFT] = 0x80;
 # endif           
 #endif
        } else if(code == VK_CONTROL) {
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(GetAsyncKeyState(VK_CONTROL) & 0x8000) {
 # else
                if(GetAsyncKeyState(VK_CONTROL, modkey_status) & 0x8000) {
@@ -391,19 +391,19 @@ void EMU::key_down(int sym, bool repeat)
                        key_status[VK_CONTROL] = 0x80;
                }
        } else if(code == VK_LCONTROL) {
-# if defined(Q_OS_WIN32
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN
                if(GetAsyncKeyState(VK_LCONTROL) & 0x8000) key_status[VK_LCONTROL] = 0x80;
 # else
                if(GetAsyncKeyState(VK_LCONTROL, modkey_status) & 0x8000) key_status[VK_LCONTROL] = 0x80;
 # endif           
        } else if(code == VK_RCONTROL) {
-# if defined(Q_OS_WIN32
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN
                if(GetAsyncKeyState(VK_RCONTROL) & 0x8000) key_status[VK_RCONTROL] = 0x80;
 # else
                if(GetAsyncKeyState(VK_RCONTROL, modkey_status) & 0x8000) key_status[VK_RCONTROL] = 0x80;
 # endif           
        } else if(code == VK_MENU) {
-# if defined(Q_OS_WIN32
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN
                if(GetAsyncKeyState(VK_MENU) & 0x8000) {
 # else
                if(GetAsyncKeyState(VK_MENU, modkey_status) & 0x8000) {
@@ -413,13 +413,13 @@ void EMU::key_down(int sym, bool repeat)
                        key_status[VK_MENU] = 0x80;
                }
        } else if(code == VK_LMENU) {
-# if defined(Q_OS_WIN32)          
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)    
                if(GetAsyncKeyState(VK_LMENU) & 0x8000) key_status[VK_LMENU] = 0x80;
 # else    
                if(GetAsyncKeyState(VK_LMENU, modkey_status) & 0x8000) key_status[VK_LMENU] = 0x80;
 # endif           
        } else if(code == VK_RMENU) {
-# if defined(Q_OS_WIN32)          
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)    
                if(GetAsyncKeyState(VK_RMENU) & 0x8000) key_status[VK_RMENU] = 0x80;
 # else    
                if(GetAsyncKeyState(VK_RMENU, modkey_status) & 0x8000) key_status[VK_RMENU] = 0x80;
@@ -476,7 +476,7 @@ void EMU::key_up(int sym)
        uint8 code = sym;
        if(code == VK_SHIFT) {
 #ifndef USE_SHIFT_NUMPAD_KEY
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_SHIFT) & 0x8000)) {
 # else            
                if(!(GetAsyncKeyState(VK_SHIFT, modkey_status) & 0x8000)) {
@@ -488,7 +488,7 @@ void EMU::key_up(int sym)
 #endif
        } else if(code == VK_LSHIFT) {
 #ifndef USE_SHIFT_NUMPAD_KEY
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_LSHIFT) & 0x8000)) key_status[VK_LSHIFT] &= 0x7f;
 # else            
                if(!(GetAsyncKeyState(VK_LSHIFT, modkey_status) & 0x8000)) key_status[VK_LSHIFT] &= 0x7f;
@@ -496,14 +496,14 @@ void EMU::key_up(int sym)
 #endif
        } else if(code == VK_RSHIFT) {
 #ifndef USE_SHIFT_NUMPAD_KEY
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_RSHIFT) & 0x8000)) key_status[VK_RSHIFT] &= 0x7f;
 # else            
                if(!(GetAsyncKeyState(VK_RSHIFT, modkey_status) & 0x8000)) key_status[VK_RSHIFT] &= 0x7f;
 # endif           
 #endif
        } else if(code == VK_CONTROL) {
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_CONTROL) & 0x8000)) {
 # else            
                if(!(GetAsyncKeyState(VK_CONTROL, modkey_status) & 0x8000)) {
@@ -513,19 +513,19 @@ void EMU::key_up(int sym)
                        key_status[VK_CONTROL] &= 0x7f;
                }
        } else if(code == VK_LCONTROL) {
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_LCONTROL) & 0x8000)) key_status[VK_LCONTROL] &= 0x7f;
 # else            
                if(!(GetAsyncKeyState(VK_LCONTROL, modkey_status) & 0x8000)) key_status[VK_LCONTROL] &= 0x7f;
 # endif                   
        } else if(code == VK_RCONTROL) {
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_RCONTROL) & 0x8000)) key_status[VK_RCONTROL] &= 0x7f;
 # else            
                if(!(GetAsyncKeyState(VK_RCONTROL, modkey_status) & 0x8000)) key_status[VK_RCONTROL] &= 0x7f;
 # endif           
        } else if(code == VK_MENU) {
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_MENU) & 0x8000)) {
 # else            
                if(!(GetAsyncKeyState(VK_MENU, modkey_status) & 0x8000)) {
@@ -535,13 +535,13 @@ void EMU::key_up(int sym)
                        key_status[VK_MENU] &= 0x7f;
                }
        } else if(code == VK_LMENU) {
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_LMENU) & 0x8000)) key_status[VK_LMENU] &= 0x7f;
 # else            
                if(!(GetAsyncKeyState(VK_LMENU, modkey_status) & 0x8000)) key_status[VK_LMENU] &= 0x7f;
 # endif           
        } else if(code == VK_RMENU) {
-# if defined(Q_OS_WIN32)
+# if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
                if(!(GetAsyncKeyState(VK_RMENU) & 0x8000)) key_status[VK_RMENU] &= 0x7f;
 # else            
                if(!(GetAsyncKeyState(VK_RMENU, modkey_status) & 0x8000)) key_status[VK_RMENU] &= 0x7f;
@@ -712,12 +712,10 @@ void EMU::start_auto_key()
   
 void EMU::stop_auto_key()
 {
-#if 1
         if(autokey_shift) {
                key_up(VK_SHIFT);
        }
        autokey_phase = autokey_shift = 0;
-#endif
 }
 #endif
 
@@ -728,19 +726,25 @@ JoyThreadClass::JoyThreadClass(QObject *parent) : QThread(parent)
        joy_num = SDL_NumJoysticks();
        for(i = 0; i < 16; i++) {
                joyhandle[i] = NULL;
+#if defined(USE_SDL2)  
                for(j = 0; j < 16; j++) guid_list[i].data[j] = 0;
                for(j = 0; j < 16; j++) guid_assign[i].data[j] = 0;
+#endif    
                names[i] = QString::fromUtf8("");
        }
-   
        if(joy_num > 0) {
                if(joy_num >= 16) joy_num = 16;
                for(i = 0; i < joy_num; i++) {
+                  
                        joyhandle[i] = SDL_JoystickOpen(i);
                        if(joyhandle[i] != NULL) {
+#if defined(USE_SDL2)                     
                                guid_list[i] = SDL_JoystickGetGUID(joyhandle[i]);
                                guid_assign[i] = SDL_JoystickGetGUID(joyhandle[i]);
                                names[i] = QString::fromUtf8(SDL_JoystickNameForIndex(i));
+#else
+                               names[i] = QString::fromUtf8(SDL_JoystickName(i));
+#endif                    
                                AGAR_DebugLog(AGAR_LOG_DEBUG, "JoyThread : Joystick %d : %s.", i, names[i].toUtf8().data());
                        }
                }
@@ -820,7 +824,8 @@ void JoyThreadClass::button_up(int index, unsigned int button)
        }
        p_emu->UnlockVM();
 }
-          
+
+#if defined(USE_SDL2)
 // SDL Event Handler
 bool JoyThreadClass::MatchJoyGUID(SDL_JoystickGUID *a, SDL_JoystickGUID *b)
 { 
@@ -840,7 +845,7 @@ bool JoyThreadClass::CheckJoyGUID(SDL_JoystickGUID *a)
        }
        return b;
 }
-
+#endif
 
 bool  JoyThreadClass::EventSDL(SDL_Event *eventQueue)
 {
@@ -850,7 +855,9 @@ bool  JoyThreadClass::EventSDL(SDL_Event *eventQueue)
        int vk;
        uint32_t sym;
        uint32_t mod;
+#if defined(USE_SDL2)
        SDL_JoystickGUID guid;
+#endif   
        int i;
        if(eventQueue == NULL) return false;
        /*
@@ -860,6 +867,8 @@ bool  JoyThreadClass::EventSDL(SDL_Event *eventQueue)
                case SDL_JOYAXISMOTION:
                        value = eventQueue->jaxis.value;
                        i = eventQueue->jaxis.which;
+          
+#if defined(USE_SDL2)
                        guid = SDL_JoystickGetDeviceGUID(i);
                        if(!CheckJoyGUID(&guid)) break;
                        for(i = 0; i < 2; i++) {
@@ -871,10 +880,18 @@ bool  JoyThreadClass::EventSDL(SDL_Event *eventQueue)
                                        }
                                }
                        }
+#else
+                       if(eventQueue->jaxis.axis == 0) { // X
+                               x_axis_changed(i, value);
+                       } else if(eventQueue->jaxis.axis == 1) { // Y
+                               y_axis_changed(i, value);
+                       }
+#endif
                        break;
                case SDL_JOYBUTTONDOWN:
                        button = eventQueue->jbutton.button;
                        i = eventQueue->jbutton.which;
+#if defined(USE_SDL2)
                        guid = SDL_JoystickGetDeviceGUID(i);
                        if(!CheckJoyGUID(&guid)) break;
                        for(i = 0; i < 2; i++) {
@@ -882,10 +899,14 @@ bool  JoyThreadClass::EventSDL(SDL_Event *eventQueue)
                                        button_down(i, button);
                                }
                        }
+#else     
+                       button_down(i, button);
+#endif    
                        break;
-               case SDL_JOYBUTTONUP:
+               case SDL_JOYBUTTONUP:      
                        button = eventQueue->jbutton.button;
                        i = eventQueue->jbutton.which;
+#if defined(USE_SDL2)
                        guid = SDL_JoystickGetDeviceGUID(i);
                        if(!CheckJoyGUID(&guid)) break;
                        for(i = 0; i < 2; i++) {
@@ -893,6 +914,9 @@ bool  JoyThreadClass::EventSDL(SDL_Event *eventQueue)
                                        button_up(i, button);
                                }
                        }
+#else     
+                       button_up(i, button);
+#endif    
                        break;
                default:
                        break;
@@ -907,7 +931,7 @@ void JoyThreadClass::doWork(const QString &params)
                if(bRunThread == false) {
                        break;
                }
-               while(SDL_PollEvent(&event) == 1) {
+               while(SDL_PollEvent(&event)) {
                        EventSDL(&event);
                }
                msleep(10);