Skip to content

Commit 4228109

Browse files
author
Roberto De Ioris
committed
fixed build for 4.17, added support for mouse in SPythonWidget
1 parent e1fbe9f commit 4228109

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "UEPyFPaintContext.h"
88
#include "UEPyFCharacterEvent.h"
99
#include "UEPyFKeyEvent.h"
10+
#include "UEPyFPointerEvent.h"
1011

1112
extern PyTypeObject ue_PySPythonWidgetType;
1213

@@ -88,6 +89,127 @@ class SPythonWidget : public SCompoundWidget
8889
return FReply::Handled();
8990
}
9091

92+
virtual FReply OnMouseMove(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
93+
{
94+
FScopePythonGIL gil;
95+
96+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_move"))
97+
return FReply::Unhandled();
98+
99+
PyObject *py_callable_on_mouse_move = PyObject_GetAttrString(self, (char *)"on_mouse_move");
100+
if (!PyCallable_Check(py_callable_on_mouse_move))
101+
{
102+
UE_LOG(LogPython, Error, TEXT("on_mouse_move is not a callable"));
103+
return FReply::Unhandled();
104+
}
105+
106+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_move, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
107+
if (!ret)
108+
{
109+
unreal_engine_py_log_error();
110+
return FReply::Unhandled();
111+
}
112+
113+
if (ret == Py_False)
114+
{
115+
Py_DECREF(ret);
116+
return FReply::Unhandled();
117+
}
118+
Py_DECREF(ret);
119+
return FReply::Handled();
120+
}
121+
122+
virtual FReply OnMouseWheel(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
123+
{
124+
FScopePythonGIL gil;
125+
126+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_wheel"))
127+
return FReply::Unhandled();
128+
129+
PyObject *py_callable_on_mouse_wheel = PyObject_GetAttrString(self, (char *)"on_mouse_wheel");
130+
if (!PyCallable_Check(py_callable_on_mouse_wheel))
131+
{
132+
UE_LOG(LogPython, Error, TEXT("on_mouse_wheel is not a callable"));
133+
return FReply::Unhandled();
134+
}
135+
136+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_wheel, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
137+
if (!ret)
138+
{
139+
unreal_engine_py_log_error();
140+
return FReply::Unhandled();
141+
}
142+
143+
if (ret == Py_False)
144+
{
145+
Py_DECREF(ret);
146+
return FReply::Unhandled();
147+
}
148+
Py_DECREF(ret);
149+
return FReply::Handled();
150+
}
151+
152+
virtual FReply OnMouseButtonDown(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
153+
{
154+
FScopePythonGIL gil;
155+
156+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_down"))
157+
return FReply::Unhandled();
158+
159+
PyObject *py_callable_on_mouse_button_down = PyObject_GetAttrString(self, (char *)"on_mouse_button_down");
160+
if (!PyCallable_Check(py_callable_on_mouse_button_down))
161+
{
162+
UE_LOG(LogPython, Error, TEXT("on_mouse_button_down is not a callable"));
163+
return FReply::Unhandled();
164+
}
165+
166+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_down, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
167+
if (!ret)
168+
{
169+
unreal_engine_py_log_error();
170+
return FReply::Unhandled();
171+
}
172+
173+
if (ret == Py_False)
174+
{
175+
Py_DECREF(ret);
176+
return FReply::Unhandled();
177+
}
178+
Py_DECREF(ret);
179+
return FReply::Handled();
180+
}
181+
182+
virtual FReply OnMouseButtonUp(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
183+
{
184+
FScopePythonGIL gil;
185+
186+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_up"))
187+
return FReply::Unhandled();
188+
189+
PyObject *py_callable_on_mouse_button_up = PyObject_GetAttrString(self, (char *)"on_mouse_button_up");
190+
if (!PyCallable_Check(py_callable_on_mouse_button_up))
191+
{
192+
UE_LOG(LogPython, Error, TEXT("on_mouse_button_up is not a callable"));
193+
return FReply::Unhandled();
194+
}
195+
196+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_up, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
197+
if (!ret)
198+
{
199+
unreal_engine_py_log_error();
200+
return FReply::Unhandled();
201+
}
202+
203+
if (ret == Py_False)
204+
{
205+
Py_DECREF(ret);
206+
return FReply::Unhandled();
207+
}
208+
Py_DECREF(ret);
209+
return FReply::Handled();
210+
}
211+
212+
91213
virtual int32 OnPaint(const FPaintArgs & Args,
92214
const FGeometry & AllottedGeometry,
93215
const FSlateRect & MyClippingRect,

Source/UnrealEnginePython/Private/Wrappers/UEPyFAssetData.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static PyObject *py_ue_fassetdata_get_thumbnail(ue_PyFAssetData *self, PyObject
4343
return py_ue_new_fobject_thumbnail(*thumbnail);
4444
}
4545

46+
#if ENGINE_MINOR_VERSION > 17
4647
static PyObject *py_ue_fassetdata_has_custom_thumbnail(ue_PyFAssetData *self, PyObject * args)
4748
{
4849

@@ -53,6 +54,7 @@ static PyObject *py_ue_fassetdata_has_custom_thumbnail(ue_PyFAssetData *self, Py
5354

5455
Py_RETURN_TRUE;
5556
}
57+
#endif
5658

5759
static PyObject *py_ue_fassetdata_has_cached_thumbnail(ue_PyFAssetData *self, PyObject * args)
5860
{
@@ -69,7 +71,9 @@ static PyMethodDef ue_PyFAssetData_methods[] = {
6971
{ "get_asset", (PyCFunction)py_ue_fassetdata_get_asset, METH_VARARGS, "" },
7072
{ "is_asset_loaded", (PyCFunction)py_ue_fassetdata_is_asset_loaded, METH_VARARGS, "" },
7173
{ "get_thumbnail", (PyCFunction)py_ue_fassetdata_get_thumbnail, METH_VARARGS, "" },
74+
#if ENGINE_MINOR_VERSION > 17
7275
{ "has_custom_thumbnail", (PyCFunction)py_ue_fassetdata_has_custom_thumbnail, METH_VARARGS, "" },
76+
#endif
7377
{ "has_cached_thumbnail", (PyCFunction)py_ue_fassetdata_has_cached_thumbnail, METH_VARARGS, "" },
7478
{ NULL } /* Sentinel */
7579
};

0 commit comments

Comments
 (0)