From eb0f36ce582cbe991e78ad1efdbb8598f6bd3af0 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 31 Jul 2024 20:11:51 +1000 Subject: [PATCH] Expose more functionality for plugins --- src/Input.h | 10 +++++++++- src/InputHandler.c | 4 ++++ src/String.c | 2 +- src/String.h | 8 ++++---- src/Window_Win.c | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Input.h b/src/Input.h index 6813a6e3e..aa891bd02 100644 --- a/src/Input.h +++ b/src/Input.h @@ -182,7 +182,15 @@ extern struct TouchPointer touches[INPUT_MAX_POINTERS]; #define TOUCH_TYPE_ALL (TOUCH_TYPE_GUI | TOUCH_TYPE_CAMERA | TOUCH_TYPE_BLOCKS) /* Data for mouse and touch */ -extern struct Pointer { int x, y; } Pointers[INPUT_MAX_POINTERS]; +struct Pointer { + int x, y; + /* Function that overrides all normal pointer input press handling */ + void (*DownHook)(int index); + /* Function that overrides all normal pointer input release handling */ + void (*UpHook) (int index); +}; +CC_VAR extern struct Pointer Pointers[INPUT_MAX_POINTERS]; + /* Raises appropriate events for a mouse vertical scroll */ void Mouse_ScrollVWheel(float delta); /* Raises appropriate events for a mouse horizontal scroll */ diff --git a/src/InputHandler.c b/src/InputHandler.c index f6471ae4f..e8f7c933d 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -784,6 +784,8 @@ cc_bool KeyBind_IsPressed(InputBind binding) { return Bind_IsTriggered[binding]; static void OnPointerDown(void* obj, int idx) { struct Screen* s; int i, x, y, mask; + if (Pointers[idx].DownHook) { Pointers[idx].DownHook(idx); return; } + /* Always set last click time, otherwise quickly tapping */ /* sometimes triggers a 'delete' in InputHandler_Tick, */ /* and then another 'delete' in CheckBlockTap. */ @@ -820,6 +822,8 @@ static void OnPointerDown(void* obj, int idx) { static void OnPointerUp(void* obj, int idx) { struct Screen* s; int i, x, y; + if (Pointers[idx].UpHook) { Pointers[idx].UpHook(idx); return; } + #ifdef CC_BUILD_TOUCH CheckBlockTap(idx); if (Input_TouchMode && !(touches[idx].type & TOUCH_TYPE_GUI)) return; diff --git a/src/String.c b/src/String.c index fe74e19d7..9c7f22f5a 100644 --- a/src/String.c +++ b/src/String.c @@ -638,7 +638,7 @@ void String_AppendUtf8(cc_string* value, const void* data, int numBytes) { } } -void String_DecodeCP1252(cc_string* value, const void* data, int numBytes) { +void String_AppendCP1252(cc_string* value, const void* data, int numBytes) { const cc_uint8* chars = (const cc_uint8*)data; int i; char c; diff --git a/src/String.h b/src/String.h index 55075dcf1..20d6838a7 100644 --- a/src/String.h +++ b/src/String.h @@ -201,16 +201,16 @@ int Convert_CP437ToUtf8(char c, cc_uint8* data); /* Attempts to append all characters from UTF16 encoded data to the given string. */ /* Characters not in code page 437 are omitted. */ -void String_AppendUtf16(cc_string* str, const void* data, int numBytes); +CC_API void String_AppendUtf16(cc_string* str, const void* data, int numBytes); /* Attempts to append all characters from UTF8 encoded data to the given string. */ /* Characters not in code page 437 are omitted. */ -void String_AppendUtf8(cc_string* str, const void* data, int numBytes); +CC_API void String_AppendUtf8(cc_string* str, const void* data, int numBytes); /* Attempts to append all characters from CP-1252 encoded data to the given string. */ /* Characters not in code page 437 are omitted. */ -void String_DecodeCP1252(cc_string* str, const void* data, int numBytes); +CC_API void String_AppendCP1252(cc_string* str, const void* data, int numBytes); /* Encodes a string in UTF8 format, also null terminating the string. */ /* Returns the number of bytes written, excluding trailing NULL terminator. */ -int String_EncodeUtf8(void* data, const cc_string* src); +CC_API int String_EncodeUtf8(void* data, const cc_string* src); /* Attempts to convert the given string into an unsigned 8 bit integer. */ CC_API cc_bool Convert_ParseUInt8(const cc_string* str, cc_uint8* value); diff --git a/src/Window_Win.c b/src/Window_Win.c index 0ed8ff638..b55b973d7 100644 --- a/src/Window_Win.c +++ b/src/Window_Win.c @@ -458,7 +458,7 @@ void Clipboard_GetText(cc_string* value) { if (unicode) { String_AppendUtf16(value, src, size - 2); } else { - String_DecodeCP1252(value, src, size - 1); + String_AppendCP1252(value, src, size - 1); } GlobalUnlock(hGlobal);