From e86d57f4f6179c138614f902c151bfcdce13bdde Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 23 Mar 2024 10:46:46 +1100 Subject: [PATCH] DS: Slightly better touch input, still needs work though --- src/Core.h | 1 + src/Window_NDS.c | 49 +++++++++++++++++++----------------------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/Core.h b/src/Core.h index c00d601ed..948037fbf 100644 --- a/src/Core.h +++ b/src/Core.h @@ -346,6 +346,7 @@ typedef cc_uint8 cc_bool; #define CC_BUILD_COOPTHREADED #define CC_BUILD_LOWMEM #define CC_BUILD_CONSOLE + #define CC_BUILD_TOUCH #undef CC_BUILD_FREETYPE #undef CC_BUILD_RESOURCES #elif defined __WIIU__ diff --git a/src/Window_NDS.c b/src/Window_NDS.c index a644ae6cc..c5ec52fd3 100644 --- a/src/Window_NDS.c +++ b/src/Window_NDS.c @@ -15,7 +15,6 @@ #include #include -static int touchActive, touchBegX, touchBegY; static cc_bool launcherMode, keyboardOpen; static int bg_id; static u16* bg_ptr; @@ -23,10 +22,9 @@ static u16* bg_ptr; struct _DisplayData DisplayInfo; struct _WindowData WindowInfo; -void Window_Init(void) { - - DisplayInfo.Width = 256; - DisplayInfo.Height = 192; +void Window_Init(void) { + DisplayInfo.Width = SCREEN_WIDTH; + DisplayInfo.Height = SCREEN_HEIGHT; DisplayInfo.Depth = 4; // 32 bit DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleY = 0.5f; @@ -36,11 +34,10 @@ void Window_Init(void) { Window_Main.Focused = true; Window_Main.Exists = true; + //Input_SetTouchMode(true); TODO not UI Input.Sources = INPUT_SOURCE_GAMEPAD; consoleDemoInit(); - consoleDebugInit(DebugDevice_NOCASH); - videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG); @@ -91,19 +88,22 @@ static void HandleButtons(int mods) { Input_SetNonRepeatable(CCPAD_DOWN, mods & KEY_DOWN); } +// Copied from Window_3DS.c static void ProcessTouchInput(int mods) { - touchPosition pos; - touchRead(&pos); + static int curX, curY; // current touch position + touchPosition touch; + touchRead(&touch); - // Set starting position for camera movement - if (!touchActive && (mods & KEY_TOUCH)) { - touchBegX = pos.px; - touchBegY = pos.py; - } - - touchActive = mods & KEY_TOUCH; - if (touchActive) { - Pointer_SetPosition(0, pos.px, pos.py); + if (keysDown() & KEY_TOUCH) { // stylus went down + curX = touch.px; + curY = touch.py; + Input_AddTouch(0, curX, curY); + } else if (mods & KEY_TOUCH) { // stylus is down + curX = touch.px; + curY = touch.py; + Input_UpdateTouch(0, curX, curY); + } else if (keysUp() & KEY_TOUCH) { // stylus was lifted + Input_RemoveTouch(0, curX, curY); } } @@ -115,7 +115,6 @@ void Window_ProcessEvents(double delta) { if (keyboardOpen) { keyboardUpdate(); } else { - Input_SetNonRepeatable(CCMOUSE_L, keys & KEY_TOUCH); ProcessTouchInput(keys); } } @@ -124,17 +123,7 @@ void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP void Window_EnableRawMouse(void) { Input.RawMode = true; } void Window_DisableRawMouse(void) { Input.RawMode = false; } -void Window_UpdateRawMouse(void) { - if (!touchActive) return; - - touchPosition touch; - touchRead(&touch); - - Event_RaiseRawMove(&PointerEvents.RawMoved, - touch.px - touchBegX, touch.py - touchBegY); - touchBegX = touch.px; - touchBegY = touch.py; -} +void Window_UpdateRawMouse(void) { } /*########################################################################################################################*