Skip to content

Commit 9187a3a

Browse files
author
Roberto De Ioris
committed
added SCanvas
1 parent 6dc85f7 commit 9187a3a

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySBoxPanel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
static PyObject *py_ue_sbox_panel_clear_children(ue_PySGridPanel *self, PyObject * args) {
1010

1111
sw_box_panel->ClearChildren();
12+
for (ue_PySWidget *item : self->s_panel.s_widget.py_swidget_slots) {
13+
Py_DECREF(item);
14+
}
15+
self->s_panel.s_widget.py_swidget_slots.Empty();
1216

1317
Py_INCREF(Py_None);
1418
return Py_None;
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
#include "UnrealEnginePythonPrivatePCH.h"
3+
4+
#include "UEPySCanvas.h"
5+
6+
7+
#define sw_canvas StaticCastSharedRef<SCanvas>(self->s_panel.s_widget.s_widget)
8+
9+
static PyObject *py_ue_scanvas_clear_children(ue_PySCanvas *self, PyObject * args) {
10+
11+
sw_canvas->ClearChildren();
12+
for (ue_PySWidget *item : self->s_panel.s_widget.py_swidget_slots) {
13+
Py_DECREF(item);
14+
}
15+
self->s_panel.s_widget.py_swidget_slots.Empty();
16+
17+
Py_RETURN_NONE;
18+
}
19+
20+
static PyObject *py_ue_scanvas_add_slot(ue_PySCanvas *self, PyObject * args, PyObject *kwargs) {
21+
PyObject *py_content;
22+
int h_align = 0;
23+
int v_align = 0;
24+
25+
PyObject *position = nullptr;
26+
PyObject *size = nullptr;
27+
28+
char *kwlist[] = { (char *)"widget",
29+
(char *)"h_align",
30+
(char *)"v_align",
31+
(char *)"position",
32+
(char *)"size",
33+
nullptr };
34+
35+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iiOO:add_slot", kwlist,
36+
&py_content,
37+
&h_align,
38+
&v_align,
39+
&position,
40+
&size)) {
41+
return NULL;
42+
}
43+
44+
ue_PySWidget *py_swidget = py_ue_is_swidget(py_content);
45+
if (!py_swidget) {
46+
return PyErr_Format(PyExc_Exception, "argument is not a SWidget");
47+
}
48+
49+
Py_INCREF(py_swidget);
50+
self->s_panel.s_widget.py_swidget_slots.Add(py_swidget);
51+
52+
SCanvas::FSlot &fslot = sw_canvas->AddSlot();
53+
fslot.AttachWidget(py_swidget->s_widget->AsShared());
54+
fslot.HAlign((EHorizontalAlignment)h_align);
55+
fslot.VAlign((EVerticalAlignment)v_align);
56+
57+
if (position && PyTuple_Check(position)) {
58+
if (PyTuple_Size(position) == 2) {
59+
PyObject *py_x = PyTuple_GetItem(position, 0);
60+
PyObject *py_y = PyTuple_GetItem(position, 1);
61+
if (PyNumber_Check(py_x)) {
62+
PyObject *py_x_float = PyNumber_Float(py_x);
63+
float x = PyFloat_AsDouble(py_x_float);
64+
Py_DECREF(py_x_float);
65+
PyObject *py_y_float = PyNumber_Float(py_y);
66+
float y = PyFloat_AsDouble(py_y_float);
67+
Py_DECREF(py_y_float);
68+
fslot.Position(FVector2D(x, y));
69+
}
70+
}
71+
}
72+
73+
if (size && PyTuple_Check(size)) {
74+
if (PyTuple_Size(size) == 2) {
75+
PyObject *py_x = PyTuple_GetItem(size, 0);
76+
PyObject *py_y = PyTuple_GetItem(size, 1);
77+
if (PyNumber_Check(py_x)) {
78+
PyObject *py_x_float = PyNumber_Float(py_x);
79+
float x = PyFloat_AsDouble(py_x_float);
80+
Py_DECREF(py_x_float);
81+
PyObject *py_y_float = PyNumber_Float(py_y);
82+
float y = PyFloat_AsDouble(py_y_float);
83+
Py_DECREF(py_y_float);
84+
fslot.Size(FVector2D(x, y));
85+
}
86+
}
87+
}
88+
89+
Py_INCREF(self);
90+
return (PyObject *)self;
91+
}
92+
93+
static PyMethodDef ue_PySCanvas_methods[] = {
94+
#pragma warning(suppress: 4191)
95+
{ "add_slot", (PyCFunction)py_ue_scanvas_add_slot, METH_VARARGS | METH_KEYWORDS, "" },
96+
{ "clear_children", (PyCFunction)py_ue_scanvas_clear_children, METH_VARARGS, "" },
97+
{ NULL } /* Sentinel */
98+
};
99+
100+
PyTypeObject ue_PySCanvasType = {
101+
PyVarObject_HEAD_INIT(NULL, 0)
102+
"unreal_engine.SCanvas", /* tp_name */
103+
sizeof(ue_PySCanvas), /* tp_basicsize */
104+
0, /* tp_itemsize */
105+
0, /* tp_dealloc */
106+
0, /* tp_print */
107+
0, /* tp_getattr */
108+
0, /* tp_setattr */
109+
0, /* tp_reserved */
110+
0, /* tp_repr */
111+
0, /* tp_as_number */
112+
0, /* tp_as_sequence */
113+
0, /* tp_as_mapping */
114+
0, /* tp_hash */
115+
0, /* tp_call */
116+
0, /* tp_str */
117+
0, /* tp_getattro */
118+
0, /* tp_setattro */
119+
0, /* tp_as_buffer */
120+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
121+
"Unreal Engine SCanvas", /* tp_doc */
122+
0, /* tp_traverse */
123+
0, /* tp_clear */
124+
0, /* tp_richcompare */
125+
0, /* tp_weaklistoffset */
126+
0, /* tp_iter */
127+
0, /* tp_iternext */
128+
ue_PySCanvas_methods, /* tp_methods */
129+
};
130+
131+
static int ue_py_scanvas_init(ue_PySCanvas *self, PyObject *args, PyObject *kwargs) {
132+
ue_py_snew_simple(SCanvas, s_panel.s_widget);
133+
return 0;
134+
}
135+
136+
void ue_python_init_scanvas(PyObject *ue_module) {
137+
138+
ue_PySCanvasType.tp_base = &ue_PySPanelType;
139+
ue_PySCanvasType.tp_init = (initproc)ue_py_scanvas_init;
140+
141+
if (PyType_Ready(&ue_PySCanvasType) < 0)
142+
return;
143+
144+
Py_INCREF(&ue_PySCanvasType);
145+
PyModule_AddObject(ue_module, "SCanvas", (PyObject *)&ue_PySCanvasType);
146+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include "UnrealEnginePython.h"
4+
5+
6+
#include "UEPySPanel.h"
7+
8+
#include "Runtime/Slate/Public/Widgets/SCanvas.h"
9+
10+
extern PyTypeObject ue_PySCanvasType;
11+
12+
typedef struct {
13+
ue_PySPanel s_panel;
14+
/* Type-specific fields go here. */
15+
} ue_PySCanvas;
16+
17+
void ue_python_init_scanvas(PyObject *);

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ void ue_python_init_slate(PyObject *module) {
495495
ue_python_init_sheader_row(module);
496496
ue_python_init_scheck_box(module);
497497
ue_python_init_snumeric_entry_box(module);
498+
ue_python_init_scanvas(module);
498499

499500

500501
#if WITH_EDITOR

Source/UnrealEnginePython/Private/Slate/UEPySlate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "UEPySHeaderRow.h"
4444
#include "UEPySCheckBox.h"
4545
#include "UEPySNumericEntryBox.h"
46+
#include "UEPySCanvas.h"
4647

4748

4849

0 commit comments

Comments
 (0)