From b60d88d6be085f699adef357e1c5fa9d9f323104 Mon Sep 17 00:00:00 2001 From: sinamas Date: Fri, 29 Mar 2013 18:03:00 +0100 Subject: [PATCH] gambatte_qt: pass by ref --- .../src/framework/include/mainwindow.h | 49 ++- .../src/framework/include/sounddialog.h | 18 +- .../src/framework/include/videodialog.h | 64 +--- gambatte_qt/src/framework/src/mainwindow.cpp | 18 +- gambatte_qt/src/framework/src/mediawidget.cpp | 12 +- gambatte_qt/src/framework/src/mediawidget.h | 6 +- gambatte_qt/src/framework/src/mediaworker.cpp | 17 +- gambatte_qt/src/framework/src/mediaworker.h | 15 +- .../src/framework/src/samplebuffer.cpp | 6 +- gambatte_qt/src/framework/src/samplebuffer.h | 17 +- gambatte_qt/src/framework/src/sounddialog.cpp | 54 +-- gambatte_qt/src/framework/src/videodialog.cpp | 329 ++++++++++-------- gambatte_qt/src/gambattemenuhandler.cpp | 245 ++++++------- gambatte_qt/src/gambattemenuhandler.h | 16 +- gambatte_qt/src/main.cpp | 4 +- 15 files changed, 444 insertions(+), 426 deletions(-) diff --git a/gambatte_qt/src/framework/include/mainwindow.h b/gambatte_qt/src/framework/include/mainwindow.h index 95672cd1..1cb54418 100644 --- a/gambatte_qt/src/framework/include/mainwindow.h +++ b/gambatte_qt/src/framework/include/mainwindow.h @@ -19,13 +19,13 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include -#include +#include "callqueue.h" +#include "pixelbuffer.h" #include "resinfo.h" #include "scalingmethod.h" #include "uncopyable.h" -#include "callqueue.h" -#include "pixelbuffer.h" +#include +#include class AudioEngineConf; class BlitterConf; @@ -37,9 +37,8 @@ class MediaWorker; class QSize; /** - * The MainWindow is one of the two main classes in this framework. - * It takes a MediaSource and presents the audio/video content produced - * by it to the user. + * The MainWindow takes a MediaSource and presents the audio/video content + * produced by it to the user. * * It calls MediaSource::update to request production of more audio/video content. * This happens in a worker thread that is separate from the main (GUI) thread. @@ -47,25 +46,33 @@ class QSize; class MainWindow : public QMainWindow { Q_OBJECT public: - /** Can be used to gain frame buffer access outside the MediaSource + /** + * Can be used to gain frame buffer access outside the MediaSource * methods that take the frame buffer as argument. */ class FrameBuffer { - MediaWidget *const mw; public: - explicit FrameBuffer(MainWindow *const mw) : mw(mw->w_) {} + explicit FrameBuffer(MainWindow &mw) + : mw_(mw.w_) + { + } class Locked : Uncopyable { - MediaWidget *mw; - PixelBuffer pb; public: Locked(FrameBuffer fb); ~Locked(); - const PixelBuffer& get() const { return pb; } + PixelBuffer const & get() const { return pb_; } + + private: + MediaWidget *mw_; + PixelBuffer pb_; }; + + private: + MediaWidget *const mw_; }; - explicit MainWindow(MediaSource *source); + explicit MainWindow(MediaSource &source); /** Sets the duration in seconds of each video frame. * Eg. use setFrameTime(1, 60) for 60 fps video. @@ -117,12 +124,16 @@ public: void setAspectRatio(const QSize &ar); void setScalingMethod(ScalingMethod smet); - /** Sets the size of the video area of the MainWindow when not full screen. - * Should be used in place of methods like QMainWindow::resize, because this one doesn't screw up full screen. - * Pass sz = QSize(-1,-1) for a variable size, such that the user may adjust the window size. - * Otherwise a fixed window size equal to sz will be used. This window size does not include window borders or menus. + /** + * Sets the size of the video area of the MainWindow when not full screen. + * Should be used in place of methods like QMainWindow::resize, because this + * one does not screw up full screen. + * + * Pass size = QSize(-1, -1) for a variable size, such that the user may adjust + * the window size. Otherwise a fixed window size equal to size will be used. + * This window size does not include window borders or menus. */ - void setWindowSize(const QSize &sz); + void setWindowSize(QSize const &size); /** Each blitter has some properties that can be accessed through its BlitterConf. */ const BlitterConf blitterConf(std::size_t blitterNo); diff --git a/gambatte_qt/src/framework/include/sounddialog.h b/gambatte_qt/src/framework/include/sounddialog.h index 47266d9b..efc19154 100644 --- a/gambatte_qt/src/framework/include/sounddialog.h +++ b/gambatte_qt/src/framework/include/sounddialog.h @@ -16,24 +16,24 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - #ifndef SOUNDDIALOG_H #define SOUNDDIALOG_H +#include + class MainWindow; class QVBoxLayout; class QComboBox; class QSpinBox; -#include - -/** A utility class that can optionally be used to provide a GUI for - * configuring sound/audio settings. +/** + * A utility class that can optionally be used to provide a GUI for + * configuring audio settings. */ class SoundDialog : public QDialog { Q_OBJECT - const MainWindow *const mw; + MainWindow const &mw_; QVBoxLayout *const topLayout; QComboBox *const engineSelector; QComboBox *const resamplerSelector; @@ -53,18 +53,18 @@ private slots: void rateIndexChange(int index); public: - explicit SoundDialog(const MainWindow *mw, QWidget *parent = 0); + explicit SoundDialog(MainWindow const &mw, QWidget *parent = 0); ~SoundDialog(); int engineIndex() const { return engineIndex_; } int resamplerNo() const { return resamplerNum; } int rate() const { return rate_; } int latency() const { return latency_; }; - static void applySettings(MainWindow *mw, const SoundDialog *sd); - public slots: void accept(); void reject(); }; +void applySettings(MainWindow &mw, SoundDialog const &sd); + #endif diff --git a/gambatte_qt/src/framework/include/videodialog.h b/gambatte_qt/src/framework/include/videodialog.h index dde36f18..f0cbb091 100644 --- a/gambatte_qt/src/framework/include/videodialog.h +++ b/gambatte_qt/src/framework/include/videodialog.h @@ -35,7 +35,8 @@ class QRadioButton; class QLabel; class QBoxLayout; -/** A utility class that can optionally be used to provide a GUI for +/** + * A utility class that can optionally be used to provide a GUI for * configuring video settings. */ class VideoDialog : public QDialog { @@ -66,7 +67,7 @@ private: PersistInt index_; public: - explicit EngineSelector(const MainWindow *mw); + explicit EngineSelector(MainWindow const &mw); void addToLayout(QBoxLayout *topLayout); const QComboBox * comboBox() const { return comboBox_; } void store(); @@ -104,52 +105,18 @@ private: int index() const { return index_; } }; - class FullResSelector { - QComboBox *const comboBox_; - const QString key_; - int index_; + class FullResSelector; + class FullHzSelector; - void fillComboBox(const QSize &sourceSize, const std::vector &resVector); - public: - FullResSelector(const QString &key, int defaultIndex, - const QSize &sourceSize, const std::vector &resVector); - ~FullResSelector(); - QWidget * widget(); - const QComboBox * comboBox() const { return comboBox_; } - void store(); - void restore(); - void setSourceSize(const QSize &sourceSize, const std::vector &resVector); - int index() const { return index_; } - }; - - class FullHzSelector { - QComboBox *const comboBox_; - const QString key_; - int index_; - - public: - FullHzSelector(const QString &key, const std::vector &rates, int defaultIndex); - ~FullHzSelector(); - QWidget * widget(); - const QComboBox * comboBox() const { return comboBox_; } - void store(); - void restore(); - void setRates(const std::vector &rates); - int index() const { return index_; } - }; - - const MainWindow *const mw; + MainWindow const &mw_; QVBoxLayout *const topLayout; QWidget *engineWidget; EngineSelector engineSelector; ScalingMethodSelector scalingMethodSelector; SourceSelector sourceSelector; - const auto_vector fullResSelectors; - const auto_vector fullHzSelectors; + auto_vector const fullResSelectors; + auto_vector const fullHzSelectors; - static auto_vector makeFullResSelectors(const QSize &sourceSize, const MainWindow *mw); - static auto_vector makeFullHzSelectors( - const auto_vector &fullResSelectors, const MainWindow *mw); void fillFullResSelectors(); void store(); void restore(); @@ -160,17 +127,18 @@ private slots: void sourceChange(int index); public: - VideoDialog(const MainWindow *mw, - const std::vector &sourceInfos, - const QString &sourcesLabel, + VideoDialog(MainWindow const &mw, + std::vector const &sourceInfos, + QString const &sourcesLabel, QWidget *parent = 0); + ~VideoDialog(); int blitterNo() const; unsigned fullResIndex(unsigned screen) const; unsigned fullRateIndex(unsigned screen) const; unsigned sourceIndex() const { return sourceSelector.index(); } - const QSize sourceSize() const; - void setVideoSources(const std::vector &sourceInfos); - void setSourceSize(const QSize &sourceSize); + QSize const sourceSize() const; + void setVideoSources(std::vector const &sourceInfos); + void setSourceSize(QSize const &sourceSize); ScalingMethod scalingMethod() const { return scalingMethodSelector.scalingMethod(); } public slots: @@ -178,6 +146,6 @@ public slots: void reject(); }; -void applySettings(MainWindow *mw, const VideoDialog *vd); +void applySettings(MainWindow &mw, VideoDialog const &vd); #endif diff --git a/gambatte_qt/src/framework/src/mainwindow.cpp b/gambatte_qt/src/framework/src/mainwindow.cpp index 3bf7e608..7a6cece8 100644 --- a/gambatte_qt/src/framework/src/mainwindow.cpp +++ b/gambatte_qt/src/framework/src/mainwindow.cpp @@ -23,18 +23,22 @@ #include #include // for Q_WS_WIN define -MainWindow::FrameBuffer::Locked::Locked(FrameBuffer fb) : mw(0), pb() { - if (fb.mw->tryLockFrameBuf(pb)) - mw = fb.mw; +MainWindow::FrameBuffer::Locked::Locked(FrameBuffer fb) +: mw_(), pb_() +{ + if (fb.mw_->tryLockFrameBuf(pb_)) + mw_ = fb.mw_; } MainWindow::FrameBuffer::Locked::~Locked() { - if (mw) - mw->unlockFrameBuf(); + if (mw_) + mw_->unlockFrameBuf(); } -MainWindow::MainWindow(MediaSource *const source) -: w_(new MediaWidget(source, *this)), winSize_(-1, -1), fullscreen_(false) +MainWindow::MainWindow(MediaSource &source) +: w_(new MediaWidget(source, *this)) +, winSize_(-1, -1) +, fullscreen_(false) { setFocusPolicy(Qt::StrongFocus); setCentralWidget(w_->widget()); diff --git a/gambatte_qt/src/framework/src/mediawidget.cpp b/gambatte_qt/src/framework/src/mediawidget.cpp index ecf31510..763d9089 100644 --- a/gambatte_qt/src/framework/src/mediawidget.cpp +++ b/gambatte_qt/src/framework/src/mediawidget.cpp @@ -209,7 +209,7 @@ void MediaWidget::WorkerCallback::consumeBlitRequest() { BlitterWidget *const blitter = mw.blitterContainer->blitter(); MediaWorker *const worker = mw.worker; - worker->source()->generateVideoFrame(blitter->inBuffer()); + worker->source().generateVideoFrame(blitter->inBuffer()); blitter->blit(); base = synctimebase; @@ -256,7 +256,7 @@ static auto_vector makeAudioEngines(const WId winId) { return audioEngines; } -MediaWidget::MediaWidget(MediaSource *const source, QWidget &parent) +MediaWidget::MediaWidget(MediaSource &source, QWidget &parent) : QObject(&parent), vbmut(), blitterContainer(new BlitterContainer(&parent)), @@ -264,7 +264,7 @@ MediaWidget::MediaWidget(MediaSource *const source, QWidget &parent) blitters(makeBlitterWidgets(VideoBufferLocker(vbmut), DwmControlHwndChange(dwmControl_))), fullModeToggler(getFullModeToggler(parent.winId())), workerCallback_(new WorkerCallback(*this)), - worker(new MediaWorker(source, audioEngines.back(), 48000, 100, 1, + worker(new MediaWorker(source, *audioEngines.back(), 48000, 100, 1, *workerCallback_, this)), frameRateControl(*worker, blitters.back()), cursorTimer(new QTimer(this)), @@ -446,7 +446,7 @@ void MediaWidget::keyPressEvent(QKeyEvent *e) { e->ignore(); if (running && !e->isAutoRepeat()) { - worker->source()->keyPressEvent(e); + worker->source().keyPressEvent(e); blitterContainer->hideCursor(); } } @@ -455,7 +455,7 @@ void MediaWidget::keyReleaseEvent(QKeyEvent *e) { e->ignore(); if (running && !e->isAutoRepeat()) - worker->source()->keyReleaseEvent(e); + worker->source().keyReleaseEvent(e); } void MediaWidget::setFrameTime(long num, long denom) { @@ -491,7 +491,7 @@ struct MediaWidget::FrameStepFun { if (mw.running && mw.worker->frameStep()) { BlitterWidget *const blitter = mw.blitterContainer->blitter(); - mw.worker->source()->generateVideoFrame(blitter->inBuffer()); + mw.worker->source().generateVideoFrame(blitter->inBuffer()); blitter->blit(); blitter->draw(); diff --git a/gambatte_qt/src/framework/src/mediawidget.h b/gambatte_qt/src/framework/src/mediawidget.h index 14a66257..dc2b3694 100644 --- a/gambatte_qt/src/framework/src/mediawidget.h +++ b/gambatte_qt/src/framework/src/mediawidget.h @@ -102,7 +102,7 @@ private slots: void updateJoysticks(); public: - MediaWidget(MediaSource *source, QWidget &parent); + MediaWidget(MediaSource &source, QWidget &parent); ~MediaWidget(); QWidget* widget() const { return blitterContainer; } @@ -130,7 +130,7 @@ public: void unlockFrameBuf() { vbmut.unlock(); } - const QSize& videoSize() const { return blitterContainer->sourceSize(); } + QSize const videoSize() const { return blitterContainer->sourceSize(); } void setFrameTime(long num, long denom); void setSamplesPerFrame(long num, long denom = 1) { worker->setSamplesPerFrame(Rational(num, denom)); } @@ -187,7 +187,7 @@ public: std::size_t numAudioEngines() const { return audioEngines.size(); } void setAudioOut(std::size_t engineNo, unsigned srateHz, unsigned msecLatency, std::size_t resamplerNo) { - worker->setAudioOut(audioEngines[engineNo], srateHz, msecLatency, resamplerNo); + worker->setAudioOut(*audioEngines[engineNo], srateHz, msecLatency, resamplerNo); } std::size_t numResamplers() const { return ResamplerInfo::num(); } diff --git a/gambatte_qt/src/framework/src/mediaworker.cpp b/gambatte_qt/src/framework/src/mediaworker.cpp index 816b7836..79c0e3ad 100755 --- a/gambatte_qt/src/framework/src/mediaworker.cpp +++ b/gambatte_qt/src/framework/src/mediaworker.cpp @@ -128,15 +128,18 @@ void MediaWorker::PauseVar::waitWhilePaused(MediaWorker::Callback &cb, AudioOut waiting = false; } -MediaWorker::MediaWorker(MediaSource *source, AudioEngine *ae, int aerate, - int aelatency, std::size_t resamplerNo, Callback &callback, QObject *parent) +MediaWorker::MediaWorker(MediaSource &source, + AudioEngine &ae, int aerate, int aelatency, + std::size_t resamplerNo, + Callback &callback, + QObject *parent) : QThread(parent), callback(callback), meanQueue(0, 0), frameTimeEst(0), doneVar(true), sampleBuffer(source), - ao_(new AudioOut(*ae, aerate, aelatency, resamplerNo)), + ao_(new AudioOut(ae, aerate, aelatency, resamplerNo)), usecft(0) { } @@ -191,19 +194,19 @@ void MediaWorker::resetAudio() { } struct MediaWorker::SetAudioOut { - MediaWorker &w; AudioEngine *const ae; const int rate; const int latency; + MediaWorker &w; AudioEngine &ae; const int rate; const int latency; const std::size_t resamplerNo; void operator()() const { const bool inited = w.ao_->initialized(); w.ao_.reset(); - w.ao_.reset(new AudioOut(*ae, rate, latency, resamplerNo)); + w.ao_.reset(new AudioOut(ae, rate, latency, resamplerNo)); if (inited) w.initAudioEngine(); } }; -void MediaWorker::setAudioOut(AudioEngine *newAe, int rate, int latency, std::size_t resamplerNo) { +void MediaWorker::setAudioOut(AudioEngine &newAe, int rate, int latency, std::size_t resamplerNo) { const SetAudioOut setAudioOutStruct = { *this, newAe, rate, latency, resamplerNo }; pushCall(setAudioOutStruct); } @@ -255,7 +258,7 @@ void MediaWorker::updateJoysticks() { SDL_Event ev; while (pollJsEvent(&ev)) - source()->joystickEvent(ev); + source().joystickEvent(ev); JoystickLock::unlock(); } diff --git a/gambatte_qt/src/framework/src/mediaworker.h b/gambatte_qt/src/framework/src/mediaworker.h index 2bb971b4..20ac7449 100755 --- a/gambatte_qt/src/framework/src/mediaworker.h +++ b/gambatte_qt/src/framework/src/mediaworker.h @@ -32,6 +32,8 @@ #include #include +class AudioEngine; + class MediaWorker : private QThread { public: class Callback { @@ -39,7 +41,6 @@ public: virtual void paused() = 0; virtual void blit(usec_t synctimebase, usec_t synctimeinc) = 0; virtual bool cancelBlit() = 0; -// virtual void sync() = 0; virtual void audioEngineFailure() = 0; virtual bool tryLockVideoBuffer(PixelBuffer &pb) = 0; virtual void unlockVideoBuffer() = 0; @@ -139,10 +140,10 @@ protected: void run(); public: - MediaWorker(MediaSource *source, class AudioEngine *ae, int aerate, int aelatency, - std::size_t resamplerNo, Callback &callback, QObject *parent = 0); - MediaSource* source() /*const */{ return sampleBuffer.source(); } - SyncVar& waitingForSync() /*const */{ return waitingForSync_; } + MediaWorker(MediaSource &source, AudioEngine &ae, int aerate, int aelatency, + std::size_t resamplerNo, Callback &callback, QObject *parent = 0); + MediaSource & source() const { return sampleBuffer.source(); } + SyncVar & waitingForSync() { return waitingForSync_; } void start(); void stop(); void pause(); @@ -153,11 +154,11 @@ public: bool paused() const { return pauseVar.waitingForUnpause(); } void resetAudio(); - void setAudioOut(class AudioEngine *newAe, int rate, int latency, std::size_t resamplerNo); + void setAudioOut(AudioEngine &newAe, int rate, int latency, std::size_t resamplerNo); void setFrameTime(Rational ft); void setSamplesPerFrame(Rational spf); - void setFrameTimeEstimate(const long ftest) { AtomicVar::Locked(frameTimeEst).set(ftest); } + void setFrameTimeEstimate(long ftest) { AtomicVar::Locked(frameTimeEst).set(ftest); } bool frameStep(); void setFastForwardSpeed(unsigned speed) { turboSkip.setSpeed(speed); } diff --git a/gambatte_qt/src/framework/src/samplebuffer.cpp b/gambatte_qt/src/framework/src/samplebuffer.cpp index 97acfb84..6da6f69e 100755 --- a/gambatte_qt/src/framework/src/samplebuffer.cpp +++ b/gambatte_qt/src/framework/src/samplebuffer.cpp @@ -26,7 +26,7 @@ static T * ptr_cast(void *p) { return static_cast(p); } void SampleBuffer::reset() { const long insrate = static_cast(ft_.reciprocal().toFloat() * spf_.toFloat() + 0.5f); - const long maxin = spf_.ceiled() + source_->overupdate; + const long maxin = spf_.ceiled() + source_.overupdate; sndInBuffer_.reset(0); resampler_.reset(); @@ -40,8 +40,8 @@ void SampleBuffer::reset() { long SampleBuffer::update(const PixelBuffer &pb) { long insamples = sndInBuffer_.size() - samplesBuffered_; - const long res = source_->update(pb, ptr_cast(sndInBuffer_ + samplesBuffered_), - insamples); + const long res = source_.update(pb, ptr_cast(sndInBuffer_ + samplesBuffered_), + insamples); samplesBuffered_ += insamples; return res < 0 ? res : samplesBuffered_ - insamples + res; } diff --git a/gambatte_qt/src/framework/src/samplebuffer.h b/gambatte_qt/src/framework/src/samplebuffer.h index 0b124ae4..32fbe744 100755 --- a/gambatte_qt/src/framework/src/samplebuffer.h +++ b/gambatte_qt/src/framework/src/samplebuffer.h @@ -19,17 +19,17 @@ #ifndef SAMPLEBUFFER_H #define SAMPLEBUFFER_H -class MediaSource; -struct PixelBuffer; - #include "array.h" #include "rational.h" #include "resample/resampler.h" #include "scoped_ptr.h" #include +class MediaSource; +struct PixelBuffer; + class SampleBuffer : Uncopyable { - MediaSource *const source_; + MediaSource &source_; scoped_ptr resampler_; Array sndInBuffer_; long samplesBuffered_; @@ -41,7 +41,7 @@ class SampleBuffer : Uncopyable { void reset(); public: - explicit SampleBuffer(MediaSource *source) + explicit SampleBuffer(MediaSource &source) : source_(source) , spf_(0) , ft_(1, 0) @@ -65,10 +65,9 @@ public: void setOutSampleRate(long outsrate) { setOutSampleRate(outsrate, resamplerNo_); } long maxOut() const { return resampler_ ? resampler_->maxOut(sndInBuffer_.size()) : 0; } - MediaSource* source() { return source_; } - const MediaSource* source() const { return source_; } - const Rational& spf() const { return spf_; } - const Rational& ft() const { return ft_; } + MediaSource & source() const { return source_; } + Rational spf() const { return spf_; } + Rational ft() const { return ft_; } long resamplerOutRate() const { return resampler_->outRate(); } void adjustResamplerOutRate(long outRate) { resampler_->adjustRate(resampler_->inRate(), outRate); } }; diff --git a/gambatte_qt/src/framework/src/sounddialog.cpp b/gambatte_qt/src/framework/src/sounddialog.cpp index 1ea4ca92..cbebdf2e 100644 --- a/gambatte_qt/src/framework/src/sounddialog.cpp +++ b/gambatte_qt/src/framework/src/sounddialog.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007 by Sindre Aam�s * + * Copyright (C) 2007 by Sindre Aamås * * sinamas@users.sourceforge.net * * * * This program is free software; you can redistribute it and/or modify * @@ -17,18 +17,18 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "sounddialog.h" -#include "mainwindow.h" #include "audioengineconf.h" +#include "mainwindow.h" #include "resample/resamplerinfo.h" #include -#include -#include #include +#include #include #include #include #include -#include +#include +#include #include namespace { @@ -114,19 +114,19 @@ static void setRate(QComboBox *rateSelector, const int r) { } -SoundDialog::SoundDialog(const MainWindow *const mw, QWidget *const parent) : - QDialog(parent), - mw(mw), - topLayout(new QVBoxLayout), - engineSelector(new QComboBox(this)), - resamplerSelector(new QComboBox(this)), - rateSelector(new QComboBox(this)), - latencySelector(new QSpinBox(this)), - engineWidget(NULL), - engineIndex_(0), - resamplerNum(1), - rate_(0), - latency_(68) +SoundDialog::SoundDialog(MainWindow const &mw, QWidget *const parent) +: QDialog(parent) +, mw_(mw) +, topLayout(new QVBoxLayout) +, engineSelector(new QComboBox(this)) +, resamplerSelector(new QComboBox(this)) +, rateSelector(new QComboBox(this)) +, latencySelector(new QSpinBox(this)) +, engineWidget() +, engineIndex_(0) +, resamplerNum(1) +, rate_(0) +, latency_(68) { setWindowTitle(tr("Sound Settings")); @@ -136,8 +136,8 @@ SoundDialog::SoundDialog(const MainWindow *const mw, QWidget *const parent) : QHBoxLayout *const hLayout = new QHBoxLayout; hLayout->addWidget(new QLabel(tr("Sound engine:"))); - for (std::size_t i = 0; i < mw->numAudioEngines(); ++i) - engineSelector->addItem(mw->audioEngineConf(i).nameString()); + for (std::size_t i = 0; i < mw.numAudioEngines(); ++i) + engineSelector->addItem(mw.audioEngineConf(i).nameString()); hLayout->addWidget(engineSelector); topLayout->addLayout(hLayout); @@ -227,7 +227,7 @@ void SoundDialog::engineChange(int index) { engineWidget->setParent(NULL); } - if ((engineWidget = mw->audioEngineConf(index).settingsWidget())) + if ((engineWidget = mw_.audioEngineConf(index).settingsWidget())) topLayout->insertWidget(1, engineWidget); } @@ -255,8 +255,8 @@ void SoundDialog::store() { } void SoundDialog::restore() { - for (std::size_t i = 0; i < mw->numAudioEngines(); ++i) - mw->audioEngineConf(i).rejectSettings(); + for (std::size_t i = 0; i < mw_.numAudioEngines(); ++i) + mw_.audioEngineConf(i).rejectSettings(); engineSelector->setCurrentIndex(engineIndex_); resamplerSelector->setCurrentIndex(resamplerNum); @@ -274,9 +274,9 @@ void SoundDialog::reject() { QDialog::reject(); } -void SoundDialog::applySettings(MainWindow *const mw, const SoundDialog *const sd) { - for (std::size_t i = 0; i < mw->numAudioEngines(); ++i) - mw->audioEngineConf(i).acceptSettings(); +void applySettings(MainWindow &mw, SoundDialog const &sd) { + for (std::size_t i = 0; i < mw.numAudioEngines(); ++i) + mw.audioEngineConf(i).acceptSettings(); - mw->setAudioOut(sd->engineIndex(), sd->rate(), sd->latency(), sd->resamplerNo()); + mw.setAudioOut(sd.engineIndex(), sd.rate(), sd.latency(), sd.resamplerNo()); } diff --git a/gambatte_qt/src/framework/src/videodialog.cpp b/gambatte_qt/src/framework/src/videodialog.cpp index 71d8ef26..396d58de 100644 --- a/gambatte_qt/src/framework/src/videodialog.cpp +++ b/gambatte_qt/src/framework/src/videodialog.cpp @@ -17,23 +17,22 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "videodialog.h" -#include "mainwindow.h" #include "blitterconf.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "mainwindow.h" #include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include #include -static int filterValue(const int value, const int upper, const int lower = 0, const int fallback = 0) { +static int filterValue(int value, int upper, int lower = 0, int fallback = 0) { if (value >= upper || value < lower) return fallback; @@ -50,11 +49,12 @@ VideoDialog::PersistInt::~PersistInt() { settings.setValue(key_, i_); } -VideoDialog::EngineSelector::EngineSelector(const MainWindow *const mw) -: comboBox_(new QComboBox), index_("video/engineIndex", mw->numBlitters()) +VideoDialog::EngineSelector::EngineSelector(MainWindow const &mw) +: comboBox_(new QComboBox) +, index_("video/engineIndex", mw.numBlitters()) { - for (std::size_t i = 0; i < mw->numBlitters(); ++i) - comboBox_->addItem(mw->blitterConf(i).nameString()); + for (std::size_t i = 0; i < mw.numBlitters(); ++i) + comboBox_->addItem(mw.blitterConf(i).nameString()); restore(); } @@ -150,61 +150,82 @@ void VideoDialog::SourceSelector::setVideoSources(const std::vector &resVector) -: comboBox_(new QComboBox), key_(key), index_(defaultIndex) -{ - fillComboBox(sourceSize, resVector); +class VideoDialog::FullResSelector { +public: + ~FullResSelector(); + QWidget * widget() const { return comboBox_; } + QComboBox const * comboBox() const { return comboBox_; } + void store() { index_ = comboBox_->currentIndex(); } + void restore() { comboBox_->setCurrentIndex(index_); } + void setSourceSize(QSize const &sourceSize, std::vector const &resVector); + int index() const { return index_; } - index_ = filterValue(comboBox_->findText(QSettings().value(key).toString()), - comboBox_->count(), 0, index_); + static auto_vector createSelectors(QSize const &sourceSize, + MainWindow const &mw) + { + auto_vector v(mw.screens()); + for (std::size_t i = 0; i < v.size(); ++i) { + v.reset(i, new FullResSelector("video/fullRes" + QString::number(i), + mw.currentResIndex(i), sourceSize, + mw.modeVector(i))); + } - restore(); -} + return v; + } + +private: + QComboBox *const comboBox_; + QString const key_; + int index_; + + FullResSelector(QString const &key, + int const defaultIndex, + QSize const &sourceSize, + std::vector const &resVector) + : comboBox_(new QComboBox) + , key_(key) + , index_(defaultIndex) + { + fillComboBox(sourceSize, resVector); + index_ = filterValue(comboBox_->findText(QSettings().value(key).toString()), + comboBox_->count(), 0, index_); + restore(); + } + + void fillComboBox(QSize const &sourceSize, std::vector const &resVector); +}; VideoDialog::FullResSelector::~FullResSelector() { QSettings settings; settings.setValue(key_, comboBox_->itemText(index_)); } -QWidget* VideoDialog::FullResSelector::widget() { - return comboBox_; -} - -void VideoDialog::FullResSelector::store() { - index_ = comboBox_->currentIndex(); -} - -void VideoDialog::FullResSelector::restore() { - comboBox_->setCurrentIndex(index_); -} - -void VideoDialog::FullResSelector::setSourceSize(const QSize &sourceSize, const std::vector &resVector) { - const QString oldtext(comboBox_->itemText(comboBox_->currentIndex())); - +void VideoDialog::FullResSelector::setSourceSize( + QSize const &sourceSize, std::vector const &resVector) { + QString const oldtext(comboBox_->itemText(comboBox_->currentIndex())); comboBox_->clear(); fillComboBox(sourceSize, resVector); - const int newIndex = comboBox_->findText(oldtext); - + int newIndex = comboBox_->findText(oldtext); if (newIndex >= 0) comboBox_->setCurrentIndex(newIndex); } -void VideoDialog::FullResSelector::fillComboBox(const QSize &sourceSize, const std::vector &resVector) { +void VideoDialog::FullResSelector::fillComboBox( + QSize const &sourceSize, std::vector const &resVector) { long maxArea = 0; std::size_t maxAreaI = 0; for (std::size_t i = 0; i < resVector.size(); ++i) { - const int hres = resVector[i].w; - const int vres = resVector[i].h; + int const hres = resVector[i].w; + int const vres = resVector[i].h; if (hres >= sourceSize.width() && vres >= sourceSize.height()) { - comboBox_->addItem(QString::number(hres) + QString("x") + QString::number(vres), static_cast(i)); + comboBox_->addItem(QString::number(hres) + QString("x") + QString::number(vres), + static_cast(i)); } else { - const long area = static_cast(std::min(hres, sourceSize.width())) * std::min(vres, sourceSize.height()); - + long area = long(std::min(hres, sourceSize.width())) + * std::min(vres, sourceSize.height()); if (area > maxArea) { maxArea = area; maxAreaI = i; @@ -212,100 +233,104 @@ void VideoDialog::FullResSelector::fillComboBox(const QSize &sourceSize, const s } } - //add resolution giving maximal area if all resolutions are too small. - if (comboBox_->count() < 1 && maxArea) - comboBox_->addItem(QString::number(resVector[maxAreaI].w) + "x" + QString::number(resVector[maxAreaI].h), static_cast(maxAreaI)); + // add resolution giving maximal area if all resolutions are too small. + if (comboBox_->count() < 1 && maxArea) { + comboBox_->addItem(QString::number(resVector[maxAreaI].w) + + "x" + QString::number(resVector[maxAreaI].h), + static_cast(maxAreaI)); + } } -VideoDialog::FullHzSelector::FullHzSelector(const QString &key, const std::vector &rates, const int defaultIndex) -: comboBox_(new QComboBox), key_(key), index_(0) -{ - setRates(rates); +class VideoDialog::FullHzSelector { +public: + ~FullHzSelector(); + QWidget * widget() const { return comboBox_; } + QComboBox const * comboBox() const { return comboBox_; } + void store() { index_ = comboBox_->currentIndex(); } + void restore() { comboBox_->setCurrentIndex(index_); } + void setRates(std::vector const &rates); + int index() const { return index_; } - index_ = filterValue( - comboBox_->findText(QSettings().value(key).toString()), - comboBox_->count(), - 0, - defaultIndex); + static auto_vector createSelectors( + auto_vector const &fullResSelectors, + MainWindow const &mw) + { + auto_vector v(fullResSelectors.size()); + for (std::size_t i = 0; i < v.size(); ++i) { + int const resindex = fullResSelectors[i]->comboBox()->currentIndex(); + std::vector const &rates = resindex >= 0 + ? mw.modeVector(i)[resindex].rates + : std::vector(); + int defaultRateIndex = resindex == static_cast(mw.currentResIndex(i)) + ? mw.currentRateIndex(i) + : 0; + v.reset(i, new FullHzSelector("video/hz" + QString::number(i), + rates, defaultRateIndex)); + } - restore(); -} + return v; + } + +private: + QComboBox *const comboBox_; + QString const key_; + int index_; + + FullHzSelector(QString const &key, + std::vector const &rates, + int const defaultIndex) + : comboBox_(new QComboBox) + , key_(key) + , index_(0) + { + setRates(rates); + index_ = filterValue(comboBox_->findText(QSettings().value(key).toString()), + comboBox_->count(), + 0, + defaultIndex); + restore(); + } +}; VideoDialog::FullHzSelector::~FullHzSelector() { QSettings settings; settings.setValue(key_, comboBox_->itemText(index_)); } -QWidget* VideoDialog::FullHzSelector::widget() { - return comboBox_; -} - -void VideoDialog::FullHzSelector::store() { - index_ = comboBox_->currentIndex(); -} - -void VideoDialog::FullHzSelector::restore() { - comboBox_->setCurrentIndex(index_); -} - -void VideoDialog::FullHzSelector::setRates(const std::vector &rates) { +void VideoDialog::FullHzSelector::setRates(std::vector const &rates) { comboBox_->clear(); - - for (std::size_t i = 0; i < rates.size(); ++i) - comboBox_->addItem(QString::number(rates[i] / 10.0) + QString(" Hz"), static_cast(i)); -} - -auto_vector VideoDialog::makeFullResSelectors( - const QSize &sourceSize, const MainWindow *const mw) -{ - auto_vector v(mw->screens()); - for (std::size_t i = 0; i < v.size(); ++i) { - v.reset(i, new FullResSelector("video/fullRes" + QString::number(i), - mw->currentResIndex(i), sourceSize, - mw->modeVector(i))); + for (std::size_t i = 0; i < rates.size(); ++i) { + comboBox_->addItem(QString::number(rates[i] / 10.0) + QString(" Hz"), + static_cast(i)); } - - return v; } -auto_vector VideoDialog::makeFullHzSelectors( - const auto_vector &fullResSelectors, const MainWindow *const mw) -{ - auto_vector v(fullResSelectors.size()); - for (std::size_t i = 0; i < v.size(); ++i) { - const int index = fullResSelectors[i]->comboBox()->currentIndex(); - v.reset(i, new FullHzSelector("video/hz" + QString::number(i), - index >= 0 ? mw->modeVector(i)[index].rates : std::vector(), - index == static_cast(mw->currentResIndex(i)) ? mw->currentRateIndex(i) : 0)); - } - - return v; -} - -VideoDialog::VideoDialog(const MainWindow *const mw, - const std::vector &sourceInfos, - const QString &sourcesLabel, +VideoDialog::VideoDialog(MainWindow const &mw, + std::vector const &sourceInfos, + QString const &sourcesLabel, QWidget *parent) -: QDialog(parent), - mw(mw), - topLayout(new QVBoxLayout), - engineWidget(0), - engineSelector(mw), - sourceSelector(sourcesLabel, sourceInfos), - fullResSelectors(makeFullResSelectors(sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize(), mw)), - fullHzSelectors(makeFullHzSelectors(fullResSelectors, mw)) +: QDialog(parent) +, mw_(mw) +, topLayout(new QVBoxLayout) +, engineWidget(0) +, engineSelector(mw) +, sourceSelector(sourcesLabel, sourceInfos) +, fullResSelectors(FullResSelector::createSelectors( + sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize(), + mw)) +, fullHzSelectors(FullHzSelector::createSelectors(fullResSelectors, mw)) { QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); engineSelector.addToLayout(topLayout); - if ((engineWidget = mw->blitterConf(engineSelector.comboBox()->currentIndex()).settingsWidget())) + if ((engineWidget = mw.blitterConf(engineSelector.comboBox()->currentIndex()).settingsWidget())) topLayout->addWidget(engineWidget); for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { QHBoxLayout *const hLayout = new QHBoxLayout; - QLabel *const label = new QLabel("Full screen mode (" + mw->screenName(i) + "):"); + QLabel *const label = new QLabel("Full screen mode (" + mw.screenName(i) + "):"); hLayout->addWidget(label); QHBoxLayout *const hhLayout = new QHBoxLayout; @@ -314,7 +339,7 @@ VideoDialog::VideoDialog(const MainWindow *const mw, hLayout->addLayout(hhLayout); topLayout->addLayout(hLayout); - if (mw->modeVector(i).empty()) { + if (mw.modeVector(i).empty()) { label->hide(); fullResSelectors[i]->widget()->hide(); fullHzSelectors[i]->widget()->hide(); @@ -339,7 +364,8 @@ VideoDialog::VideoDialog(const MainWindow *const mw, connect(engineSelector.comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(engineChange(int))); for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { - connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(fullresChange(int))); + connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), + this, SLOT(fullresChange(int))); } connect(sourceSelector.comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(sourceChange(int))); @@ -349,27 +375,31 @@ VideoDialog::VideoDialog(const MainWindow *const mw, setWindowTitle(tr("Video Settings")); } +VideoDialog::~VideoDialog() { +} + void VideoDialog::fillFullResSelectors() { - const QSize &sourceSize = sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize(); - + QSize const &sourceSize = + sourceSelector.comboBox()->itemData(sourceSelector.comboBox()->currentIndex()).toSize(); for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { - const int oldResIndex = fullResSelectors[i]->comboBox()->currentIndex(); + int const oldResIndex = fullResSelectors[i]->comboBox()->currentIndex(); - disconnect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(fullresChange(int))); - fullResSelectors[i]->setSourceSize(sourceSize, mw->modeVector(i)); - connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), this, SLOT(fullresChange(int))); + disconnect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), + this, SLOT(fullresChange(int))); + fullResSelectors[i]->setSourceSize(sourceSize, mw_.modeVector(i)); + connect(fullResSelectors[i]->comboBox(), SIGNAL(currentIndexChanged(int)), + this, SLOT(fullresChange(int))); - const int newResIndex = fullResSelectors[i]->comboBox()->currentIndex(); - - if (newResIndex != oldResIndex) - fullHzSelectors[i]->setRates(newResIndex >= 0 ? mw->modeVector(i)[newResIndex].rates : std::vector()); + int const newResIndex = fullResSelectors[i]->comboBox()->currentIndex(); + if (newResIndex != oldResIndex) { + fullHzSelectors[i]->setRates(newResIndex >= 0 + ? mw_.modeVector(i)[newResIndex].rates + : std::vector()); + } } } void VideoDialog::store() { -// for (std::size_t i = 0; i < mw->numBlitters(); ++i) -// mw->blitterConf(i).acceptSettings(); - engineSelector.store(); scalingMethodSelector.store(); sourceSelector.store(); @@ -378,8 +408,8 @@ void VideoDialog::store() { } void VideoDialog::restore() { - for (std::size_t i = 0; i < mw->numBlitters(); ++i) - mw->blitterConf(i).rejectSettings(); + for (std::size_t i = 0; i < mw_.numBlitters(); ++i) + mw_.blitterConf(i).rejectSettings(); engineSelector.restore(); scalingMethodSelector.restore(); @@ -394,14 +424,16 @@ void VideoDialog::engineChange(int index) { engineWidget->setParent(0); } - if ((engineWidget = mw->blitterConf(index).settingsWidget())) + if ((engineWidget = mw_.blitterConf(index).settingsWidget())) topLayout->insertWidget(1, engineWidget); } -void VideoDialog::fullresChange(const int index) { +void VideoDialog::fullresChange(int const index) { for (std::size_t i = 0; i < fullResSelectors.size(); ++i) { if (sender() == fullResSelectors[i]->comboBox()) { - fullHzSelectors[i]->setRates(index >= 0 ? mw->modeVector(i)[index].rates : std::vector()); + fullHzSelectors[i]->setRates(index >= 0 + ? mw_.modeVector(i)[index].rates + : std::vector()); break; } } @@ -447,22 +479,21 @@ void VideoDialog::reject() { QDialog::reject(); } -void applySettings(MainWindow *const mw, const VideoDialog *const vd) { +void applySettings(MainWindow &mw, VideoDialog const &vd) { { - const BlitterConf curBlitter = mw->currentBlitterConf(); - - for (std::size_t i = 0; i < mw->numBlitters(); ++i) { - if (mw->blitterConf(i) != curBlitter) - mw->blitterConf(i).acceptSettings(); + BlitterConf const curBlitter = mw.currentBlitterConf(); + for (std::size_t i = 0; i < mw.numBlitters(); ++i) { + if (mw.blitterConf(i) != curBlitter) + mw.blitterConf(i).acceptSettings(); } - const QSize &srcSz = vd->sourceSize(); - mw->setVideoFormatAndBlitter(srcSz.width(), srcSz.height(), vd->blitterNo()); + QSize const srcSz = vd.sourceSize(); + mw.setVideoFormatAndBlitter(srcSz.width(), srcSz.height(), vd.blitterNo()); curBlitter.acceptSettings(); } - mw->setScalingMethod(vd->scalingMethod()); + mw.setScalingMethod(vd.scalingMethod()); - for (std::size_t i = 0; i < mw->screens(); ++i) - mw->setFullScreenMode(i, vd->fullResIndex(i), vd->fullRateIndex(i)); + for (std::size_t i = 0; i < mw.screens(); ++i) + mw.setFullScreenMode(i, vd.fullResIndex(i), vd.fullRateIndex(i)); } diff --git a/gambatte_qt/src/gambattemenuhandler.cpp b/gambatte_qt/src/gambattemenuhandler.cpp index 3cea94e3..8bddd954 100644 --- a/gambatte_qt/src/gambattemenuhandler.cpp +++ b/gambatte_qt/src/gambattemenuhandler.cpp @@ -38,17 +38,17 @@ static QString const strippedName(QString const &fullFileName) { } struct TmpPauser : private Uncopyable { - MainWindow *const mw; + MainWindow &mw; unsigned const inc; - explicit TmpPauser(MainWindow *mw, unsigned inc = 4) + explicit TmpPauser(MainWindow &mw, unsigned inc = 4) : mw(mw), inc(inc) { - mw->incPause(inc); + mw.incPause(inc); } ~TmpPauser() { - mw->decPause(inc); + mw.decPause(inc); } }; @@ -272,16 +272,17 @@ static void printUsage(char const *const arg0, QList const &actions) } } -GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, - GambatteSource *const source, +GambatteMenuHandler::GambatteMenuHandler(MainWindow &mw, + GambatteSource &source, int const argc, char const *const argv[]) : mw_(mw) , source_(source) -, soundDialog_(new SoundDialog(mw, mw)) -, videoDialog_(new VideoDialog(mw, source->generateVideoSourceInfos(), QString("Video filter:"), mw)) -, miscDialog_(new MiscDialog(settingsPath() + "/saves", mw)) -, cheatDialog_(new CheatDialog(settingsPath() + "/cheats.ini", mw)) +, soundDialog_(new SoundDialog(mw, &mw)) +, videoDialog_(new VideoDialog(mw, source.generateVideoSourceInfos(), + QString("Video filter:"), &mw)) +, miscDialog_(new MiscDialog(settingsPath() + "/saves", &mw)) +, cheatDialog_(new CheatDialog(settingsPath() + "/cheats.ini", &mw)) , recentFileActs_() , pauseAction_() , syncFrameRateAction_() @@ -291,35 +292,35 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, , recentMenu_() , globalPaletteDialog_() , romPaletteDialog_() -, stateSlotGroup_(new QActionGroup(mw)) -, windowSizeMenu_(*mw, *videoDialog_) +, stateSlotGroup_(new QActionGroup(&mw)) +, windowSizeMenu_(mw, *videoDialog_) , pauseInc_(4) { - mw->setWindowTitle("Gambatte"); - source->inputDialog()->setParent(mw, source->inputDialog()->windowFlags()); + mw.setWindowTitle("Gambatte"); + source.inputDialog()->setParent(&mw, source.inputDialog()->windowFlags()); { QString const &settingspath = settingsPath(); QString const &palpath = settingspath + "/palettes"; QDir::root().mkpath(settingspath + "/saves"); QDir::root().mkpath(palpath); - globalPaletteDialog_ = new PaletteDialog(palpath, 0, mw); - romPaletteDialog_ = new PaletteDialog(palpath, globalPaletteDialog_, mw); + globalPaletteDialog_ = new PaletteDialog(palpath, 0, &mw); + romPaletteDialog_ = new PaletteDialog(palpath, globalPaletteDialog_, &mw); connect(globalPaletteDialog_, SIGNAL(accepted()), this, SLOT(globalPaletteChange())); connect(romPaletteDialog_, SIGNAL(accepted()), this, SLOT(romPaletteChange())); } - QActionGroup *const romLoadedActions = new QActionGroup(mw); + QActionGroup *const romLoadedActions = new QActionGroup(&mw); romLoadedActions->setExclusive(false); { for (int i = 0; i < max_recent_files; ++i) { - recentFileActs_[i] = new QAction(mw); + recentFileActs_[i] = new QAction(&mw); recentFileActs_[i]->setVisible(false); connect(recentFileActs_[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); } - QMenu *fileMenu = mw->menuBar()->addMenu(tr("&File")); + QMenu *fileMenu = mw.menuBar()->addMenu(tr("&File")); fileMenu->addAction(tr("&Open..."), this, SLOT(open()), tr("Ctrl+O")); recentMenu_ = fileMenu->addMenu(tr("Open Re¢")); @@ -362,11 +363,11 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, updateRecentFileActions(); } - FrameRateAdjuster *const frameRateAdjuster = new FrameRateAdjuster(*miscDialog_, *mw, this); + FrameRateAdjuster *const frameRateAdjuster = new FrameRateAdjuster(*miscDialog_, mw, this); QList cmdactions; { - QMenu *const playm = mw->menuBar()->addMenu(tr("&Play")); + QMenu *const playm = mw.menuBar()->addMenu(tr("&Play")); romLoadedActions->addAction(pauseAction_ = playm->addAction( tr("&Pause"), this, SLOT(pauseChange()), QString("Ctrl+P"))); pauseAction_->setCheckable(true); @@ -378,7 +379,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, connect(syncFrameRateAction_, SIGNAL(triggered(bool)), frameRateAdjuster, SLOT(setDisabled(bool))); connect(syncFrameRateAction_, SIGNAL(triggered(bool)), - mw, SLOT(setSyncToRefreshRate(bool))); + &mw, SLOT(setSyncToRefreshRate(bool))); foreach (QAction *action, frameRateAdjuster->actions()) playm->addAction(romLoadedActions->addAction(action)); @@ -386,7 +387,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, cmdactions += playm->actions(); } - QMenu *const settingsm = mw->menuBar()->addMenu(tr("&Settings")); + QMenu *const settingsm = mw.menuBar()->addMenu(tr("&Settings")); settingsm->addAction(tr("&Input..."), this, SLOT(execInputDialog())); settingsm->addAction(tr("&Miscellaneous..."), this, SLOT(execMiscDialog())); settingsm->addAction(tr("&Sound..."), this, SLOT(execSoundDialog())); @@ -414,47 +415,47 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, fsAct_->setCheckable(true); cmdactions += settingsm->actions(); - romLoadedActions->addAction(mw->menuBar()->addMenu(tr("&Tools"))->addAction(tr("&Cheats..."), + romLoadedActions->addAction(mw.menuBar()->addMenu(tr("&Tools"))->addAction(tr("&Cheats..."), cheatDialog_, SLOT(exec()))); romLoadedActions->setEnabled(false); - mw->menuBar()->addSeparator(); + mw.menuBar()->addSeparator(); - QMenu *const helpMenu = mw->menuBar()->addMenu(tr("&Help")); + QMenu *const helpMenu = mw.menuBar()->addMenu(tr("&Help")); helpMenu->addAction(tr("&About"), this, SLOT(about())); - mw->addActions(mw->menuBar()->actions()); + mw.addActions(mw.menuBar()->actions()); { - QAction *escAct = new QAction(mw); + QAction *escAct = new QAction(&mw); escAct->setShortcut(tr("Esc")); connect(escAct, SIGNAL(triggered()), this, SLOT(escPressed())); - mw->addAction(escAct); + mw.addAction(escAct); } - mw->setSamplesPerFrame(35112); - connect(source, SIGNAL(setTurbo(bool)), mw, SLOT(setFastForward(bool))); - connect(source, SIGNAL(togglePause()), pauseAction_, SLOT(trigger())); - connect(source, SIGNAL(frameStep()), this, SLOT(frameStep())); - connect(source, SIGNAL(decFrameRate()), frameRateAdjuster, SLOT(decFrameRate())); - connect(source, SIGNAL(incFrameRate()), frameRateAdjuster, SLOT(incFrameRate())); - connect(source, SIGNAL(resetFrameRate()), frameRateAdjuster, SLOT(resetFrameRate())); - connect(source, SIGNAL(prevStateSlot()), this, SLOT(prevStateSlot())); - connect(source, SIGNAL(nextStateSlot()), this, SLOT(nextStateSlot())); - connect(source, SIGNAL(saveStateSignal()), this, SLOT(saveState())); - connect(source, SIGNAL(loadStateSignal()), this, SLOT(loadState())); - connect(source, SIGNAL(quit()), qApp, SLOT(closeAllWindows())); + mw.setSamplesPerFrame(35112); + connect(&source, SIGNAL(setTurbo(bool)), &mw, SLOT(setFastForward(bool))); + connect(&source, SIGNAL(togglePause()), pauseAction_, SLOT(trigger())); + connect(&source, SIGNAL(frameStep()), this, SLOT(frameStep())); + connect(&source, SIGNAL(decFrameRate()), frameRateAdjuster, SLOT(decFrameRate())); + connect(&source, SIGNAL(incFrameRate()), frameRateAdjuster, SLOT(incFrameRate())); + connect(&source, SIGNAL(resetFrameRate()), frameRateAdjuster, SLOT(resetFrameRate())); + connect(&source, SIGNAL(prevStateSlot()), this, SLOT(prevStateSlot())); + connect(&source, SIGNAL(nextStateSlot()), this, SLOT(nextStateSlot())); + connect(&source, SIGNAL(saveStateSignal()), this, SLOT(saveState())); + connect(&source, SIGNAL(loadStateSignal()), this, SLOT(loadState())); + connect(&source, SIGNAL(quit()), qApp, SLOT(closeAllWindows())); connect(videoDialog_, SIGNAL(accepted()), this, SLOT(videoDialogChange())); connect(soundDialog_, SIGNAL(accepted()), this, SLOT(soundDialogChange())); connect(miscDialog_, SIGNAL(accepted()), this, SLOT(miscDialogChange())); connect(cheatDialog_, SIGNAL(accepted()), this, SLOT(cheatDialogChange())); - connect(mw, SIGNAL(videoBlitterFailure()), this, SLOT(videoBlitterFailure())); - connect(mw, SIGNAL(audioEngineFailure()), this, SLOT(audioEngineFailure())); - connect(mw, SIGNAL(closing()), this, SLOT(saveWindowSizeIfNotFullScreen())); - connect(mw, SIGNAL(dwmCompositionChange()), this, SLOT(reconsiderSyncFrameRateActionEnable())); + connect(&mw, SIGNAL(videoBlitterFailure()), this, SLOT(videoBlitterFailure())); + connect(&mw, SIGNAL(audioEngineFailure()), this, SLOT(audioEngineFailure())); + connect(&mw, SIGNAL(closing()), this, SLOT(saveWindowSizeIfNotFullScreen())); + connect(&mw, SIGNAL(dwmCompositionChange()), this, SLOT(reconsiderSyncFrameRateActionEnable())); connect(this, SIGNAL(romLoaded(bool)), romLoadedActions, SLOT(setEnabled(bool))); connect(this, SIGNAL(romLoaded(bool)), stateSlotGroup_->actions().at(0), SLOT(setChecked(bool))); - mw->setAspectRatio(QSize(160, 144)); + mw.setAspectRatio(QSize(160, 144)); videoDialogChange(); soundDialogChange(); miscDialogChange(); @@ -481,7 +482,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, for (int i = 1; i < argc; ++i) { if (argv[i][0] != '-') { if (fsAct_->isChecked()) - mw->menuBar()->hide(); + mw.menuBar()->hide(); loadFile(QFileInfo(QString(argv[i])).absoluteFilePath()); break; @@ -529,66 +530,66 @@ void GambatteMenuHandler::loadFile(QString const &fileName) { TmpPauser tmpPauser(mw_, 4); pauseAction_->setChecked(false); pauseChange(); - mw_->waitUntilPaused(); + mw_.waitUntilPaused(); if (gambatte::LoadRes const error = - source_->load(fileName.toLocal8Bit().constData(), - gbaCgbAction_->isChecked() * gambatte::GB::GBA_CGB - + forceDmgAction_->isChecked() * gambatte::GB::FORCE_DMG - + miscDialog_->multicartCompat() * gambatte::GB::MULTICART_COMPAT)) { - mw_->stop(); + source_.load(fileName.toLocal8Bit().constData(), + gbaCgbAction_->isChecked() * gambatte::GB::GBA_CGB + + forceDmgAction_->isChecked() * gambatte::GB::FORCE_DMG + + miscDialog_->multicartCompat() * gambatte::GB::MULTICART_COMPAT)) { + mw_.stop(); emit dmgRomLoaded(false); emit romLoaded(false); QMessageBox::critical( - mw_, + &mw_, tr("File Load Error"), tr("Failed to load file\n") + fileName + ".\n\n" + gambatte::to_string(error).c_str() + "."); return; } - QString const &romTitle = QString::fromStdString(source_->romTitle()).trimmed(); + QString const &romTitle = QString::fromStdString(source_.romTitle()).trimmed(); cheatDialog_->setGameName(romTitle.isEmpty() ? QFileInfo(fileName).completeBaseName() : romTitle); cheatDialogChange(); - if (!source_->isCgb()) { + if (!source_.isCgb()) { romPaletteDialog_->setSettingsFile( QFileInfo(fileName).completeBaseName() + ".pal", romTitle); setDmgPaletteColors(); } - gambatte::PakInfo const &pak = source_->pakInfo(); + gambatte::PakInfo const &pak = source_.pakInfo(); std::cout << romTitle.toStdString() << '\n' << "GamePak type: " << pak.mbc() << " rambanks: " << pak.rambanks() << " rombanks: " << pak.rombanks() << '\n' << "header checksum: " << (pak.headerChecksumOk() ? "ok" : "bad") << '\n' - << "cgb: " << source_->isCgb() << std::endl; + << "cgb: " << source_.isCgb() << std::endl; - mw_->setWindowTitle(strippedName(fileName) + (pak.headerChecksumOk() ? "" : " [bad]") + " - Gambatte"); + mw_.setWindowTitle(strippedName(fileName) + (pak.headerChecksumOk() ? "" : " [bad]") + " - Gambatte"); setCurrentFile(fileName); emit romLoaded(true); - emit dmgRomLoaded(!source_->isCgb()); + emit dmgRomLoaded(!source_.isCgb()); - mw_->resetAudio(); - mw_->run(); + mw_.resetAudio(); + mw_.run(); } void GambatteMenuHandler::open() { TmpPauser tmpPauser(mw_, 4); - mw_->waitUntilPaused(); + mw_.waitUntilPaused(); QString const &fileName = QFileDialog::getOpenFileName( - mw_, tr("Open"), recentFileActs_[0]->data().toString(), + &mw_, tr("Open"), recentFileActs_[0]->data().toString(), tr("Game Boy ROM Images (*.dmg *.gb *.gbc *.sgb *.zip *.gz);;All Files (*)")); if (!fileName.isEmpty()) loadFile(fileName); // giving back focus after getOpenFileName seems to fail at times, which // can be problematic with current exclusive mode handling. - mw_->setFocus(); + mw_.setFocus(); } void GambatteMenuHandler::openRecentFile() { @@ -599,7 +600,7 @@ void GambatteMenuHandler::openRecentFile() { void GambatteMenuHandler::about() { TmpPauser tmpPauser(mw_, pauseInc_); QMessageBox::about( - mw_, + &mw_, "About Gambatte", QString::fromUtf8( "

