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) {
|
||||
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->updateSettings();
|
||||
if (restart)
|
||||
app->window->recreateCanvas();
|
||||
if (recreate)
|
||||
app->window->recreateUIAssets();
|
||||
});
|
||||
|
||||
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;
|
||||
if (restart)
|
||||
app->window->recreateCanvas();
|
||||
if (recreate)
|
||||
app->window->recreateUIAssets();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -460,28 +460,28 @@ void EmuApplication::startInputTimer()
|
|||
|
||||
void EmuApplication::loadState(int slot)
|
||||
{
|
||||
emu_thread->runOnThread([&] {
|
||||
emu_thread->runOnThread([&, slot] {
|
||||
core->loadState(slot);
|
||||
});
|
||||
}
|
||||
|
||||
void EmuApplication::loadState(std::string filename)
|
||||
{
|
||||
emu_thread->runOnThread([&] {
|
||||
emu_thread->runOnThread([&, filename] {
|
||||
core->loadState(filename);
|
||||
});
|
||||
}
|
||||
|
||||
void EmuApplication::saveState(int slot)
|
||||
{
|
||||
emu_thread->runOnThread([&] {
|
||||
emu_thread->runOnThread([&, slot] {
|
||||
core->saveState(slot);
|
||||
});
|
||||
}
|
||||
|
||||
void EmuApplication::saveState(std::string filename)
|
||||
{
|
||||
emu_thread->runOnThread([&] {
|
||||
emu_thread->runOnThread([&, filename] {
|
||||
core->saveState(filename);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ class EmuCanvas : public QWidget
|
|||
virtual void draw() = 0;
|
||||
void paintEvent(QPaintEvent *) override = 0;
|
||||
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 throttle();
|
||||
void resizeEvent(QResizeEvent *event) override = 0;
|
||||
|
|
|
@ -174,11 +174,7 @@ void EmuCanvasOpenGL::createContext()
|
|||
|
||||
if (config->display_messages == EmuConfig::eOnscreen)
|
||||
{
|
||||
auto defaults = S9xImGuiGetDefaults();
|
||||
defaults.font_size = config->osd_size;
|
||||
defaults.spacing = defaults.font_size / 2.4;
|
||||
S9xImGuiInit(&defaults);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
recreateUIAssets();
|
||||
}
|
||||
|
||||
loadShaders();
|
||||
|
@ -383,3 +379,20 @@ void EmuCanvasOpenGL::saveParameters(std::string filename)
|
|||
if (shader)
|
||||
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 showParametersDialog() override;
|
||||
void saveParameters(std::string filename) override;
|
||||
|
||||
void recreateUIAssets() override;
|
||||
|
||||
private:
|
||||
void resizeTexture(int width, int height);
|
||||
|
|
|
@ -300,3 +300,20 @@ void EmuCanvasVulkan::saveParameters(std::string filename)
|
|||
if (shader_chain && shader_chain->preset)
|
||||
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;
|
||||
|
||||
bool initImGui();
|
||||
void recreateUIAssets();
|
||||
vk::UniqueRenderPass imgui_render_pass;
|
||||
vk::UniqueDescriptorPool imgui_descriptor_pool;
|
||||
|
||||
|
|
|
@ -633,3 +633,11 @@ void EmuMainWindow::output(uint8_t *buffer, int width, int height, QImage::Forma
|
|||
if (canvas)
|
||||
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();
|
||||
void openFile();
|
||||
bool openFile(std::string filename);
|
||||
void recreateUIAssets();
|
||||
std::vector<std::string> getDisplayDeviceList();
|
||||
EmuApplication *app;
|
||||
EmuCanvas *canvas;
|
||||
|
|
Loading…
Reference in New Issue