Skip to content

Commit 2e0a38d

Browse files
committed
Widen default SDL window and Settings panel
1 parent bbca72c commit 2e0a38d

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

‎src/main.cpp‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
namespace fs = std::filesystem;
2121

22+
inline fs::path utf8_to_path(const std::string& s) {
23+
return fs::path(reinterpret_cast<const char8_t*>(s.c_str()));
24+
}
25+
inline std::string path_to_utf8(const fs::path& p) {
26+
auto u8 = p.u8string();
27+
return std::string(reinterpret_cast<const char*>(u8.c_str()), u8.size());
28+
}
29+
2230
// Default Key Mapping
2331
struct KeyConfig {
2432
SDL_Keycode up{SDLK_UP};
@@ -116,7 +124,7 @@ int main(int argc, char* argv[]) {
116124
SDL_Window* window = SDL_CreateWindow(
117125
"GameBoy Emulator - created by shinnei1509",
118126
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
119-
1280, 800,
127+
1420, 800,
120128
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI
121129
);
122130

@@ -166,10 +174,10 @@ int main(int argc, char* argv[]) {
166174

167175
// ROM Browser State - Default to src/rom folder
168176
std::string current_rom_dir = "src/rom";
169-
if (!fs::exists(current_rom_dir)) {
177+
if (!fs::exists(utf8_to_path(current_rom_dir))) {
170178
current_rom_dir = ".";
171179
}
172-
current_rom_dir = fs::absolute(current_rom_dir).string();
180+
current_rom_dir = path_to_utf8(fs::absolute(utf8_to_path(current_rom_dir)));
173181
std::string selected_rom_info = "No ROM Loaded";
174182

175183
// Debugger & Memory Editor
@@ -215,13 +223,13 @@ int main(int argc, char* argv[]) {
215223
if (event.type == SDL_DROPFILE) {
216224
std::string dropped_file = event.drop.file;
217225
try {
218-
fs::path src(dropped_file);
219-
fs::path dest = fs::path(current_rom_dir) / src.filename();
226+
fs::path src = utf8_to_path(dropped_file);
227+
fs::path dest = utf8_to_path(current_rom_dir) / src.filename();
220228
if (src != dest) {
221229
fs::copy_file(src, dest, fs::copy_options::overwrite_existing);
222230
}
223-
if (system.load_rom(dest.string())) {
224-
selected_rom_info = dest.filename().string();
231+
if (system.load_rom(path_to_utf8(dest))) {
232+
selected_rom_info = path_to_utf8(dest.filename());
225233
serial_log_buffer.clear();
226234
}
227235
} catch(const std::exception& e) {
@@ -307,28 +315,29 @@ int main(int argc, char* argv[]) {
307315
ImGui::Text("Current Directory:");
308316
ImGui::SameLine();
309317
if (ImGui::SmallButton("Up (..)")) {
310-
fs::path p(current_rom_dir);
318+
fs::path p = utf8_to_path(current_rom_dir);
311319
if (p.has_parent_path()) {
312-
current_rom_dir = p.parent_path().string();
320+
current_rom_dir = path_to_utf8(p.parent_path());
313321
}
314322
}
315323
ImGui::TextWrapped("%s", current_rom_dir.c_str());
316324
ImGui::Separator();
317325

318326
ImGui::BeginChild("ROMList", ImVec2(0, -55.0f), true);
319327
try {
320-
if (fs::exists(current_rom_dir) && fs::is_directory(current_rom_dir)) {
321-
for (const auto& entry : fs::directory_iterator(current_rom_dir)) {
322-
std::string filename = entry.path().filename().string();
328+
fs::path current_p = utf8_to_path(current_rom_dir);
329+
if (fs::exists(current_p) && fs::is_directory(current_p)) {
330+
for (const auto& entry : fs::directory_iterator(current_p)) {
331+
std::string filename = path_to_utf8(entry.path().filename());
323332
if (entry.is_directory()) {
324333
std::string label = "[DIR] " + filename;
325334
if (ImGui::Selectable(label.c_str())) {
326-
current_rom_dir = entry.path().string();
335+
current_rom_dir = path_to_utf8(entry.path());
327336
}
328-
} else if (filename.ends_with(".gb") || filename.ends_with(".gbc")) {
337+
} else if (filename.ends_with(".gb")) {
329338
std::string label = "[ROM] " + filename;
330339
if (ImGui::Selectable(label.c_str())) {
331-
std::string full_path = entry.path().string();
340+
std::string full_path = path_to_utf8(entry.path());
332341
if (system.load_rom(full_path)) {
333342
selected_rom_info = filename;
334343
serial_log_buffer.clear();
@@ -348,7 +357,7 @@ int main(int argc, char* argv[]) {
348357
ImGui::EndChild();
349358

350359
ImGui::Separator();
351-
ImGui::TextWrapped("Tip: You can drag and drop a .gb/.gbc file directly into the emulator to copy and load it instantly.");
360+
ImGui::TextWrapped("Tip: You can drag and drop a .gb file directly into the emulator to copy and load it instantly.");
352361
}
353362
ImGui::End();
354363

@@ -392,7 +401,7 @@ int main(int argc, char* argv[]) {
392401

393402
// 4. Settings Panel (Audio & Controller & Hardware Quirks)
394403
ImGui::SetNextWindowPos(ImVec2(950, 30), ImGuiCond_FirstUseEver);
395-
ImGui::SetNextWindowSize(ImVec2(320, 750), ImGuiCond_FirstUseEver);
404+
ImGui::SetNextWindowSize(ImVec2(450, 750), ImGuiCond_FirstUseEver);
396405
ImGui::Begin("Settings & Controls");
397406
{
398407
if (ImGui::CollapsingHeader("Emulation Controls", ImGuiTreeNodeFlags_DefaultOpen)) {

0 commit comments

Comments
 (0)