diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/n3ds/SDL_n3dstouch.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/n3ds/SDL_n3dstouch.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/n3ds/SDL_n3dstouch.c b/contrib/SDL-3.2.8/src/video/n3ds/SDL_n3dstouch.c new file mode 100644 index 0000000..8116e4a --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/n3ds/SDL_n3dstouch.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | |||
| 24 | #ifdef SDL_VIDEO_DRIVER_N3DS | ||
| 25 | |||
| 26 | #include <3ds.h> | ||
| 27 | |||
| 28 | #include "../../events/SDL_touch_c.h" | ||
| 29 | #include "../SDL_sysvideo.h" | ||
| 30 | #include "SDL_n3dstouch.h" | ||
| 31 | #include "SDL_n3dsvideo.h" | ||
| 32 | |||
| 33 | #define N3DS_TOUCH_ID 1 | ||
| 34 | #define N3DS_TOUCH_FINGER 1 | ||
| 35 | |||
| 36 | /* | ||
| 37 | Factors used to convert touchscreen coordinates to | ||
| 38 | SDL's 0-1 values. Note that the N3DS's screen is | ||
| 39 | internally in a portrait disposition so the | ||
| 40 | GSP_SCREEN constants are flipped. | ||
| 41 | */ | ||
| 42 | #define TOUCHSCREEN_SCALE_X 1.0f / (GSP_SCREEN_HEIGHT_BOTTOM - 1) | ||
| 43 | #define TOUCHSCREEN_SCALE_Y 1.0f / (GSP_SCREEN_WIDTH - 1) | ||
| 44 | |||
| 45 | void N3DS_InitTouch(void) | ||
| 46 | { | ||
| 47 | SDL_AddTouch(N3DS_TOUCH_ID, SDL_TOUCH_DEVICE_DIRECT, "Touchscreen"); | ||
| 48 | } | ||
| 49 | |||
| 50 | void N3DS_QuitTouch(void) | ||
| 51 | { | ||
| 52 | SDL_DelTouch(N3DS_TOUCH_ID); | ||
| 53 | } | ||
| 54 | |||
| 55 | void N3DS_PollTouch(SDL_VideoDevice *_this) | ||
| 56 | { | ||
| 57 | SDL_VideoData *internal = (SDL_VideoData *)_this->internal; | ||
| 58 | touchPosition touch; | ||
| 59 | SDL_Window *window; | ||
| 60 | SDL_VideoDisplay *display; | ||
| 61 | static bool was_pressed = false; | ||
| 62 | bool pressed; | ||
| 63 | hidTouchRead(&touch); | ||
| 64 | pressed = (touch.px != 0 || touch.py != 0); | ||
| 65 | |||
| 66 | display = SDL_GetVideoDisplay(internal->touch_display); | ||
| 67 | window = display ? display->fullscreen_window : NULL; | ||
| 68 | |||
| 69 | if (pressed != was_pressed) { | ||
| 70 | was_pressed = pressed; | ||
| 71 | SDL_SendTouch(0, N3DS_TOUCH_ID, N3DS_TOUCH_FINGER, | ||
| 72 | window, | ||
| 73 | pressed ? SDL_EVENT_FINGER_DOWN : SDL_EVENT_FINGER_UP, | ||
| 74 | touch.px * TOUCHSCREEN_SCALE_X, | ||
| 75 | touch.py * TOUCHSCREEN_SCALE_Y, | ||
| 76 | pressed ? 1.0f : 0.0f); | ||
| 77 | } else if (pressed) { | ||
| 78 | SDL_SendTouchMotion(0, N3DS_TOUCH_ID, N3DS_TOUCH_FINGER, | ||
| 79 | window, | ||
| 80 | touch.px * TOUCHSCREEN_SCALE_X, | ||
| 81 | touch.py * TOUCHSCREEN_SCALE_Y, | ||
| 82 | 1.0f); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | #endif // SDL_VIDEO_DRIVER_N3DS | ||
