diff --git a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs index e30e9438d..53eabebb4 100644 --- a/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs +++ b/Source/Editor/GUI/Dialogs/ColorPickerDialog.cs @@ -112,6 +112,9 @@ namespace FlaxEditor.GUI.Dialogs _onChanged = colorChanged; _onClosed = pickerClosed; + // Register the event for eyedropper pixels being read. + Screenshot.PixelReadDelegate += PixelDataRead; + // Selector _cSelector = new ColorSelectorWithSliders(180, 18) { @@ -211,17 +214,16 @@ namespace FlaxEditor.GUI.Dialogs SelectedColor = initialValue; } + private void PixelDataRead(Color32 pixel_color) + { + Color color = pixel_color; + Editor.Log(string.Format("Color: {0} {1} {2}", color.R, color.G, color.B)); + } + private void OnEyedropColor() { - Float2 mousePosition = new Float2(0, 0); - foreach (EditorWindow window in Editor.Instance.Windows.Windows) - { - if (window.IsMouseOver) - { - mousePosition = window.RootWindow.MousePosition; - } - } - Editor.Log("Color: " + Screenshot.GetPixelAt(Mathf.FloorToInt(mousePosition.X), Mathf.FloorToInt(mousePosition.Y)).ToString()); + Float2 mousePosition = FlaxEngine.Input.MouseScreenPosition; + Screenshot.GetPixelAt(Mathf.FloorToInt(mousePosition.X), Mathf.FloorToInt(mousePosition.Y)); } private void OnRGBAChanged() diff --git a/Source/Engine/Utilities/Screenshot.cpp b/Source/Engine/Utilities/Screenshot.cpp index c946ef695..0635180a8 100644 --- a/Source/Engine/Utilities/Screenshot.cpp +++ b/Source/Engine/Utilities/Screenshot.cpp @@ -130,7 +130,7 @@ void CaptureScreenshot::OnFail() ThreadPoolTask::OnFail(); } - +Delegate Screenshot::PixelReadDelegate; /// /// Capture screenshot helper @@ -176,9 +176,12 @@ bool GetPixelData::Run() mipData->GetPixels(pixels, _data.Width, _data.Height, _data.Format); LOG(Warning, "{0}, {1} ({2} at {3})", x, y, pixels.Count(), (y * _data.Width) + x); - //_color = pixels[(y * _data.Width) + x]; - //LOG(Warning, "really real"); - //LOG(Warning, "Color: {0} {1} {2}", _color.R, _color.B, _color.G); + _color = pixels[(y * _data.Width) + x]; + LOG(Warning, "really real"); + LOG(Warning, "Color: R: {0}, G: {1}, B: {2}", _color.R, _color.G, _color.B); + + LOG(Warning, "Bound functions: {0}", Screenshot::PixelReadDelegate.Count()); + Screenshot::PixelReadDelegate(_color); return false; } @@ -314,8 +317,8 @@ Color32 Screenshot::GetPixelAt(int32 x, int32 y) { Task* downloadTask = swapChain->DownloadDataAsync(getPixelTask->GetData()); downloadTask->ContinueWith(getPixelTask); + LOG(Warning, "Started download task. real"); downloadTask->Start(); - //downloadTask->Wait(750); return getPixelTask->GetColor(); } diff --git a/Source/Engine/Utilities/Screenshot.h b/Source/Engine/Utilities/Screenshot.h index e2b95e748..4fe497355 100644 --- a/Source/Engine/Utilities/Screenshot.h +++ b/Source/Engine/Utilities/Screenshot.h @@ -47,4 +47,6 @@ API_CLASS(Static) class FLAXENGINE_API Screenshot /// The y coordinate to read. /// The color API_FUNCTION() static Color32 GetPixelAt(int32 x, int32 y); + + API_EVENT() static Delegate PixelReadDelegate; };