You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.5 KiB
95 lines
2.5 KiB
3 years ago
|
/*
|
||
|
Copyright 2020-2021 Brad Parker
|
||
|
|
||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
|
|
||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License.
|
||
|
*/
|
||
|
|
||
|
#ifndef __MAINWINDOW_H_
|
||
|
#define __MAINWINDOW_H_
|
||
|
#include <QOpenGLWidget>
|
||
|
#include <QQueue>
|
||
|
#include <QOpenGLFunctions>
|
||
|
#include <QSettings>
|
||
|
|
||
|
#ifndef NO_SOUND
|
||
|
#include <QAudio>
|
||
|
|
||
|
class QAudioOutput;
|
||
|
class QAudioFormat;
|
||
|
#endif
|
||
|
|
||
|
class Core;
|
||
|
class QPaintEvent;
|
||
|
class QCloseEvent;
|
||
|
class QKeyEvent;
|
||
|
class QMouseEvent;
|
||
|
class QOpenGLFramebufferObject;
|
||
|
class CoreOptionsDialog;
|
||
|
|
||
|
// you will have no vsync when just using a QMainWindow instead of a QOpenGLWidget
|
||
|
class MainWindow : public QOpenGLWidget, protected QOpenGLFunctions {
|
||
|
Q_OBJECT
|
||
|
public:
|
||
|
MainWindow(QWidget *parent = nullptr);
|
||
|
~MainWindow();
|
||
|
void setCorePath(QString path);
|
||
|
void setCoreMuted(bool on);
|
||
|
void setROMPath(QString path);
|
||
|
void setFullScreen(bool on);
|
||
|
static MainWindow* instance();
|
||
|
void openCoreOptionsDialog();
|
||
|
signals:
|
||
|
void audioStreamReady();
|
||
|
public slots:
|
||
|
void loadCore();
|
||
|
void loadContent();
|
||
|
void onAudioSample(int16_t left, int16_t right);
|
||
|
void onAudioSampleBatch(const int16_t *data, size_t frames);
|
||
|
void go();
|
||
|
void saveState();
|
||
|
void loadState();
|
||
|
void saveCoreOptions();
|
||
|
private slots:
|
||
|
#ifndef NO_SOUND
|
||
|
void startAudio(QAudioFormat *format);
|
||
|
void audioStateChanged(QAudio::State state);
|
||
|
#endif
|
||
|
void onCoreOptionsChanged();
|
||
|
|
||
|
private:
|
||
|
Core *m_core;
|
||
|
#ifndef NO_SOUND
|
||
|
QAudioOutput *m_audioOutput;
|
||
|
#endif
|
||
|
bool m_audioReady;
|
||
|
QIODevice *m_audioStream;
|
||
|
QString m_corePath;
|
||
|
QString m_romPath;
|
||
|
CoreOptionsDialog *m_coreOptionsDialog;
|
||
|
QSettings m_settings;
|
||
|
|
||
|
protected:
|
||
|
void paintEvent(QPaintEvent *e) override;
|
||
|
void keyPressEvent(QKeyEvent *e) override;
|
||
|
void keyReleaseEvent(QKeyEvent *e) override;
|
||
|
void mouseMoveEvent(QMouseEvent *e) override;
|
||
|
void mousePressEvent(QMouseEvent *e) override;
|
||
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||
|
void closeEvent(QCloseEvent *e) override;
|
||
|
// the base GL function implementations actually do nothing
|
||
|
void initializeGL() override;
|
||
|
void paintGL() override;
|
||
|
void resizeGL(int w, int h) override;
|
||
|
};
|
||
|
#endif // __MAINWINDOW_H_
|