From bba008f1626b67e4a55ebcd556d4a4f026abb0da Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 18 Feb 2019 05:00:28 -0800 Subject: [PATCH] Qt: Cleanup indentation. Also some NULL -> nullptr. No actual code changes. --- Qt/QtMain.cpp | 355 +++++++++++++++++++++++------------------------- SDL/SDLMain.cpp | 4 +- 2 files changed, 174 insertions(+), 185 deletions(-) diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 73b6f540ad..32129d42dd 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -40,7 +40,7 @@ #include -MainUI *emugl = NULL; +MainUI *emugl = nullptr; static int refreshRate = 60000; static int browseFileEvent = -1; static int browseFolderEvent = -1; @@ -242,9 +242,8 @@ void MainUI::EmuThreadJoin() { emuThread = std::thread(); } -MainUI::MainUI(QWidget *parent): - QGLWidget(parent) -{ +MainUI::MainUI(QWidget *parent) + : QGLWidget(parent) { emuThreadState = (int)EmuThreadState::DISABLED; setAttribute(Qt::WA_AcceptTouchEvents); #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) @@ -259,8 +258,7 @@ MainUI::MainUI(QWidget *parent): startTimer(16); } -MainUI::~MainUI() -{ +MainUI::~MainUI() { ILOG("MainUI::Destructor"); if (emuThreadState != (int)EmuThreadState::DISABLED) { ILOG("EmuThreadStop"); @@ -279,133 +277,128 @@ MainUI::~MainUI() graphicsContext = nullptr; } -QString MainUI::InputBoxGetQString(QString title, QString defaultValue) -{ - bool ok; - QString text = QInputDialog::getText(this, title, title, QLineEdit::Normal, defaultValue, &ok); - if (!ok) - text = QString(); - return text; +QString MainUI::InputBoxGetQString(QString title, QString defaultValue) { + bool ok; + QString text = QInputDialog::getText(this, title, title, QLineEdit::Normal, defaultValue, &ok); + if (!ok) + text = QString(); + return text; } -void MainUI::resizeGL(int w, int h) -{ - if (UpdateScreenScale(w, h)) { - NativeMessageReceived("gpu_resized", ""); - } - xscale = w / this->width(); - yscale = h / this->height(); +void MainUI::resizeGL(int w, int h) { + if (UpdateScreenScale(w, h)) { + NativeMessageReceived("gpu_resized", ""); + } + xscale = w / this->width(); + yscale = h / this->height(); - PSP_CoreParameter().pixelWidth = pixel_xres; - PSP_CoreParameter().pixelHeight = pixel_yres; + PSP_CoreParameter().pixelWidth = pixel_xres; + PSP_CoreParameter().pixelHeight = pixel_yres; } -void MainUI::timerEvent(QTimerEvent *) -{ - updateGL(); - emit newFrame(); +void MainUI::timerEvent(QTimerEvent *) { + updateGL(); + emit newFrame(); } -void MainUI::changeEvent(QEvent *e) -{ - QGLWidget::changeEvent(e); - if(e->type() == QEvent::WindowStateChange) - Core_NotifyWindowHidden(isMinimized()); +void MainUI::changeEvent(QEvent *e) { + QGLWidget::changeEvent(e); + if (e->type() == QEvent::WindowStateChange) + Core_NotifyWindowHidden(isMinimized()); } -bool MainUI::event(QEvent *e) -{ - TouchInput input; - QList touchPoints; - switch(e->type()) - { - case QEvent::TouchBegin: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - touchPoints = static_cast(e)->touchPoints(); - foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) { - switch (touchPoint.state()) { - case Qt::TouchPointStationary: - break; - case Qt::TouchPointPressed: - case Qt::TouchPointReleased: - input.x = touchPoint.pos().x() * g_dpi_scale_x * xscale; - input.y = touchPoint.pos().y() * g_dpi_scale_y * yscale; - input.flags = (touchPoint.state() == Qt::TouchPointPressed) ? TOUCH_DOWN : TOUCH_UP; - input.id = touchPoint.id(); - NativeTouch(input); - break; - case Qt::TouchPointMoved: - input.x = touchPoint.pos().x() * g_dpi_scale_x * xscale; - input.y = touchPoint.pos().y() * g_dpi_scale_y * yscale; - input.flags = TOUCH_MOVE; - input.id = touchPoint.id(); - NativeTouch(input); - break; - default: - break; - } - } - break; - case QEvent::MouseButtonDblClick: - if (!g_Config.bShowTouchControls || GetUIState() != UISTATE_INGAME) - emit doubleClick(); - break; - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale_x * xscale; - input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale_y * yscale; - input.flags = (e->type() == QEvent::MouseButtonPress) ? TOUCH_DOWN : TOUCH_UP; - input.id = 0; - NativeTouch(input); - break; - case QEvent::MouseMove: - input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale_x * xscale; - input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale_y * yscale; - input.flags = TOUCH_MOVE; - input.id = 0; - NativeTouch(input); - break; - case QEvent::Wheel: - NativeKey(KeyInput(DEVICE_ID_MOUSE, ((QWheelEvent*)e)->delta()<0 ? NKCODE_EXT_MOUSEWHEEL_DOWN : NKCODE_EXT_MOUSEWHEEL_UP, KEY_DOWN)); - break; - case QEvent::KeyPress: - { - auto qtKeycode = ((QKeyEvent*)e)->key(); - auto iter = KeyMapRawQttoNative.find(qtKeycode); - int nativeKeycode = 0; - if (iter != KeyMapRawQttoNative.end()) { - nativeKeycode = iter->second; - NativeKey(KeyInput(DEVICE_ID_KEYBOARD, nativeKeycode, KEY_DOWN)); - } +bool MainUI::event(QEvent *e) { + TouchInput input; + QList touchPoints; - // Also get the unicode value. - QString text = ((QKeyEvent*)e)->text(); - std::string str = text.toStdString(); - // Now, we don't want CHAR events for non-printable characters. Not quite sure how we'll best - // do that, but here's one attempt.... - switch (nativeKeycode) { - case NKCODE_DEL: - case NKCODE_FORWARD_DEL: - case NKCODE_TAB: - break; - default: - if (str.size()) { - int pos = 0; - int code = u8_nextchar(str.c_str(), &pos); - NativeKey(KeyInput(DEVICE_ID_KEYBOARD, code, KEY_CHAR)); - } - break; - } + switch (e->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + touchPoints = static_cast(e)->touchPoints(); + foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) { + switch (touchPoint.state()) { + case Qt::TouchPointStationary: + break; + case Qt::TouchPointPressed: + case Qt::TouchPointReleased: + input.x = touchPoint.pos().x() * g_dpi_scale_x * xscale; + input.y = touchPoint.pos().y() * g_dpi_scale_y * yscale; + input.flags = (touchPoint.state() == Qt::TouchPointPressed) ? TOUCH_DOWN : TOUCH_UP; + input.id = touchPoint.id(); + NativeTouch(input); + break; + case Qt::TouchPointMoved: + input.x = touchPoint.pos().x() * g_dpi_scale_x * xscale; + input.y = touchPoint.pos().y() * g_dpi_scale_y * yscale; + input.flags = TOUCH_MOVE; + input.id = touchPoint.id(); + NativeTouch(input); + break; + default: + break; + } + } + break; + case QEvent::MouseButtonDblClick: + if (!g_Config.bShowTouchControls || GetUIState() != UISTATE_INGAME) + emit doubleClick(); + break; + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale_x * xscale; + input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale_y * yscale; + input.flags = (e->type() == QEvent::MouseButtonPress) ? TOUCH_DOWN : TOUCH_UP; + input.id = 0; + NativeTouch(input); + break; + case QEvent::MouseMove: + input.x = ((QMouseEvent*)e)->pos().x() * g_dpi_scale_x * xscale; + input.y = ((QMouseEvent*)e)->pos().y() * g_dpi_scale_y * yscale; + input.flags = TOUCH_MOVE; + input.id = 0; + NativeTouch(input); + break; + case QEvent::Wheel: + NativeKey(KeyInput(DEVICE_ID_MOUSE, ((QWheelEvent*)e)->delta()<0 ? NKCODE_EXT_MOUSEWHEEL_DOWN : NKCODE_EXT_MOUSEWHEEL_UP, KEY_DOWN)); + break; + case QEvent::KeyPress: + { + auto qtKeycode = ((QKeyEvent*)e)->key(); + auto iter = KeyMapRawQttoNative.find(qtKeycode); + int nativeKeycode = 0; + if (iter != KeyMapRawQttoNative.end()) { + nativeKeycode = iter->second; + NativeKey(KeyInput(DEVICE_ID_KEYBOARD, nativeKeycode, KEY_DOWN)); + } + + // Also get the unicode value. + QString text = ((QKeyEvent*)e)->text(); + std::string str = text.toStdString(); + // Now, we don't want CHAR events for non-printable characters. Not quite sure how we'll best + // do that, but here's one attempt.... + switch (nativeKeycode) { + case NKCODE_DEL: + case NKCODE_FORWARD_DEL: + case NKCODE_TAB: + break; + default: + if (str.size()) { + int pos = 0; + int code = u8_nextchar(str.c_str(), &pos); + NativeKey(KeyInput(DEVICE_ID_KEYBOARD, code, KEY_CHAR)); } - break; - case QEvent::KeyRelease: - NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawQttoNative.find(((QKeyEvent*)e)->key())->second, KEY_UP)); - break; + break; + } + } + break; + case QEvent::KeyRelease: + NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawQttoNative.find(((QKeyEvent*)e)->key())->second, KEY_UP)); + break; - default: + default: if (e->type() == browseFileEvent) { - QString fileName = QFileDialog::getOpenFileName(NULL, "Load ROM", g_Config.currentDirectory.c_str(), "PSP ROMs (*.iso *.cso *.pbp *.elf *.zip *.ppdmp)"); + QString fileName = QFileDialog::getOpenFileName(nullptr, "Load ROM", g_Config.currentDirectory.c_str(), "PSP ROMs (*.iso *.cso *.pbp *.elf *.zip *.ppdmp)"); if (QFile::exists(fileName)) { QDir newPath; g_Config.currentDirectory = newPath.filePath(fileName).toStdString(); @@ -421,11 +414,11 @@ bool MainUI::event(QEvent *e) NativeMessageReceived("browse_folderSelect", fileName.toStdString().c_str()); } } else { - return QWidget::event(e); + return QWidget::event(e); } - } - e->accept(); - return true; + } + e->accept(); + return true; } void MainUI::initializeGL() { @@ -459,9 +452,9 @@ void MainUI::initializeGL() { } void MainUI::paintGL() { - #ifdef SDL +#ifdef SDL SDL_PumpEvents(); - #endif +#endif updateAccelerometer(); if (emuThreadState == (int)EmuThreadState::DISABLED) { UpdateRunLoop(); @@ -471,28 +464,27 @@ void MainUI::paintGL() { } } -void MainUI::updateAccelerometer() -{ +void MainUI::updateAccelerometer() { #if defined(MOBILE_DEVICE) - // TODO: Toggle it depending on whether it is enabled - QAccelerometerReading *reading = acc->reading(); - if (reading) { - AxisInput axis; - axis.deviceId = DEVICE_ID_ACCELEROMETER; - axis.flags = 0; + // TODO: Toggle it depending on whether it is enabled + QAccelerometerReading *reading = acc->reading(); + if (reading) { + AxisInput axis; + axis.deviceId = DEVICE_ID_ACCELEROMETER; + axis.flags = 0; - axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X; - axis.value = reading->x(); - NativeAxis(axis); + axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X; + axis.value = reading->x(); + NativeAxis(axis); - axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y; - axis.value = reading->y(); - NativeAxis(axis); + axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y; + axis.value = reading->y(); + NativeAxis(axis); - axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z; - axis.value = reading->z(); - NativeAxis(axis); - } + axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z; + axis.value = reading->z(); + NativeAxis(axis); + } #endif } @@ -504,49 +496,46 @@ void MainUI::updateAccelerometer() #define AUDIO_SAMPLESIZE 16 #define AUDIO_BUFFERS 5 -MainAudio::~MainAudio() -{ - if (feed != NULL) { - killTimer(timer); - feed->close(); - } - if (output) { - output->stop(); - delete output; - } - if (mixbuf) - free(mixbuf); +MainAudio::~MainAudio() { + if (feed != nullptr) { + killTimer(timer); + feed->close(); + } + if (output) { + output->stop(); + delete output; + } + if (mixbuf) + free(mixbuf); } -void MainAudio::run() -{ - QAudioFormat fmt; - fmt.setSampleRate(AUDIO_FREQ); - fmt.setCodec("audio/pcm"); - fmt.setChannelCount(AUDIO_CHANNELS); - fmt.setSampleSize(AUDIO_SAMPLESIZE); - fmt.setByteOrder(QAudioFormat::LittleEndian); - fmt.setSampleType(QAudioFormat::SignedInt); - mixlen = sizeof(short)*AUDIO_BUFFERS*AUDIO_CHANNELS*AUDIO_SAMPLES; - mixbuf = (char*)malloc(mixlen); - output = new QAudioOutput(fmt); - output->setBufferSize(mixlen); - feed = output->start(); - if (feed != NULL) { - // buffering has already done in the internal mixed buffer - // use a small interval to copy mixed audio stream from - // internal buffer to audio output buffer as soon as possible - // use 1 instead of 0 to prevent CPU exhausting - timer = startTimer(1); - } +void MainAudio::run() { + QAudioFormat fmt; + fmt.setSampleRate(AUDIO_FREQ); + fmt.setCodec("audio/pcm"); + fmt.setChannelCount(AUDIO_CHANNELS); + fmt.setSampleSize(AUDIO_SAMPLESIZE); + fmt.setByteOrder(QAudioFormat::LittleEndian); + fmt.setSampleType(QAudioFormat::SignedInt); + mixlen = sizeof(short)*AUDIO_BUFFERS*AUDIO_CHANNELS*AUDIO_SAMPLES; + mixbuf = (char*)malloc(mixlen); + output = new QAudioOutput(fmt); + output->setBufferSize(mixlen); + feed = output->start(); + if (feed != nullptr) { + // buffering has already done in the internal mixed buffer + // use a small interval to copy mixed audio stream from + // internal buffer to audio output buffer as soon as possible + // use 1 instead of 0 to prevent CPU exhausting + timer = startTimer(1); + } } -void MainAudio::timerEvent(QTimerEvent *) -{ - memset(mixbuf, 0, mixlen); - size_t frames = NativeMix((short *)mixbuf, AUDIO_BUFFERS*AUDIO_SAMPLES); - if (frames > 0) - feed->write(mixbuf, sizeof(short) * AUDIO_CHANNELS * frames); +void MainAudio::timerEvent(QTimerEvent *) { + memset(mixbuf, 0, mixlen); + size_t frames = NativeMix((short *)mixbuf, AUDIO_BUFFERS*AUDIO_SAMPLES); + if (frames > 0) + feed->write(mixbuf, sizeof(short) * AUDIO_CHANNELS * frames); } #endif diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 0daf922b9b..1f390da5bd 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -442,11 +442,11 @@ int main(int argc, char *argv[]) { // If we're on mobile, don't try for windowed either. #if defined(MOBILE_DEVICE) - mode |= SDL_WINDOW_FULLSCREEN; + mode |= SDL_WINDOW_FULLSCREEN; #elif defined(USING_FBDEV) mode |= SDL_WINDOW_FULLSCREEN_DESKTOP; #else - mode |= SDL_WINDOW_RESIZABLE; + mode |= SDL_WINDOW_RESIZABLE; #endif if (mode & SDL_WINDOW_FULLSCREEN_DESKTOP) {