From 362c9877d426bea7e931d8ee419028199bddb185 Mon Sep 17 00:00:00 2001 From: Andrea Odetti Date: Sat, 3 Apr 2021 09:46:56 +0100 Subject: [PATCH] ImGui settings: add video. Signed-off-by: Andrea Odetti --- source/frontends/sdl/imgui/sdlsettings.cpp | 60 ++++++++++++++++++- source/frontends/sdl/imgui/settingshelper.cpp | 38 +++++++++++- source/frontends/sdl/imgui/settingshelper.h | 6 +- 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/source/frontends/sdl/imgui/sdlsettings.cpp b/source/frontends/sdl/imgui/sdlsettings.cpp index bb982195..1290393f 100644 --- a/source/frontends/sdl/imgui/sdlsettings.cpp +++ b/source/frontends/sdl/imgui/sdlsettings.cpp @@ -45,6 +45,19 @@ namespace return color; } + uint8_t roundToRGB(float x) + { + // c++ cast truncates + return uint8_t(x * 255 + 0.5); + } + + COLORREF imVec4ToColorref(const ImVec4 & color) + { + const bgra_t bgra = {roundToRGB(color.x), roundToRGB(color.y), roundToRGB(color.z), roundToRGB(color.w)}; + const COLORREF * cr = reinterpret_cast(&bgra); + return *cr; + } + ImVec4 debuggerGetColor(int iColor) { const COLORREF cr = DebuggerGetColor(iColor); @@ -242,7 +255,7 @@ namespace sa2 } standardLabelText("CPU", getCPUName(GetMainCpu()).c_str()); - standardLabelText("Mode", getModeName(g_nAppMode).c_str()); + standardLabelText("Mode", getAppModeName(g_nAppMode).c_str()); ImGui::Separator(); @@ -481,6 +494,51 @@ namespace sa2 ImGui::EndTabItem(); } + if (ImGui::BeginTabItem("Video")) + { + Video & video = GetVideo(); + const VideoType_e videoType = video.GetVideoType(); + if (ImGui::BeginCombo("Video mode", getVideoTypeName(videoType).c_str())) + { + for (size_t value = VT_MONO_CUSTOM; value < NUM_VIDEO_MODES; ++value) + { + const bool isSelected = value == videoType; + if (ImGui::Selectable(getVideoTypeName(VideoType_e(value)).c_str(), isSelected)) + { + video.SetVideoType(VideoType_e(value)); + frame->ApplyVideoModeChange(); + } + if (isSelected) + { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + + ImVec4 color = colorrefToImVec4(video.GetMonochromeRGB()); + ImGui::ColorEdit3("Monochrome Color", (float*)&color, 0); + const COLORREF cr = imVec4ToColorref(color); + video.SetMonochromeRGB(cr); + frame->ApplyVideoModeChange(); + + bool scanLines = video.IsVideoStyle(VS_HALF_SCANLINES); + if (ImGui::Checkbox("50% Scan lines", &scanLines)) + { + setVideoStyle(video, VS_HALF_SCANLINES, scanLines); + frame->ApplyVideoModeChange(); + } + + bool verticalBlend = video.IsVideoStyle(VS_COLOR_VERTICAL_BLEND); + if (ImGui::Checkbox("Vertical blend", &verticalBlend)) + { + setVideoStyle(video, VS_COLOR_VERTICAL_BLEND, verticalBlend); + frame->ApplyVideoModeChange(); + } + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Debugger")) { if (ImGui::RadioButton("Color", g_iColorScheme == SCHEME_COLOR)) { g_iColorScheme = SCHEME_COLOR; } ImGui::SameLine(); diff --git a/source/frontends/sdl/imgui/settingshelper.cpp b/source/frontends/sdl/imgui/settingshelper.cpp index 2cd6334f..9c4ebf5d 100644 --- a/source/frontends/sdl/imgui/settingshelper.cpp +++ b/source/frontends/sdl/imgui/settingshelper.cpp @@ -52,7 +52,7 @@ namespace {CPU_Z80, "CPU_Z80"}, }; - const std::map modes = + const std::map appModes = { {MODE_LOGO, "MODE_LOGO"}, {MODE_PAUSED, "MODE_PAUSED"}, @@ -70,6 +70,19 @@ namespace {DISK_STATUS_PROT, "PROT"}, }; + const std::map videoTypes = + { + {VT_MONO_CUSTOM, "Monochrome (Custom)"}, + {VT_COLOR_IDEALIZED, "Color (Composite Idealized)"}, + {VT_COLOR_VIDEOCARD_RGB, "Color (RGB Card/Monitor)"}, + {VT_COLOR_MONITOR_NTSC, "Color (Composite Monitor)"}, + {VT_COLOR_TV, "Color TV"}, + {VT_MONO_TV, "B&W TV"}, + {VT_MONO_AMBER, "Monochrome (Amber)"}, + {VT_MONO_GREEN, "Monochrome (Green)"}, + {VT_MONO_WHITE, "Monochrome (White)"}, + }; + const std::map> cardsForSlots = { {0, {CT_Empty, CT_LanguageCard, CT_Saturn128K}}, @@ -104,9 +117,14 @@ namespace sa2 return cpuTypes.at(cpu); } - const std::string & getModeName(AppMode_e mode) + const std::string & getAppModeName(AppMode_e mode) { - return modes.at(mode); + return appModes.at(mode); + } + + const std::string & getVideoTypeName(VideoType_e type) + { + return videoTypes.at(type); } const std::vector & getCardsForSlot(size_t slot) @@ -152,4 +170,18 @@ namespace sa2 }; } + void setVideoStyle(Video & video, const VideoStyle_e style, const bool enabled) + { + VideoStyle_e currentVideoStyle = video.GetVideoStyle(); + if (enabled) + { + currentVideoStyle = VideoStyle_e(currentVideoStyle | style); + } + else + { + currentVideoStyle = VideoStyle_e(currentVideoStyle & (~style)); + } + video.SetVideoStyle(currentVideoStyle); + } + } diff --git a/source/frontends/sdl/imgui/settingshelper.h b/source/frontends/sdl/imgui/settingshelper.h index e11421a2..c9b2ed84 100644 --- a/source/frontends/sdl/imgui/settingshelper.h +++ b/source/frontends/sdl/imgui/settingshelper.h @@ -4,6 +4,7 @@ #include "CPU.h" #include "Common.h" #include "DiskImage.h" +#include "Video.h" #include #include @@ -15,12 +16,15 @@ namespace sa2 const std::string & getCardName(SS_CARDTYPE card); const std::string & getApple2Name(eApple2Type type); const std::string & getCPUName(eCpuType cpu); - const std::string & getModeName(AppMode_e mode); + const std::string & getAppModeName(AppMode_e mode); const std::string & getDiskStatusName(Disk_Status_e status); + const std::string & getVideoTypeName(VideoType_e type); const std::vector & getCardsForSlot(size_t slot); const std::vector & getExpansionCards(); const std::map & getAapple2Types(); void insertCard(size_t slot, SS_CARDTYPE card); + + void setVideoStyle(Video & video, const VideoStyle_e style, const bool enabled); }