Skip to content

Commit

Permalink
switch: use latest devkitpro. touchscreen support. cleaner abort
Browse files Browse the repository at this point in the history
Use latest devkitpro image.
Call diagAbortWithResult on fatal errors instead of freezing/infinite
loop.
Add Exit button on main content screen.
Touchscreen support.
  • Loading branch information
flyinghead committed Jan 16, 2024
1 parent e03c37b commit cfb7ff3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ubuntu-latest
container: devkitpro/devkita64:20220128
container: devkitpro/devkita64:latest

strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion core/linux/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ double os_GetSeconds()
return a.tv_sec-tvs_base+a.tv_usec/1000000.0;
}

#if !defined(__unix__) && !defined(LIBRETRO)
#if !defined(__unix__) && !defined(LIBRETRO) && !defined(__SWITCH__)
[[noreturn]] void os_DebugBreak()
{
__builtin_trap();
Expand Down
7 changes: 7 additions & 0 deletions core/linux/libnx_vmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,11 @@ void __libnx_exception_handler(ThreadExceptionDump *ctx)
}
}
#endif // TARGET_NO_EXCEPTIONS

#ifndef LIBRETRO
[[noreturn]] void os_DebugBreak()
{
diagAbortWithResult(MAKERESULT(350, 1));
}
#endif
#endif // __SWITCH__
15 changes: 11 additions & 4 deletions core/rend/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void gui_initFonts()
ImGui::GetStyle().TabRounding = 0;
ImGui::GetStyle().ItemSpacing = ImVec2(8, 8); // from 8,4
ImGui::GetStyle().ItemInnerSpacing = ImVec2(4, 6); // from 4,4
#if defined(__ANDROID__) || defined(TARGET_IPHONE)
#if defined(__ANDROID__) || defined(TARGET_IPHONE) || defined(__SWITCH__)
ImGui::GetStyle().TouchExtraPadding = ImVec2(1, 1); // from 0,0
#endif
if (settings.display.uiScale > 1)
Expand Down Expand Up @@ -378,7 +378,7 @@ static void gui_newFrame()
else
io.AddMousePosEvent(mouseX, mouseY);
static bool delayTouch;
#if defined(__ANDROID__) || defined(TARGET_IPHONE)
#if defined(__ANDROID__) || defined(TARGET_IPHONE) || defined(__SWITCH__)
// Delay touch by one frame to allow widgets to be hovered before click
// This is required for widgets using ImGuiButtonFlags_AllowItemOverlap such as TabItem's
if (!delayTouch && (mouseButtons & (1 << 0)) != 0 && !io.MouseDown[ImGuiMouseButton_Left])
Expand Down Expand Up @@ -2798,18 +2798,25 @@ static void gui_display_content()
ImGui::Unindent(10 * settings.display.uiScale);

static ImGuiTextFilter filter;
#if !defined(__ANDROID__) && !defined(TARGET_IPHONE) && !defined(TARGET_UWP)
#if !defined(__ANDROID__) && !defined(TARGET_IPHONE) && !defined(TARGET_UWP) && !defined(__SWITCH__)
ImGui::SameLine(0, 32 * settings.display.uiScale);
filter.Draw("Filter");
#endif
if (gui_state != GuiState::SelectDisk)
{
#ifdef TARGET_UWP
void gui_load_game();
ImGui::SameLine(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize("Settings").x - ImGui::GetStyle().FramePadding.x * 4.0f - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Load...").x);
ImGui::SameLine(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize("Settings").x
- ImGui::GetStyle().FramePadding.x * 4.0f - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Load...").x);
if (ImGui::Button("Load..."))
gui_load_game();
ImGui::SameLine();
#elif defined(__SWITCH__)
ImGui::SameLine(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize("Settings").x
- ImGui::GetStyle().FramePadding.x * 4.0f - ImGui::GetStyle().ItemSpacing.x - ImGui::CalcTextSize("Exit").x);
if (ImGui::Button("Exit"))
dc_exit();
ImGui::SameLine();
#else
ImGui::SameLine(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize("Settings").x - ImGui::GetStyle().FramePadding.x * 2.0f);
#endif
Expand Down
32 changes: 32 additions & 0 deletions core/sdl/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,38 @@ void input_sdl_handle()
case SDL_DROPFILE:
gui_start_game(event.drop.file);
break;

// Switch touchscreen support
case SDL_FINGERDOWN:
case SDL_FINGERMOTION:
{
int x = event.tfinger.x * settings.display.width;
int y = event.tfinger.y * settings.display.height;
gui_set_mouse_position(x, y);
if (mouseCaptured && gameRunning && event.type == SDL_FINGERMOTION)
{
int dx = event.tfinger.dx * settings.display.width;
int dy = event.tfinger.dy * settings.display.height;
sdl_mouse->setRelPos(dx, dy);
}
else
sdl_mouse->setAbsPos(x, y);
if (event.type == SDL_FINGERDOWN) {
sdl_mouse->setButton(Mouse::LEFT_BUTTON, true);
gui_set_mouse_button(0, true);
}
}
break;
case SDL_FINGERUP:
{
int x = event.tfinger.x * settings.display.width;
int y = event.tfinger.y * settings.display.height;
gui_set_mouse_position(x, y);
gui_set_mouse_button(0, false);
sdl_mouse->setAbsPos(x, y);
sdl_mouse->setButton(Mouse::LEFT_BUTTON, false);
}
break;
}
}
}
Expand Down

0 comments on commit cfb7ff3

Please sign in to comment.