2021-12-04 21:33:04 +01:00
|
|
|
#include "qt_rendererstack.hpp"
|
|
|
|
|
#include "ui_qt_rendererstack.h"
|
|
|
|
|
|
|
|
|
|
#include "qt_softwarerenderer.hpp"
|
|
|
|
|
#include "qt_hardwarerenderer.hpp"
|
|
|
|
|
|
2021-11-30 16:26:49 +06:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
#include <CoreGraphics/CoreGraphics.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#include <86box/mouse.h>
|
|
|
|
|
#include <86box/plat.h>
|
|
|
|
|
#include <86box/video.h>
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
RendererStack::RendererStack(QWidget *parent) :
|
|
|
|
|
QStackedWidget(parent),
|
|
|
|
|
ui(new Ui::RendererStack)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
imagebufs = QVector<QImage>(2);
|
|
|
|
|
imagebufs[0] = QImage{QSize(2048 + 64, 2048 + 64), QImage::Format_RGB32};
|
|
|
|
|
imagebufs[1] = QImage{QSize(2048 + 64, 2048 + 64), QImage::Format_RGB32};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RendererStack::~RendererStack()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 11:15:42 +06:00
|
|
|
extern "C" void macos_poll_mouse();
|
2021-11-30 16:26:49 +06:00
|
|
|
void
|
|
|
|
|
qt_mouse_capture(int on)
|
|
|
|
|
{
|
|
|
|
|
if (!on)
|
|
|
|
|
{
|
|
|
|
|
mouse_capture = 0;
|
|
|
|
|
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
CGAssociateMouseAndMouseCursorPosition(true);
|
|
|
|
|
#endif
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mouse_capture = 1;
|
|
|
|
|
QApplication::setOverrideCursor(Qt::BlankCursor);
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
CGAssociateMouseAndMouseCursorPosition(false);
|
|
|
|
|
#endif
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
void RendererStack::mousePoll()
|
2021-11-30 16:26:49 +06:00
|
|
|
{
|
2021-12-01 11:15:42 +06:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
return macos_poll_mouse();
|
|
|
|
|
#else
|
2021-11-30 16:26:49 +06:00
|
|
|
mouse_x = mousedata.deltax;
|
|
|
|
|
mouse_y = mousedata.deltay;
|
|
|
|
|
mouse_z = mousedata.deltaz;
|
|
|
|
|
mousedata.deltax = mousedata.deltay = mousedata.deltaz = 0;
|
|
|
|
|
mouse_buttons = mousedata.mousebuttons;
|
2021-12-02 16:26:33 +06:00
|
|
|
#ifdef WAYLAND
|
2021-12-05 12:02:57 +06:00
|
|
|
if (QApplication::platformName().contains("wayland"))
|
2021-12-02 16:26:33 +06:00
|
|
|
wl_mouse_poll();
|
|
|
|
|
#endif
|
2021-12-01 11:15:42 +06:00
|
|
|
#endif
|
2021-11-30 16:26:49 +06:00
|
|
|
}
|
|
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
void RendererStack::mouseReleaseEvent(QMouseEvent *event)
|
2021-11-30 16:26:49 +06:00
|
|
|
{
|
|
|
|
|
if (this->geometry().contains(event->pos()) && event->button() == Qt::LeftButton && !mouse_capture)
|
|
|
|
|
{
|
2021-12-01 01:11:06 +06:00
|
|
|
plat_mouse_capture(1);
|
2021-12-02 16:26:33 +06:00
|
|
|
this->setCursor(Qt::BlankCursor);
|
2021-11-30 16:26:49 +06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mouse_capture && event->button() == Qt::MiddleButton && mouse_get_buttons() < 3)
|
|
|
|
|
{
|
2021-12-01 01:11:06 +06:00
|
|
|
plat_mouse_capture(0);
|
2021-12-02 16:26:33 +06:00
|
|
|
this->setCursor(Qt::ArrowCursor);
|
2021-11-30 16:26:49 +06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (mouse_capture)
|
|
|
|
|
{
|
|
|
|
|
mousedata.mousebuttons &= ~event->button();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-04 21:33:04 +01:00
|
|
|
void RendererStack::mousePressEvent(QMouseEvent *event)
|
2021-11-30 16:26:49 +06:00
|
|
|
{
|
|
|
|
|
if (mouse_capture)
|
|
|
|
|
{
|
|
|
|
|
mousedata.mousebuttons |= event->button();
|
|
|
|
|
}
|
2021-12-02 16:26:33 +06:00
|
|
|
event->accept();
|
2021-11-30 16:26:49 +06:00
|
|
|
}
|
2021-12-04 21:33:04 +01:00
|
|
|
void RendererStack::wheelEvent(QWheelEvent *event)
|
2021-11-30 16:26:49 +06:00
|
|
|
{
|
|
|
|
|
if (mouse_capture)
|
|
|
|
|
{
|
2021-12-06 16:33:25 +06:00
|
|
|
mousedata.deltaz += event->pixelDelta().y();
|
2021-11-30 16:26:49 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ignoreNextMouseEvent = 0;
|
2021-12-04 21:33:04 +01:00
|
|
|
void RendererStack::mouseMoveEvent(QMouseEvent *event)
|
2021-11-30 16:26:49 +06:00
|
|
|
{
|
2021-12-02 16:26:33 +06:00
|
|
|
if (QApplication::platformName().contains("wayland"))
|
|
|
|
|
{
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-30 16:26:49 +06:00
|
|
|
if (!mouse_capture) { event->ignore(); return; }
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
#else
|
|
|
|
|
static QPoint oldPos = QCursor::pos();
|
|
|
|
|
if (ignoreNextMouseEvent) { oldPos = event->pos(); ignoreNextMouseEvent--; event->accept(); return; }
|
|
|
|
|
mousedata.deltax += event->pos().x() - oldPos.x();
|
|
|
|
|
mousedata.deltay += event->pos().y() - oldPos.y();
|
|
|
|
|
QCursor::setPos(mapToGlobal(QPoint(width() / 2, height() / 2)));
|
|
|
|
|
oldPos = event->pos();
|
|
|
|
|
ignoreNextMouseEvent = 1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
// called from blitter thread
|
|
|
|
|
void RendererStack::blit(int x, int y, int w, int h)
|
2021-11-30 16:26:49 +06:00
|
|
|
{
|
2021-12-04 21:33:04 +01:00
|
|
|
if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL))
|
2021-11-30 16:26:49 +06:00
|
|
|
{
|
|
|
|
|
video_blit_complete();
|
2021-12-04 21:33:04 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sx = x;
|
|
|
|
|
sy = y;
|
|
|
|
|
sw = this->w = w;
|
|
|
|
|
sh = this->h = h;
|
|
|
|
|
auto imagebits = imagebufs[currentBuf].bits();
|
|
|
|
|
video_copy(imagebits + y * ((2048 + 64) * 4) + x * 4, &(buffer32->line[y][x]), h * (2048 + 64) * sizeof(uint32_t));
|
|
|
|
|
|
|
|
|
|
if (screenshots)
|
|
|
|
|
{
|
|
|
|
|
video_screenshot((uint32_t *)imagebits, 0, 0, 2048 + 64);
|
|
|
|
|
}
|
|
|
|
|
video_blit_complete();
|
|
|
|
|
blitToRenderer(imagebufs[currentBuf], sx, sy, sw, sh);
|
|
|
|
|
currentBuf = (currentBuf + 1) % 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RendererStack::on_RendererStack_currentChanged(int arg1) {
|
|
|
|
|
disconnect(this, &RendererStack::blitToRenderer, nullptr, nullptr);
|
|
|
|
|
switch (arg1) {
|
|
|
|
|
case 0:
|
|
|
|
|
connect(this, &RendererStack::blitToRenderer, dynamic_cast<SoftwareRenderer*>(currentWidget()), &SoftwareRenderer::onBlit);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
connect(this, &RendererStack::blitToRenderer, dynamic_cast<HardwareRenderer*>(currentWidget()), &HardwareRenderer::onBlit);
|
|
|
|
|
break;
|
2021-11-30 16:26:49 +06:00
|
|
|
}
|
2021-11-30 20:52:14 +01:00
|
|
|
}
|