diff --git a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs index c5842a41f..bdef28db2 100644 --- a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs +++ b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs @@ -221,18 +221,25 @@ namespace FlaxEditor.GUI.Dialogs return pixelColor; } + private void ColorPicked(Color32 colorPicked) + { + Editor.LogWarning("Ok???"); + _activeEyedropper = false; + SelectedColor = colorPicked; + ScreenUtils.PickColorDone -= ColorPicked; + } + private void OnEyedropStart() { _activeEyedropper = true; - ScreenUtils.BlockAndReadMouse(); + ScreenUtils.PickColor(); + ScreenUtils.PickColorDone += ColorPicked; } private void UpdateEyedrop() { Color32 pixelColor = GetEyedropColor(); - SelectedColor = new Color(pixelColor.R, pixelColor.G, pixelColor.B); - - + SelectedColor = pixelColor; } private void OnRGBAChanged() diff --git a/Source/Engine/Platform/Base/ScreenUtilsBase.cpp b/Source/Engine/Platform/Base/ScreenUtilsBase.cpp index 7445ee4ab..833588336 100644 --- a/Source/Engine/Platform/Base/ScreenUtilsBase.cpp +++ b/Source/Engine/Platform/Base/ScreenUtilsBase.cpp @@ -12,3 +12,8 @@ Int2 ScreenUtilsBase::GetScreenCursorPosition() { void ScreenUtilsBase::BlockAndReadMouse() { } + +void ScreenUtilsBase::PickColor() { +} + +Delegate ScreenUtilsBase::PickColorDone; diff --git a/Source/Engine/Platform/Base/ScreenUtilsBase.h b/Source/Engine/Platform/Base/ScreenUtilsBase.h index 86a776fc1..9a4299ad6 100644 --- a/Source/Engine/Platform/Base/ScreenUtilsBase.h +++ b/Source/Engine/Platform/Base/ScreenUtilsBase.h @@ -1,6 +1,7 @@ #pragma once #include "Engine/Core/Types/BaseTypes.h" +#include "Engine/Core/Delegate.h" API_INJECT_CODE(cpp, "#include \"Engine/Platform/ScreenUtils.h\""); @@ -27,8 +28,18 @@ public: /// Cursor position, in screen coordinates. API_FUNCTION() static Int2 GetScreenCursorPosition(); + /// + /// Starts async color picking. Will return a color through ColorReturnCallback. + /// /// Blocks mouse input and runs a callback /// API_FUNCTION() static void BlockAndReadMouse(); + + /// + /// Called when PickColor() is finished. + /// + API_EVENT() static Delegate PickColorDone; }; diff --git a/Source/Engine/Platform/Windows/WindowsScreenUtils.cpp b/Source/Engine/Platform/Windows/WindowsScreenUtils.cpp index f0ec7acf0..17bcfa2a8 100644 --- a/Source/Engine/Platform/Windows/WindowsScreenUtils.cpp +++ b/Source/Engine/Platform/Windows/WindowsScreenUtils.cpp @@ -1,6 +1,7 @@ #include "WindowsScreenUtils.h" #include "Engine/Core/Math/Color32.h" #include "Engine/Core/Math/Vector2.h" +#include "Engine/Core/Delegate.h" #include @@ -8,6 +9,7 @@ #pragma comment(lib, "Gdi32.lib") #endif #include +#include Color32 ScreenUtils::GetPixelAt(int32 x, int32 y) { @@ -48,8 +50,12 @@ LRESULT CALLBACK ScreenUtilsMouseCallback( if (nCode >= 0 && wParam == WM_LBUTTONDOWN) { // Now try to run our code. LOG(Warning, "Mouse callback hit. Skipping event. (hopefully)"); UnhookWindowsHookEx(_mouseCallbackHook); + + ScreenUtils::PickSelected(); return 1; } + + return CallNextHookEx(NULL, nCode, wParam, lParam); } void ScreenUtils::BlockAndReadMouse() @@ -61,3 +67,25 @@ void ScreenUtils::BlockAndReadMouse() LOG(Warning, "Error: {0}", GetLastError()); } } + +Delegate ScreenUtils::PickColorDone; + +void ScreenUtils::Test(Color32 testVal) { + LOG(Warning, "GOT IT"); +} + +void ScreenUtils::PickSelected() { + // Push event with color. + Int2 cursorPos = ScreenUtils::GetScreenCursorPosition(); + Color32 colorPicked = ScreenUtils::GetPixelAt(cursorPos.X, cursorPos.Y); + + LOG(Warning, "REAL: {0}", PickColorDone.Count()); + PickColorDone(colorPicked); + LOG(Warning, "FAKE"); +} + +void ScreenUtils::PickColor() +{ + MCore::AttachThread(); + BlockAndReadMouse(); +} diff --git a/Source/Engine/Platform/Windows/WindowsScreenUtils.h b/Source/Engine/Platform/Windows/WindowsScreenUtils.h index c10179eac..d8cd1c9f7 100644 --- a/Source/Engine/Platform/Windows/WindowsScreenUtils.h +++ b/Source/Engine/Platform/Windows/WindowsScreenUtils.h @@ -2,8 +2,8 @@ #if PLATFORM_WINDOWS -#include "Engine/Core/Math/Color32.h" #include "Engine/Platform/Base/ScreenUtilsBase.h" +#include "Engine/Core/Math/Color32.h" class FLAXENGINE_API ScreenUtils : public ScreenUtilsBase { public: @@ -12,6 +12,12 @@ public: static Color32 GetPixelAt(int32 x, int32 y); static Int2 GetScreenCursorPosition(); static void BlockAndReadMouse(); + static void PickColor(); + static Delegate PickColorDone; + +public: + static void PickSelected(); + static void Test(Color32 testVal); }; #endif