From 4228109eace5afc368683b99b553015f17c7f717 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 18 Nov 2017 17:57:03 +0100 Subject: [PATCH] fixed build for 4.17, added support for mouse in SPythonWidget --- .../Private/Slate/UEPySPythonWidget.h | 122 ++++++++++++++++++ .../Private/Wrappers/UEPyFAssetData.cpp | 4 + 2 files changed, 126 insertions(+) diff --git a/Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h b/Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h index 7d2ceaf57..13f0942de 100644 --- a/Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h +++ b/Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h @@ -7,6 +7,7 @@ #include "UEPyFPaintContext.h" #include "UEPyFCharacterEvent.h" #include "UEPyFKeyEvent.h" +#include "UEPyFPointerEvent.h" extern PyTypeObject ue_PySPythonWidgetType; @@ -88,6 +89,127 @@ class SPythonWidget : public SCompoundWidget return FReply::Handled(); } + virtual FReply OnMouseMove(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override + { + FScopePythonGIL gil; + + if (!PyObject_HasAttrString(self, (char *)"on_mouse_move")) + return FReply::Unhandled(); + + PyObject *py_callable_on_mouse_move = PyObject_GetAttrString(self, (char *)"on_mouse_move"); + if (!PyCallable_Check(py_callable_on_mouse_move)) + { + UE_LOG(LogPython, Error, TEXT("on_mouse_move is not a callable")); + return FReply::Unhandled(); + } + + PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_move, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent)); + if (!ret) + { + unreal_engine_py_log_error(); + return FReply::Unhandled(); + } + + if (ret == Py_False) + { + Py_DECREF(ret); + return FReply::Unhandled(); + } + Py_DECREF(ret); + return FReply::Handled(); + } + + virtual FReply OnMouseWheel(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override + { + FScopePythonGIL gil; + + if (!PyObject_HasAttrString(self, (char *)"on_mouse_wheel")) + return FReply::Unhandled(); + + PyObject *py_callable_on_mouse_wheel = PyObject_GetAttrString(self, (char *)"on_mouse_wheel"); + if (!PyCallable_Check(py_callable_on_mouse_wheel)) + { + UE_LOG(LogPython, Error, TEXT("on_mouse_wheel is not a callable")); + return FReply::Unhandled(); + } + + PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_wheel, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent)); + if (!ret) + { + unreal_engine_py_log_error(); + return FReply::Unhandled(); + } + + if (ret == Py_False) + { + Py_DECREF(ret); + return FReply::Unhandled(); + } + Py_DECREF(ret); + return FReply::Handled(); + } + + virtual FReply OnMouseButtonDown(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override + { + FScopePythonGIL gil; + + if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_down")) + return FReply::Unhandled(); + + PyObject *py_callable_on_mouse_button_down = PyObject_GetAttrString(self, (char *)"on_mouse_button_down"); + if (!PyCallable_Check(py_callable_on_mouse_button_down)) + { + UE_LOG(LogPython, Error, TEXT("on_mouse_button_down is not a callable")); + return FReply::Unhandled(); + } + + PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_down, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent)); + if (!ret) + { + unreal_engine_py_log_error(); + return FReply::Unhandled(); + } + + if (ret == Py_False) + { + Py_DECREF(ret); + return FReply::Unhandled(); + } + Py_DECREF(ret); + return FReply::Handled(); + } + + virtual FReply OnMouseButtonUp(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override + { + FScopePythonGIL gil; + + if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_up")) + return FReply::Unhandled(); + + PyObject *py_callable_on_mouse_button_up = PyObject_GetAttrString(self, (char *)"on_mouse_button_up"); + if (!PyCallable_Check(py_callable_on_mouse_button_up)) + { + UE_LOG(LogPython, Error, TEXT("on_mouse_button_up is not a callable")); + return FReply::Unhandled(); + } + + PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_up, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent)); + if (!ret) + { + unreal_engine_py_log_error(); + return FReply::Unhandled(); + } + + if (ret == Py_False) + { + Py_DECREF(ret); + return FReply::Unhandled(); + } + Py_DECREF(ret); + return FReply::Handled(); + } + + virtual int32 OnPaint(const FPaintArgs & Args, const FGeometry & AllottedGeometry, const FSlateRect & MyClippingRect, diff --git a/Source/UnrealEnginePython/Private/Wrappers/UEPyFAssetData.cpp b/Source/UnrealEnginePython/Private/Wrappers/UEPyFAssetData.cpp index 5660715cc..9749c5c67 100644 --- a/Source/UnrealEnginePython/Private/Wrappers/UEPyFAssetData.cpp +++ b/Source/UnrealEnginePython/Private/Wrappers/UEPyFAssetData.cpp @@ -43,6 +43,7 @@ static PyObject *py_ue_fassetdata_get_thumbnail(ue_PyFAssetData *self, PyObject return py_ue_new_fobject_thumbnail(*thumbnail); } +#if ENGINE_MINOR_VERSION > 17 static PyObject *py_ue_fassetdata_has_custom_thumbnail(ue_PyFAssetData *self, PyObject * args) { @@ -53,6 +54,7 @@ static PyObject *py_ue_fassetdata_has_custom_thumbnail(ue_PyFAssetData *self, Py Py_RETURN_TRUE; } +#endif static PyObject *py_ue_fassetdata_has_cached_thumbnail(ue_PyFAssetData *self, PyObject * args) { @@ -69,7 +71,9 @@ static PyMethodDef ue_PyFAssetData_methods[] = { { "get_asset", (PyCFunction)py_ue_fassetdata_get_asset, METH_VARARGS, "" }, { "is_asset_loaded", (PyCFunction)py_ue_fassetdata_is_asset_loaded, METH_VARARGS, "" }, { "get_thumbnail", (PyCFunction)py_ue_fassetdata_get_thumbnail, METH_VARARGS, "" }, +#if ENGINE_MINOR_VERSION > 17 { "has_custom_thumbnail", (PyCFunction)py_ue_fassetdata_has_custom_thumbnail, METH_VARARGS, "" }, +#endif { "has_cached_thumbnail", (PyCFunction)py_ue_fassetdata_has_cached_thumbnail, METH_VARARGS, "" }, { NULL } /* Sentinel */ };