Skip to content

Commit f5733bf

Browse files
author
Roberto De Ioris
committed
added more widgets to the slate api
1 parent c0a6ab6 commit f5733bf

19 files changed

+752
-11
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#if WITH_EDITOR
2+
3+
#include "UnrealEnginePythonPrivatePCH.h"
4+
5+
#include "UEPySBorder.h"
6+
7+
8+
9+
#define GET_s_border TSharedRef<SBorder> s_border = StaticCastSharedRef<SBorder>(self->s_compound_widget.s_widget.s_widget)
10+
11+
static PyObject *py_ue_sborder_clear_content(ue_PySBorder *self, PyObject * args) {
12+
GET_s_border;
13+
14+
s_border->ClearContent();
15+
16+
Py_INCREF(Py_None);
17+
return Py_None;
18+
}
19+
20+
static PyObject *py_ue_sborder_set_content(ue_PySBorder *self, PyObject * args) {
21+
PyObject *py_content;
22+
if (!PyArg_ParseTuple(args, "O:set_content", &py_content)) {
23+
return NULL;
24+
}
25+
26+
ue_PySWidget *py_swidget = py_ue_is_swidget(py_content);
27+
if (!py_swidget) {
28+
return PyErr_Format(PyExc_Exception, "argument is not a SWidget");
29+
}
30+
// TODO: decrement reference when destroying parent
31+
Py_INCREF(py_swidget);
32+
33+
GET_s_border;
34+
35+
s_border->SetContent(py_swidget->s_widget);
36+
37+
Py_INCREF(self);
38+
return (PyObject *)self;
39+
}
40+
41+
static PyObject *ue_PySBorder_str(ue_PySBorder *self)
42+
{
43+
return PyUnicode_FromFormat("<unreal_engine.SWindow '%p'>",
44+
&self->s_compound_widget.s_widget.s_widget.Get());
45+
}
46+
47+
static PyMethodDef ue_PySBorder_methods[] = {
48+
{ "clear_content", (PyCFunction)py_ue_sborder_clear_content, METH_VARARGS, "" },
49+
{ "set_content", (PyCFunction)py_ue_sborder_set_content, METH_VARARGS, "" },
50+
{ NULL } /* Sentinel */
51+
};
52+
53+
PyTypeObject ue_PySBorderType = {
54+
PyVarObject_HEAD_INIT(NULL, 0)
55+
"unreal_engine.SBorder", /* tp_name */
56+
sizeof(ue_PySBorder), /* tp_basicsize */
57+
0, /* tp_itemsize */
58+
0, /* tp_dealloc */
59+
0, /* tp_print */
60+
0, /* tp_getattr */
61+
0, /* tp_setattr */
62+
0, /* tp_reserved */
63+
0, /* tp_repr */
64+
0, /* tp_as_number */
65+
0, /* tp_as_sequence */
66+
0, /* tp_as_mapping */
67+
0, /* tp_hash */
68+
0, /* tp_call */
69+
(reprfunc)ue_PySBorder_str, /* tp_str */
70+
0, /* tp_getattro */
71+
0, /* tp_setattro */
72+
0, /* tp_as_buffer */
73+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
74+
"Unreal Engine SBorder", /* tp_doc */
75+
0, /* tp_traverse */
76+
0, /* tp_clear */
77+
0, /* tp_richcompare */
78+
0, /* tp_weaklistoffset */
79+
0, /* tp_iter */
80+
0, /* tp_iternext */
81+
ue_PySBorder_methods, /* tp_methods */
82+
};
83+
84+
static int ue_py_sborder_init(ue_PySWindow *self, PyObject *args, PyObject *kwargs) {
85+
self->s_compound_widget.s_widget.s_widget = TSharedRef<SBorder>(SNew(SBorder));
86+
return 0;
87+
}
88+
89+
void ue_python_init_sborder(PyObject *ue_module) {
90+
ue_PySBorderType.tp_new = PyType_GenericNew;
91+
92+
ue_PySBorderType.tp_init = (initproc)ue_py_sborder_init;
93+
94+
ue_PySBorderType.tp_base = &ue_PySCompoundWidgetType;
95+
96+
if (PyType_Ready(&ue_PySBorderType) < 0)
97+
return;
98+
99+
Py_INCREF(&ue_PySBorderType);
100+
PyModule_AddObject(ue_module, "SBorder", (PyObject *)&ue_PySBorderType);
101+
}
102+
103+
104+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include "UnrealEnginePython.h"
4+
5+
#if WITH_EDITOR
6+
7+
#include "UEPySCompoundWidget.h"
8+
9+
#include "Runtime/Slate/Public/Widgets/Layout/SBorder.h"
10+
11+
extern PyTypeObject ue_PySBorderType;
12+
13+
typedef struct {
14+
ue_PySCompoundWidget s_compound_widget;
15+
/* Type-specific fields go here. */
16+
} ue_PySBorder;
17+
18+
void ue_python_init_sborder(PyObject *);
19+
20+
#endif
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#if WITH_EDITOR
2+
3+
#include "UnrealEnginePythonPrivatePCH.h"
4+
5+
#include "UEPySButton.h"
6+
7+
8+
9+
#define GET_s_button TSharedRef<SButton> s_button = StaticCastSharedRef<SButton>(self->s_border.s_compound_widget.s_widget.s_widget)
10+
11+
static PyObject *py_ue_sbutton_is_pressed(ue_PySButton *self, PyObject * args) {
12+
GET_s_button;
13+
14+
if (s_button->IsPressed()) {
15+
Py_INCREF(Py_True);
16+
return Py_True;
17+
}
18+
19+
Py_INCREF(Py_False);
20+
return Py_False;
21+
}
22+
23+
24+
static PyObject *ue_PySButton_str(ue_PySButton *self)
25+
{
26+
return PyUnicode_FromFormat("<unreal_engine.SButton '%p'>",
27+
&self->s_border.s_compound_widget.s_widget.s_widget.Get());
28+
}
29+
30+
static PyObject *py_ue_sbutton_bind_on_clicked(ue_PySButton *self, PyObject * args) {
31+
PyObject *py_callable;
32+
if (!PyArg_ParseTuple(args, "O:bind_on_clicked", &py_callable)) {
33+
return NULL;
34+
}
35+
36+
if (!PyCallable_Check(py_callable)) {
37+
return PyErr_Format(PyExc_Exception, "argument is not callable");
38+
}
39+
40+
FOnClicked handler;
41+
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
42+
py_delegate->SetPyCallable(py_callable);
43+
py_delegate->AddToRoot();
44+
handler.BindUObject(py_delegate, &UPythonSlateDelegate::OnClicked);
45+
46+
GET_s_button;
47+
48+
s_button->SetOnClicked(handler);
49+
50+
Py_INCREF(self);
51+
return (PyObject *)self;
52+
}
53+
54+
static PyMethodDef ue_PySButton_methods[] = {
55+
{ "is_pressed", (PyCFunction)py_ue_sbutton_is_pressed, METH_VARARGS, "" },
56+
{ "bind_on_clicked", (PyCFunction)py_ue_sbutton_bind_on_clicked, METH_VARARGS, "" },
57+
{ NULL } /* Sentinel */
58+
};
59+
60+
PyTypeObject ue_PySButtonType = {
61+
PyVarObject_HEAD_INIT(NULL, 0)
62+
"unreal_engine.SButton", /* tp_name */
63+
sizeof(ue_PySButton), /* tp_basicsize */
64+
0, /* tp_itemsize */
65+
0, /* tp_dealloc */
66+
0, /* tp_print */
67+
0, /* tp_getattr */
68+
0, /* tp_setattr */
69+
0, /* tp_reserved */
70+
0, /* tp_repr */
71+
0, /* tp_as_number */
72+
0, /* tp_as_sequence */
73+
0, /* tp_as_mapping */
74+
0, /* tp_hash */
75+
0, /* tp_call */
76+
(reprfunc)ue_PySButton_str, /* tp_str */
77+
0, /* tp_getattro */
78+
0, /* tp_setattro */
79+
0, /* tp_as_buffer */
80+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
81+
"Unreal Engine SButton", /* tp_doc */
82+
0, /* tp_traverse */
83+
0, /* tp_clear */
84+
0, /* tp_richcompare */
85+
0, /* tp_weaklistoffset */
86+
0, /* tp_iter */
87+
0, /* tp_iternext */
88+
ue_PySButton_methods, /* tp_methods */
89+
};
90+
91+
static int ue_py_sbutton_init(ue_PySButton *self, PyObject *args, PyObject *kwargs) {
92+
self->s_border.s_compound_widget.s_widget.s_widget = TSharedRef<SButton>(SNew(SButton));
93+
return 0;
94+
}
95+
96+
void ue_python_init_sbutton(PyObject *ue_module) {
97+
ue_PySButtonType.tp_new = PyType_GenericNew;
98+
99+
ue_PySButtonType.tp_init = (initproc)ue_py_sbutton_init;
100+
101+
ue_PySButtonType.tp_base = &ue_PySBorderType;
102+
103+
if (PyType_Ready(&ue_PySButtonType) < 0)
104+
return;
105+
106+
Py_INCREF(&ue_PySButtonType);
107+
PyModule_AddObject(ue_module, "SButton", (PyObject *)&ue_PySButtonType);
108+
}
109+
110+
111+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include "UnrealEnginePython.h"
4+
5+
#if WITH_EDITOR
6+
7+
#include "UEPySBorder.h"
8+
9+
#include "Runtime/Slate/Public/Widgets/Input/SButton.h"
10+
11+
extern PyTypeObject ue_PySButtonType;
12+
13+
typedef struct {
14+
ue_PySBorder s_border;
15+
/* Type-specific fields go here. */
16+
} ue_PySButton;
17+
18+
void ue_python_init_sbutton(PyObject *);
19+
20+
#endif

