Skip to content

Commit d309d05

Browse files
author
Roberto De Ioris
committed
fixed component ticking, added draw_box
1 parent e99069a commit d309d05

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

‎Source/UnrealEnginePython/Private/PythonComponent.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void UPythonComponent::InitializePythonComponent() {
6969

7070
// disable ticking if no tick method is exposed
7171
if (!PyObject_HasAttrString(py_component_instance, (char *)"tick") || PythonTickForceDisabled) {
72-
SetComponentTickEnabled(false);
72+
PrimaryComponentTick.bCanEverTick = false;
7373
}
7474

7575
if (!PythonDisableAutoBinding)
@@ -150,7 +150,7 @@ void UPythonComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActo
150150

151151
FScopePythonGIL gil;
152152

153-
// no need to check for method availability, we did it in begin_play
153+
// no need to check for method availability, we did it in component initialization
154154

155155
PyObject *ret = PyObject_CallMethod(py_component_instance, (char *)"tick", (char *)"f", DeltaTime);
156156
if (!ret) {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
#include "UEPyFGeometry.h"
44

5+
static PyObject *py_ue_fgeometry_get_local_size(ue_PyFGeometry *self, PyObject * args) {
6+
FVector2D size = self->geometry.GetLocalSize();
7+
return Py_BuildValue("(ff)", size.X, size.Y);
8+
}
9+
510
static PyMethodDef ue_PyFGeometry_methods[] = {
11+
{ "get_local_size", (PyCFunction)py_ue_fgeometry_get_local_size, METH_VARARGS, "" },
612
{ NULL } /* Sentinel */
713
};
814

@@ -54,9 +60,9 @@ void ue_python_init_fgeometry(PyObject *ue_module) {
5460
}
5561

5662
ue_PyFGeometry *py_ue_is_fgeometry(PyObject *obj) {
57-
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFGeometryType))
58-
return nullptr;
59-
return (ue_PyFGeometry *)obj;
63+
if (!PyObject_IsInstance(obj, (PyObject *)&ue_PyFGeometryType))
64+
return nullptr;
65+
return (ue_PyFGeometry *)obj;
6066
}
6167

6268
PyObject *py_ue_new_fgeometry(FGeometry geometry) {

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "UEPyFPaintContext.h"
44

5+
static FSlateBrush global_simple_brush;
6+
57
static PyObject *py_ue_fpaint_context_draw_line(ue_PyFPaintContext *self, PyObject * args) {
68
float x1, y1, x2, y2;
79
PyObject *py_linear_color = nullptr;
@@ -41,6 +43,49 @@ static PyObject *py_ue_fpaint_context_draw_line(ue_PyFPaintContext *self, PyObje
4143
Py_RETURN_NONE;
4244
}
4345

46+
static PyObject *py_ue_fpaint_context_draw_box(ue_PyFPaintContext *self, PyObject * args) {
47+
float x, y, w, h;
48+
49+
PyObject *py_brush = nullptr;
50+
PyObject *py_linear_color = nullptr;
51+
52+
if (!PyArg_ParseTuple(args, "(ff)(ff)|OO:draw_line", &x, &y, &w, &h, &py_linear_color, &py_brush))
53+
return nullptr;
54+
55+
FLinearColor tint = FLinearColor::White;
56+
57+
if (py_linear_color) {
58+
if (ue_PyFLinearColor *linear_color = py_ue_is_flinearcolor(py_linear_color)) {
59+
tint = linear_color->color;
60+
}
61+
else {
62+
return PyErr_Format(PyExc_Exception, "argument is not a FlinearColor");
63+
}
64+
}
65+
66+
FSlateBrush *brush = &global_simple_brush;
67+
68+
if (py_brush) {
69+
FSlateBrush *custom_brush = ue_py_check_struct<FSlateBrush>(py_brush);
70+
if (!custom_brush)
71+
return PyErr_Format(PyExc_Exception, "argument is not a FSlateBrush");
72+
brush = custom_brush;
73+
}
74+
75+
FPaintContext context = self->paint_context;
76+
context.MaxLayer++;
77+
78+
#if ENGINE_MINOR_VERSION >= 17
79+
FSlateDrawElement::MakeBox(context.OutDrawElements, context.MaxLayer, context.AllottedGeometry.ToPaintGeometry(FVector2D(x, y), FVector2D(w, h)),
80+
brush, ESlateDrawEffect::None, tint);
81+
#else
82+
FSlateDrawElement::MakeBox(context.OutDrawElements, context.MaxLayer, context.AllottedGeometry.ToPaintGeometry(FVector2D(x, y), FVector2D(w, h)),
83+
brush, context.MyClippingRect, ESlateDrawEffect::None, tint);
84+
#endif
85+
86+
Py_RETURN_NONE;
87+
}
88+
4489
static PyObject *py_ue_fpaint_context_draw_text(ue_PyFPaintContext *self, PyObject * args) {
4590
float x, y;
4691
char *text;
@@ -184,8 +229,14 @@ static PyObject *py_ue_fpaint_context_draw_lines(ue_PyFPaintContext *self, PyObj
184229
Py_RETURN_NONE;
185230
}
186231

232+
static PyObject *py_ue_fpaint_context_get_geometry(ue_PyFPaintContext *self, PyObject * args) {
233+
return py_ue_new_fgeometry(self->paint_context.AllottedGeometry);
234+
}
235+
187236
static PyMethodDef ue_PyFPaintContext_methods[] = {
237+
{ "get_geometry", (PyCFunction)py_ue_fpaint_context_get_geometry, METH_VARARGS, "" },
188238
{ "draw_line", (PyCFunction)py_ue_fpaint_context_draw_line, METH_VARARGS, "" },
239+
{ "draw_box", (PyCFunction)py_ue_fpaint_context_draw_box, METH_VARARGS, "" },
189240
{ "draw_lines", (PyCFunction)py_ue_fpaint_context_draw_lines, METH_VARARGS, "" },
190241
{ "draw_spline", (PyCFunction)py_ue_fpaint_context_draw_spline, METH_VARARGS, "" },
191242
{ "draw_text", (PyCFunction)py_ue_fpaint_context_draw_text, METH_VARARGS, "" },

0 commit comments

Comments
 (0)