Skip to content

Commit f748b40

Browse files
author
Roberto De Ioris
committed
completed mouse events for slate widgets
1 parent 21df504 commit f748b40

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySWidget.cpp

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,82 @@ static PyObject *py_ue_swidget_bind_on_mouse_button_down(ue_PySWidget *self, PyO
4747
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
4848
py_delegate->SetPyCallable(py_callable);
4949
py_delegate->AddToRoot();
50-
handler.BindUObject(py_delegate, &UPythonSlateDelegate::OnMouseButtonDown);
50+
handler.BindUObject(py_delegate, &UPythonSlateDelegate::OnMouseEvent);
5151

5252
self->s_widget->SetOnMouseButtonDown(handler);
5353

5454
Py_INCREF(self);
5555
return (PyObject *)self;
5656
}
5757

58+
static PyObject *py_ue_swidget_bind_on_mouse_button_up(ue_PySWidget *self, PyObject * args) {
59+
PyObject *py_callable;
60+
if (!PyArg_ParseTuple(args, "O:bind_on_mouse_button_up", &py_callable)) {
61+
return NULL;
62+
}
63+
64+
if (!PyCallable_Check(py_callable)) {
65+
return PyErr_Format(PyExc_Exception, "argument is not callable");
66+
}
67+
68+
FPointerEventHandler handler;
69+
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
70+
py_delegate->SetPyCallable(py_callable);
71+
py_delegate->AddToRoot();
72+
handler.BindUObject(py_delegate, &UPythonSlateDelegate::OnMouseEvent);
73+
74+
self->s_widget->SetOnMouseButtonUp(handler);
75+
76+
Py_INCREF(self);
77+
return (PyObject *)self;
78+
}
79+
80+
static PyObject *py_ue_swidget_bind_on_mouse_double_click(ue_PySWidget *self, PyObject * args) {
81+
PyObject *py_callable;
82+
if (!PyArg_ParseTuple(args, "O:bind_on_mouse_double_click", &py_callable)) {
83+
return NULL;
84+
}
85+
86+
if (!PyCallable_Check(py_callable)) {
87+
return PyErr_Format(PyExc_Exception, "argument is not callable");
88+
}
89+
90+
FPointerEventHandler handler;
91+
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
92+
py_delegate->SetPyCallable(py_callable);
93+
py_delegate->AddToRoot();
94+
handler.BindUObject(py_delegate, &UPythonSlateDelegate::OnMouseEvent);
95+
96+
self->s_widget->SetOnMouseDoubleClick(handler);
97+
98+
Py_INCREF(self);
99+
return (PyObject *)self;
100+
}
101+
102+
static PyObject *py_ue_swidget_bind_on_mouse_move(ue_PySWidget *self, PyObject * args) {
103+
PyObject *py_callable;
104+
if (!PyArg_ParseTuple(args, "O:bind_on_mouse_move", &py_callable)) {
105+
return NULL;
106+
}
107+
108+
if (!PyCallable_Check(py_callable)) {
109+
return PyErr_Format(PyExc_Exception, "argument is not callable");
110+
}
111+
112+
FPointerEventHandler handler;
113+
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
114+
py_delegate->SetPyCallable(py_callable);
115+
py_delegate->AddToRoot();
116+
handler.BindUObject(py_delegate, &UPythonSlateDelegate::OnMouseEvent);
117+
118+
self->s_widget->SetOnMouseMove(handler);
119+
120+
Py_INCREF(self);
121+
return (PyObject *)self;
122+
}
123+
124+
125+
58126
static PyObject *py_ue_swidget_has_keyboard_focus(ue_PySWidget *self, PyObject * args) {
59127

60128
if (self->s_widget->HasKeyboardFocus()) {
@@ -78,6 +146,9 @@ static PyMethodDef ue_PySWidget_methods[] = {
78146
{ "set_tooltip_text", (PyCFunction)py_ue_swidget_set_tooltip_text, METH_VARARGS, "" },
79147
{ "has_keyboard_focus", (PyCFunction)py_ue_swidget_has_keyboard_focus, METH_VARARGS, "" },
80148
{ "bind_on_mouse_button_down", (PyCFunction)py_ue_swidget_bind_on_mouse_button_down, METH_VARARGS, "" },
149+
{ "bind_on_mouse_button_up", (PyCFunction)py_ue_swidget_bind_on_mouse_button_down, METH_VARARGS, "" },
150+
{ "bind_on_mouse_double_click", (PyCFunction)py_ue_swidget_bind_on_mouse_double_click, METH_VARARGS, "" },
151+
{ "bind_on_mouse_move", (PyCFunction)py_ue_swidget_bind_on_mouse_move, METH_VARARGS, "" },
81152
{ NULL } /* Sentinel */
82153
};
83154

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
#include "UEPySlate.h"
1010

11-
FReply UPythonSlateDelegate::OnMouseButtonDown(const FGeometry &geometry, const FPointerEvent &pointer_event) {
11+
FReply UPythonSlateDelegate::OnMouseEvent(const FGeometry &geometry, const FPointerEvent &pointer_event) {
1212
FScopePythonGIL gil;
1313

14-
UE_LOG(LogPython, Warning, TEXT("MOUSE BUTTON DOWN"));
15-
1614
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"OO", py_ue_new_uscriptstruct(FGeometry::StaticStruct(), (uint8 *)&geometry), py_ue_new_uscriptstruct(FPointerEvent::StaticStruct(), (uint8 *)&pointer_event));
1715
if (!ret) {
1816
unreal_engine_py_log_error();

Source/UnrealEnginePython/Private/Slate/UEPySlate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class UPythonSlateDelegate : public UPythonDelegate
6363
GENERATED_BODY()
6464

6565
public:
66-
FReply OnMouseButtonDown(const FGeometry &geometry, const FPointerEvent &pointer_event);
66+
FReply OnMouseEvent(const FGeometry &geometry, const FPointerEvent &pointer_event);
6767
FReply OnClicked();
6868
};
6969

0 commit comments

Comments
 (0)