Correctly implement the ScreenUtils class
This commit is contained in:
@@ -112,9 +112,6 @@ namespace FlaxEditor.GUI.Dialogs
|
|||||||
_onChanged = colorChanged;
|
_onChanged = colorChanged;
|
||||||
_onClosed = pickerClosed;
|
_onClosed = pickerClosed;
|
||||||
|
|
||||||
// Register the event for eyedropper pixels being read.
|
|
||||||
Screenshot.PixelReadDelegate += PixelDataRead;
|
|
||||||
|
|
||||||
// Selector
|
// Selector
|
||||||
_cSelector = new ColorSelectorWithSliders(180, 18)
|
_cSelector = new ColorSelectorWithSliders(180, 18)
|
||||||
{
|
{
|
||||||
@@ -204,7 +201,7 @@ namespace FlaxEditor.GUI.Dialogs
|
|||||||
{
|
{
|
||||||
Parent = this,
|
Parent = this,
|
||||||
};
|
};
|
||||||
_cEyedropper.Clicked += OnEyedropColor;
|
_cEyedropper.Clicked += OnEyedropStart;
|
||||||
_cEyedropper.Height = (_cValue.Bottom - _cEyedropper.Y) * 0.5f;
|
_cEyedropper.Height = (_cValue.Bottom - _cEyedropper.Y) * 0.5f;
|
||||||
_cEyedropper.Width = _cEyedropper.Height;
|
_cEyedropper.Width = _cEyedropper.Height;
|
||||||
_cEyedropper.X -= _cEyedropper.Width;
|
_cEyedropper.X -= _cEyedropper.Width;
|
||||||
@@ -214,18 +211,21 @@ namespace FlaxEditor.GUI.Dialogs
|
|||||||
SelectedColor = initialValue;
|
SelectedColor = initialValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PixelDataRead(Color32 pixel_color)
|
private Color32 GetEyedropColor()
|
||||||
{
|
{
|
||||||
Color color = pixel_color;
|
Int2 mousePosition = ScreenUtils.GetScreenCursorPosition();
|
||||||
Editor.Log(string.Format("Color: {0} {1} {2}", color.R, color.G, color.B));
|
Color32 pixelColor = ScreenUtils.GetPixelAt(mousePosition.X, mousePosition.Y);
|
||||||
|
|
||||||
|
return pixelColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEyedropColor()
|
private void OnEyedropStart()
|
||||||
{
|
{
|
||||||
Float2 mousePosition = FlaxEngine.Input.MouseScreenPosition;
|
Color32 pixelColor = GetEyedropColor();
|
||||||
Screenshot.GetPixelAt(Mathf.FloorToInt(mousePosition.X), Mathf.FloorToInt(mousePosition.Y));
|
Editor.Log(string.Format("Pixel Color: ({0}, {1}, {2})", pixelColor.R, pixelColor.G, pixelColor.B));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnRGBAChanged()
|
private void OnRGBAChanged()
|
||||||
{
|
{
|
||||||
if (_disableEvents)
|
if (_disableEvents)
|
||||||
@@ -251,6 +251,14 @@ namespace FlaxEditor.GUI.Dialogs
|
|||||||
SelectedColor = color;
|
SelectedColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Update(float deltaTime)
|
||||||
|
{
|
||||||
|
base.Update(deltaTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include "ScreenUtilsBase.h"
|
||||||
|
#include "Engine/Core/Math/Color32.h"
|
||||||
|
#include "Engine/Core/Math/Vector2.h"
|
||||||
|
|
||||||
|
Color32 ScreenUtilsBase::GetPixelAt(int32 x, int32 y) {
|
||||||
|
return Color32::Black;
|
||||||
|
}
|
||||||
|
|
||||||
|
Int2 ScreenUtilsBase::GetScreenCursorPosition() {
|
||||||
|
return { 0, 0 };
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Engine/Core/Types/BaseTypes.h"
|
||||||
|
|
||||||
|
API_INJECT_CODE(cpp, "#include \"Engine/Platform/ScreenUtils.h\"");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Platform-dependent screen utilties.
|
||||||
|
/// </summary>
|
||||||
|
API_CLASS(Static, Name = "ScreenUtils", Tag = "NativeInvokeUseName")
|
||||||
|
class FLAXENGINE_API ScreenUtilsBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static struct FLAXENGINE_API ScriptingTypeInitializer TypeInitializer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the pixel color at the specified coordinates.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">X Coordinate to read.</param>
|
||||||
|
/// <param name="y">Y Coordinate to read.</param>
|
||||||
|
/// <returns>Pixel color at the specified coordinates.</returns>
|
||||||
|
API_FUNCTION() static Color32 GetPixelAt(int32 x, int32 y);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the cursor position, in screen cooridnates.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Cursor position, in screen coordinates.</returns>
|
||||||
|
API_FUNCTION() static Int2 GetScreenCursorPosition();
|
||||||
|
};
|
||||||
|
|||||||
@@ -9,9 +9,3 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "Engine/Scripting/ScriptingType.h"
|
|
||||||
|
|
||||||
API_CLASS(Static) class FLAXENGINE_API ScreenUtils
|
|
||||||
{
|
|
||||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(ScreenUtils);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
Color32 PlatformScreenUtils::GetPixelAt(int32 x, int32 y) {
|
#if PLATFORM_WINDOWS
|
||||||
|
#pragma comment(lib, "Gdi32.lib")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Color32 ScreenUtils::GetPixelAt(int32 x, int32 y) {
|
||||||
HDC deviceContext = GetDC(NULL);
|
HDC deviceContext = GetDC(NULL);
|
||||||
COLORREF color = GetPixel(deviceContext, x, y);
|
COLORREF color = GetPixel(deviceContext, x, y);
|
||||||
ReleaseDC(NULL, deviceContext);
|
ReleaseDC(NULL, deviceContext);
|
||||||
@@ -13,7 +17,7 @@ Color32 PlatformScreenUtils::GetPixelAt(int32 x, int32 y) {
|
|||||||
return returnColor;
|
return returnColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int2 PlatformScreenUtils::GetScreenCursorPosition() {
|
Int2 ScreenUtils::GetScreenCursorPosition() {
|
||||||
POINT cursorPos;
|
POINT cursorPos;
|
||||||
GetCursorPos(&cursorPos);
|
GetCursorPos(&cursorPos);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Engine/Core/Math/Color32.h"
|
|
||||||
|
|
||||||
class PlatformScreenUtils {
|
#if PLATFORM_WINDOWS
|
||||||
|
|
||||||
|
#include "Engine/Core/Math/Color32.h"
|
||||||
|
#include "Engine/Platform/Base/ScreenUtilsBase.h"
|
||||||
|
|
||||||
|
class FLAXENGINE_API ScreenUtils : public ScreenUtilsBase {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// [ScreenUtilsBase]
|
||||||
static Color32 GetPixelAt(int32 x, int32 y);
|
static Color32 GetPixelAt(int32 x, int32 y);
|
||||||
static Int2 GetScreenCursorPosition();
|
static Int2 GetScreenCursorPosition();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user