Skip to content

Commit

Permalink
ScreenSizeModes
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Jul 28, 2024
1 parent 5e64a0b commit b477c0a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 16 deletions.
3 changes: 2 additions & 1 deletion emulator/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ void Emulator_SetSpeed(uint16_t realspeed)
{
case 0: speedpercent = 200; break;
case 1: speedpercent = 100; break;
case 2: speedpercent = 200; break;
case 2: speedpercent = 120; break;
case 3: speedpercent = 240; break;
case 0x7fff: speedpercent = 50; break;
case 0x7ffe: speedpercent = 25; break;
default: speedpercent = 100; break;
Expand Down
13 changes: 13 additions & 0 deletions emulator/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ void Settings_SetHardFilePath(int slot, LPCTSTR sFilePath);
void Settings_GetHardFilePath(int slot, LPTSTR buffer);
void Settings_SetScreenViewMode(int mode);
int Settings_GetScreenViewMode();
void Settings_SetScreenSizeMode(int mode);
int Settings_GetScreenSizeMode();
BOOL Settings_GetScreenVsync();
void Settings_SetScreenVsync(BOOL flag);
void Settings_SetScreenshotMode(int mode);
Expand Down Expand Up @@ -187,6 +189,17 @@ enum ScreenViewMode
GrayScreen = 2,
};

enum ScreenSizeMode
{
ScreenSizeFill = 0,
ScreenSize4to3ratio = 1,
ScreenSize640x480 = 2,
ScreenSize800x600 = 3,
ScreenSize960x720 = 4,
ScreenSize1280x960 = 5,
ScreenSize1600x1200 = 6,
};

void ScreenView_Init();
void ScreenView_Done();
void ScreenView_ImGuiWidget();
Expand Down
74 changes: 64 additions & 10 deletions emulator/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void ImGuiAboutPopup();

void MainWindow_DoEmulatorSpeed(WORD speed);
void MainWindow_DoScreenViewMode(ScreenViewMode mode);
void MainWindow_DoScreenSizeMode(ScreenSizeMode mode);
void MainWindow_DoFloppyImageSelect(int slot);
void MainWindow_DoFloppyImageEject(int slot);
void MainWindow_DoCartridgeSelect(int slot);
Expand Down Expand Up @@ -113,11 +114,11 @@ void ImGuiMainMenu()
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Screenshot"))
if (ImGui::MenuItem(ICON_FA_CAMERA " Screenshot"))
MainWindow_DoFileScreenshot();

ImGui::Separator();
if (ImGui::MenuItem("Settings"))
if (ImGui::MenuItem(ICON_FA_COG " Settings"))
open_settings_popup = true;

//ImGui::MenuItem("Quit");//TODO
Expand Down Expand Up @@ -165,9 +166,13 @@ void ImGuiMainMenu()
ImGui::BeginDisabled(checked100);
if (ImGui::MenuItem("Speed 100%", nullptr, &checked100)) MainWindow_DoEmulatorSpeed(1);
ImGui::EndDisabled();
bool checked200 = speed == 2;
ImGui::BeginDisabled(checked200);
if (ImGui::MenuItem("Speed 200%", nullptr, &checked200)) MainWindow_DoEmulatorSpeed(2);
bool checked120 = speed == 2;
ImGui::BeginDisabled(checked120);
if (ImGui::MenuItem("Speed 200%", nullptr, &checked120)) MainWindow_DoEmulatorSpeed(2);
ImGui::EndDisabled();
bool checked240 = speed == 3;
ImGui::BeginDisabled(checked240);
if (ImGui::MenuItem("Speed 200%", nullptr, &checked240)) MainWindow_DoEmulatorSpeed(3);
ImGui::EndDisabled();
bool checkedMax = speed == 0;
ImGui::BeginDisabled(checkedMax);
Expand Down Expand Up @@ -269,6 +274,37 @@ void ImGuiMainMenu()
if (ImGui::MenuItem("Grayscale Screen", nullptr, &checkedGray)) MainWindow_DoScreenViewMode(GrayScreen);
ImGui::EndDisabled();

