Move ImGui Settings window(s) to a separate class.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
462f02e77f
commit
ddd1c4f301
5 changed files with 196 additions and 155 deletions
|
@ -49,10 +49,12 @@ target_sources(sa2 PRIVATE
|
|||
imgui/sdlimguiframe.cpp
|
||||
imgui/image.cpp
|
||||
imgui/settingshelper.cpp
|
||||
imgui/sdlsettings.cpp
|
||||
|
||||
imgui/sdlimguiframe.h
|
||||
imgui/image.h
|
||||
imgui/settingshelper.h
|
||||
imgui/sdlsettings.h
|
||||
imgui/imconfig.h
|
||||
imgui/gles.h
|
||||
|
||||
|
|
|
@ -5,35 +5,12 @@
|
|||
#include "frontends/common2/fileregistry.h"
|
||||
#include "frontends/common2/programoptions.h"
|
||||
#include "frontends/sdl/imgui/image.h"
|
||||
#include "frontends/sdl/imgui/settingshelper.h"
|
||||
|
||||
#include "Interface.h"
|
||||
#include "Core.h"
|
||||
#include "CPU.h"
|
||||
#include "CardManager.h"
|
||||
#include "Speaker.h"
|
||||
#include "Mockingboard.h"
|
||||
#include "Registry.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void HelpMarker(const char* desc)
|
||||
{
|
||||
ImGui::TextDisabled("(?)");
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
|
||||
ImGui::TextUnformatted(desc);
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace sa2
|
||||
{
|
||||
|
@ -84,14 +61,14 @@ namespace sa2
|
|||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
mySettings.iniFileLocation = common2::GetConfigFile("imgui.ini");
|
||||
if (mySettings.iniFileLocation.empty())
|
||||
myIniFileLocation = common2::GetConfigFile("imgui.ini");
|
||||
if (myIniFileLocation.empty())
|
||||
{
|
||||
io.IniFilename = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
io.IniFilename = mySettings.iniFileLocation.c_str();
|
||||
io.IniFilename = myIniFileLocation.c_str();
|
||||
}
|
||||
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
@ -147,23 +124,7 @@ namespace sa2
|
|||
const ImVec2 uv0(0, 1);
|
||||
const ImVec2 uv1(1, 0);
|
||||
|
||||
float menuBarHeight;
|
||||
|
||||
if (ImGui::BeginMainMenuBar())
|
||||
{
|
||||
menuBarHeight = ImGui::GetWindowHeight();
|
||||
if (ImGui::BeginMenu("System"))
|
||||
{
|
||||
ImGui::MenuItem("Settings", nullptr, &mySettings.showSettings);
|
||||
ImGui::MenuItem("Demo", nullptr, &mySettings.showDemo);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
menuBarHeight = 0.0;
|
||||
}
|
||||
const float menuBarHeight = mySettings.drawMenuBar();
|
||||
|
||||
if (mySettings.windowed)
|
||||
{
|
||||
|
@ -182,113 +143,13 @@ namespace sa2
|
|||
}
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::ShowSettings()
|
||||
{
|
||||
if (mySettings.showSettings)
|
||||
{
|
||||
if (ImGui::Begin("Settings", &mySettings.showSettings))
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (ImGui::BeginTabBar("Settings"))
|
||||
{
|
||||
if (ImGui::BeginTabItem("General"))
|
||||
{
|
||||
ImGui::Checkbox("Apple Video windowed", &mySettings.windowed);
|
||||
ImGui::SameLine(); HelpMarker("Show Apple Video in a separate window.");
|
||||
|
||||
ImGui::Checkbox("Show Demo", &mySettings.showDemo);
|
||||
ImGui::SameLine(); HelpMarker("Show Dear ImGui DemoWindow.");
|
||||
|
||||
ImGui::Text("FPS: %d", int(io.Framerate));
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Hardware"))
|
||||
{
|
||||
if (ImGui::BeginTable("Cards", 2, ImGuiTableFlags_RowBg))
|
||||
{
|
||||
CardManager & manager = GetCardMgr();
|
||||
ImGui::TableSetupColumn("Slot");
|
||||
ImGui::TableSetupColumn("Card");
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
for (size_t slot = 0; slot < 8; ++slot)
|
||||
{
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable(std::to_string(slot).c_str());
|
||||
ImGui::TableNextColumn();
|
||||
const SS_CARDTYPE card = manager.QuerySlot(slot);;
|
||||
ImGui::Selectable(getCardName(card).c_str());
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable("AUX");
|
||||
ImGui::TableNextColumn();
|
||||
const SS_CARDTYPE card = manager.QueryAux();
|
||||
ImGui::Selectable(getCardName(card).c_str());
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::BeginTable("Type", 2, ImGuiTableFlags_RowBg))
|
||||
{
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable("Apple 2");
|
||||
ImGui::TableNextColumn();
|
||||
const eApple2Type a2e = GetApple2Type();
|
||||
ImGui::Selectable(getApple2Name(a2e).c_str());
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable("CPU");
|
||||
ImGui::TableNextColumn();
|
||||
const eCpuType cpu = GetMainCpu();
|
||||
ImGui::Selectable(getCPUName(cpu).c_str());
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Audio"))
|
||||
{
|
||||
const int volumeMax = GetPropertySheet().GetVolumeMax();
|
||||
if (ImGui::SliderInt("Speaker volume", &mySettings.speakerVolume, 0, volumeMax))
|
||||
{
|
||||
SpkrSetVolume(volumeMax - mySettings.speakerVolume, volumeMax);
|
||||
REGSAVE(TEXT(REGVALUE_SPKR_VOLUME), SpkrGetVolume());
|
||||
}
|
||||
|
||||
if (ImGui::SliderInt("Mockingboard volume", &mySettings.mockingboardVolume, 0, volumeMax))
|
||||
{
|
||||
MB_SetVolume(volumeMax - mySettings.mockingboardVolume, volumeMax);
|
||||
REGSAVE(TEXT(REGVALUE_MB_VOLUME), MB_GetVolume());
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::RenderPresent()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame(myWindow.get());
|
||||
ImGui::NewFrame();
|
||||
|
||||
ShowSettings();
|
||||
|
||||
if (mySettings.showDemo)
|
||||
{
|
||||
ImGui::ShowDemoWindow(&mySettings.showDemo);
|
||||
}
|
||||
|
||||
mySettings.show();
|
||||
DrawAppleVideo();
|
||||
|
||||
ImGui::Render();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "frontends/sdl/sdlframe.h"
|
||||
#include "frontends/sdl/imgui/sdlsettings.h"
|
||||
#include "frontends/sdl/imgui/gles.h"
|
||||
|
||||
namespace common2
|
||||
|
@ -29,17 +30,6 @@ namespace sa2
|
|||
|
||||
void ClearBackground();
|
||||
void DrawAppleVideo();
|
||||
void ShowSettings();
|
||||
|
||||
struct ImGuiSettings
|
||||
{
|
||||
std::string iniFileLocation;
|
||||
bool windowed = false;
|
||||
bool showDemo = false;
|
||||
bool showSettings = false;
|
||||
int speakerVolume = 50;
|
||||
int mockingboardVolume = 50;
|
||||
};
|
||||
|
||||
size_t myPitch;
|
||||
size_t myOffset;
|
||||
|
@ -49,6 +39,7 @@ namespace sa2
|
|||
SDL_GLContext myGLContext;
|
||||
ImTextureID myTexture;
|
||||
|
||||
std::string myIniFileLocation;
|
||||
ImGuiSettings mySettings;
|
||||
};
|
||||
|
||||
|
|
162
source/frontends/sdl/imgui/sdlsettings.cpp
Normal file
162
source/frontends/sdl/imgui/sdlsettings.cpp
Normal file
|
@ -0,0 +1,162 @@
|
|||
#include "StdAfx.h"
|
||||
#include "frontends/sdl/imgui/sdlsettings.h"
|
||||
#include "frontends/sdl/imgui/settingshelper.h"
|
||||
|
||||
#include "Interface.h"
|
||||
#include "CardManager.h"
|
||||
#include "Core.h"
|
||||
#include "CPU.h"
|
||||
#include "CardManager.h"
|
||||
#include "Speaker.h"
|
||||
#include "Mockingboard.h"
|
||||
#include "Registry.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void HelpMarker(const char* desc)
|
||||
{
|
||||
ImGui::TextDisabled("(?)");
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
|
||||
ImGui::TextUnformatted(desc);
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace sa2
|
||||
{
|
||||
|
||||
void ImGuiSettings::showSettings()
|
||||
{
|
||||
if (ImGui::Begin("Settings", &myShowSettings))
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (ImGui::BeginTabBar("Settings"))
|
||||
{
|
||||
if (ImGui::BeginTabItem("General"))
|
||||
{
|
||||
ImGui::Checkbox("Apple Video windowed", &windowed);
|
||||
ImGui::SameLine(); HelpMarker("Show Apple Video in a separate window.");
|
||||
|
||||
ImGui::Checkbox("Show Demo", &myShowDemo);
|
||||
ImGui::SameLine(); HelpMarker("Show Dear ImGui DemoWindow.");
|
||||
|
||||
ImGui::Text("FPS: %d", int(io.Framerate));
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Hardware"))
|
||||
{
|
||||
if (ImGui::BeginTable("Cards", 2, ImGuiTableFlags_RowBg))
|
||||
{
|
||||
CardManager & manager = GetCardMgr();
|
||||
ImGui::TableSetupColumn("Slot");
|
||||
ImGui::TableSetupColumn("Card");
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
for (size_t slot = 0; slot < 8; ++slot)
|
||||
{
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable(std::to_string(slot).c_str());
|
||||
ImGui::TableNextColumn();
|
||||
const SS_CARDTYPE card = manager.QuerySlot(slot);;
|
||||
ImGui::Selectable(getCardName(card).c_str());
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable("AUX");
|
||||
ImGui::TableNextColumn();
|
||||
const SS_CARDTYPE card = manager.QueryAux();
|
||||
ImGui::Selectable(getCardName(card).c_str());
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::BeginTable("Type", 2, ImGuiTableFlags_RowBg))
|
||||
{
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable("Apple 2");
|
||||
ImGui::TableNextColumn();
|
||||
const eApple2Type a2e = GetApple2Type();
|
||||
ImGui::Selectable(getApple2Name(a2e).c_str());
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Selectable("CPU");
|
||||
ImGui::TableNextColumn();
|
||||
const eCpuType cpu = GetMainCpu();
|
||||
ImGui::Selectable(getCPUName(cpu).c_str());
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui::BeginTabItem("Audio"))
|
||||
{
|
||||
const int volumeMax = GetPropertySheet().GetVolumeMax();
|
||||
if (ImGui::SliderInt("Speaker volume", &mySpeakerVolume, 0, volumeMax))
|
||||
{
|
||||
SpkrSetVolume(volumeMax - mySpeakerVolume, volumeMax);
|
||||
REGSAVE(TEXT(REGVALUE_SPKR_VOLUME), SpkrGetVolume());
|
||||
}
|
||||
|
||||
if (ImGui::SliderInt("Mockingboard volume", &myMockingboardVolume, 0, volumeMax))
|
||||
{
|
||||
MB_SetVolume(volumeMax - myMockingboardVolume, volumeMax);
|
||||
REGSAVE(TEXT(REGVALUE_MB_VOLUME), MB_GetVolume());
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void ImGuiSettings::show()
|
||||
{
|
||||
if (myShowSettings)
|
||||
{
|
||||
showSettings();
|
||||
}
|
||||
|
||||
if (myShowDemo)
|
||||
{
|
||||
ImGui::ShowDemoWindow(&myShowDemo);
|
||||
}
|
||||
}
|
||||
|
||||
float ImGuiSettings::drawMenuBar()
|
||||
{
|
||||
float menuBarHeight;
|
||||
|
||||
if (ImGui::BeginMainMenuBar())
|
||||
{
|
||||
menuBarHeight = ImGui::GetWindowHeight();
|
||||
if (ImGui::BeginMenu("System"))
|
||||
{
|
||||
ImGui::MenuItem("Settings", nullptr, &myShowSettings);
|
||||
ImGui::MenuItem("Demo", nullptr, &myShowDemo);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
menuBarHeight = 0.0;
|
||||
}
|
||||
|
||||
return menuBarHeight;
|
||||
}
|
||||
|
||||
}
|
25
source/frontends/sdl/imgui/sdlsettings.h
Normal file
25
source/frontends/sdl/imgui/sdlsettings.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "frontends/sdl/imgui/gles.h"
|
||||
|
||||
namespace sa2
|
||||
{
|
||||
|
||||
class ImGuiSettings
|
||||
{
|
||||
public:
|
||||
void show();
|
||||
float drawMenuBar();
|
||||
|
||||
bool windowed = false;
|
||||
|
||||
private:
|
||||
bool myShowDemo = false;
|
||||
bool myShowSettings = false;
|
||||
int mySpeakerVolume = 50;
|
||||
int myMockingboardVolume = 50;
|
||||
|
||||
void showSettings();
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue