Skip to content

Commit 14c1c13

Browse files
author
Roberto De Ioris
committed
first round of slate refactoring
1 parent ee68791 commit 14c1c13

22 files changed

+518
-507
lines changed

Source/UnrealEnginePython/Private/Slate/UEPyFMenuBuilder.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ static PyObject *py_ue_fmenu_builder_add_menu_entry(ue_PyFMenuBuilder *self, PyO
4141
char *label;
4242
char *tooltip;
4343
PyObject *py_callable;
44-
PyObject *py_obj = nullptr;
45-
PyObject *py_uiaction_obj = nullptr;
44+
PyObject *py_obj = nullptr;
45+
PyObject *py_uiaction_obj = nullptr;
4646
if (!PyArg_ParseTuple(args, "ssO|OO:add_menu_entry", &label, &tooltip, &py_callable, &py_obj, &py_uiaction_obj))
4747
return nullptr;
4848

@@ -53,23 +53,21 @@ static PyObject *py_ue_fmenu_builder_add_menu_entry(ue_PyFMenuBuilder *self, PyO
5353

5454

5555
FExecuteAction handler;
56-
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
57-
py_delegate->SetPyCallable(py_callable);
58-
py_delegate->AddToRoot();
56+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable);
5957

6058
if (py_obj)
6159
{
6260
Py_INCREF(py_obj);
63-
handler.BindUObject(py_delegate, &UPythonSlateDelegate::ExecuteAction, py_obj);
61+
handler.BindSP(py_delegate, &FPythonSlateDelegate::ExecuteAction, py_obj);
6462
}
6563
else
6664
{
67-
handler.BindUObject(py_delegate, &UPythonSlateDelegate::SimpleExecuteAction);
65+
handler.BindSP(py_delegate, &FPythonSlateDelegate::SimpleExecuteAction);
6866
}
6967

70-
ue_PyESlateEnums *py_uiaction_enum = py_uiaction_obj ? py_ue_is_eslate_enums(py_uiaction_obj) : nullptr;
71-
self->menu_builder.AddMenuEntry(FText::FromString(UTF8_TO_TCHAR(label)), FText::FromString(UTF8_TO_TCHAR(tooltip)), FSlateIcon(), FUIAction(handler), NAME_None,
72-
py_uiaction_enum ? (EUserInterfaceActionType::Type)(py_uiaction_enum->val) : EUserInterfaceActionType::Button);
68+
ue_PyESlateEnums *py_uiaction_enum = py_uiaction_obj ? py_ue_is_eslate_enums(py_uiaction_obj) : nullptr;
69+
self->menu_builder.AddMenuEntry(FText::FromString(UTF8_TO_TCHAR(label)), FText::FromString(UTF8_TO_TCHAR(tooltip)), FSlateIcon(), FUIAction(handler), NAME_None,
70+
py_uiaction_enum ? (EUserInterfaceActionType::Type)(py_uiaction_enum->val) : EUserInterfaceActionType::Button);
7371

7472
Py_RETURN_NONE;
7573
}

Source/UnrealEnginePython/Private/Slate/UEPyFToolBarBuilder.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
#include "Runtime/Slate/Public/Framework/Commands/UIAction.h"
66