ImGui::Separator();
int sizemode = Settings_GetScreenSizeMode();
bool checked0 = sizemode == 0;
ImGui::BeginDisabled(checked0);
if (ImGui::MenuItem("Fill the box", nullptr, &checked0)) MainWindow_DoScreenSizeMode(ScreenSizeFill);
ImGui::EndDisabled();
bool checked1 = sizemode == 1;
ImGui::BeginDisabled(checked1);
if (ImGui::MenuItem("Maintain 4:3 ratio", nullptr, &checked1)) MainWindow_DoScreenSizeMode(ScreenSize4to3ratio);
ImGui::EndDisabled();
bool checked2 = sizemode == 2;
ImGui::BeginDisabled(checked2);
if (ImGui::MenuItem("640 x 480", nullptr, &checked2)) MainWindow_DoScreenSizeMode(ScreenSize640x480);
ImGui::EndDisabled();
bool checked3 = sizemode == 3;
ImGui::BeginDisabled(checked3);
if (ImGui::MenuItem("800 x 600", nullptr, &checked3)) MainWindow_DoScreenSizeMode(ScreenSize800x600);
ImGui::EndDisabled();
bool checked4 = sizemode == 4;
ImGui::BeginDisabled(checked4);
if (ImGui::MenuItem("960 x 720", nullptr, &checked4)) MainWindow_DoScreenSizeMode(ScreenSize960x720);
ImGui::EndDisabled();
bool checked5 = sizemode == 5;
ImGui::BeginDisabled(checked5);
if (ImGui::MenuItem("1280 x 960", nullptr, &checked5)) MainWindow_DoScreenSizeMode(ScreenSize1280x960);
ImGui::EndDisabled();
bool checked6 = sizemode == 6;
ImGui::BeginDisabled(checked6);
if (ImGui::MenuItem("1600 x 1200", nullptr, &checked6)) MainWindow_DoScreenSizeMode(ScreenSize1600x1200);
ImGui::EndDisabled();

