Skip to content

Commit 1790a28

Browse files
author
Roberto De Ioris
committed
attempt to fake UnrealHeaderTool
1 parent dcd640f commit 1790a28

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

Source/UnrealEnginePython/Private/PyUserWidget.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,22 +339,55 @@ bool UPyUserWidget::NativeIsInteractable() const
339339
return false;
340340
}
341341

342+
#if ENGINE_MINOR_VERSION < 20
342343
void UPyUserWidget::NativePaint(FPaintContext & InContext) const
344+
#else
345+
int32 UPyUserWidget::NativePaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
346+
#endif
343347
{
348+
349+
#if ENGINE_MINOR_VERSION >= 20
350+
FPaintContext InContext(AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, bParentEnabled);
351+
#endif
352+
344353
if (!py_user_widget_instance)
354+
#if ENGINE_MINOR_VERSION >= 20
355+
return -1;
356+
#else
345357
return;
358+
#endif
346359

347360
FScopePythonGIL gil;
348361

349362
if (!PyObject_HasAttrString(py_user_widget_instance, (char *)"paint"))
363+
#if ENGINE_MINOR_VERSION >= 20
364+
return -1;
365+
#else
350366
return;
367+
#endif
351368

352369
PyObject *ret = PyObject_CallMethod(py_user_widget_instance, (char *)"paint", (char *)"O", py_ue_new_fpaint_context(InContext));
353370
if (!ret) {
354371
unreal_engine_py_log_error();
372+
#if ENGINE_MINOR_VERSION >= 20
373+
return -1;
374+
#else
355375
return;
376+
#endif
356377
}
378+
#if ENGINE_MINOR_VERSION >= 20
379+
int32 RetValue = -1;
380+
if (PyNumber_Check(ret))
381+
{
382+
PyObject *py_value = PyNumber_Long(ret);
383+
RetValue = PyLong_AsLong(py_value);
384+
Py_DECREF(py_value);
385+
}
386+
#endif
357387
Py_DECREF(ret);
388+
#if ENGINE_MINOR_VERSION >= 20
389+
return RetValue;
390+
#endif
358391
}
359392

360393
UPyUserWidget::UPyUserWidget(const FObjectInitializer& ObjectInitializer)

Source/UnrealEnginePython/Public/PyUserWidget.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"
44
#include "UnrealEnginePython.h"
5+
#include "Runtime/Launch/Resources/Version.h"
56
#include "PyUserWidget.generated.h"
67

7-
8+
#if ENGINE_MINOR_VERSION < 20
9+
#define NativePaintArgs FPaintContext & InContext
10+
#define NativePaintRetValue void
11+
#else
12+
#define NativePaintArgs const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled
13+
#define NativePaintRetValue int32
14+
#endif
815

916
UCLASS(BlueprintType, Blueprintable)
1017
class UNREALENGINEPYTHON_API UPyUserWidget : public UUserWidget
@@ -21,7 +28,7 @@ class UNREALENGINEPYTHON_API UPyUserWidget : public UUserWidget
2128
// Called every frame
2229
virtual void NativeTick(const FGeometry & MyGeometry, float InDeltaTime) override;
2330

24-
virtual void NativePaint(FPaintContext & InContext) const override;
31+
virtual NativePaintRetValue NativePaint(NativePaintArgs) const override;
2532

2633
virtual bool NativeIsInteractable() const override;
2734

0 commit comments

Comments
 (0)