|
2 | 2 |
|
3 | 3 | #include "UEPyFPaintContext.h" |
4 | 4 |
|
| 5 | +static FSlateBrush global_simple_brush; |
| 6 | + |
5 | 7 | static PyObject *py_ue_fpaint_context_draw_line(ue_PyFPaintContext *self, PyObject * args) { |
6 | 8 | float x1, y1, x2, y2; |
7 | 9 | PyObject *py_linear_color = nullptr; |
@@ -41,6 +43,49 @@ static PyObject *py_ue_fpaint_context_draw_line(ue_PyFPaintContext *self, PyObje |
41 | 43 | Py_RETURN_NONE; |
42 | 44 | } |
43 | 45 |
|
| 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 | + |
44 | 89 | static PyObject *py_ue_fpaint_context_draw_text(ue_PyFPaintContext *self, PyObject * args) { |
45 | 90 | float x, y; |
46 | 91 | char *text; |
@@ -184,8 +229,14 @@ static PyObject *py_ue_fpaint_context_draw_lines(ue_PyFPaintContext *self, PyObj |
184 | 229 | Py_RETURN_NONE; |
185 | 230 | } |
186 | 231 |
|
| 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 | + |
187 | 236 | static PyMethodDef ue_PyFPaintContext_methods[] = { |
| 237 | + { "get_geometry", (PyCFunction)py_ue_fpaint_context_get_geometry, METH_VARARGS, "" }, |
188 | 238 | { "draw_line", (PyCFunction)py_ue_fpaint_context_draw_line, METH_VARARGS, "" }, |
| 239 | + { "draw_box", (PyCFunction)py_ue_fpaint_context_draw_box, METH_VARARGS, "" }, |
189 | 240 | { "draw_lines", (PyCFunction)py_ue_fpaint_context_draw_lines, METH_VARARGS, "" }, |
190 | 241 | { "draw_spline", (PyCFunction)py_ue_fpaint_context_draw_spline, METH_VARARGS, "" }, |
191 | 242 | { "draw_text", (PyCFunction)py_ue_fpaint_context_draw_text, METH_VARARGS, "" }, |
|
0 commit comments