mirror of https://github.com/snes9xgit/snes9x.git
UI element resize without canvas recreate. Capture slot by value when loading/saving states.
This commit is contained in:
parent
61bafc329d
commit
8bb1e7747d
|
@ -82,19 +82,19 @@ DisplayPanel::DisplayPanel(EmuApplication *app_)
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(comboBox_messages, &QComboBox::currentIndexChanged, [&](int index) {
|
QObject::connect(comboBox_messages, &QComboBox::currentIndexChanged, [&](int index) {
|
||||||
bool restart = (app->config->display_messages == EmuConfig::eOnscreen || index == EmuConfig::eOnscreen);
|
bool recreate = (app->config->display_messages == EmuConfig::eOnscreen || index == EmuConfig::eOnscreen);
|
||||||
|
|
||||||
app->config->display_messages = index;
|
app->config->display_messages = index;
|
||||||
app->updateSettings();
|
app->updateSettings();
|
||||||
if (restart)
|
if (recreate)
|
||||||
app->window->recreateCanvas();
|
app->window->recreateUIAssets();
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(spinBox_osd_size, &QSpinBox::valueChanged, [&](int value) {
|
QObject::connect(spinBox_osd_size, &QSpinBox::valueChanged, [&](int value) {
|
||||||
bool restart = (app->config->osd_size != value && app->config->display_messages == EmuConfig::eOnscreen);
|
bool recreate = (app->config->osd_size != value && app->config->display_messages == EmuConfig::eOnscreen);
|
||||||
app->config->osd_size = value;
|
app->config->osd_size = value;
|
||||||
if (restart)
|
if (recreate)
|
||||||
app->window->recreateCanvas();
|
app->window->recreateUIAssets();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -460,28 +460,28 @@ void EmuApplication::startInputTimer()
|
||||||
|
|
||||||
void EmuApplication::loadState(int slot)
|
void EmuApplication::loadState(int slot)
|
||||||
{
|
{
|
||||||
emu_thread->runOnThread([&] {
|
emu_thread->runOnThread([&, slot] {
|
||||||
core->loadState(slot);
|
core->loadState(slot);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuApplication::loadState(std::string filename)
|
void EmuApplication::loadState(std::string filename)
|
||||||
{
|
{
|
||||||
emu_thread->runOnThread([&] {
|
emu_thread->runOnThread([&, filename] {
|
||||||
core->loadState(filename);
|
core->loadState(filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuApplication::saveState(int slot)
|
void EmuApplication::saveState(int slot)
|
||||||
{
|
{
|
||||||
emu_thread->runOnThread([&] {
|
emu_thread->runOnThread([&, slot] {
|
||||||
core->saveState(slot);
|
core->saveState(slot);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuApplication::saveState(std::string filename)
|
void EmuApplication::saveState(std::string filename)
|
||||||
{
|
{
|
||||||
emu_thread->runOnThread([&] {
|
emu_thread->runOnThread([&, filename] {
|
||||||
core->saveState(filename);
|
core->saveState(filename);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ class EmuCanvas : public QWidget
|
||||||
virtual void draw() = 0;
|
virtual void draw() = 0;
|
||||||
void paintEvent(QPaintEvent *) override = 0;
|
void paintEvent(QPaintEvent *) override = 0;
|
||||||
virtual void createContext() {}
|
virtual void createContext() {}
|
||||||
|
virtual void recreateUIAssets() {}
|
||||||
void output(uint8_t *buffer, int width, int height, QImage::Format format, int bytes_per_line, double frame_rate);
|
void output(uint8_t *buffer, int width, int height, QImage::Format format, int bytes_per_line, double frame_rate);
|
||||||
void throttle();
|
void throttle();
|
||||||
void resizeEvent(QResizeEvent *event) override = 0;
|
void resizeEvent(QResizeEvent *event) override = 0;
|
||||||
|
|
|
@ -174,11 +174,7 @@ void EmuCanvasOpenGL::createContext()
|
||||||
|
|
||||||
if (config->display_messages == EmuConfig::eOnscreen)
|
if (config->display_messages == EmuConfig::eOnscreen)
|
||||||
{
|
{
|
||||||
auto defaults = S9xImGuiGetDefaults();
|
recreateUIAssets();
|
||||||
defaults.font_size = config->osd_size;
|
|
||||||
defaults.spacing = defaults.font_size / 2.4;
|
|
||||||
S9xImGuiInit(&defaults);
|
|
||||||
ImGui_ImplOpenGL3_Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadShaders();
|
loadShaders();
|
||||||
|
@ -382,4 +378,21 @@ void EmuCanvasOpenGL::saveParameters(std::string filename)
|
||||||
{
|
{
|
||||||
if (shader)
|
if (shader)
|
||||||
shader->save(filename.c_str());
|
shader->save(filename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmuCanvasOpenGL::recreateUIAssets()
|
||||||
|
{
|
||||||
|
if (S9xImGuiRunning())
|
||||||
|
{
|
||||||
|
S9xImGuiDeinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->display_messages != EmuConfig::eOnscreen)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto defaults = S9xImGuiGetDefaults();
|
||||||
|
defaults.font_size = config->osd_size;
|
||||||
|
defaults.spacing = defaults.font_size / 2.4;
|
||||||
|
S9xImGuiInit(&defaults);
|
||||||
|
ImGui_ImplOpenGL3_Init();
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ class EmuCanvasOpenGL : public EmuCanvas
|
||||||
void shaderChanged() override;
|
void shaderChanged() override;
|
||||||
void showParametersDialog() override;
|
void showParametersDialog() override;
|
||||||
void saveParameters(std::string filename) override;
|
void saveParameters(std::string filename) override;
|
||||||
|
void recreateUIAssets() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resizeTexture(int width, int height);
|
void resizeTexture(int width, int height);
|
||||||
|
|
|
@ -299,4 +299,21 @@ void EmuCanvasVulkan::saveParameters(std::string filename)
|
||||||
{
|
{
|
||||||
if (shader_chain && shader_chain->preset)
|
if (shader_chain && shader_chain->preset)
|
||||||
shader_chain->preset->save_to_file(filename);
|
shader_chain->preset->save_to_file(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmuCanvasVulkan::recreateUIAssets()
|
||||||
|
{
|
||||||
|
if (ImGui::GetCurrentContext())
|
||||||
|
{
|
||||||
|
context->wait_idle();
|
||||||
|
imgui_descriptor_pool.reset();
|
||||||
|
imgui_render_pass.reset();
|
||||||
|
ImGui_ImplVulkan_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config->display_messages != EmuConfig::eOnscreen)
|
||||||
|
return;
|
||||||
|
|
||||||
|
initImGui();
|
||||||
}
|
}
|
|
@ -30,6 +30,7 @@ class EmuCanvasVulkan : public EmuCanvas
|
||||||
void draw() override;
|
void draw() override;
|
||||||
|
|
||||||
bool initImGui();
|
bool initImGui();
|
||||||
|
void recreateUIAssets();
|
||||||
vk::UniqueRenderPass imgui_render_pass;
|
vk::UniqueRenderPass imgui_render_pass;
|
||||||
vk::UniqueDescriptorPool imgui_descriptor_pool;
|
vk::UniqueDescriptorPool imgui_descriptor_pool;
|
||||||
|
|
||||||
|
|
|
@ -632,4 +632,12 @@ void EmuMainWindow::output(uint8_t *buffer, int width, int height, QImage::Forma
|
||||||
{
|
{
|
||||||
if (canvas)
|
if (canvas)
|
||||||
canvas->output(buffer, width, height, format, bytes_per_line, frame_rate);
|
canvas->output(buffer, width, height, format, bytes_per_line, frame_rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmuMainWindow::recreateUIAssets()
|
||||||
|
{
|
||||||
|
app->emu_thread->runOnThread([&] {
|
||||||
|
if (canvas)
|
||||||
|
canvas->recreateUIAssets();
|
||||||
|
}, true);
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ class EmuMainWindow : public QMainWindow
|
||||||
bool isActivelyDrawing();
|
bool isActivelyDrawing();
|
||||||
void openFile();
|
void openFile();
|
||||||
bool openFile(std::string filename);
|
bool openFile(std::string filename);
|
||||||
|
void recreateUIAssets();
|
||||||
std::vector<std::string> getDisplayDeviceList();
|
std::vector<std::string> getDisplayDeviceList();
|
||||||
EmuApplication *app;
|
EmuApplication *app;
|
||||||
EmuCanvas *canvas;
|
EmuCanvas *canvas;
|
||||||
|
|
Loading…
Reference in New Issue