2021-02-06 16:55:08 +00:00
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "frontends/sdl/imgui/sdlimguiframe.h"
|
2021-02-07 19:23:28 +00:00
|
|
|
|
2021-02-06 16:55:08 +00:00
|
|
|
#include "frontends/sdl/utils.h"
|
2021-02-07 16:10:54 +00:00
|
|
|
#include "frontends/common2/fileregistry.h"
|
2021-02-09 16:02:36 +00:00
|
|
|
#include "frontends/common2/programoptions.h"
|
2021-02-07 19:23:28 +00:00
|
|
|
#include "frontends/sdl/imgui/image.h"
|
|
|
|
#include "frontends/sdl/imgui/settingshelper.h"
|
2021-02-06 16:55:08 +00:00
|
|
|
|
|
|
|
#include "Interface.h"
|
|
|
|
#include "Core.h"
|
2021-02-07 19:23:28 +00:00
|
|
|
#include "CPU.h"
|
|
|
|
#include "CardManager.h"
|
2021-02-07 19:55:11 +00:00
|
|
|
#include "Speaker.h"
|
|
|
|
#include "Mockingboard.h"
|
|
|
|
#include "Registry.h"
|
2021-02-06 16:55:08 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2021-02-07 16:10:54 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-09 16:02:36 +00:00
|
|
|
SDLImGuiFrame::SDLImGuiFrame(const EmulatorOptions & options)
|
2021-02-06 16:55:08 +00:00
|
|
|
{
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, SDL_CONTEXT_MAJOR); // from local gles.h
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
|
|
|
|
|
|
// Create window with graphics context
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
|
|
|
|
2021-02-20 15:21:53 +00:00
|
|
|
const SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
|
|
|
const Geometry & geometry = options.geometry;
|
|
|
|
|
|
|
|
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, windowFlags), SDL_DestroyWindow);
|
2021-02-06 16:55:08 +00:00
|
|
|
if (!myWindow)
|
|
|
|
{
|
|
|
|
throw std::runtime_error(SDL_GetError());
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:23:28 +00:00
|
|
|
SetApplicationIcon();
|
|
|
|
|
2021-02-06 16:55:08 +00:00
|
|
|
myGLContext = SDL_GL_CreateContext(myWindow.get());
|
|
|
|
if (!myGLContext)
|
|
|
|
{
|
|
|
|
throw std::runtime_error(SDL_GetError());
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_GL_MakeCurrent(myWindow.get(), myGLContext);
|
|
|
|
|
|
|
|
// Setup Platform/Renderer backends
|
2021-02-06 17:09:06 +00:00
|
|
|
std::cerr << "IMGUI_VERSION: " << IMGUI_VERSION << std::endl;
|
2021-02-06 16:55:08 +00:00
|
|
|
std::cerr << "GL_VENDOR: " << glGetString(GL_VENDOR) << std::endl;
|
|
|
|
std::cerr << "GL_RENDERER: " << glGetString(GL_RENDERER) << std::endl;
|
|
|
|
std::cerr << "GL_VERSION: " << glGetString(GL_VERSION) << std::endl;
|
|
|
|
std::cerr << "GL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
|
|
|
|
// const char* runtime_gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
// std::cerr << "GL_EXTENSIONS: " << runtime_gl_extensions << std::endl;
|
|
|
|
|
|
|
|
// Setup Dear ImGui context
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
2021-02-07 16:10:54 +00:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
mySettings.iniFileLocation = GetConfigFile("imgui.ini");
|
|
|
|
if (mySettings.iniFileLocation.empty())
|
|
|
|
{
|
|
|
|
io.IniFilename = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
io.IniFilename = mySettings.iniFileLocation.c_str();
|
|
|
|
}
|
|
|
|
|
2021-02-06 16:55:08 +00:00
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
|
|
|
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
|
|
|
|
ImGui_ImplSDL2_InitForOpenGL(myWindow.get(), myGLContext);
|
|
|
|
|
|
|
|
ImGui_ImplOpenGL3_Init();
|
|
|
|
|
|
|
|
glGenTextures(1, &myTexture);
|
|
|
|
|
2021-02-09 16:02:36 +00:00
|
|
|
Video & video = GetVideo();
|
|
|
|
|
|
|
|
myBorderlessWidth = video.GetFrameBufferBorderlessWidth();
|
|
|
|
myBorderlessHeight = video.GetFrameBufferBorderlessHeight();
|
|
|
|
|
2021-02-06 16:55:08 +00:00
|
|
|
const int width = video.GetFrameBufferWidth();
|
|
|
|
const size_t borderWidth = video.GetFrameBufferBorderWidth();
|
|
|
|
const size_t borderHeight = video.GetFrameBufferBorderHeight();
|
|
|
|
|
|
|
|
myPitch = width;
|
|
|
|
myOffset = (width * borderHeight + borderWidth) * sizeof(bgra_t);
|
2021-02-08 11:42:14 +00:00
|
|
|
|
|
|
|
allocateTexture(myTexture, myBorderlessWidth, myBorderlessHeight);
|
2021-02-06 16:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDLImGuiFrame::~SDLImGuiFrame()
|
|
|
|
{
|
|
|
|
glDeleteTextures(1, &myTexture);
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplSDL2_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
SDL_GL_DeleteContext(myGLContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDLImGuiFrame::UpdateTexture()
|
|
|
|
{
|
2021-02-08 11:42:14 +00:00
|
|
|
loadTextureFromData(myTexture, myFramebuffer.data() + myOffset, myBorderlessWidth, myBorderlessHeight, myPitch);
|
2021-02-06 16:55:08 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 16:05:32 +00:00
|
|
|
void SDLImGuiFrame::ClearBackground()
|
|
|
|
{
|
|
|
|
const ImVec4 background(0.45f, 0.55f, 0.60f, 1.00f);
|
|
|
|
glClearColor(background.x, background.y, background.z, background.w);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2021-02-07 16:10:54 +00:00
|
|
|
void SDLImGuiFrame::DrawAppleVideo()
|
|
|
|
{
|
|
|
|
// need to flip the texture vertically
|
|
|
|
const ImVec2 uv0(0, 1);
|
|
|
|
const ImVec2 uv1(1, 0);
|
|
|
|
|
2021-02-21 18:43:46 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-02-07 16:10:54 +00:00
|
|
|
|
|
|
|
if (mySettings.windowed)
|
|
|
|
{
|
|
|
|
if (ImGui::Begin("Apple ]["))
|
|
|
|
{
|
|
|
|
ImGui::Image(myTexture, ImGui::GetContentRegionAvail(), uv0, uv1);
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
const ImVec2 zero(0, menuBarHeight);
|
2021-02-07 16:10:54 +00:00
|
|
|
// draw on the background
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2021-02-07 16:10:54 +00:00
|
|
|
ImGui::GetBackgroundDrawList()->AddImage(myTexture, zero, io.DisplaySize, uv0, uv1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDLImGuiFrame::ShowSettings()
|
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
if (mySettings.showSettings)
|
2021-02-07 16:10:54 +00:00
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
if (ImGui::Begin("Settings", &mySettings.showSettings))
|
2021-02-07 19:23:28 +00:00
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
if (ImGui::BeginTabBar("Settings"))
|
2021-02-07 19:23:28 +00:00
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
if (ImGui::BeginTabItem("General"))
|
|
|
|
{
|
|
|
|
ImGui::Checkbox("Apple Video windowed", &mySettings.windowed);
|
|
|
|
ImGui::SameLine(); HelpMarker("Show Apple Video in a separate window.");
|
2021-02-07 19:23:28 +00:00
|
|
|
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGui::Checkbox("Show Demo", &mySettings.showDemo);
|
|
|
|
ImGui::SameLine(); HelpMarker("Show Dear ImGui DemoWindow.");
|
2021-02-07 19:23:28 +00:00
|
|
|
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGui::Text("FPS: %d", int(io.Framerate));
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
|
|
|
if (ImGui::BeginTabItem("Hardware"))
|
|
|
|
{
|
|
|
|
if (ImGui::BeginTable("Cards", 2, ImGuiTableFlags_RowBg))
|
2021-02-07 19:23:28 +00:00
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
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());
|
|
|
|
}
|
2021-02-07 19:23:28 +00:00
|
|
|
ImGui::TableNextColumn();
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGui::Selectable("AUX");
|
2021-02-07 19:23:28 +00:00
|
|
|
ImGui::TableNextColumn();
|
2021-02-21 18:43:46 +00:00
|
|
|
const SS_CARDTYPE card = manager.QueryAux();
|
2021-02-07 19:23:28 +00:00
|
|
|
ImGui::Selectable(getCardName(card).c_str());
|
2021-02-21 18:43:46 +00:00
|
|
|
|
|
|
|
ImGui::EndTable();
|
2021-02-07 19:23:28 +00:00
|
|
|
}
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGui::Separator();
|
2021-02-07 19:55:11 +00:00
|
|
|
|
2021-02-21 18:43:46 +00:00
|
|
|
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();
|
2021-02-07 19:55:11 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 18:43:46 +00:00
|
|
|
if (ImGui::BeginTabItem("Audio"))
|
2021-02-07 19:55:11 +00:00
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
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();
|
2021-02-07 19:55:11 +00:00
|
|
|
}
|
2021-02-07 19:23:28 +00:00
|
|
|
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGui::EndTabBar();
|
2021-02-07 19:23:28 +00:00
|
|
|
}
|
2021-02-09 16:05:32 +00:00
|
|
|
|
2021-02-07 19:23:28 +00:00
|
|
|
}
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGui::End();
|
2021-02-07 16:10:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-06 16:55:08 +00:00
|
|
|
void SDLImGuiFrame::RenderPresent()
|
|
|
|
{
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplSDL2_NewFrame(myWindow.get());
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
2021-02-07 16:10:54 +00:00
|
|
|
ShowSettings();
|
|
|
|
|
|
|
|
if (mySettings.showDemo)
|
|
|
|
{
|
2021-02-21 18:43:46 +00:00
|
|
|
ImGui::ShowDemoWindow(&mySettings.showDemo);
|
2021-02-07 16:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DrawAppleVideo();
|
2021-02-06 16:55:08 +00:00
|
|
|
|
|
|
|
ImGui::Render();
|
2021-02-09 16:05:32 +00:00
|
|
|
ClearBackground();
|
2021-02-06 16:55:08 +00:00
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
SDL_GL_SwapWindow(myWindow.get());
|
|
|
|
}
|