Implement C# callback for pixels finished reading

This commit is contained in:
Menotdan
2023-05-10 00:58:38 -04:00
parent 1ebf4d49e5
commit 59c54db275
3 changed files with 21 additions and 14 deletions

View File

@@ -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()

View File

@@ -130,7 +130,7 @@ void CaptureScreenshot::OnFail()
ThreadPoolTask::OnFail();
}
Delegate<Color32> Screenshot::PixelReadDelegate;
/// <summary>
/// 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();
}

View File

@@ -47,4 +47,6 @@ API_CLASS(Static) class FLAXENGINE_API Screenshot
/// <param name="y">The y coordinate to read.</param>
/// <returns>The color </returns>
API_FUNCTION() static Color32 GetPixelAt(int32 x, int32 y);
API_EVENT() static Delegate<Color32> PixelReadDelegate;
};