Source/UnrealEnginePython/Private/Slate/UEPySCompoundWidget.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44

55
#include "UEPySCompoundWidget.h"
66

7+
#define GET_s_compound_widget TSharedRef<SCompoundWidget> s_compound_widget = StaticCastSharedRef<SCompoundWidget>(self->s_widget.s_widget)
8+
79
static PyObject *ue_PySCompoundWidget_str(ue_PySCompoundWidget *self)
810
{
911
return PyUnicode_FromFormat("<unreal_engine.SCompoundWidget '%p'>",
1012
&self->s_widget.s_widget.Get());
1113
}
1214

15+
static PyObject *py_ue_scompound_widget_get_color_and_opacity(ue_PySCompoundWidget *self, PyObject * args) {
16+
17+
GET_s_compound_widget;
18+
19+
FLinearColor color = s_compound_widget->GetColorAndOpacity();
20+
21+
return py_ue_new_flinearcolor(color);
22+
}
23+
1324
static PyMethodDef ue_PySCompoundWidget_methods[] = {
25+
{ "get_color_and_opacity", (PyCFunction)py_ue_scompound_widget_get_color_and_opacity, METH_VARARGS, "" },
1426
{ NULL } /* Sentinel */
1527
};
1628

@@ -46,12 +58,10 @@ PyTypeObject ue_PySCompoundWidgetType = {
4658
ue_PySCompoundWidget_methods, /* tp_methods */
4759
};
4860

49-
extern struct ue_PySWidgetType;
50-
5161
void ue_python_init_scompound_widget(PyObject *ue_module) {
5262
ue_PySCompoundWidgetType.tp_new = PyType_GenericNew;
5363

54-
//ue_PySCompoundWidgetType.tp_base = &ue_PySWidgetType;
64+
ue_PySCompoundWidgetType.tp_base = &ue_PySWidgetType;
5565

5666
if (PyType_Ready(&ue_PySCompoundWidgetType) < 0)
5767
return;

Source/UnrealEnginePython/Private/Slate/UEPySCompoundWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "UEPySWidget.h"
99

10-
struct ue_PySCompoundWidgetType;
10+
extern PyTypeObject ue_PySCompoundWidgetType;
1111

1212
typedef struct {
1313
ue_PySWidget s_widget;

0 commit comments

Comments
 (0)