|
1 | 1 | #include "UnrealEnginePythonPrivatePCH.h" |
2 | 2 |
|
3 | 3 | #include "UEPyFSlateStyleSet.h" |
| 4 | +#include "SlateTypes.h" |
| 5 | +#include "Map.h" |
4 | 6 |
|
5 | 7 | static PyObject *py_ue_fslate_style_set_set_content_root(ue_PyFSlateStyleSet *self, PyObject * args) |
6 | 8 | { |
@@ -87,9 +89,119 @@ static PyObject *py_ue_fslate_style_set_set(ue_PyFSlateStyleSet *self, PyObject |
87 | 89 | return PyErr_Format(PyExc_ValueError, "unsupported value type"); |
88 | 90 | } |
89 | 91 |
|
| 92 | +namespace { |
| 93 | + template <typename WidgetStyleType> |
| 94 | + PyObject* pyGetWidgetStyle(FSlateStyleSet& InStyle, FName PropertyName) |
| 95 | + { |
| 96 | + const WidgetStyleType styleWidgetStyle = InStyle.GetWidgetStyle<WidgetStyleType>(PropertyName); |
| 97 | + return py_ue_new_uscriptstruct(WidgetStyleType::StaticStruct(), (const uint8*)&styleWidgetStyle); |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +static PyObject *py_ue_fslate_style_set_get(ue_PyFSlateStyleSet *self, PyObject * args) |
| 102 | +{ |
| 103 | + if (!(self && self->style_set)) |
| 104 | + return PyErr_Format(PyExc_Exception, "fstyleset is in invalid state"); |
| 105 | + |
| 106 | + char *name = nullptr; |
| 107 | + PyObject *py_type = nullptr; |
| 108 | + |
| 109 | + if (!PyArg_ParseTuple(args, "sO:get", &name, &py_type)) |
| 110 | + return NULL; |
| 111 | + |
| 112 | + PyObject *ret = nullptr; |
| 113 | + |
| 114 | + if (ue_py_check_struct<FSlateSound>(py_type)) |
| 115 | + { |
| 116 | + const FSlateSound& styleSound = self->style_set->GetSound(FName(name)); |
| 117 | + ret = py_ue_new_uscriptstruct(FSlateSound::StaticStruct(), (const uint8*)&styleSound); |
| 118 | + } |
| 119 | + else if (ue_py_check_struct<FSlateBrush>(py_type)) |
| 120 | + { |
| 121 | + if (const FSlateBrush* styleBrush = self->style_set->GetBrush(FName(name))) |
| 122 | + { |
| 123 | + ret = py_ue_new_uscriptstruct(FSlateBrush::StaticStruct(), (const uint8*)styleBrush); |
| 124 | + } |
| 125 | + } |
| 126 | + else if (ue_py_check_struct<FSlateColor>(py_type)) |
| 127 | + { |
| 128 | + const FSlateColor styleSlateColor = self->style_set->GetSlateColor(FName(name)); |
| 129 | + ret = py_ue_new_uscriptstruct(FSlateColor::StaticStruct(), (const uint8*)&styleSlateColor); |
| 130 | + } |
| 131 | + else if (ue_py_check_struct<FSlateFontInfo>(py_type)) |
| 132 | + { |
| 133 | + const FSlateFontInfo styleFontInfo = self->style_set->GetFontStyle(FName(name)); |
| 134 | + ret = py_ue_new_uscriptstruct(FSlateFontInfo::StaticStruct(), (const uint8*)&styleFontInfo); |
| 135 | + } |
| 136 | + else if (ue_py_check_childstruct<FSlateWidgetStyle>(py_type)) |
| 137 | + { |
| 138 | + typedef TFunction<PyObject* (FSlateStyleSet&, FName)> WStyleGetter; |
| 139 | + typedef TPair<UScriptStruct*, WStyleGetter> WStylePair; |
| 140 | + static const WStylePair validWidgetStyleUStructList[] = { |
| 141 | + WStylePair{ FTextBlockStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FTextBlockStyle> (InStyle, InName); }) }, |
| 142 | + WStylePair{ FButtonStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FButtonStyle> (InStyle, InName); }) }, |
| 143 | + WStylePair{ FComboButtonStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FComboButtonStyle> (InStyle, InName); }) }, |
| 144 | + WStylePair{ FComboBoxStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FComboBoxStyle> (InStyle, InName); }) }, |
| 145 | + WStylePair{ FHyperlinkStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FHyperlinkStyle> (InStyle, InName); }) }, |
| 146 | + WStylePair{ FEditableTextStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FEditableTextStyle> (InStyle, InName); }) }, |
| 147 | + WStylePair{ FScrollBarStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FScrollBarStyle> (InStyle, InName); }) }, |
| 148 | + WStylePair{ FEditableTextBoxStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FEditableTextBoxStyle> (InStyle, InName); }) }, |
| 149 | + WStylePair{ FInlineEditableTextBlockStyle::StaticStruct(), WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FInlineEditableTextBlockStyle>(InStyle, InName); }) }, |
| 150 | + WStylePair{ FProgressBarStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FProgressBarStyle> (InStyle, InName); }) }, |
| 151 | + WStylePair{ FExpandableAreaStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FExpandableAreaStyle> (InStyle, InName); }) }, |
| 152 | + WStylePair{ FSearchBoxStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FSearchBoxStyle> (InStyle, InName); }) }, |
| 153 | + WStylePair{ FSliderStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FSliderStyle> (InStyle, InName); }) }, |
| 154 | + WStylePair{ FVolumeControlStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FVolumeControlStyle> (InStyle, InName); }) }, |
| 155 | + WStylePair{ FInlineTextImageStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FInlineTextImageStyle> (InStyle, InName); }) }, |
| 156 | + WStylePair{ FSpinBoxStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FSpinBoxStyle> (InStyle, InName); }) }, |
| 157 | + WStylePair{ FSplitterStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FSplitterStyle> (InStyle, InName); }) }, |
| 158 | + WStylePair{ FTableRowStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FTableRowStyle> (InStyle, InName); }) }, |
| 159 | + WStylePair{ FTableColumnHeaderStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FTableColumnHeaderStyle> (InStyle, InName); }) }, |
| 160 | + WStylePair{ FHeaderRowStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FHeaderRowStyle> (InStyle, InName); }) }, |
| 161 | + WStylePair{ FDockTabStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FDockTabStyle> (InStyle, InName); }) }, |
| 162 | + WStylePair{ FScrollBoxStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FScrollBoxStyle> (InStyle, InName); }) }, |
| 163 | + WStylePair{ FScrollBorderStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FScrollBorderStyle> (InStyle, InName); }) }, |
| 164 | + WStylePair{ FWindowStyle::StaticStruct() , WStyleGetter([](FSlateStyleSet& InStyle, FName InName) { return pyGetWidgetStyle<FWindowStyle> (InStyle, InName); }) }, |
| 165 | + }; |
| 166 | + |
| 167 | + for(WStylePair widgetStyleUStruct : validWidgetStyleUStructList) |
| 168 | + { |
| 169 | + if (do_ue_py_check_struct(py_type, widgetStyleUStruct.Key)) |
| 170 | + { |
| 171 | + ret = widgetStyleUStruct.Value(*self->style_set, FName(name)); |
| 172 | + break; |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + if (!ret) |
| 177 | + { |
| 178 | + return PyErr_Format(PyExc_ValueError, "Unsupported FSlateWidgetStyle type. Add it manually."); |
| 179 | + } |
| 180 | + } |
| 181 | + else if (py_ue_is_flinearcolor(py_type)) |
| 182 | + { |
| 183 | + ret = py_ue_new_flinearcolor(self->style_set->GetColor(FName(name))); |
| 184 | + } |
| 185 | + else if (PyNumber_Check(py_type)) |
| 186 | + { |
| 187 | + ret = PyFloat_FromDouble(self->style_set->GetFloat(FName(name))); |
| 188 | + } |
| 189 | + else |
| 190 | + { |
| 191 | + return PyErr_Format(PyExc_ValueError, "unsupported value type"); |
| 192 | + } |
| 193 | + |
| 194 | + if (!ret) |
| 195 | + return PyErr_Format(PyExc_Exception, "Retrieved style object is in invalid state"); |
| 196 | + |
| 197 | + return ret; |
| 198 | + |
| 199 | +} |
| 200 | + |
90 | 201 | static PyMethodDef ue_PyFSlateStyleSet_methods[] = { |
91 | 202 | { "set_content_root", (PyCFunction)py_ue_fslate_style_set_set_content_root, METH_VARARGS, "" }, |
92 | 203 | { "set", (PyCFunction)py_ue_fslate_style_set_set, METH_VARARGS, "" }, |
| 204 | + { "get", (PyCFunction)py_ue_fslate_style_set_get, METH_VARARGS, "" }, |
93 | 205 | { "register", (PyCFunction)py_ue_fslate_style_set_register, METH_VARARGS, "" }, |
94 | 206 | { NULL } /* Sentinel */ |
95 | 207 | }; |
@@ -139,11 +251,18 @@ static int ue_py_fslate_style_set_init(ue_PyFSlateStyleSet *self, PyObject *args |
139 | 251 | { |
140 | 252 | return -1; |
141 | 253 | } |
142 | | - |
| 254 | + //TODO: roberto: ikrimae- I think this leaks? How is FSlateIcon destroyed ever? |
143 | 255 | self->style_set = new FSlateStyleSet(name); |
144 | 256 | return 0; |
145 | 257 | } |
146 | 258 |
|
| 259 | +ue_PyFSlateStyleSet* py_ue_new_fslate_style_set(FSlateStyleSet* styleSet) |
| 260 | +{ |
| 261 | + ue_PyFSlateStyleSet *ret = (ue_PyFSlateStyleSet *)PyObject_New(ue_PyFSlateStyleSet, &ue_PyFSlateStyleSetType); |
| 262 | + ret->style_set = styleSet; |
| 263 | + return ret; |
| 264 | +} |
| 265 | + |
147 | 266 | void ue_python_init_fslate_style_set(PyObject *ue_module) |
148 | 267 | { |
149 | 268 | ue_PyFSlateStyleSetType.tp_new = PyType_GenericNew; |
|
0 commit comments