ImGui::EndMenu();
}
if (ImGui::BeginMenu("Debug"))
Expand Down Expand Up @@ -360,11 +396,15 @@ void ImGuiAboutPopup()
{
if (ImGui::BeginPopupModal("about_popup", nullptr, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("UKNCBTL ImGui version " APP_VERSION_STRING);
ImGui::TextLinkOpenURL("Source code", "https://github.com/nzeemin/ukncbtl-imgui");
ImGui::SeparatorText("UKNCBTL ImGui");
ImGui::Text("UKNCBTL ImGui version %s revision %d", APP_VERSION_STRING, APP_REVISION);
ImGui::Text("Build date: %s %s", __DATE__, __TIME__);

ImGui::Text("Source code: "); ImGui::SameLine();
ImGui::TextLinkOpenURL("github.com/nzeemin/ukncbtl-imgui", "https://github.com/nzeemin/ukncbtl-imgui");
ImGui::Spacing();

ImGui::Separator();
ImGui::SeparatorText("ImGui");
ImGui::Text("Dear ImGui version %s %d", IMGUI_VERSION, IMGUI_VERSION_NUM);
ImGui::Spacing();

Expand Down Expand Up @@ -430,7 +470,11 @@ void ControlView_ImGuiWidget()
ImGui::EndDisabled();
ImGui::SameLine(0.0f, 0.0f);
ImGui::BeginDisabled(speed == 2);
if (ImGui::Button("200")) MainWindow_DoEmulatorSpeed(2);
if (ImGui::Button("120")) MainWindow_DoEmulatorSpeed(2);
ImGui::EndDisabled();
ImGui::SameLine(0.0f, 0.0f);
ImGui::BeginDisabled(speed == 3);
if (ImGui::Button("240")) MainWindow_DoEmulatorSpeed(3);
ImGui::EndDisabled();
ImGui::SameLine(0.0f, 0.0f);
ImGui::BeginDisabled(speed == 0);
Expand Down Expand Up @@ -466,7 +510,7 @@ void ControlView_ImGuiWidget()
else
ImGui::Text("%3.f", floor(vMouse.y));

if (ImGui::Button("Screenshot"))
if (ImGui::Button(ICON_FA_CAMERA " Screenshot"))
MainWindow_DoFileScreenshot();

ImGui::SeparatorText("Floppies");
Expand Down Expand Up @@ -576,6 +620,11 @@ void ControlView_ImGuiWidget()
ImGui::Spacing();
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
#endif

ImGui::Spacing();
if (ImGui::Button(ICON_FA_COG " Settings"))
open_settings_popup = true;

ImGui::End();
}

Expand All @@ -590,6 +639,11 @@ void MainWindow_DoScreenViewMode(ScreenViewMode mode)
Settings_SetScreenViewMode(mode);
}

void MainWindow_DoScreenSizeMode(ScreenSizeMode mode)
{
Settings_SetScreenSizeMode(mode);
}

void MainWindow_DoFloppyImageSelect(int slot)
{
// File Open dialog
Expand Down
38 changes: 35 additions & 3 deletions emulator/ScreenView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,41 @@ void ScreenView_ImGuiWidget()

ImVec2 vMin = ImGui::GetWindowContentRegionMin();
ImVec2 vMax = ImGui::GetWindowContentRegionMax();
ImVec2 size(vMax.x - vMin.x, vMax.y - vMin.y);
//TODO: Calculate size for selected view mode
//ImVec2 size(640.0f, 480.0f);

int sizemode = Settings_GetScreenSizeMode();
ImVec2 size;
switch (sizemode)
{
default: // Fill the box
size = ImVec2(vMax.x - vMin.x, vMax.y - vMin.y);
break;
case ScreenSize4to3ratio:
if ((vMax.x - vMin.x) / 4.0f <= (vMax.y - vMin.y) / 3.0f)
{
size.x = vMax.x - vMin.x;
size.y = size.x / 4.0f * 3.0f;
}
{
size.y = vMax.y - vMin.y;
size.x = size.y / 3.0f * 4.0f;
}
break;
case ScreenSize640x480:
size = ImVec2(640.0f, 480.0f);
break;
case ScreenSize800x600:
size = ImVec2(800.0f, 600.0f);
break;
case ScreenSize960x720:
size = ImVec2(960.0f, 720.0f);
break;
case ScreenSize1280x960:
size = ImVec2(1280.0f, 960.0f);
break;
case ScreenSize1600x1200:
size = ImVec2(1600.0f, 1200.0f);
break;
}

ImGui::Image(g_ScreenTextureID, size);

Expand Down
2 changes: 2 additions & 0 deletions emulator/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ void Settings_SetCartridgeFilePath(int slot, LPCTSTR sFilePath)

SETTINGS_GETSET_DWORD(ScreenViewMode, _T("ScreenViewMode"), int, 1);

SETTINGS_GETSET_DWORD(ScreenSizeMode, _T("ScreenSizeMode"), int, 0);

SETTINGS_GETSET_DWORD(ScreenVsync, _T("ScreenVsync"), BOOL, FALSE);

SETTINGS_GETSET_DWORD(ScreenHeightMode, _T("ScreenHeightMode"), int, 0);
Expand Down
6 changes: 4 additions & 2 deletions emulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ int main(int, char**)
nFrameDelay = 1000ll / 25 * 4 - 3;
else if (Settings_GetRealSpeed() == 0x7fff) // Speed 50%
nFrameDelay = 1000ll / 25 * 2 - 3;
else if (Settings_GetRealSpeed() == 2) // Speed 200%
nFrameDelay = 1000ll / 25 / 2 - 4;
else if (Settings_GetRealSpeed() == 2) // Speed 120%
nFrameDelay = 1000ll / 30 - 3;
else if (Settings_GetRealSpeed() == 3) // Speed 240%
nFrameDelay = 1000ll / 30 / 2 - 2;

for (;;)
{
Expand Down

0 comments on commit b477c0a

Please sign in to comment.