2017-07-02 20:55:56 +01:00
|
|
|
#include "video.h"
|
|
|
|
|
2017-07-03 21:00:42 +01:00
|
|
|
#include <QPainter>
|
2017-07-04 12:14:04 +01:00
|
|
|
#include <QKeyEvent>
|
2017-07-02 20:55:56 +01:00
|
|
|
|
|
|
|
#include "StdAfx.h"
|
2020-11-22 09:36:28 +00:00
|
|
|
#include "linux/videobuffer.h"
|
2019-12-07 11:20:37 +00:00
|
|
|
#include "linux/keyboard.h"
|
2020-06-18 13:56:14 +01:00
|
|
|
#include "linux/paddle.h"
|
2019-12-31 18:19:45 +00:00
|
|
|
#include "Common.h"
|
|
|
|
#include "CardManager.h"
|
2017-10-07 20:44:42 +01:00
|
|
|
#include "MouseInterface.h"
|
2020-11-12 18:43:04 +00:00
|
|
|
#include "AppleWin.h"
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
Video::Video(QWidget *parent) : VIDEO_BASECLASS(parent)
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
2019-11-22 20:32:32 +00:00
|
|
|
setMouseTracking(true);
|
2017-07-04 12:14:04 +01:00
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
myLogo = QImage(":/resources/APPLEWINLOGO.BMP").mirrored(false, true);
|
2017-07-02 20:55:56 +01:00
|
|
|
}
|
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
QImage Video::getScreen() const
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
2019-11-22 20:32:32 +00:00
|
|
|
uint8_t * data;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int sx, sy;
|
|
|
|
int sw, sh;
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
getScreenData(data, width, height, sx, sy, sw, sh);
|
2019-11-29 20:31:31 +00:00
|
|
|
QImage frameBuffer(data, width, height, QImage::Format_ARGB32_Premultiplied);
|
2017-07-09 20:49:26 +01:00
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
QImage screen = frameBuffer.copy(sx, sy, sw, sh);
|
2017-07-04 12:14:04 +01:00
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
return screen;
|
2017-07-02 20:55:56 +01:00
|
|
|
}
|
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
void Video::displayLogo()
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
2019-11-22 20:32:32 +00:00
|
|
|
uint8_t * data;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int sx, sy;
|
|
|
|
int sw, sh;
|
2017-07-02 20:55:56 +01:00
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
getScreenData(data, width, height, sx, sy, sw, sh);
|
2019-11-29 20:31:31 +00:00
|
|
|
QImage frameBuffer(data, width, height, QImage::Format_ARGB32_Premultiplied);
|
2017-10-17 21:14:36 +01:00
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
QPainter painter(&frameBuffer);
|
|
|
|
painter.drawImage(sx, sy, myLogo);
|
2017-07-02 20:55:56 +01:00
|
|
|
}
|
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
void Video::paintEvent(QPaintEvent *)
|
2017-07-02 20:55:56 +01:00
|
|
|
{
|
2019-11-22 20:32:32 +00:00
|
|
|
uint8_t * data;
|
2019-11-20 21:23:27 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int sx, sy;
|
|
|
|
int sw, sh;
|
|
|
|
|
|
|
|
getScreenData(data, width, height, sx, sy, sw, sh);
|
2019-11-29 20:31:31 +00:00
|
|
|
QImage frameBuffer(data, width, height, QImage::Format_ARGB32_Premultiplied);
|
2019-11-20 21:23:27 +00:00
|
|
|
|
2017-07-03 21:00:42 +01:00
|
|
|
const QSize actual = size();
|
2019-11-20 21:23:27 +00:00
|
|
|
const double scaleX = double(actual.width()) / sw;
|
|
|
|
const double scaleY = double(actual.height()) / sh;
|
2017-07-03 21:00:42 +01:00
|
|
|
|
2019-11-20 21:23:27 +00:00
|
|
|
// then paint it on the widget with scale
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
// scale and flip vertically
|
|
|
|
const QTransform transform(scaleX, 0.0, 0.0, -scaleY, 0.0, actual.height());
|
|
|
|
painter.setTransform(transform);
|
|
|
|
|
2019-11-22 20:32:32 +00:00
|
|
|
painter.drawImage(0, 0, frameBuffer, sx, sy, sw, sh);
|
2017-07-02 20:55:56 +01:00
|
|
|
}
|
|
|
|
}
|
2017-07-04 12:14:04 +01:00
|
|
|
|
2020-06-18 13:56:14 +01:00
|
|
|
bool Video::event(QEvent *event)
|
|
|
|
{
|
|
|
|
if (isEnabled() && (event->type() == QEvent::KeyPress))
|
|
|
|
{
|
|
|
|
// This code bypasses the special QWidget handling of QKeyEvents
|
|
|
|
// Tab and Backtab (?) to move focus
|
|
|
|
// KeyPad Navigation
|
|
|
|
// F1 for whatsthis
|
|
|
|
QKeyEvent *k = (QKeyEvent *)event;
|
|
|
|
keyPressEvent(k);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return VIDEO_BASECLASS::event(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Video::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (!event->isAutoRepeat())
|
|
|
|
{
|
|
|
|
// Qt::Key_Alt does not seem to work
|
2020-06-18 20:13:29 +01:00
|
|
|
// Qt::Key_AltGr & Qt::Key_Menu work well, but are on the same side
|
|
|
|
const int key = event->key();
|
|
|
|
switch (key)
|
2020-06-18 13:56:14 +01:00
|
|
|
{
|
2020-06-18 20:13:29 +01:00
|
|
|
case Qt::Key_AltGr:
|
2020-06-18 13:56:14 +01:00
|
|
|
Paddle::setButtonReleased(Paddle::ourOpenApple);
|
2020-06-19 18:23:29 +01:00
|
|
|
return;
|
2020-06-18 20:13:29 +01:00
|
|
|
case Qt::Key_Menu:
|
2020-10-11 10:29:37 +01:00
|
|
|
Paddle::setButtonReleased(Paddle::ourSolidApple);
|
2020-06-19 18:23:29 +01:00
|
|
|
return;
|
2020-06-18 13:56:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIDEO_BASECLASS::keyReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
void Video::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
2020-06-19 18:23:29 +01:00
|
|
|
const int key = event->key();
|
|
|
|
|
2020-06-18 13:56:14 +01:00
|
|
|
if (!event->isAutoRepeat())
|
|
|
|
{
|
2020-06-18 20:13:29 +01:00
|
|
|
switch (key)
|
2020-06-18 13:56:14 +01:00
|
|
|
{
|
2020-06-18 20:13:29 +01:00
|
|
|
case Qt::Key_AltGr:
|
2020-06-18 13:56:14 +01:00
|
|
|
Paddle::setButtonPressed(Paddle::ourOpenApple);
|
2020-06-19 18:23:29 +01:00
|
|
|
return;
|
2020-06-18 20:13:29 +01:00
|
|
|
case Qt::Key_Menu:
|
2020-10-11 10:29:37 +01:00
|
|
|
Paddle::setButtonPressed(Paddle::ourSolidApple);
|
2020-06-19 18:23:29 +01:00
|
|
|
return;
|
2020-06-18 13:56:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
BYTE ch = 0;
|
|
|
|
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case Qt::Key_Return:
|
|
|
|
case Qt::Key_Enter:
|
|
|
|
ch = 0x0d;
|
|
|
|
break;
|
2020-06-15 10:53:42 +01:00
|
|
|
case Qt::Key_Backspace: // same as AppleWin
|
2017-07-04 14:37:35 +01:00
|
|
|
case Qt::Key_Left:
|
|
|
|
ch = 0x08;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Right:
|
|
|
|
ch = 0x15;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Up:
|
|
|
|
ch = 0x0b;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
ch = 0x0a;
|
|
|
|
break;
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
ch = 0x7f;
|
|
|
|
break;
|
2017-07-09 16:49:56 +01:00
|
|
|
case Qt::Key_Escape:
|
|
|
|
ch = 0x1b;
|
|
|
|
break;
|
2020-06-18 13:56:24 +01:00
|
|
|
case Qt::Key_Tab:
|
|
|
|
ch = 0x09;
|
|
|
|
break;
|
2020-06-19 18:23:29 +01:00
|
|
|
case 'A' ... 'Z':
|
|
|
|
case ']':
|
|
|
|
case '[':
|
|
|
|
case '\\':
|
|
|
|
{
|
|
|
|
ch = key;
|
|
|
|
const Qt::KeyboardModifiers modifiers = event->modifiers();
|
|
|
|
if (modifiers & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
ch = (ch - 'A') + 1;
|
|
|
|
}
|
|
|
|
else if (modifiers & Qt::ShiftModifier)
|
|
|
|
{
|
|
|
|
ch += 'a' - 'A';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '-':
|
|
|
|
{
|
|
|
|
ch = key;
|
|
|
|
const Qt::KeyboardModifiers modifiers = event->modifiers();
|
|
|
|
if (modifiers & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
ch = 0x1f;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-07-04 12:14:04 +01:00
|
|
|
default:
|
2020-06-19 18:23:29 +01:00
|
|
|
{
|
2017-07-04 12:14:04 +01:00
|
|
|
if (key < 0x80)
|
|
|
|
{
|
|
|
|
ch = key;
|
|
|
|
}
|
|
|
|
}
|
2020-06-19 18:23:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-04 12:14:04 +01:00
|
|
|
|
|
|
|
if (ch)
|
|
|
|
{
|
2019-12-07 11:20:37 +00:00
|
|
|
addKeyToBuffer(ch);
|
2020-06-19 18:23:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VIDEO_BASECLASS::keyPressEvent(event);
|
2017-07-04 14:37:35 +01:00
|
|
|
}
|
2017-10-07 20:44:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Video::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
2020-10-12 20:58:32 +01:00
|
|
|
CardManager & cardManager = GetCardMgr();
|
|
|
|
|
|
|
|
if (cardManager.IsMouseCardInstalled() && cardManager.GetMouseCard()->IsActiveAndEnabled())
|
2017-07-04 14:37:35 +01:00
|
|
|
{
|
2017-10-07 20:44:42 +01:00
|
|
|
int iX, iMinX, iMaxX;
|
|
|
|
int iY, iMinY, iMaxY;
|
2020-10-12 20:58:32 +01:00
|
|
|
cardManager.GetMouseCard()->GetXY(iX, iMinX, iMaxX, iY, iMinY, iMaxY);
|
2017-10-07 20:44:42 +01:00
|
|
|
|
|
|
|
const QPointF p = event->localPos();
|
|
|
|
const QSize s = size();
|
|
|
|
|
|
|
|
const int newX = lround((p.x() / s.width()) * (iMaxX - iMinX) + iMinX);
|
|
|
|
const int newY = lround((p.y() / s.height()) * (iMaxY - iMinY) + iMinY);
|
|
|
|
|
|
|
|
const int dx = newX - iX;
|
|
|
|
const int dy = newY - iY;
|
|
|
|
|
|
|
|
int outOfBoundsX;
|
|
|
|
int outOfBoundsY;
|
2020-10-12 20:58:32 +01:00
|
|
|
cardManager.GetMouseCard()->SetPositionRel(dx, dy, &outOfBoundsX, &outOfBoundsY);
|
2017-10-07 20:44:42 +01:00
|
|
|
|
|
|
|
event->accept();
|
2017-07-04 12:14:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 20:44:42 +01:00
|
|
|
void Video::mousePressEvent(QMouseEvent *event)
|
2017-07-04 12:14:04 +01:00
|
|
|
{
|
2020-10-12 20:58:32 +01:00
|
|
|
CardManager & cardManager = GetCardMgr();
|
|
|
|
|
|
|
|
if (cardManager.IsMouseCardInstalled() && cardManager.GetMouseCard()->IsActiveAndEnabled())
|
2017-10-07 20:44:42 +01:00
|
|
|
{
|
|
|
|
Qt::MouseButton button = event->button();
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2020-10-12 20:58:32 +01:00
|
|
|
cardManager.GetMouseCard()->SetButton(BUTTON0, BUTTON_DOWN);
|
2017-10-07 20:44:42 +01:00
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
2020-10-12 20:58:32 +01:00
|
|
|
cardManager.GetMouseCard()->SetButton(BUTTON1, BUTTON_DOWN);
|
2017-10-07 20:44:42 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Video::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
2020-10-12 20:58:32 +01:00
|
|
|
CardManager & cardManager = GetCardMgr();
|
|
|
|
|
|
|
|
if (cardManager.IsMouseCardInstalled() && cardManager.GetMouseCard()->IsActiveAndEnabled())
|
2017-10-07 20:44:42 +01:00
|
|
|
{
|
|
|
|
Qt::MouseButton button = event->button();
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case Qt::LeftButton:
|
2020-10-12 20:58:32 +01:00
|
|
|
cardManager.GetMouseCard()->SetButton(BUTTON0, BUTTON_UP);
|
2017-10-07 20:44:42 +01:00
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
2020-10-12 20:58:32 +01:00
|
|
|
cardManager.GetMouseCard()->SetButton(BUTTON1, BUTTON_UP);
|
2017-10-07 20:44:42 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
}
|
2017-07-04 12:14:04 +01:00
|
|
|
}
|