Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI stuff #333

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ set(RENDERER_SW_SOURCE_FILES src/core/renderer_sw/renderer_sw.cpp)

# Frontend source files
if(ENABLE_QT_GUI)
set(FRONTEND_SOURCE_FILES src/panda_qt/main.cpp src/panda_qt/screen.cpp src/panda_qt/main_window.cpp)
set(FRONTEND_HEADER_FILES include/panda_qt/screen.hpp include/panda_qt/main_window.hpp)
set(FRONTEND_SOURCE_FILES src/panda_qt/main.cpp src/panda_qt/screen.cpp src/panda_qt/main_window.cpp src/panda_qt/about_window.cpp)
set(FRONTEND_HEADER_FILES include/panda_qt/screen.hpp include/panda_qt/main_window.hpp include/panda_qt/about_window.hpp)

source_group("Source Files\\Qt" FILES ${FRONTEND_SOURCE_FILES})
source_group("Header Files\\Qt" FILES ${FRONTEND_HEADER_FILES})
Expand Down Expand Up @@ -429,7 +429,7 @@ if(ENABLE_QT_GUI)
qt_add_resources(Alber "app_images"
PREFIX "/"
FILES
docs/img/rsob_icon.png
docs/img/rsob_icon.png docs/img/rstarstruck_icon.png
)
else()
target_compile_definitions(Alber PUBLIC "PANDA3DS_FRONTEND_SDL=1")
Expand Down
Binary file added docs/img/rstarstruck_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions include/emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ class Emulator {
// We bind gyro to right click + mouse movement
bool holdingRightClick = false;

public:
static constexpr u32 width = 400;
static constexpr u32 height = 240 * 2; // * 2 because 2 screens
ROMType romType = ROMType::None;
bool running = false; // Is the emulator running a game?
bool programRunning = false; // Is the emulator program itself running?

private:
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
HttpServer httpServer;
friend struct HttpServer;
Expand Down
12 changes: 12 additions & 0 deletions include/panda_qt/about_window.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <QApplication>
#include <QDialog>
#include <QWidget>

class AboutWindow : public QDialog {
Q_OBJECT

public:
AboutWindow(QWidget* parent = nullptr);
};
38 changes: 34 additions & 4 deletions include/panda_qt/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#include <filesystem>
#include <mutex>
#include <thread>
#include <vector>

#include "emulator.hpp"
#include "panda_qt/about_window.hpp"
#include "panda_qt/screen.hpp"
#include "services/hid.hpp"

class MainWindow : public QMainWindow {
Q_OBJECT
Expand All @@ -21,19 +24,40 @@ class MainWindow : public QMainWindow {
System = 0,
Light = 1,
Dark = 2,
GreetingsCat = 3,
};

// Types of messages we might send from the GUI thread to the emulator thread
enum class MessageType {
LoadROM, Reset, Pause, Resume, TogglePause, DumpRomFS, PressKey, ReleaseKey
};

// Tagged union representing our message queue messages
struct EmulatorMessage {
MessageType type;

union {
struct {
std::filesystem::path* p;
} path;

struct {
u32 key;
} key;
};
};

// This would normally be an std::unique_ptr but it's shared between threads so definitely not
Emulator* emu = nullptr;
std::thread emuThread;

std::atomic<bool> appRunning = true; // Is the application itself running?
std::mutex messageQueueMutex; // Used for synchronizing messages between the emulator and UI
std::filesystem::path romToLoad = "";

bool needToLoadROM = false;
// Used for synchronizing messages between the emulator and UI
std::mutex messageQueueMutex;
std::vector<EmulatorMessage> messageQueue;

ScreenWidget screen;
AboutWindow* aboutWindow;
QComboBox* themeSelect = nullptr;
QMenuBar* menuBar = nullptr;

Expand All @@ -43,6 +67,9 @@ class MainWindow : public QMainWindow {
void emuThreadMainLoop();
void selectROM();
void dumpRomFS();
void showAboutMenu();
void sendMessage(const EmulatorMessage& message);
void dispatchMessage(const EmulatorMessage& message);

// Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer
bool usingGL = false;
Expand All @@ -51,4 +78,7 @@ class MainWindow : public QMainWindow {
public:
MainWindow(QApplication* app, QWidget* parent = nullptr);
~MainWindow();

void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
};
62 changes: 62 additions & 0 deletions src/panda_qt/about_window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "panda_qt/about_window.hpp"

#include <QLabel>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QtGlobal>

// Based on https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/DolphinQt/AboutDialog.cpp

AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) {
resize(200, 200);

setWindowTitle(tr("About Panda3DS"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);

const QString text =
QStringLiteral(R"(
<p style='font-size:38pt; font-weight:400;'>Panda3DS</p>

<p>
%ABOUT_PANDA3DS%<br>
<a href='https://panda3ds.com/'>%SUPPORT%</a><br>
</p>

<p>
<a>%AUTHORS%</a>
</p>
)")
.replace(QStringLiteral("%ABOUT_PANDA3DS%"), tr("Panda3DS is a free and open source Nintendo 3DS emulator, for Windows, MacOS and Linux"))
.replace(QStringLiteral("%SUPPORT%"), tr("Visit panda3ds.com for help with Panda3DS and links to our official support sites."))
.replace(
QStringLiteral("%AUTHORS%"), tr("Panda3DS is developed by volunteers in their spare time. Below is a list of some of these"
" volunteers who've agreed to be listed here, in no particular order.<br>If you think you should be "
"listed here too, please inform us<br><br>"
"- Peach (wheremyfoodat)<br>"
"- noumidev<br>"
"- liuk707<br>"
"- Wunk<br>"
"- marysaka<br>"
"- Sky<br>"
"- merryhime<br>"
"- TGP17<br>")
);

QLabel* textLabel = new QLabel(text);
textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
textLabel->setOpenExternalLinks(true);

QLabel* logo = new QLabel();
logo->setPixmap(QPixmap(":/docs/img/rstarstruck_icon.png"));
logo->setContentsMargins(30, 0, 30, 0);

QVBoxLayout* mainLayout = new QVBoxLayout;
QHBoxLayout* hLayout = new QHBoxLayout;

setLayout(mainLayout);
mainLayout->addLayout(hLayout);

hLayout->setAlignment(Qt::AlignLeft);
hLayout->addWidget(logo);
hLayout->addWidget(textLabel);
}
Loading
Loading