summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
committer3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
commit5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch)
tree8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c')
-rw-r--r--contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c
new file mode 100644
index 0000000..7181023
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitamouse.c
@@ -0,0 +1,105 @@
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#include "SDL_internal.h"
22
23#ifdef SDL_VIDEO_DRIVER_VITA
24
25#include <psp2/kernel/processmgr.h>
26#include <psp2/ctrl.h>
27#include <psp2/hid.h>
28
29#include "SDL_vitavideo.h"
30#include "SDL_vitamouse_c.h"
31#include "../../events/SDL_mouse_c.h"
32
33SceHidMouseReport m_reports[SCE_HID_MAX_REPORT];
34int mouse_hid_handle = 0;
35Uint8 prev_buttons = 0;
36
37void VITA_InitMouse(void)
38{
39 sceHidMouseEnumerate(&mouse_hid_handle, 1);
40
41 if (mouse_hid_handle > 0) {
42 SDL_AddMouse((SDL_MouseID)mouse_hid_handle, NULL, false);
43 }
44}
45
46void VITA_PollMouse(void)
47{
48 // We skip polling mouse if no window is created
49 if (!Vita_Window) {
50 return;
51 }
52
53 if (mouse_hid_handle > 0) {
54 SDL_MouseID mouseID = (SDL_MouseID)mouse_hid_handle;
55 int numReports = sceHidMouseRead(mouse_hid_handle, (SceHidMouseReport **)&m_reports, SCE_HID_MAX_REPORT);
56 if (numReports > 0) {
57 for (int i = 0; i <= numReports - 1; i++) {
58 Uint8 changed_buttons = m_reports[i].buttons ^ prev_buttons;
59
60 if (changed_buttons & 0x1) {
61 if (prev_buttons & 0x1)
62 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_LEFT, false);
63 else
64 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_LEFT, true);
65 }
66 if (changed_buttons & 0x2) {
67 if (prev_buttons & 0x2)
68 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_RIGHT, false);
69 else
70 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_RIGHT, true);
71 }
72 if (changed_buttons & 0x4) {
73 if (prev_buttons & 0x4)
74 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_MIDDLE, false);
75 else
76 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_MIDDLE, true);
77 }
78 if (changed_buttons & 0x8) {
79 if (prev_buttons & 0x8)
80 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X1, false);
81 else
82 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X1, true);
83 }
84 if (changed_buttons & 0x10) {
85 if (prev_buttons & 0x10)
86 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X2, false);
87 else
88 SDL_SendMouseButton(0, Vita_Window, mouseID, SDL_BUTTON_X2, true);
89 }
90
91 prev_buttons = m_reports[i].buttons;
92
93 if (m_reports[i].rel_x || m_reports[i].rel_y) {
94 SDL_SendMouseMotion(0, Vita_Window, mouseID, true, (float)m_reports[i].rel_x, (float)m_reports[i].rel_y);
95 }
96
97 if (m_reports[i].tilt != 0 || m_reports[i].wheel != 0) {
98 SDL_SendMouseWheel(0, Vita_Window, mouseID, m_reports[i].tilt, m_reports[i].wheel, SDL_MOUSEWHEEL_NORMAL);
99 }
100 }
101 }
102 }
103}
104
105#endif // SDL_VIDEO_DRIVER_VITA