Atlas - SDL_vitamouse.c
Home / ext / SDL / src / video / vita Lines: 1 | Size: 4091 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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); 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 106[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.