Skip to content

Commit 704ec27

Browse files
author
Roberto De Ioris
committed
added text api
1 parent 5b36111 commit 704ec27

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Source/UnrealEnginePython/Private/Slate/UEPyFPaintContext.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,49 @@ static PyObject *py_ue_fpaint_context_draw_line(ue_PyFPaintContext *self, PyObje
3636
Py_RETURN_NONE;
3737
}
3838

39+
static PyObject *py_ue_fpaint_context_draw_text(ue_PyFPaintContext *self, PyObject * args) {
40+
float x, y;
41+
char *text;
42+
PyObject *py_linear_color = nullptr;
43+
PyObject *py_font = nullptr;
44+
45+
if (!PyArg_ParseTuple(args, "(ff)s|OO:draw_text", &x, &y, &text, &py_linear_color, &py_font))
46+
return nullptr;
47+
48+
FLinearColor tint = FLinearColor::White;
49+
FSlateFontInfo font = FCoreStyle::Get().GetWidgetStyle<FTextBlockStyle>("NormalText").Font;
50+
51+
if (py_linear_color) {
52+
if (ue_PyFLinearColor *linear_color = py_ue_is_flinearcolor(py_linear_color)) {
53+
tint = linear_color->color;
54+
}
55+
else {
56+
return PyErr_Format(PyExc_Exception, "argument is not a FlinearColor");
57+
}
58+
}
59+
60+
if (py_font) {
61+
FSlateFontInfo *font_struct = ue_py_check_struct<FSlateFontInfo>(py_font);
62+
if (font_struct) {
63+
font = *font_struct;
64+
}
65+
else {
66+
return PyErr_Format(PyExc_Exception, "argument is not a SlateFontInfo USTRUCT");
67+
}
68+
}
69+
70+
FVector2D position = FVector2D(x, y);
71+
72+
FPaintContext context = self->paint_context;
73+
74+
context.MaxLayer++;
75+
76+
FSlateDrawElement::MakeText(context.OutDrawElements, context.MaxLayer, context.AllottedGeometry.ToOffsetPaintGeometry(position),
77+
FText::FromString(UTF8_TO_TCHAR(text)), font, context.MyClippingRect, ESlateDrawEffect::None, tint);
78+
79+
Py_RETURN_NONE;
80+
}
81+
3982
static PyObject *py_ue_fpaint_context_draw_spline(ue_PyFPaintContext *self, PyObject * args) {
4083
float x1, y1, dx1, dy1;
4184
float x2, y2, dx2, dy2;
@@ -124,6 +167,7 @@ static PyMethodDef ue_PyFPaintContext_methods[] = {
124167
{ "draw_line", (PyCFunction)py_ue_fpaint_context_draw_line, METH_VARARGS, "" },
125168
{ "draw_lines", (PyCFunction)py_ue_fpaint_context_draw_lines, METH_VARARGS, "" },
126169
{ "draw_spline", (PyCFunction)py_ue_fpaint_context_draw_spline, METH_VARARGS, "" },
170+
{ "draw_text", (PyCFunction)py_ue_fpaint_context_draw_text, METH_VARARGS, "" },
127171
{ NULL } /* Sentinel */
128172
};
129173

0 commit comments

Comments
 (0)