removed sdl from gleswidget, use slots to update mouse movement
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#include <SDL.h>
|
||||
#include <QApplication>
|
||||
#include "qt_gleswidget.hpp"
|
||||
#ifdef __APPLE__
|
||||
@@ -12,14 +11,6 @@ extern "C"
|
||||
#include <86box/video.h>
|
||||
}
|
||||
|
||||
typedef struct mouseinputdata
|
||||
{
|
||||
int deltax, deltay, deltaz;
|
||||
int mousebuttons;
|
||||
} mouseinputdata;
|
||||
|
||||
mouseinputdata mousedata;
|
||||
SDL_mutex* mousemutex;
|
||||
|
||||
void
|
||||
qt_mouse_capture(int on)
|
||||
@@ -41,15 +32,13 @@ qt_mouse_capture(int on)
|
||||
return;
|
||||
}
|
||||
|
||||
void qt_mouse_poll()
|
||||
void GLESWidget::qt_mouse_poll()
|
||||
{
|
||||
SDL_LockMutex(mousemutex);
|
||||
mouse_x = mousedata.deltax;
|
||||
mouse_y = mousedata.deltay;
|
||||
mouse_z = mousedata.deltaz;
|
||||
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
|
||||
mouse_buttons = mousedata.mousebuttons;
|
||||
SDL_UnlockMutex(mousemutex);
|
||||
}
|
||||
|
||||
void GLESWidget::resizeGL(int w, int h)
|
||||
@@ -83,27 +72,21 @@ void GLESWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
}
|
||||
if (mouse_capture)
|
||||
{
|
||||
SDL_LockMutex(mousemutex);
|
||||
mousedata.mousebuttons &= ~event->button();
|
||||
SDL_UnlockMutex(mousemutex);
|
||||
}
|
||||
}
|
||||
void GLESWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (mouse_capture)
|
||||
{
|
||||
SDL_LockMutex(mousemutex);
|
||||
mousedata.mousebuttons |= event->button();
|
||||
SDL_UnlockMutex(mousemutex);
|
||||
}
|
||||
}
|
||||
void GLESWidget::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (mouse_capture)
|
||||
{
|
||||
SDL_LockMutex(mousemutex);
|
||||
mousedata.deltay += event->pixelDelta().y();
|
||||
SDL_UnlockMutex(mousemutex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,10 +100,8 @@ void GLESWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
#else
|
||||
static QPoint oldPos = QCursor::pos();
|
||||
if (ignoreNextMouseEvent) { oldPos = event->pos(); ignoreNextMouseEvent--; event->accept(); return; }
|
||||
SDL_LockMutex(mousemutex);
|
||||
mousedata.deltax += event->pos().x() - oldPos.x();
|
||||
mousedata.deltay += event->pos().y() - oldPos.y();
|
||||
SDL_UnlockMutex(mousemutex);
|
||||
QCursor::setPos(mapToGlobal(QPoint(width() / 2, height() / 2)));
|
||||
oldPos = event->pos();
|
||||
ignoreNextMouseEvent = 1;
|
||||
|
@@ -38,4 +38,13 @@ public:
|
||||
}
|
||||
public slots:
|
||||
void qt_real_blit(int x, int y, int w, int h);
|
||||
};
|
||||
void qt_mouse_poll();
|
||||
|
||||
private:
|
||||
struct mouseinputdata {
|
||||
int deltax, deltay, deltaz;
|
||||
int mousebuttons;
|
||||
};
|
||||
mouseinputdata mousedata;
|
||||
|
||||
};
|
||||
|
@@ -76,7 +76,6 @@ main_thread_fn()
|
||||
is_quit = 1;
|
||||
}
|
||||
|
||||
extern SDL_mutex* mousemutex;
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
#ifdef __APPLE__
|
||||
@@ -85,7 +84,6 @@ int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
elapsed_timer.start();
|
||||
SDL_Init(SDL_INIT_TIMER);
|
||||
mousemutex = SDL_CreateMutex();
|
||||
|
||||
main_window = new MainWindow();
|
||||
main_window->show();
|
||||
|
@@ -51,9 +51,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
connect(this, &MainWindow::showMessageForNonQtThread, this, &MainWindow::showMessage_, Qt::BlockingQueuedConnection);
|
||||
|
||||
connect(this, &MainWindow::pollMouse, this, [] {
|
||||
qt_mouse_poll();
|
||||
});
|
||||
connect(this, &MainWindow::pollMouse, hw_widget, &GLESWidget::qt_mouse_poll);
|
||||
|
||||
connect(this, &MainWindow::setMouseCapture, this, [this](bool state) {
|
||||
mouse_capture = state ? 1 : 0;
|
||||
@@ -83,17 +81,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
ui->actionKeyboard_requires_capture->setChecked(kbd_req_capture);
|
||||
ui->actionRight_CTRL_is_left_ALT->setChecked(rctrl_is_lalt);
|
||||
#if 0
|
||||
sdl_inits();
|
||||
sdl_timer = new QTimer(this);
|
||||
connect(sdl_timer, &QTimer::timeout, this, [] {
|
||||
auto status = sdl_main();
|
||||
if (status == SdlMainQuit) {
|
||||
QApplication::quit();
|
||||
}
|
||||
});
|
||||
sdl_timer->start(5);
|
||||
#endif
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
|
@@ -9,6 +9,8 @@ namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class GLESWidget;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -56,7 +58,7 @@ private:
|
||||
DeltaPos mouseDelta;
|
||||
QWindow* sdl_wrapped_window;
|
||||
QWidget* sdl_wrapped_widget;
|
||||
QWidget* hw_widget;
|
||||
GLESWidget* hw_widget;
|
||||
QTimer* sdl_timer;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user