Gambatte Qt (git)

" @@ -631,18 +632,18 @@ void GambatteMenuHandler::romPaletteChange() { namespace { struct SetDmgPaletteColorFun { - GambatteSource *source; unsigned palnum; unsigned colornum; unsigned rgb32; - void operator()() const { source->setDmgPaletteColor(palnum, colornum, rgb32); } + GambatteSource &source; unsigned palnum; unsigned colornum; unsigned rgb32; + void operator()() const { source.setDmgPaletteColor(palnum, colornum, rgb32); } }; struct SetVideoSourceFun { - GambatteSource *source; unsigned sourceIndex; - void operator()() const { source->setVideoSource(sourceIndex); } + GambatteSource &source; unsigned sourceIndex; + void operator()() const { source.setVideoSource(sourceIndex); } }; struct SetSaveDirFun { - GambatteSource *source; QString path; - void operator()() const { source->setSavedir(path.toLocal8Bit().constData()); } + GambatteSource &source; QString path; + void operator()() const { source.setSavedir(path.toLocal8Bit().constData()); } }; } // anon ns @@ -652,31 +653,31 @@ void GambatteMenuHandler::setDmgPaletteColors() { for (unsigned colornum = 0; colornum < 4; ++colornum) { SetDmgPaletteColorFun fun = { source_, palnum, colornum, romPaletteDialog_->color(palnum, colornum) }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } } void GambatteMenuHandler::videoDialogChange() { { SetVideoSourceFun fun = { source_, videoDialog_->sourceIndex() }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } - applySettings(mw_, videoDialog_); + applySettings(mw_, *videoDialog_); windowSizeMenu_.videoDialogChange(*videoDialog_); reconsiderSyncFrameRateActionEnable(); } void GambatteMenuHandler::soundDialogChange() { - SoundDialog::applySettings(mw_, soundDialog_); + applySettings(mw_, *soundDialog_); } void GambatteMenuHandler::miscDialogChange() { SetSaveDirFun const setSaveDirFun = { source_, miscDialog_->savePath() }; - mw_->callInWorkerThread(setSaveDirFun); - mw_->setDwmTripleBuffer(miscDialog_->dwmTripleBuf()); - mw_->setFastForwardSpeed(miscDialog_->turboSpeed()); - mw_->setPauseOnFocusOut(miscDialog_->pauseOnFocusOut() ? 2 : 0); + mw_.callInWorkerThread(setSaveDirFun); + mw_.setDwmTripleBuffer(miscDialog_->dwmTripleBuf()); + mw_.setFastForwardSpeed(miscDialog_->turboSpeed()); + mw_.setPauseOnFocusOut(miscDialog_->pauseOnFocusOut() ? 2 : 0); pauseInc_ = miscDialog_->pauseOnDialogs() ? 4 : 0; } @@ -691,12 +692,12 @@ void GambatteMenuHandler::cheatDialogChange() { gameSharkCodes += s.toStdString() + ";"; } - source_->setGameGenie(gameGenieCodes); - source_->setGameShark(gameSharkCodes); + source_.setGameGenie(gameGenieCodes); + source_.setGameShark(gameSharkCodes); } void GambatteMenuHandler::reconsiderSyncFrameRateActionEnable() { - if (mw_->blitterConf(videoDialog_->blitterNo()).maxSwapInterval() + if (mw_.blitterConf(videoDialog_->blitterNo()).maxSwapInterval() && !MainWindow::isDwmCompositionEnabled()) { syncFrameRateAction_->setEnabled(true); } else { @@ -719,7 +720,7 @@ void GambatteMenuHandler::execRomPaletteDialog() { void GambatteMenuHandler::execInputDialog() { TmpPauser tmpPauser(mw_, pauseInc_); - source_->inputDialog()->exec(); + source_.inputDialog()->exec(); } void GambatteMenuHandler::execSoundDialog() { @@ -738,56 +739,56 @@ void GambatteMenuHandler::execMiscDialog() { } void GambatteMenuHandler::prevStateSlot() { - stateSlotGroup_->actions().at(source_->currentState() < 2 - ? source_->currentState() + 8 - : source_->currentState() - 2)->trigger(); + stateSlotGroup_->actions().at(source_.currentState() < 2 + ? source_.currentState() + 8 + : source_.currentState() - 2)->trigger(); } void GambatteMenuHandler::nextStateSlot() { - stateSlotGroup_->actions().at(source_->currentState())->trigger(); + stateSlotGroup_->actions().at(source_.currentState())->trigger(); } namespace { struct SelectStateFun { - GambatteSource *source; int i; - void operator()() const { source->selectState(i); } + GambatteSource &source; int i; + void operator()() const { source.selectState(i); } }; struct SaveStateFun { - GambatteSource *source; + GambatteSource &source; MainWindow::FrameBuffer fb; void operator()() const { - source->saveState(MainWindow::FrameBuffer::Locked(fb).get()); + source.saveState(MainWindow::FrameBuffer::Locked(fb).get()); } }; struct LoadStateFun { - GambatteSource *source; - void operator()() const { source->loadState(); } + GambatteSource &source; + void operator()() const { source.loadState(); } }; struct SaveStateAsFun { - GambatteSource *source; + GambatteSource &source; MainWindow::FrameBuffer fb; QString fileName; void operator()() const { - source->saveState(MainWindow::FrameBuffer::Locked(fb).get(), - fileName.toLocal8Bit().constData()); + source.saveState(MainWindow::FrameBuffer::Locked(fb).get(), + fileName.toLocal8Bit().constData()); } }; struct LoadStateFromFun { - GambatteSource *source; + GambatteSource &source; QString fileName; void operator()() const { - source->loadState(fileName.toLocal8Bit().constData()); + source.loadState(fileName.toLocal8Bit().constData()); } }; struct ResetFun { - GambatteSource *source; - void operator()() const { source->reset(); } + GambatteSource &source; + void operator()() const { source.reset(); } }; } // anon ns @@ -795,61 +796,61 @@ struct ResetFun { void GambatteMenuHandler::selectStateSlot() { if (QAction *action = stateSlotGroup_->checkedAction()) { SelectStateFun fun = { source_, action->data().toInt() }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } } void GambatteMenuHandler::saveState() { SaveStateFun fun = { source_, MainWindow::FrameBuffer(mw_) }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } void GambatteMenuHandler::loadState() { LoadStateFun fun = { source_ }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } void GambatteMenuHandler::saveStateAs() { TmpPauser tmpPauser(mw_, 4); - mw_->waitUntilPaused(); + mw_.waitUntilPaused(); QString const &fileName = QFileDialog::getSaveFileName( - mw_, tr("Save State"), QString(), + &mw_, tr("Save State"), QString(), tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); if (!fileName.isEmpty()) { SaveStateAsFun fun = { source_, MainWindow::FrameBuffer(mw_), fileName }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } } void GambatteMenuHandler::loadStateFrom() { TmpPauser tmpPauser(mw_, 4); - mw_->waitUntilPaused(); + mw_.waitUntilPaused(); QString const &fileName = QFileDialog::getOpenFileName( - mw_, tr("Load State"), QString(), + &mw_, tr("Load State"), QString(), tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); if (!fileName.isEmpty()) { LoadStateFromFun fun = { source_, fileName }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } } void GambatteMenuHandler::reset() { ResetFun fun = { source_ }; - mw_->callInWorkerThread(fun); + mw_.callInWorkerThread(fun); } void GambatteMenuHandler::pauseChange() { if (pauseAction_->isChecked()) - mw_->pause(); + mw_.pause(); else - mw_->unpause(); + mw_.unpause(); } void GambatteMenuHandler::frameStep() { if (pauseAction_->isChecked()) - mw_->frameStep(); + mw_.frameStep(); else pauseAction_->trigger(); } @@ -859,35 +860,35 @@ void GambatteMenuHandler::escPressed() { if (fsAct_->isChecked()) fsAct_->trigger(); #else - mw_->menuBar()->setVisible(!mw_->menuBar()->isVisible()); + mw_.menuBar()->setVisible(!mw_.menuBar()->isVisible()); - if (!mw_->menuBar()->isVisible()) - mw_->hideCursor(); + if (!mw_.menuBar()->isVisible()) + mw_.hideCursor(); #endif } void GambatteMenuHandler::videoBlitterFailure() { TmpPauser tmpPauser(mw_, pauseInc_); - QMessageBox::critical(mw_, tr("Video engine failure"), + QMessageBox::critical(&mw_, tr("Video engine failure"), tr("Failed to update video output. This may be fixed by changing the video engine settings.")); videoDialog_->exec(); } void GambatteMenuHandler::audioEngineFailure() { TmpPauser tmpPauser(mw_, pauseInc_); - QMessageBox::critical(mw_, tr("Sound engine failure"), + QMessageBox::critical(&mw_, tr("Sound engine failure"), tr("Failed to output audio. This may be fixed by changing the sound settings.")); soundDialog_->exec(); } void GambatteMenuHandler::toggleFullScreen() { saveWindowSizeIfNotFullScreen(); - mw_->toggleFullScreen(); + mw_.toggleFullScreen(); } void GambatteMenuHandler::saveWindowSizeIfNotFullScreen() { - if (!mw_->isFullScreen()) { + if (!mw_.isFullScreen()) { QSettings settings; - settings.setValue("mainwindow/size", mw_->size()); + settings.setValue("mainwindow/size", mw_.size()); } } diff --git a/gambatte_qt/src/gambattemenuhandler.h b/gambatte_qt/src/gambattemenuhandler.h index ee503c29..e61c6922 100644 --- a/gambatte_qt/src/gambattemenuhandler.h +++ b/gambatte_qt/src/gambattemenuhandler.h @@ -24,17 +24,17 @@ #include #include -class MainWindow; +class CheatDialog; class GambatteSource; -class QAction; +class MainWindow; +class MiscDialog; class PaletteDialog; -class QString; +class QAction; class QActionGroup; class QMenu; +class QString; class SoundDialog; class VideoDialog; -class MiscDialog; -class CheatDialog; class FrameRateAdjuster : public QObject { public: @@ -121,7 +121,7 @@ private slots: class GambatteMenuHandler : public QObject { public: - GambatteMenuHandler(MainWindow *mw, GambatteSource *source, + GambatteMenuHandler(MainWindow &mw, GambatteSource &source, int argc, char const *const argv[]); ~GambatteMenuHandler(); @@ -130,8 +130,8 @@ private: enum { max_recent_files = 9 }; - MainWindow *const mw_; - GambatteSource *const source_; + MainWindow &mw_; + GambatteSource &source_; SoundDialog *const soundDialog_; VideoDialog *const videoDialog_; MiscDialog *const miscDialog_; diff --git a/gambatte_qt/src/main.cpp b/gambatte_qt/src/main.cpp index ce8c952d..a99a8c04 100644 --- a/gambatte_qt/src/main.cpp +++ b/gambatte_qt/src/main.cpp @@ -28,8 +28,8 @@ int main(int argc, char *argv[]) { QCoreApplication::setApplicationName("gambatte_qt"); GambatteSource source; - MainWindow mw(&source); - GambatteMenuHandler mh(&mw, &source, argc, argv); + MainWindow mw(source); + GambatteMenuHandler mh(mw, source, argc, argv); mw.show(); return app.exec(); }