Skip to content

Commit 4f21ff1

Browse files
committed
frontend: Add DualShock 2 icon
1 parent fc3b546 commit 4f21ff1

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

deps/imgui

Submodule imgui updated 72 files

frontend/imgui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ INCBIN(symbols, "../res/MaterialSymbolsRounded.ttf");
2525
INCBIN(firacode, "../res/FiraCode-Regular.ttf");
2626
INCBIN(ps1_memory_card_icon, "../res/ps1_mcd.png");
2727
INCBIN(ps2_memory_card_icon, "../res/ps2_mcd.png");
28+
INCBIN(dualshock2_icon, "../res/ds2.png");
2829
INCBIN(pocketstation_icon, "../res/pocketstation.png");
2930
INCBIN(iris_icon, "../res/iris.png");
3031
INCBIN(vertex_shader, "../shaders/vertex.spv");
@@ -864,6 +865,7 @@ bool init(iris::instance* iris) {
864865
iris->ps1_memory_card_icon = load_texture(g_ps1_memory_card_icon_data, g_ps1_memory_card_icon_size);
865866
iris->ps2_memory_card_icon = load_texture(g_ps2_memory_card_icon_data, g_ps2_memory_card_icon_size);
866867
iris->pocketstation_icon = load_texture(g_pocketstation_icon_data, g_pocketstation_icon_size);
868+
iris->dualshock2_icon = load_texture(g_dualshock2_icon_data, g_dualshock2_icon_size);
867869
iris->iris_icon = load_texture(g_iris_icon_data, g_iris_icon_size);
868870

869871
return true;
@@ -873,6 +875,7 @@ void cleanup(iris::instance* iris) {
873875
vulkan::free_texture(iris, iris->ps1_memory_card_icon);
874876
vulkan::free_texture(iris, iris->ps2_memory_card_icon);
875877
vulkan::free_texture(iris, iris->pocketstation_icon);
878+
vulkan::free_texture(iris, iris->dualshock2_icon);
876879
vulkan::free_texture(iris, iris->iris_icon);
877880

878881
ImGui_ImplVulkan_Shutdown();

frontend/iris.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,11 @@ void update_window(iris::instance* iris) {
304304
menubar_offset += iris->menubar_height;
305305
}
306306

307-
GetBackgroundDrawList()->AddRectFilled(
308-
ImVec2(width - ts.x - offset.x - padding.x, menubar_offset + offset.y - padding.y),
309-
ImVec2(width - offset.x + padding.x, menubar_offset + ts.y + offset.y + padding.y),
310-
GetColorU32(GetStyleColorVec4(ImGuiCol_WindowBg)), 8.0f
311-
);
307+
// GetBackgroundDrawList()->AddRectFilled(
308+
// ImVec2(width - ts.x - offset.x - padding.x, menubar_offset + offset.y - padding.y),
309+
// ImVec2(width - offset.x + padding.x, menubar_offset + ts.y + offset.y + padding.y),
310+
// GetColorU32(GetStyleColorVec4(ImGuiCol_WindowBg)), 8.0f
311+
// );
312312

313313
GetBackgroundDrawList(GetMainViewport())->AddText(
314314
ImVec2(width - ts.x - offset.x, menubar_offset + offset.y),
@@ -509,14 +509,14 @@ SDL_AppResult handle_events(iris::instance* iris, SDL_Event* event) {
509509
SDL_Log("Failed to open gamepad ID %u: %s", (unsigned int) event->gdevice.which, SDL_GetError());
510510
}
511511

512-
if ((iris->input_devices[0] == nullptr) || (iris->input_devices[0]->get_type() == 0)) {
512+
if (iris->ds[0] && ((iris->input_devices[0] == nullptr) || (iris->input_devices[0]->get_type() == 0))) {
513513
if (iris->input_devices[0]) delete iris->input_devices[0];
514514

515515
iris->input_devices[0] = new iris::gamepad_device(event->gdevice.which);
516516
iris->input_devices[0]->set_slot(0);
517517

518518
push_info(iris, "\'" + std::string(SDL_GetGamepadName(gamepad)) + "\' connected to slot 1");
519-
} else if ((iris->input_devices[1] == nullptr) || (iris->input_devices[1]->get_type() == 0)) {
519+
} else if (iris->ds[1] && ((iris->input_devices[1] == nullptr) || (iris->input_devices[1]->get_type() == 0))) {
520520
if (iris->input_devices[1]) delete iris->input_devices[1];
521521

522522
iris->input_devices[1] = new iris::gamepad_device(event->gdevice.which);
@@ -528,8 +528,6 @@ SDL_AppResult handle_events(iris::instance* iris, SDL_Event* event) {
528528
}
529529

530530
iris->gamepads[event->gdevice.which] = gamepad;
531-
532-
533531
} break;
534532

535533
case SDL_EVENT_GAMEPAD_REMOVED: {

frontend/iris.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ struct instance {
370370
texture ps2_memory_card_icon = {};
371371
texture ps1_memory_card_icon = {};
372372
texture pocketstation_icon = {};
373+
texture dualshock2_icon = {};
373374
texture iris_icon = {};
374375

375376
ImFont* font_small_code = nullptr;

frontend/ui/settings.cpp

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,56 @@ void show_controller_slot(iris::instance* iris, int slot) {
407407
if (BeginChild(label, ImVec2(GetContentRegionAvail().x / (slot ? 1.0 : 2.0) - 10.0, 0))) {
408408
std::string& path = slot ? iris->mcd1_path : iris->mcd0_path;
409409

410+
float avail_width = GetContentRegionAvail().x;
411+
410412
ImVec4 col = GetStyleColorVec4(iris->ds[slot] ? ImGuiCol_Text : ImGuiCol_TextDisabled);
411413

412414
col.w = 1.0;
413415

416+
PushFont(iris->font_heading);
417+
Text("Slot %d", slot+1);
418+
PopFont();
419+
420+
Text("Controller");
421+
422+
std::string controller_name = "None";
423+
424+
if (iris->ds[slot]) {
425+
controller_name = "DualShock 2";
426+
}
427+
428+
SetNextItemWidth(avail_width);
429+
430+
if (BeginCombo("##controller", controller_name.c_str())) {
431+
if (Selectable("None")) {
432+
if (iris->ds[slot]) {
433+
ps2_sio2_detach_device(iris->ps2->sio2, slot);
434+
435+
iris->ds[slot] = nullptr;
436+
}
437+
}
438+
439+
if (Selectable("DualShock 2")) {
440+
if (!iris->ds[slot]) {
441+
iris->ds[slot] = ds_attach(iris->ps2->sio2, slot);
442+
}
443+
}
444+
445+
EndCombo();
446+
}
447+
414448
InvisibleButton("##slot0", ImVec2(10, 10));
415449

416-
texture* tex = &iris->ps2_memory_card_icon;
450+
texture* tex = &iris->dualshock2_icon;
417451

418-
SetCursorPosX((GetContentRegionAvail().x / 2.0) - (tex->width / 2.0));
452+
float width = 225.0f;
453+
float height = (tex->height * width) / tex->width;
454+
455+
SetCursorPosX((GetContentRegionAvail().x / 2.0) - (width / 2.0));
419456

420457
Image(
421458
(ImTextureID)(intptr_t)tex->descriptor_set,
422-
ImVec2(tex->width, tex->height),
459+
ImVec2(width, height),
423460
ImVec2(0, 0), ImVec2(1, 1),
424461
col,
425462
ImVec4(0.0, 0.0, 0.0, 0.0)
@@ -429,10 +466,6 @@ void show_controller_slot(iris::instance* iris, int slot) {
429466

430467
BeginDisabled(!iris->ds[slot]);
431468

432-
PushFont(iris->font_heading);
433-
Text("Slot %d", slot+1);
434-
PopFont();
435-
436469
Text("Input device");
437470

438471
std::string name = "None";
@@ -447,6 +480,8 @@ void show_controller_slot(iris::instance* iris, int slot) {
447480
name = SDL_GetGamepadNameForID(gp->get_id());
448481
}
449482

483+
SetNextItemWidth(avail_width);
484+
450485
if (BeginCombo("##devicetype", name.c_str())) {
451486
if (Selectable("Keyboard")) {
452487
if (iris->input_devices[slot]) {
@@ -456,6 +491,7 @@ void show_controller_slot(iris::instance* iris, int slot) {
456491
}
457492

458493
iris->input_devices[slot] = new keyboard_device();
494+
iris->input_devices[slot]->set_slot(slot);
459495
}
460496

461497
for (auto gamepad : iris->gamepads) {
@@ -467,6 +503,7 @@ void show_controller_slot(iris::instance* iris, int slot) {
467503
}
468504

469505
iris->input_devices[slot] = new gamepad_device(gamepad.first);
506+
iris->input_devices[slot]->set_slot(slot);
470507
}
471508
}
472509

@@ -1174,8 +1211,8 @@ void show_settings(iris::instance* iris) {
11741211
ImGuiWindowFlags_NoCollapse |
11751212
ImGuiWindowFlags_NoDocking;
11761213

1177-
SetNextWindowSize(ImVec2(650, 560), ImGuiCond_FirstUseEver);
1178-
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(650, 560));
1214+
SetNextWindowSize(ImVec2(675, 560), ImGuiCond_FirstUseEver);
1215+
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(675, 560));
11791216

11801217
if (GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable && !GetIO().ConfigViewportsNoDecoration)
11811218
flags |= ImGuiWindowFlags_NoTitleBar;

res/ds2.png

23.2 KB
Loading

0 commit comments

Comments
 (0)