7-
static PyObject *py_ue_ftool_bar_builder_begin_section(ue_PyFToolBarBuilder *self, PyObject * args) {
7+
static PyObject *py_ue_ftool_bar_builder_begin_section(ue_PyFToolBarBuilder *self, PyObject * args)
8+
{
89
char *name;
910
if (!PyArg_ParseTuple(args, "s:begin_section", &name))
1011
return NULL;
@@ -15,14 +16,16 @@ static PyObject *py_ue_ftool_bar_builder_begin_section(ue_PyFToolBarBuilder *sel
1516
return Py_None;
1617
}
1718

18-
static PyObject *py_ue_ftool_bar_builder_end_section(ue_PyFToolBarBuilder *self, PyObject * args) {
19+
static PyObject *py_ue_ftool_bar_builder_end_section(ue_PyFToolBarBuilder *self, PyObject * args)
20+
{
1921
self->tool_bar_builder.EndSection();
2022

2123
Py_INCREF(Py_None);
2224
return Py_None;
2325
}
2426

25-
static PyObject *py_ue_ftool_bar_builder_add_tool_bar_button(ue_PyFToolBarBuilder *self, PyObject * args) {
27+
static PyObject *py_ue_ftool_bar_builder_add_tool_bar_button(ue_PyFToolBarBuilder *self, PyObject * args)
28+
{
2629
char *hook;
2730
char *label;
2831
char *tooltip;
@@ -33,25 +36,27 @@ static PyObject *py_ue_ftool_bar_builder_add_tool_bar_button(ue_PyFToolBarBuilde
3336
return NULL;
3437

3538
ue_PyFSlateIcon *py_slate_icon = py_ue_is_fslate_icon(py_icon);
36-
if (!py_slate_icon) {
39+
if (!py_slate_icon)
40+
{
3741
return PyErr_Format(PyExc_Exception, "argument is not a FSlateIcon");
3842
}
3943

40-
if (!PyCalllable_Check_Extended(py_callable)) {
44+
if (!PyCalllable_Check_Extended(py_callable))
45+
{
4146
return PyErr_Format(PyExc_Exception, "argument is not callable");
4247
}
4348

4449
FExecuteAction handler;
45-
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
46-
py_delegate->SetPyCallable(py_callable);
47-
py_delegate->AddToRoot();
50+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable);
4851

49-
if (py_obj) {
52+
if (py_obj)
53+
{
5054
Py_INCREF(py_obj);
51-
handler.BindUObject(py_delegate, &UPythonSlateDelegate::ExecuteAction, py_obj);
55+
handler.BindSP(py_delegate, &FPythonSlateDelegate::ExecuteAction, py_obj);
5256
}
53-
else {
54-
handler.BindUObject(py_delegate, &UPythonSlateDelegate::SimpleExecuteAction);
57+
else
58+
{
59+
handler.BindSP(py_delegate, &FPythonSlateDelegate::SimpleExecuteAction);
5560
}
5661

5762
self->tool_bar_builder.AddToolBarButton(FUIAction(handler), FName(hook), FText::FromString(UTF8_TO_TCHAR(label)), FText::FromString(UTF8_TO_TCHAR(tooltip)), py_slate_icon->icon);
@@ -60,7 +65,8 @@ static PyObject *py_ue_ftool_bar_builder_add_tool_bar_button(ue_PyFToolBarBuilde
6065
return Py_None;
6166
}
6267

63-
static PyObject *py_ue_ftool_bar_builder_add_separator(ue_PyFToolBarBuilder *self, PyObject * args) {
68+
static PyObject *py_ue_ftool_bar_builder_add_separator(ue_PyFToolBarBuilder *self, PyObject * args)
69+
{
6470
char *hook = nullptr;
6571

6672
if (!PyArg_ParseTuple(args, "|s:add_separator", &hook))
@@ -78,25 +84,28 @@ static PyObject *py_ue_ftool_bar_builder_add_separator(ue_PyFToolBarBuilder *sel
7884
}
7985

8086

81-
static PyObject *py_ue_ftool_bar_builder_begin_block_group(ue_PyFToolBarBuilder *self, PyObject * args) {
87+
static PyObject *py_ue_ftool_bar_builder_begin_block_group(ue_PyFToolBarBuilder *self, PyObject * args)
88+
{
8289
self->tool_bar_builder.BeginBlockGroup();
8390

8491
Py_INCREF(Py_None);
8592
return Py_None;
8693
}
8794

88-
static PyObject *py_ue_ftool_bar_builder_end_block_group(ue_PyFToolBarBuilder *self, PyObject * args) {
95+
static PyObject *py_ue_ftool_bar_builder_end_block_group(ue_PyFToolBarBuilder *self, PyObject * args)
96+
{
8997
self->tool_bar_builder.EndBlockGroup();
9098

9199
Py_INCREF(Py_None);
92100
return Py_None;
93101
}
94102

95-
static PyObject *py_ue_ftool_bar_builder_make_widget(ue_PyFToolBarBuilder *self, PyObject * args) {
96-
ue_PySWidget *ret = (ue_PySWidget *)PyObject_New(ue_PySWidget, &ue_PySWidgetType);
103+
static PyObject *py_ue_ftool_bar_builder_make_widget(ue_PyFToolBarBuilder *self, PyObject * args)
104+
{
105+
ue_PySWidget *ret = (ue_PySWidget *)PyObject_New(ue_PySWidget, &ue_PySWidgetType);
97106
ue_py_setup_swidget(ret);
98-
ret->s_widget = self->tool_bar_builder.MakeWidget();
99-
return (PyObject *)ret;
107+
ret->s_widget = self->tool_bar_builder.MakeWidget();
108+
return (PyObject *)ret;
100109
}
101110

102111
static PyMethodDef ue_PyFToolBarBuilder_methods[] = {
@@ -106,7 +115,7 @@ static PyMethodDef ue_PyFToolBarBuilder_methods[] = {
106115
{ "add_separator", (PyCFunction)py_ue_ftool_bar_builder_add_separator, METH_VARARGS, "" },
107116
{ "begin_block_group", (PyCFunction)py_ue_ftool_bar_builder_begin_block_group, METH_VARARGS, "" },
108117
{ "end_block_group", (PyCFunction)py_ue_ftool_bar_builder_end_block_group, METH_VARARGS, "" },
109-
{ "make_widget", (PyCFunction)py_ue_ftool_bar_builder_make_widget, METH_VARARGS, "" },
118+
{ "make_widget", (PyCFunction)py_ue_ftool_bar_builder_make_widget, METH_VARARGS, "" },
110119
{ NULL } /* Sentinel */
111120
};
112121

@@ -117,7 +126,8 @@ static PyObject *ue_PyFToolBarBuilder_str(ue_PyFToolBarBuilder *self)
117126
&self->tool_bar_builder);
118127
}
119128

120-
static void ue_py_ftool_bar_builder_dealloc(ue_PyFToolBarBuilder *self) {
129+
static void ue_py_ftool_bar_builder_dealloc(ue_PyFToolBarBuilder *self)
130+
{
121131
#if PY_MAJOR_VERSION < 3
122132
self->ob_type->tp_free((PyObject*)self);
123133
#else
@@ -156,13 +166,15 @@ static PyTypeObject ue_PyFToolBarBuilderType = {
156166
ue_PyFToolBarBuilder_methods, /* tp_methods */
157167
};
158168

159-
static int ue_py_ftool_bar_builder_init(ue_PyFToolBarBuilder *self, PyObject *args, PyObject *kwargs) {
160-
new(&self->tool_bar_builder) FToolBarBuilder(TSharedPtr<FUICommandList>(), FMultiBoxCustomization::None);
169+
static int ue_py_ftool_bar_builder_init(ue_PyFToolBarBuilder *self, PyObject *args, PyObject *kwargs)
170+
{
171+
new(&self->tool_bar_builder) FToolBarBuilder(TSharedPtr<FUICommandList>(), FMultiBoxCustomization::None);
161172
return 0;
162173
}
163174

164175

165-
void ue_python_init_ftool_bar_builder(PyObject *ue_module) {
176+
void ue_python_init_ftool_bar_builder(PyObject *ue_module)
177+
{
166178
ue_PyFToolBarBuilderType.tp_new = PyType_GenericNew;
167179

168180
ue_PyFToolBarBuilderType.tp_init = (initproc)ue_py_ftool_bar_builder_init;
@@ -174,7 +186,8 @@ void ue_python_init_ftool_bar_builder(PyObject *ue_module) {
174186
PyModule_AddObject(ue_module, "FToolBarBuilder", (PyObject *)&ue_PyFToolBarBuilderType);
175187
}
176188

177-
PyObject *py_ue_new_ftool_bar_builder(FToolBarBuilder tool_bar_builder) {
189+
PyObject *py_ue_new_ftool_bar_builder(FToolBarBuilder tool_bar_builder)
190+
{
178191
ue_PyFToolBarBuilder *ret = (ue_PyFToolBarBuilder *)PyObject_New(ue_PyFToolBarBuilder, &ue_PyFToolBarBuilderType);
179192
new(&ret->tool_bar_builder) FToolBarBuilder(tool_bar_builder);
180193
return (PyObject *)ret;

Source/UnrealEnginePython/Private/Slate/UEPySBorder.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ static PyObject *py_ue_sborder_clear_content(ue_PySBorder *self, PyObject * args
1010
{
1111

1212
sw_border->ClearContent();
13-
Py_XDECREF(self->s_compound_widget.s_widget.py_swidget_content);
1413

15-
Py_INCREF(Py_None);
16-
return Py_None;
14+
Py_RETURN_NONE;
1715
}
1816

1917
static PyObject *py_ue_sborder_set_content(ue_PySBorder *self, PyObject * args)
@@ -30,9 +28,9 @@ static PyObject *py_ue_sborder_set_content(ue_PySBorder *self, PyObject * args)
3028
return PyErr_Format(PyExc_Exception, "argument is not a SWidget");
3129
}
3230

33-
Py_XDECREF(self->s_compound_widget.s_widget.py_swidget_content);
31+
3432
Py_INCREF(py_swidget);
35-
self->s_compound_widget.s_widget.py_swidget_content = py_swidget;
33+
3634

3735
sw_border->SetContent(py_swidget->s_widget->AsShared());
3836

Source/UnrealEnginePython/Private/Slate/UEPySBox.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66

77
#define sw_box StaticCastSharedRef<SBox>(self->s_panel.s_widget.s_widget)
88

9-
static PyObject *py_ue_sbox_set_content(ue_PySBox *self, PyObject * args) {
9+
static PyObject *py_ue_sbox_set_content(ue_PySBox *self, PyObject * args)
10+
{
1011
PyObject *py_content;
11-
if (!PyArg_ParseTuple(args, "O:set_content", &py_content)) {
12+
if (!PyArg_ParseTuple(args, "O:set_content", &py_content))
13+
{
1214
return NULL;
1315
}
1416

1517
ue_PySWidget *py_swidget = py_ue_is_swidget(py_content);
16-
if (!py_swidget) {
18+
if (!py_swidget)
19+
{
1720
return PyErr_Format(PyExc_Exception, "argument is not a SWidget");
1821
}
1922

20-
Py_XDECREF(self->s_panel.s_widget.py_swidget_content);
2123
Py_INCREF(py_swidget);
22-
self->s_panel.s_widget.py_swidget_content = py_swidget;
2324

2425
sw_box->SetContent(py_swidget->s_widget->AsShared());
2526

@@ -63,7 +64,8 @@ PyTypeObject ue_PySBoxType = {
6364
ue_PySBox_methods, /* tp_methods */
6465
};
6566

66-
static int ue_py_sbox_init(ue_PySBox *self, PyObject *args, PyObject *kwargs) {
67+
static int ue_py_sbox_init(ue_PySBox *self, PyObject *args, PyObject *kwargs)
68+
{
6769

6870
ue_py_slate_setup_farguments(SBox);
6971

@@ -78,13 +80,14 @@ static int ue_py_sbox_init(ue_PySBox *self, PyObject *args, PyObject *kwargs) {
7880
ue_py_slate_farguments_optional_foptional_size("max_desired_width", MaxDesiredWidth);
7981
ue_py_slate_farguments_optional_foptional_size("min_desired_height", MinDesiredHeight);
8082
ue_py_slate_farguments_optional_foptional_size("min_desired_width", MinDesiredWidth);
81-
83+
8284
ue_py_snew(SBox, s_panel.s_widget);
8385

8486
return 0;
8587
}
8688

87-
void ue_python_init_sbox(PyObject *ue_module) {
89+
void ue_python_init_sbox(PyObject *ue_module)
90+
{
8891

8992
ue_PySBoxType.tp_init = (initproc)ue_py_sbox_init;
9093
ue_PySBoxType.tp_call = (ternaryfunc)py_ue_sbox_set_content;

Source/UnrealEnginePython/Private/Slate/UEPySBoxPanel.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66

77
#define sw_box_panel StaticCastSharedRef<SBoxPanel>(self->s_panel.s_widget.s_widget)
88

9-
static PyObject *py_ue_sbox_panel_clear_children(ue_PySGridPanel *self, PyObject * args) {
9+
static PyObject *py_ue_sbox_panel_clear_children(ue_PySGridPanel *self, PyObject * args)
10+
{
1011

1112
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();
1613

17-
Py_INCREF(Py_None);
18-
return Py_None;
14+
Py_RETURN_NONE;
1915
}
2016

2117
static PyMethodDef ue_PySBoxPanel_methods[] = {
@@ -54,7 +50,8 @@ PyTypeObject ue_PySBoxPanelType = {
5450
ue_PySBoxPanel_methods, /* tp_methods */
5551
};
5652

57-
void ue_python_init_sbox_panel(PyObject *ue_module) {
53+
void ue_python_init_sbox_panel(PyObject *ue_module)
54+
{
5855

5956
ue_PySBoxPanelType.tp_base = &ue_PySPanelType;
6057

Source/UnrealEnginePython/Private/Slate/UEPySButton.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ static PyObject *py_ue_sbutton_bind_on_clicked(ue_PySButton *self, PyObject * ar
3333
}
3434

3535
FOnClicked handler;
36-
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
36+
TSharedRef<FPythonSlateDelegate>py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_border.s_compound_widget.s_widget.s_widget, py_callable);
3737
py_delegate->SetPyCallable(py_callable);
38-
py_delegate->AddToRoot();
39-
handler.BindUObject(py_delegate, &UPythonSlateDelegate::OnClicked);
40-
self->s_border.s_compound_widget.s_widget.delegates.Add(py_delegate);
38+
handler.BindSP(py_delegate, &FPythonSlateDelegate::OnClicked);
4139

4240
sw_button->SetOnClicked(handler);
4341

@@ -106,7 +104,7 @@ static int ue_py_sbutton_init(ue_PySButton *self, PyObject *args, PyObject *kwar
106104
ue_py_slate_farguments_text("text", Text);
107105
ue_py_slate_farguments_optional_enum("text_flow_direction", TextFlowDirection, ETextFlowDirection);
108106
ue_py_slate_farguments_optional_enum("text_shaping_method", TextShapingMethod, ETextShapingMethod);
109-
ue_py_slate_farguments_optional_struct_ptr("button_style", ButtonStyle, FButtonStyle);
107+
ue_py_slate_farguments_optional_struct_ptr("button_style", ButtonStyle, FButtonStyle);
110108
ue_py_slate_farguments_optional_struct_ptr("text_style", TextStyle, FTextBlockStyle);
111109
ue_py_slate_farguments_optional_enum("touch_method", TouchMethod, EButtonTouchMethod::Type);
112110
ue_py_slate_farguments_optional_enum("v_align", VAlign, EVerticalAlignment);

0 commit comments

Comments
 (0)