|
7 | 7 | #include "UEPyFPaintContext.h" |
8 | 8 | #include "UEPyFCharacterEvent.h" |
9 | 9 | #include "UEPyFKeyEvent.h" |
| 10 | +#include "UEPyFPointerEvent.h" |
10 | 11 |
|
11 | 12 | extern PyTypeObject ue_PySPythonWidgetType; |
12 | 13 |
|
@@ -88,6 +89,127 @@ class SPythonWidget : public SCompoundWidget |
88 | 89 | return FReply::Handled(); |
89 | 90 | } |
90 | 91 |
|
| 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 | + |
91 | 213 | virtual int32 OnPaint(const FPaintArgs & Args, |
92 | 214 | const FGeometry & AllottedGeometry, |
93 | 215 | const FSlateRect & MyClippingRect, |
|
0 commit comments