First meaningful usage of ImGui features.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
c8ad71ed07
commit
7865fc3457
4 changed files with 131 additions and 26 deletions
|
@ -28,6 +28,17 @@ namespace
|
|||
std::replace(value.begin(), value.end(), '_', ' ');
|
||||
}
|
||||
|
||||
std::string getHomeDir()
|
||||
{
|
||||
const char* homeDir = getenv("HOME");
|
||||
if (!homeDir)
|
||||
{
|
||||
throw std::runtime_error("${HOME} not set, cannot locate configuration file");
|
||||
}
|
||||
|
||||
return std::string(homeDir);
|
||||
}
|
||||
|
||||
class Configuration : public PTreeRegistry
|
||||
{
|
||||
public:
|
||||
|
@ -73,37 +84,38 @@ namespace
|
|||
|
||||
}
|
||||
|
||||
std::string GetConfigFile(const std::string & filename)
|
||||
{
|
||||
const std::string dir = getHomeDir() + "/.applewin";
|
||||
const int status = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
if (!status || (errno == EEXIST))
|
||||
{
|
||||
return dir + "/" + filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char * s = strerror(errno);
|
||||
LogFileOutput("No registry. Cannot create %s in %s: %s\n", filename.c_str(), dir.c_str(), s);
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeFileRegistry(const EmulatorOptions & options)
|
||||
{
|
||||
const char* homeDir = getenv("HOME");
|
||||
if (!homeDir)
|
||||
{
|
||||
throw std::runtime_error("${HOME} not set, cannot locate configuration file");
|
||||
}
|
||||
const std::string homeDir = getHomeDir();
|
||||
|
||||
std::string filename;
|
||||
bool saveOnExit;
|
||||
|
||||
if (options.useQtIni)
|
||||
{
|
||||
filename = std::string(homeDir) + "/.config/" + ORGANIZATION_NAME + "/" + APPLICATION_NAME + ".conf";
|
||||
filename = homeDir + "/.config/" + ORGANIZATION_NAME + "/" + APPLICATION_NAME + ".conf";
|
||||
saveOnExit = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::string dir = std::string(homeDir) + "/.applewin";
|
||||
const int status = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
filename = dir + "/applewin.conf";
|
||||
if (!status || (errno == EEXIST))
|
||||
{
|
||||
saveOnExit = options.saveConfigurationOnExit;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char * s = strerror(errno);
|
||||
LogFileOutput("No registry. Cannot create %s: %s\n", dir.c_str(), s);
|
||||
saveOnExit = false;
|
||||
}
|
||||
filename = GetConfigFile("applewin.conf");
|
||||
saveOnExit = !filename.empty() && options.saveConfigurationOnExit;
|
||||
}
|
||||
|
||||
std::shared_ptr<Configuration> config(new Configuration(filename, saveOnExit));
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
|
||||
struct EmulatorOptions;
|
||||
|
||||
std::string GetConfigFile(const std::string & filename);
|
||||
void InitializeFileRegistry(const EmulatorOptions & options);
|
||||
|
|
|
@ -2,12 +2,31 @@
|
|||
#include "frontends/sdl/imgui/sdlimguiframe.h"
|
||||
#include "frontends/sdl/imgui/image.h"
|
||||
#include "frontends/sdl/utils.h"
|
||||
#include "frontends/common2/fileregistry.h"
|
||||
|
||||
#include "Interface.h"
|
||||
#include "Core.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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SDLImGuiFrame::SDLImGuiFrame()
|
||||
{
|
||||
Video & video = GetVideo();
|
||||
|
@ -52,7 +71,18 @@ SDLImGuiFrame::SDLImGuiFrame()
|
|||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
mySettings.iniFileLocation = GetConfigFile("imgui.ini");
|
||||
if (mySettings.iniFileLocation.empty())
|
||||
{
|
||||
io.IniFilename = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
io.IniFilename = mySettings.iniFileLocation.c_str();
|
||||
}
|
||||
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
|
@ -86,18 +116,67 @@ void SDLImGuiFrame::UpdateTexture()
|
|||
LoadTextureFromData(myTexture, myFramebuffer.data() + myOffset, myBorderlessWidth, myBorderlessHeight, myPitch);
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::DrawAppleVideo()
|
||||
{
|
||||
// need to flip the texture vertically
|
||||
const ImVec2 uv0(0, 1);
|
||||
const ImVec2 uv1(1, 0);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
if (mySettings.windowed)
|
||||
{
|
||||
if (ImGui::Begin("Apple ]["))
|
||||
{
|
||||
ImGui::Image(myTexture, ImGui::GetContentRegionAvail(), uv0, uv1);
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
// must clean background if in windowed mode
|
||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ImVec2 zero(0, 0);
|
||||
// draw on the background
|
||||
ImGui::GetBackgroundDrawList()->AddImage(myTexture, zero, io.DisplaySize, uv0, uv1);
|
||||
}
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::ShowSettings()
|
||||
{
|
||||
if (ImGui::Begin("Settings"))
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
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::End();
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::RenderPresent()
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame(myWindow.get());
|
||||
ImGui::NewFrame();
|
||||
|
||||
// need to flip the texture vertically
|
||||
const ImVec2 uv0(0, 1);
|
||||
const ImVec2 uv1(1, 0);
|
||||
const ImVec2 zero(0, 0);
|
||||
// draw on the background
|
||||
ImGui::GetBackgroundDrawList()->AddImage(myTexture, zero, ImGui::GetIO().DisplaySize, uv0, uv1);
|
||||
ShowSettings();
|
||||
|
||||
if (mySettings.showDemo)
|
||||
{
|
||||
ImGui::ShowDemoWindow();
|
||||
}
|
||||
|
||||
DrawAppleVideo();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
|
|
@ -14,6 +14,17 @@ public:
|
|||
void RenderPresent() override;
|
||||
|
||||
private:
|
||||
|
||||
void DrawAppleVideo();
|
||||
void ShowSettings();
|
||||
|
||||
struct ImGuiSettings
|
||||
{
|
||||
std::string iniFileLocation;
|
||||
bool windowed = false;
|
||||
bool showDemo = false;
|
||||
};
|
||||
|
||||
size_t myPitch;
|
||||
size_t myOffset;
|
||||
size_t myBorderlessWidth;
|
||||
|
@ -21,4 +32,6 @@ private:
|
|||
|
||||
SDL_GLContext myGLContext;
|
||||
ImTextureID myTexture;
|
||||
|
||||
ImGuiSettings mySettings;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue