Qt: Load arbitrary images for GB Camera
Vicki Pfau vi@endrift.com
Wed, 26 Jul 2017 11:11:49 -0700
4 files changed,
26 insertions(+),
3 deletions(-)
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -81,7 +81,9 @@ #endif
m_image.startRequestImage = [](mImageSource* context) { InputControllerImage* image = static_cast<InputControllerImage*>(context); - image->image.load(":/res/no-cam.png"); + if (image->image.isNull()) { + image->image.load(":/res/no-cam.png"); + } }; m_image.stopRequestImage = nullptr; m_image.requestImage = [](mImageSource* context, unsigned w, unsigned h, const uint32_t** buffer, size_t* stride) {@@ -91,10 +93,10 @@ image->resizedImage = image->resizedImage.convertToFormat(QImage::Format_RGB32);
const uint32_t* bits = reinterpret_cast<const uint32_t*>(image->resizedImage.constBits()); QSize size = image->resizedImage.size(); if (size.width() > w) { - bits += size.width() / 2; + bits += (size.width() - w) / 2; } if (size.height() > h) { - bits += (size.height() / 2) * size.width(); + bits += ((size.height() - h) / 2) * size.width(); } *buffer = bits; *stride = size.width();@@ -641,6 +643,11 @@ void InputController::releaseFocus(QWidget* focus) {
if (focus == m_focusParent) { m_focusParent = m_topLevel; } +} + +void InputController::loadCamImage(const QString& path) { + m_image.image.load(path); + m_image.resizedImage = QImage(); } void InputController::increaseLuminanceLevel() {
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -81,6 +81,8 @@
void stealFocus(QWidget* focus); void releaseFocus(QWidget* focus); + void loadCamImage(const QString& path); + mRumble* rumble(); mRotationSource* rotationSource(); mImageSource* imageSource() { return &m_image; }
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -372,6 +372,13 @@ widget->setAttribute(Qt::WA_DeleteOnClose);
widget->show(); } +void Window::loadCamImage() { + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select image"), tr("Image file (*.png *.gif *.jpg *.jpeg);;All files (*)")); + if (!filename.isEmpty()) { + m_inputController.loadCamImage(filename); + } +} + void Window::importSharkport() { QString filename = GBAApp::app()->getOpenFileName(this, tr("Select save"), tr("GameShark saves (*.sps *.xps)")); if (!filename.isEmpty()) {@@ -1063,6 +1070,11 @@ m_gameActions.append(quickSave);
m_nonMpActions.append(quickSave); addControlledAction(quickSaveMenu, quickSave, QString("quickSave.%1").arg(i)); } + + fileMenu->addSeparator(); + QAction* camImage = new QAction(tr("Load camera image..."), fileMenu); + connect(camImage, &QAction::triggered, this, &Window::loadCamImage); + addControlledAction(fileMenu, camImage, "loadCamImage"); #ifdef M_CORE_GBA fileMenu->addSeparator();
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -76,6 +76,8 @@ void loadConfig();
void reloadConfig(); void saveConfig(); + void loadCamImage(); + void replaceROM(); void multiplayerChanged();