all repos — mgba @ 7935d58eacb96ce42b848d1cc868e63f467d31a3

mGBA Game Boy Advance Emulator

Qt: Light sensor setting from GUI
Jeffrey Pfau jeffrey@endrift.com
Tue, 30 Dec 2014 23:23:16 -0800
commit

7935d58eacb96ce42b848d1cc868e63f467d31a3

parent

d759305e23c8d858cb4fe18b859fc9943eb849e4

M CHANGESCHANGES

@@ -10,6 +10,7 @@ - List of recently opened games

- Support for games using the Solar Sensor - Debugger: Add CLI functions for writing to memory - Better audio resampling via blip-buf + - Game Pak overrides dialog for setting savetype and sensor values Bugfixes: - Qt: Fix issue with set frame sizes being the wrong height - Qt: Fix emulator crashing when full screen if a game is not running
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -48,9 +48,21 @@ m_threadContext.userData = this;

m_threadContext.rewindBufferCapacity = 0; m_threadContext.logLevel = -1; + m_lux.p = this; + m_lux.sample = [] (GBALuminanceSource* context) { + GameControllerLux* lux = static_cast<GameControllerLux*>(context); + lux->value = 0xFF - lux->p->m_luxValue; + }; + + m_lux.readLuminance = [] (GBALuminanceSource* context) { + GameControllerLux* lux = static_cast<GameControllerLux*>(context); + return lux->value; + }; + m_threadContext.startCallback = [] (GBAThread* context) { GameController* controller = static_cast<GameController*>(context->userData); controller->m_audioProcessor->setInput(context); + context->gba->luminanceSource = &controller->m_lux; controller->gameStarted(context); };
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -13,6 +13,7 @@ #include <QMutex>

#include <QString> extern "C" { +#include "gba-sensors.h" #include "gba-thread.h" #ifdef BUILD_SDL #include "sdl-events.h"

@@ -91,6 +92,7 @@ void setFrameskip(int);

void setTurbo(bool, bool forced = true); void setAVStream(GBAAVStream*); void clearAVStream(); + void setLuminanceValue(uint8_t value) { m_luxValue = value; } void setLogLevel(int); void enableLogLevel(int);

@@ -136,6 +138,12 @@ bool m_turbo;

bool m_turboForced; InputController* m_inputController; + + struct GameControllerLux : GBALuminanceSource { + GameController* p; + uint8_t value; + } m_lux; + uint8_t m_luxValue; }; }
M src/platform/qt/GamePakView.cppsrc/platform/qt/GamePakView.cpp

@@ -21,6 +21,8 @@ m_ui.setupUi(this);

connect(controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*))); connect(controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped())); + connect(m_ui.lightSpin, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int))); + connect(m_ui.lightSlide, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int))); if (controller->isLoaded()) { gameStarted(controller->thread());

@@ -61,3 +63,18 @@ m_ui.sensorRTC->setChecked(false);

m_ui.sensorGyro->setChecked(false); m_ui.sensorLight->setChecked(false); } + +void GamePakView::setLuminanceValue(int value) { + bool oldState; + value = std::max(0, std::min(value, 255)); + + oldState = m_ui.lightSpin->blockSignals(true); + m_ui.lightSpin->setValue(value); + m_ui.lightSpin->blockSignals(oldState); + + oldState = m_ui.lightSlide->blockSignals(true); + m_ui.lightSlide->setValue(value); + m_ui.lightSlide->blockSignals(oldState); + + m_controller->setLuminanceValue(value); +}
M src/platform/qt/GamePakView.hsrc/platform/qt/GamePakView.h

@@ -25,6 +25,7 @@

private slots: void gameStarted(GBAThread*); void gameStopped(); + void setLuminanceValue(int); private: Ui::GamePakView m_ui;