Tweaks to support QT on Windows

This commit is contained in:
ts-korhonen
2021-12-02 19:35:08 +02:00
parent bddc0c0698
commit b0a4f70fa9
4 changed files with 70 additions and 5 deletions

View File

@@ -11,6 +11,7 @@
#include <thread> #include <thread>
#define SDL_MAIN_HANDLED
#include "SDL.h" #include "SDL.h"
#include "SDL_mutex.h" #include "SDL_mutex.h"
#include "SDL_timer.h" #include "SDL_timer.h"

View File

@@ -622,7 +622,9 @@ static std::array<uint32_t, 256>& selected_keycode = x11_to_xt_base;
uint16_t x11_keycode_to_keysym(uint32_t keycode) uint16_t x11_keycode_to_keysym(uint32_t keycode)
{ {
#ifdef __APPLE__ #if defined(Q_OS_WINDOWS)
return keycode & 0xFFFF;
#elif defined(__APPLE__)
return darwin_to_xt[keycode]; return darwin_to_xt[keycode];
#else #else
static Display* x11display = nullptr; static Display* x11display = nullptr;

View File

@@ -44,6 +44,9 @@ private:
}; };
extern "C" { extern "C" {
#ifdef Q_OS_WINDOWS
#include <windows.h>
#endif
#include <86box/86box.h> #include <86box/86box.h>
#include <86box/device.h> #include <86box/device.h>
#include <86box/gameport.h> #include <86box/gameport.h>
@@ -87,7 +90,11 @@ do_stop(void)
void plat_get_exe_name(char *s, int size) void plat_get_exe_name(char *s, int size)
{ {
CharPointer(s, size) = QCoreApplication::applicationFilePath().toUtf8(); QByteArray exepath_temp = QCoreApplication::applicationDirPath().toLocal8Bit();
memcpy(s, exepath_temp.data(), std::min(exepath_temp.size(),size));
plat_path_slash(s);
} }
uint32_t uint32_t
@@ -140,6 +147,8 @@ plat_fopen(const char *path, const char *mode)
return nullptr; return nullptr;
} }
*/ */
/* Not sure if any this is necessary, fopen seems to work on Windows -Manaatti
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
wchar_t *pathw, *modew; wchar_t *pathw, *modew;
int len; int len;
@@ -165,8 +174,9 @@ plat_fopen(const char *path, const char *mode)
} }
#endif #endif
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
*/
return fopen(path, mode); return fopen(path, mode);
#endif //#endif
} }
FILE * FILE *
@@ -216,11 +226,23 @@ plat_get_extension(char *s)
char * char *
plat_get_filename(char *s) plat_get_filename(char *s)
{ {
#ifdef Q_OS_WINDOWS
int c = strlen(s) - 1;
while (c > 0) {
if (s[c] == '/' || s[c] == '\\')
return(&s[c+1]);
c--;
}
return(s);
#else
auto idx = QByteArray::fromRawData(s, strlen(s)).lastIndexOf(QDir::separator().toLatin1()); auto idx = QByteArray::fromRawData(s, strlen(s)).lastIndexOf(QDir::separator().toLatin1());
if (idx >= 0) { if (idx >= 0) {
return s+idx+1; return s+idx+1;
} }
return s; return s;
#endif
} }
int int
@@ -292,7 +314,11 @@ plat_mmap(size_t size, uint8_t executable)
void void
plat_munmap(void *ptr, size_t size) plat_munmap(void *ptr, size_t size)
{ {
#if defined Q_OS_WINDOWS
VirtualFree(ptr, 0, MEM_RELEASE);
#else
munmap(ptr, size); munmap(ptr, size);
#endif
} }
void void
@@ -391,3 +417,39 @@ void endblit()
} }
} }
#ifdef Q_OS_WINDOWS
size_t mbstoc16s(uint16_t dst[], const char src[], int len)
{
if (src == NULL) return 0;
if (len < 0) return 0;
size_t ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, reinterpret_cast<LPWSTR>(dst), dst == NULL ? 0 : len);
if (!ret) {
return -1;
}
return ret;
}
size_t c16stombs(char dst[], const uint16_t src[], int len)
{
if (src == NULL) return 0;
if (len < 0) return 0;
size_t ret = WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<LPCWCH>(src), -1, dst, dst == NULL ? 0 : len, NULL, NULL);
if (!ret) {
return -1;
}
return ret;
}
#endif
int
plat_chdir(char *path)
{
return QDir::setCurrent(QString(path)) ? 0 : -1;
}

View File

@@ -62,8 +62,8 @@ void plat_mouse_capture(int on) {
} }
int ui_msgbox_header(int flags, void *header, void* message) { int ui_msgbox_header(int flags, void *header, void* message) {
if (header <= (void*)7168) header = plat_get_string(reinterpret_cast<long>(header)); if (header <= (void*)7168) header = plat_get_string((uintptr_t)header);
if (message <= (void*)7168) message = plat_get_string(reinterpret_cast<long>(message)); if (message <= (void*)7168) message = plat_get_string((uintptr_t)message);
auto hdr = QString::fromWCharArray(reinterpret_cast<const wchar_t*>(header)); auto hdr = QString::fromWCharArray(reinterpret_cast<const wchar_t*>(header));
auto msg = QString::fromWCharArray(reinterpret_cast<const wchar_t*>(message)); auto msg = QString::fromWCharArray(reinterpret_cast<const wchar_t*>(message));