Add a delegate, unfortunately it doesn't work?
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -12,3 +12,8 @@ Int2 ScreenUtilsBase::GetScreenCursorPosition() {
|
||||
|
||||
void ScreenUtilsBase::BlockAndReadMouse() {
|
||||
}
|
||||
|
||||
void ScreenUtilsBase::PickColor() {
|
||||
}
|
||||
|
||||
Delegate<Color32> ScreenUtilsBase::PickColorDone;
|
||||
|
||||
@@ -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:
|
||||
/// <returns>Cursor position, in screen coordinates.</returns>
|
||||
API_FUNCTION() static Int2 GetScreenCursorPosition();
|
||||
|
||||
/// <summary>
|
||||
/// Starts async color picking. Will return a color through ColorReturnCallback.
|
||||
/// </summary
|
||||
API_FUNCTION() static void PickColor();
|
||||
|
||||
/// <summary>
|
||||
/// Blocks mouse input and runs a callback
|
||||
/// </summary>
|
||||
API_FUNCTION() static void BlockAndReadMouse();
|
||||
|
||||
/// <summary>
|
||||
/// Called when PickColor() is finished.
|
||||
/// </summary>
|
||||
API_EVENT() static Delegate<Color32> PickColorDone;
|
||||
};
|
||||
|
||||
@@ -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 <Windows.h>
|
||||
|
||||
@@ -8,6 +9,7 @@
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
#endif
|
||||
#include <Engine/Core/Log.h>
|
||||
#include <Engine/Scripting/ManagedCLR/MCore.h>
|
||||
|
||||
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<Color32> 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();
|
||||
}
|
||||
|
||||
@@ -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<Color32> PickColorDone;
|
||||
|
||||
public:
|
||||
static void PickSelected();
|
||||
static void Test(Color32 testVal);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user