Skip to content

Commit 3ff4d72

Browse files
author
Roberto De Ioris
committed
working color picker
1 parent f47b172 commit 3ff4d72

File tree

5 files changed

+59
-17
lines changed

5 files changed

+59
-17
lines changed

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "Runtime/Slate/Public/Widgets/Views/STableRow.h"
1313
#include "Editor/ContentBrowser/Public/ContentBrowserModule.h"
1414

15+
#include "Runtime/AppFramework/Public/Widgets/Colors/SColorPicker.h"
16+
1517

1618
#include "UEPySlate.h"
1719

@@ -110,6 +112,17 @@ void UPythonSlateDelegate::OnFloatChanged(float value) {
110112
Py_DECREF(ret);
111113
}
112114

115+
void UPythonSlateDelegate::OnLinearColorChanged(FLinearColor color) {
116+
FScopePythonGIL gil;
117+
118+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"O", py_ue_new_flinearcolor(color));
119+
if (!ret) {
120+
unreal_engine_py_log_error();
121+
return;
122+
}
123+
Py_DECREF(ret);
124+
}
125+
113126
void UPythonSlateDelegate::OnFloatCommitted(float value, ETextCommit::Type commit_type) {
114127
FScopePythonGIL gil;
115128

@@ -811,3 +824,39 @@ PyObject *py_unreal_engine_unregister_nomad_tab_spawner(PyObject * self, PyObjec
811824
Py_INCREF(Py_None);
812825
return Py_None;
813826
}
827+
828+
829+
PyObject *py_unreal_engine_open_color_picker(PyObject *self, PyObject *args, PyObject *kwargs) {
830+
831+
PyObject *py_callable_on_color_committed = nullptr;
832+
833+
char *kwlist[] = {
834+
(char *)"on_color_committed",
835+
nullptr };
836+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:open_color_picker", kwlist,
837+
&py_callable_on_color_committed)) {
838+
return nullptr;
839+
}
840+
841+
if (!PyCallable_Check(py_callable_on_color_committed)) {
842+
return PyErr_Format(PyExc_Exception, "on_color_committed must be a callable");
843+
}
844+
845+
UPythonSlateDelegate *py_delegate = NewObject<UPythonSlateDelegate>();
846+
py_delegate->SetPyCallable(py_callable_on_color_committed);
847+
// TODO: this memory should be freed...
848+
py_delegate->AddToRoot();
849+
850+
FColorPickerArgs color_args;
851+
color_args.OnColorCommitted.BindUObject(py_delegate, &UPythonSlateDelegate::OnLinearColorChanged);
852+
853+
if (OpenColorPicker(color_args)) {
854+
Py_RETURN_TRUE;
855+
}
856+
Py_RETURN_FALSE;
857+
}
858+
859+
PyObject *py_unreal_engine_destroy_color_picker(PyObject *self, PyObject * args) {
860+
DestroyColorPicker();
861+
Py_RETURN_NONE;
862+
}

Source/UnrealEnginePython/Private/Slate/UEPySlate.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ PyObject *py_unreal_engine_add_tool_bar_extension(PyObject *, PyObject *);
8585
PyObject *py_unreal_engine_register_nomad_tab_spawner(PyObject *, PyObject *);
8686
PyObject *py_unreal_engine_unregister_nomad_tab_spawner(PyObject *, PyObject *);
8787

88+
PyObject *py_unreal_engine_open_color_picker(PyObject *, PyObject *, PyObject *);
89+
PyObject *py_unreal_engine_destroy_color_picker(PyObject *, PyObject *);
90+
8891
void ue_py_register_swidget(SWidget *, ue_PySWidget *);
8992
void ue_py_unregister_swidget(SWidget *);
9093

@@ -111,6 +114,8 @@ template<typename T> ue_PySWidget *py_ue_new_swidget(TSharedRef<SWidget> s_widge
111114

112115
#define ue_py_snew_with_args(T, field, args) ue_py_snew_base(T, field, RequiredArgs::MakeRequiredArgs(args), arguments)
113116

117+
118+
114119
ue_PySWidget *ue_py_get_swidget(TSharedRef<SWidget> s_widget);
115120

116121
#define ue_py_slate_base_up(_base, _func, _param, _attribute) \
@@ -382,6 +387,8 @@ class UPythonSlateDelegate : public UPythonDelegate
382387
void OnFloatChanged(float value);
383388
void OnFloatCommitted(float value, ETextCommit::Type commit_type);
384389

390+
void OnLinearColorChanged(FLinearColor color);
391+
385392
void OnStringChanged(const FString &text);
386393

387394
TSharedRef<SDockTab> SpawnPythonTab(const FSpawnTabArgs& args);

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "Kismet/KismetSystemLibrary.h"
44
#include "Kismet/KismetMathLibrary.h"
55

6-
#include "Runtime/AppFramework/Public/Widgets/Colors/SColorPicker.h"
6+
77

88
PyObject *py_unreal_engine_log(PyObject * self, PyObject * args) {
99
PyObject *py_message;
@@ -701,15 +701,3 @@ PyObject *py_unreal_engine_editor_get_pie_viewport_size(PyObject *self, PyObject
701701
#endif
702702

703703

704-
PyObject *py_unreal_engine_open_color_picker(PyObject *self, PyObject * args) {
705-
FColorPickerArgs color_args;
706-
if (OpenColorPicker(color_args)) {
707-
Py_RETURN_TRUE;
708-
}
709-
Py_RETURN_FALSE;
710-
}
711-
712-
PyObject *py_unreal_engine_destroy_color_picker(PyObject *self, PyObject * args) {
713-
DestroyColorPicker();
714-
Py_RETURN_NONE;
715-
}

Source/UnrealEnginePython/Private/UEPyEngine.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ PyObject *py_unreal_engine_convert_relative_path_to_full(PyObject *, PyObject *)
4545
PyObject *py_unreal_engine_get_viewport_screenshot(PyObject *, PyObject *);
4646
PyObject *py_unreal_engine_get_viewport_size(PyObject *, PyObject *);
4747

48-
PyObject *py_unreal_engine_open_color_picker(PyObject *, PyObject *);
49-
PyObject *py_unreal_engine_destroy_color_picker(PyObject *, PyObject *);
5048

5149
#if WITH_EDITOR
5250
PyObject *py_unreal_engine_editor_get_active_viewport_screenshot(PyObject *, PyObject *);

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ static PyMethodDef unreal_engine_methods[] = {
278278
{ "get_viewport_size", py_unreal_engine_get_viewport_size, METH_VARARGS, "" },
279279

280280
{ "get_game_viewport_client", py_unreal_engine_get_game_viewport_client, METH_VARARGS, "" },
281-
282-
{ "open_color_picker", py_unreal_engine_open_color_picker, METH_VARARGS, "" },
281+
#pragma warning(suppress: 4191)
282+
{ "open_color_picker", (PyCFunction)py_unreal_engine_open_color_picker, METH_VARARGS| METH_KEYWORDS, "" },
283283
{ "destroy_color_picker", py_unreal_engine_destroy_color_picker, METH_VARARGS, "" },
284284
#if WITH_EDITOR
285285
{ "editor_play_in_viewport", py_unreal_engine_editor_play_in_viewport, METH_VARARGS, "" },

0 commit comments

Comments
 (0)