Skip to content

Commit

Permalink
fixed build for 4.17, added support for mouse in SPythonWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto De Ioris committed Nov 18, 2017
1 parent e1fbe9f commit 4228109
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
122 changes: 122 additions & 0 deletions Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "UEPyFPaintContext.h"
#include "UEPyFCharacterEvent.h"
#include "UEPyFKeyEvent.h"
#include "UEPyFPointerEvent.h"

extern PyTypeObject ue_PySPythonWidgetType;

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions Source/UnrealEnginePython/Private/Wrappers/UEPyFAssetData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand All @@ -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)
{
Expand All @@ -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 */
};
Expand Down

0 comments on commit 4228109

Please sign in to comment.