Skip to content

Commit e57d0b6

Browse files
author
Roberto De Ioris
committed
last round of refactoring
1 parent 05cfcb4 commit e57d0b6

7 files changed

Lines changed: 111 additions & 48 deletions

File tree

‎Source/UnrealEnginePython/Private/PyActor.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,6 @@ APyActor::~APyActor()
298298
UE_LOG(LogPython, Warning, TEXT("Python AActor %p (mapped to %p) wrapper XDECREF'ed"), this, py_uobject ? py_uobject->py_proxy : nullptr);
299299
#endif
300300

301-
// this could trigger the distruction of the python/uobject mapper
301+
// this could trigger the destruction of the python/uobject mapper
302302
Py_XDECREF(py_uobject);
303303
}

‎Source/UnrealEnginePython/Private/Slate/UEPyFPointerEvent.cpp‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22

33
#include "UEPyFPointerEvent.h"
44

5-
static PyObject *py_ue_fpointer_event_get_effecting_button(ue_PyFPointerEvent *self, PyObject * args) {
5+
static PyObject *py_ue_fpointer_event_get_effecting_button(ue_PyFPointerEvent *self, PyObject * args)
6+
{
67
FKey key = self->pointer.GetEffectingButton();
78
return py_ue_new_uscriptstruct(FKey::StaticStruct(), (uint8*)&key);
89
}
910

10-
static PyObject *py_ue_fpointer_event_get_effecting_button_name(ue_PyFPointerEvent *self, PyObject * args) {
11+
static PyObject *py_ue_fpointer_event_get_effecting_button_name(ue_PyFPointerEvent *self, PyObject * args)
12+
{
1113
FKey key = self->pointer.GetEffectingButton();
1214
return PyUnicode_FromString(TCHAR_TO_UTF8(*key.ToString()));
1315
}
1416

15-
static PyObject *py_ue_fpointer_event_get_wheel_delta(ue_PyFPointerEvent *self, PyObject * args) {
17+
static PyObject *py_ue_fpointer_event_get_wheel_delta(ue_PyFPointerEvent *self, PyObject * args)
18+
{
1619
float delta = self->pointer.GetWheelDelta();
1720
return PyFloat_FromDouble(delta);
1821
}
1922

20-
static PyObject *py_ue_fpointer_event_get_cursor_delta(ue_PyFPointerEvent *self, PyObject * args) {
23+
static PyObject *py_ue_fpointer_event_get_cursor_delta(ue_PyFPointerEvent *self, PyObject * args)
24+
{
2125
FVector2D delta = self->pointer.GetCursorDelta();
2226
return Py_BuildValue((char *)"(ff)", delta.X, delta.Y);
2327
}
2428

25-
static PyObject *py_ue_fpointer_event_get_screen_space_position(ue_PyFPointerEvent *self, PyObject * args) {
29+
static PyObject *py_ue_fpointer_event_get_screen_space_position(ue_PyFPointerEvent *self, PyObject * args)
30+
{
2631
FVector2D pos = self->pointer.GetScreenSpacePosition();
2732
return Py_BuildValue((char *)"(ff)", pos.X, pos.Y);
2833
}
@@ -73,7 +78,8 @@ static PyTypeObject ue_PyFPointerEventType = {
7378
ue_PyFPointerEvent_methods, /* tp_methods */
7479
};
7580

76-
void ue_python_init_fpointer_event(PyObject *ue_module) {
81+
void ue_python_init_fpointer_event(PyObject *ue_module)
82+
{
7783

7884
ue_PyFPointerEventType.tp_base = &ue_PyFInputEventType;
7985

@@ -84,9 +90,17 @@ void ue_python_init_fpointer_event(PyObject *ue_module) {
8490
PyModule_AddObject(ue_module, "FPointerEvent", (PyObject *)&ue_PyFPointerEventType);
8591
}
8692

87-
PyObject *py_ue_new_fpointer_event(FPointerEvent pointer) {
93+
PyObject *py_ue_new_fpointer_event(FPointerEvent pointer)
94+
{
8895
ue_PyFPointerEvent *ret = (ue_PyFPointerEvent *)PyObject_New(ue_PyFPointerEvent, &ue_PyFPointerEventType);
8996
new(&ret->pointer) FPointerEvent(pointer);
9097
new(&ret->f_input.input) FInputEvent(pointer);
9198
return (PyObject *)ret;
9299
}
100+
101+
ue_PyFPointerEvent *py_ue_is_fpointer_event(PyObject *obj)
102+
{
103+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFPointerEventType))
104+
return nullptr;
105+
return (ue_PyFPointerEvent *)obj;
106+
}

‎Source/UnrealEnginePython/Private/Slate/UEPyFPointerEvent.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ typedef struct {
1515
void ue_python_init_fpointer_event(PyObject *);
1616

1717
PyObject *py_ue_new_fpointer_event(FPointerEvent);
18+
ue_PyFPointerEvent *py_ue_is_fpointer_event(PyObject *);

‎Source/UnrealEnginePython/Private/Slate/UEPySWidget.cpp‎

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,34 @@ static PyObject *py_ue_swidget_set_visibility(ue_PySWidget *self, PyObject * arg
3636
return nullptr;
3737
}
3838

39-
if (!PyNumber_Check(py_object))
40-
{
41-
return PyErr_Format(PyExc_Exception, "argument is not a ESlateVisibility");
42-
}
43-
44-
PyObject *py_value = PyNumber_Long(py_object);
45-
ESlateVisibility slateVisibility = (ESlateVisibility)PyLong_AsLong(py_value);
46-
Py_DECREF(py_value);
47-
48-
EVisibility visibility;
49-
switch (slateVisibility)
50-
{
51-
case ESlateVisibility::Visible:
52-
visibility = EVisibility::Visible;
53-
break;
54-
case ESlateVisibility::Collapsed:
55-
visibility = EVisibility::Collapsed;
56-
break;
57-
case ESlateVisibility::Hidden:
58-
visibility = EVisibility::Hidden;
59-
break;
60-
case ESlateVisibility::HitTestInvisible:
61-
visibility = EVisibility::HitTestInvisible;
62-
break;
63-
case ESlateVisibility::SelfHitTestInvisible:
64-
visibility = EVisibility::SelfHitTestInvisible;
65-
break;
66-
}
39+
if (!PyNumber_Check(py_object))
40+
{
41+
return PyErr_Format(PyExc_Exception, "argument is not a ESlateVisibility");
42+
}
43+
44+
PyObject *py_value = PyNumber_Long(py_object);
45+
ESlateVisibility slateVisibility = (ESlateVisibility)PyLong_AsLong(py_value);
46+
Py_DECREF(py_value);
47+
48+
EVisibility visibility;
49+
switch (slateVisibility)
50+
{
51+
case ESlateVisibility::Visible:
52+
visibility = EVisibility::Visible;
53+
break;
54+
case ESlateVisibility::Collapsed:
55+
visibility = EVisibility::Collapsed;
56+
break;
57+
case ESlateVisibility::Hidden:
58+
visibility = EVisibility::Hidden;
59+
break;
60+
case ESlateVisibility::HitTestInvisible:
61+
visibility = EVisibility::HitTestInvisible;
62+
break;
63+
case ESlateVisibility::SelfHitTestInvisible:
64+
visibility = EVisibility::SelfHitTestInvisible;
65+
break;
66+
}
6767

6868
self->s_widget->SetVisibility(visibility);
6969

@@ -258,6 +258,36 @@ static PyObject *py_ue_swidget_invalidate(ue_PySWidget *self, PyObject * args)
258258
Py_RETURN_NONE;
259259
}
260260

261+
static PyObject *py_ue_swidget_on_mouse_button_down(ue_PySWidget *self, PyObject * args)
262+
{
263+
PyObject *py_geometry;
264+
PyObject *py_pointer_event;
265+
if (!PyArg_ParseTuple(args, "OO:on_mouse_button_down", &py_geometry, &py_pointer_event))
266+
{
267+
return nullptr;
268+
}
269+
270+
ue_PyFGeometry *geometry = py_ue_is_fgeometry(py_geometry);
271+
if (!geometry)
272+
{
273+
return PyErr_Format(PyExc_Exception, "argument is not a FGeomtry");
274+
}
275+
276+
ue_PyFPointerEvent *pointer = py_ue_is_fpointer_event(py_pointer_event);
277+
if (!pointer)
278+
{
279+
return PyErr_Format(PyExc_Exception, "argument is not a FPointerEvent");
280+
}
281+
282+
FReply reply = self->s_widget->OnMouseButtonDown(geometry->geometry, pointer->pointer);
283+
284+
if (reply.IsEventHandled())
285+
{
286+
Py_RETURN_TRUE;
287+
}
288+
289+
Py_RETURN_FALSE;
290+
}
261291

262292
static PyMethodDef ue_PySWidget_methods[] = {
263293
{ "get_shared_reference_count", (PyCFunction)py_ue_swidget_get_shared_reference_count, METH_VARARGS, "" },
@@ -276,6 +306,7 @@ static PyMethodDef ue_PySWidget_methods[] = {
276306
{ "bind_on_mouse_double_click", (PyCFunction)py_ue_swidget_bind_on_mouse_double_click, METH_VARARGS, "" },
277307
{ "bind_on_mouse_move", (PyCFunction)py_ue_swidget_bind_on_mouse_move, METH_VARARGS, "" },
278308
#endif
309+
{ "on_mouse_button_down", (PyCFunction)py_ue_swidget_on_mouse_button_down, METH_VARARGS, "" },
279310
{ NULL } /* Sentinel */
280311
};
281312

‎Source/UnrealEnginePython/Private/UEPyModule.h‎

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
//#include "UEPyModule.generated.h"
1010

11-
typedef struct {
11+
typedef struct
12+
{
1213
PyObject_HEAD
13-
/* Type-specific fields go here. */
14-
UObject *ue_object;
14+
/* Type-specific fields go here. */
15+
UObject *ue_object;
1516
// reference to proxy class (can be null)
1617
PyObject *py_proxy;
1718
// list of exposed delegates
@@ -45,29 +46,45 @@ UClass *unreal_engine_new_uclass(char *, UClass *);
4546
UFunction *unreal_engine_add_function(UClass *, char *, PyObject *, uint32);
4647

4748

48-
template <typename T> T *ue_py_check_type(PyObject *py_obj) {
49+
template <typename T> T *ue_py_check_type(PyObject *py_obj)
50+
{
4951
ue_PyUObject *ue_py_obj = ue_is_pyuobject(py_obj);
50-
if (!ue_py_obj) {
52+
if (!ue_py_obj)
53+
{
54+
return nullptr;
55+
}
56+
57+
if (!ue_py_obj->ue_object || !ue_py_obj->ue_object->IsValidLowLevel() || ue_py_obj->ue_object->IsPendingKillOrUnreachable())
58+
{
59+
UE_LOG(LogPython, Error, TEXT("invalid UObject in ue_PyUObject %p"), ue_py_obj);
5160
return nullptr;
5261
}
5362

5463
return Cast<T>(ue_py_obj->ue_object);
5564
}
5665

57-
template <typename T> T *ue_py_check_type(ue_PyUObject *py_obj) {
66+
template <typename T> T *ue_py_check_type(ue_PyUObject *py_obj)
67+
{
68+
if (!py_obj->ue_object || !py_obj->ue_object->IsValidLowLevel() || py_obj->ue_object->IsPendingKillOrUnreachable())
69+
{
70+
UE_LOG(LogPython, Error, TEXT("invalid UObject in ue_PyUObject %p"), py_obj);
71+
return nullptr;
72+
}
5873
return Cast<T>(py_obj->ue_object);
5974
}
6075

6176
uint8 *do_ue_py_check_struct(PyObject *py_obj, UScriptStruct* chk_u_struct);
6277

63-
template <typename T> T *ue_py_check_struct(PyObject *py_obj) {
64-
return (T*)do_ue_py_check_struct(py_obj, T::StaticStruct());
78+
template <typename T> T *ue_py_check_struct(PyObject *py_obj)
79+
{
80+
return (T*)do_ue_py_check_struct(py_obj, T::StaticStruct());
6581
}
6682

6783
bool do_ue_py_check_childstruct(PyObject *py_obj, UScriptStruct* parent_u_struct);
6884

69-
template <typename T> bool ue_py_check_childstruct(PyObject *py_obj) {
70-
return do_ue_py_check_childstruct(py_obj, T::StaticStruct());
85+
template <typename T> bool ue_py_check_childstruct(PyObject *py_obj)
86+
{
87+
return do_ue_py_check_childstruct(py_obj, T::StaticStruct());
7188
}
7289

7390
FGuid *ue_py_check_fguid(PyObject *);

‎Source/UnrealEnginePython/Private/UnrealEnginePythonPrivatePCH.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#pragma once
44

5-
#define UEPY_MEMORY_DEBUG 1
5+
//#define UEPY_MEMORY_DEBUG 1
66
//#define UEPY_THREADING 1
77

88
#include "UnrealEnginePython.h"

‎Source/UnrealEnginePython/UnrealEnginePython.Build.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ private string GetWindowsPythonLibFile(string basePath)
370370
// first try with python3
371371
for (int i = 9; i >= 0; i--)
372372
{
373-
string fileName = string.Format("python3{0}_d.lib", i);
373+
string fileName = string.Format("python3{0}.lib", i);
374374
string fullPath = Path.Combine(basePath, "libs", fileName);
375375
if (File.Exists(fullPath))
376376
{

0 commit comments

Comments
 (0)