From b6756873758062842d411b9139a81141f5b741c3 Mon Sep 17 00:00:00 2001 From: Olly Date: Wed, 11 Oct 2023 14:53:06 +0100 Subject: [PATCH] ExternalImage: Add UserData property --- .../simba.import_externalimage.pas | 11 +++++++++++ Source/script/simba.script_pluginmethods.pas | 16 ++++++++++++++-- Source/simba.externalimage.pas | 18 ++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Source/script/imports/simbaclasses/simba.import_externalimage.pas b/Source/script/imports/simbaclasses/simba.import_externalimage.pas index 4bedfd9d7..ee49531e7 100644 --- a/Source/script/imports/simbaclasses/simba.import_externalimage.pas +++ b/Source/script/imports/simbaclasses/simba.import_externalimage.pas @@ -501,6 +501,16 @@ procedure _LapeExternalImage_SetMemory(const Params: PParamArray); LAPE_WRAPPER_ PSimbaExternalImage(Params^[0])^.SetMemory(PPointer(Params^[1])^, PInteger(Params^[2])^, PInteger(Params^[3])^); end; +procedure _LapeExternalImage_GetUserData(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPointer(Result)^ := PSimbaExternalImage(Params^[0])^.GetUserData(); +end; + +procedure _LapeExternalImage_SetUserData(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalImage(Params^[0])^.SetUserData(PPointer(Params^[1])^); +end; + procedure ImportSimbaExternalImage(Compiler: TSimbaScript_Compiler); begin with Compiler do @@ -515,6 +525,7 @@ procedure ImportSimbaExternalImage(Compiler: TSimbaScript_Compiler); addClassVar('TExternalImage', 'FontAntialiasing', 'Boolean', @_LapeExternalImage_FontAntialiasing_Read, @_LapeExternalImage_FontAntialiasing_Write); addClassVar('TExternalImage', 'FontBold', 'Boolean', @_LapeExternalImage_FontBold_Read, @_LapeExternalImage_FontBold_Write); addClassVar('TExternalImage', 'FontItalic', 'Boolean', @_LapeExternalImage_FontItalic_Read, @_LapeExternalImage_FontItalic_Write); + addClassVar('TExternalImage', 'UserData', 'Pointer', @_LapeExternalImage_GetUserData, @_LapeExternalImage_SetUserData); addGlobalFunc('function TExternalImage.TextWidth(Text: String): Integer;', @_LapeExternalImage_TextWidth); addGlobalFunc('function TExternalImage.TextHeight(Text: String): Integer;', @_LapeExternalImage_TextHeight); diff --git a/Source/script/simba.script_pluginmethods.pas b/Source/script/simba.script_pluginmethods.pas index d53a00861..e1bbea4d5 100644 --- a/Source/script/simba.script_pluginmethods.pas +++ b/Source/script/simba.script_pluginmethods.pas @@ -50,9 +50,10 @@ interface ExternalImage_TryLock: function(Img: Pointer): Boolean; cdecl; ExternalImage_Lock: procedure(Img: Pointer); cdecl; ExternalImage_UnLock: procedure(Img: Pointer); cdecl; - ExternalImage_AddCallbackOnUnlock: procedure(Img: Pointer; Callback: TSimbaExternalImageCallback); cdecl; ExternalImage_RemoveCallbackOnUnlock: procedure(Img: Pointer; Callback: TSimbaExternalImageCallback); cdecl; + ExternalImage_SetUserData: procedure(Img: Pointer; UserData: Pointer); cdecl; + ExternalImage_GetUserData: function(Img: Pointer): Pointer; cdecl; // Extend this but do not remove, reorder or change datatypes. end; @@ -306,6 +307,16 @@ procedure Plugin_ExternalImage_RemoveCallbackOnUnlock(Img: Pointer; Callback: TS TSimbaExternalImage(Img).RemoveUnlockCallback(Callback); end; +procedure Plugin_ExternalImage_SetUserData(Img: Pointer; UserData: Pointer); cdecl; +begin + TSimbaExternalImage(Img).SetUserData(UserData); +end; + +function Plugin_ExternalImage_GetUserData(Img: Pointer): Pointer; cdecl; +begin + Result := TSimbaExternalImage(Img).GetUserData(); +end; + initialization with SimbaPluginMethods do @@ -338,9 +349,10 @@ initialization ExternalImage_TryLock := @Plugin_ExternalImage_TryLock; ExternalImage_Lock := @Plugin_ExternalImage_Lock; ExternalImage_Unlock := @Plugin_ExternalImage_UnLock; - ExternalImage_AddCallbackOnUnlock := @Plugin_ExternalImage_AddCallbackOnUnlock; ExternalImage_RemoveCallbackOnUnlock := @Plugin_ExternalImage_RemoveCallbackOnUnlock; + ExternalImage_GetUserData := @Plugin_ExternalImage_GetUserData; + ExternalImage_SetUserData := @Plugin_ExternalImage_SetUserData; end; end. diff --git a/Source/simba.externalimage.pas b/Source/simba.externalimage.pas index ffe91bfaf..073ea580e 100644 --- a/Source/simba.externalimage.pas +++ b/Source/simba.externalimage.pas @@ -9,7 +9,7 @@ interface simba.mufasatypes, simba.baseclass, simba.image, simba.simplelock; type - TSimbaExternalImageCallback = procedure(Image: Pointer); cdecl; + TSimbaExternalImageCallback = procedure(Image: Pointer; UserData: Pointer); cdecl; PSimbaExternalImage = ^TSimbaExternalImage; TSimbaExternalImage = class(TSimbaBaseClass) @@ -17,6 +17,7 @@ TSimbaExternalImage = class(TSimbaBaseClass) FImage: TSimbaImage; FLock: TSimpleEnterableLock; FLockCount: Integer; + FUserData: Pointer; FUnlockCallbacks: array of TSimbaExternalImageCallback; @@ -53,6 +54,9 @@ TSimbaExternalImage = class(TSimbaBaseClass) property FontBold: Boolean read GetFontBold write SetFontBold; property FontItalic: Boolean read GetFontItalic write SetFontItalic; + procedure SetUserData(UserData: Pointer); + function GetUserData: Pointer; + procedure SetMemory(Data: PColorBGRA; AWidth, AHeight: Integer); function TextWidth(Text: String): Integer; @@ -257,7 +261,7 @@ procedure TSimbaExternalImage.Unlock; Dec(FLockCount); if (FLockCount = 0) then for i := 0 to High(FUnlockCallbacks) do - FUnlockCallbacks[i](Self); + FUnlockCallbacks[i](Self, FUserData); FLock.Leave(); end; @@ -287,6 +291,16 @@ procedure TSimbaExternalImage.SetMemory(Data: PColorBGRA; AWidth, AHeight: Integ end; end; +procedure TSimbaExternalImage.SetUserData(UserData: Pointer); +begin + FUserData := UserData; +end; + +function TSimbaExternalImage.GetUserData: Pointer; +begin + Result := FUserData; +end; + function TSimbaExternalImage.TextWidth(Text: String): Integer; begin Lock();