Skip to content

Commit

Permalink
ExternalImage: Add UserData property
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Oct 11, 2023
1 parent 999a94c commit b675687
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Source/script/imports/simbaclasses/simba.import_externalimage.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions Source/script/simba.script_pluginmethods.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 16 additions & 2 deletions Source/simba.externalimage.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ 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)
protected
FImage: TSimbaImage;
FLock: TSimpleEnterableLock;
FLockCount: Integer;
FUserData: Pointer;

FUnlockCallbacks: array of TSimbaExternalImageCallback;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b675687

Please sign in to comment.