Tweak a few classes, add the Base classes.
This commit is contained in:
0
Source/Engine/Platform/Base/ScreenUtilsBase.cpp
Normal file
0
Source/Engine/Platform/Base/ScreenUtilsBase.cpp
Normal file
0
Source/Engine/Platform/Base/ScreenUtilsBase.h
Normal file
0
Source/Engine/Platform/Base/ScreenUtilsBase.h
Normal file
0
Source/Engine/Platform/ScreenUtils.cpp
Normal file
0
Source/Engine/Platform/ScreenUtils.cpp
Normal file
17
Source/Engine/Platform/ScreenUtils.h
Normal file
17
Source/Engine/Platform/ScreenUtils.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#if PLATFORM_WINDOWS
|
||||||
|
#include "Windows/WindowsScreenUtils.h"
|
||||||
|
#elif PLATFORM_LINUX
|
||||||
|
#include "Linux/LinuxScreenUtils.h"
|
||||||
|
#elif PLATFORM_MAC
|
||||||
|
#include "Mac/MacScreenUtils.h"
|
||||||
|
#else
|
||||||
|
#error No Screen Utils For This Platform! Please ensure you are not targetting an Editor build.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Types.h"
|
||||||
|
#include "Engine/Scripting/ScriptingType.h"
|
||||||
|
|
||||||
|
API_CLASS(Static) class FLAXENGINE_API ScreenUtils
|
||||||
|
{
|
||||||
|
DECLARE_SCRIPTING_TYPE_NO_SPAWN(ScreenUtils);
|
||||||
|
};
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include "WindowsScreenUtils.h"
|
||||||
|
#include "Engine/Core/Math/Color32.h"
|
||||||
|
#include "Engine/Core/Math/Vector2.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
Color32 PlatformScreenUtils::GetPixelAt(int32 x, int32 y) {
|
||||||
|
HDC deviceContext = GetDC(NULL);
|
||||||
|
COLORREF color = GetPixel(deviceContext, x, y);
|
||||||
|
ReleaseDC(NULL, deviceContext);
|
||||||
|
|
||||||
|
Color32 returnColor = { GetRValue(color), GetGValue(color), GetBValue(color), 255 };
|
||||||
|
return returnColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
Int2 PlatformScreenUtils::GetScreenCursorPosition() {
|
||||||
|
POINT cursorPos;
|
||||||
|
GetCursorPos(&cursorPos);
|
||||||
|
|
||||||
|
Int2 returnCursorPos = { cursorPos.x, cursorPos.y };
|
||||||
|
return returnCursorPos;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
class WindowsScreenUtils
|
#include "Engine/Core/Math/Color32.h"
|
||||||
{
|
|
||||||
|
class PlatformScreenUtils {
|
||||||
|
public:
|
||||||
|
static Color32 GetPixelAt(int32 x, int32 y);
|
||||||
|
static Int2 GetScreenCursorPosition();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -130,70 +130,6 @@ void CaptureScreenshot::OnFail()
|
|||||||
ThreadPoolTask::OnFail();
|
ThreadPoolTask::OnFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
Delegate<Color32> Screenshot::PixelReadDelegate;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Capture screenshot helper
|
|
||||||
/// </summary>
|
|
||||||
/// <seealso cref="ThreadPoolTask" />
|
|
||||||
class GetPixelData : public ThreadPoolTask
|
|
||||||
{
|
|
||||||
friend Screenshot;
|
|
||||||
private:
|
|
||||||
TextureData _data;
|
|
||||||
Color32 _color;
|
|
||||||
|
|
||||||
public:
|
|
||||||
int32 x;
|
|
||||||
int32 y;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the texture data container.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Texture data</returns>
|
|
||||||
FORCE_INLINE TextureData& GetData()
|
|
||||||
{
|
|
||||||
return _data;
|
|
||||||
}
|
|
||||||
|
|
||||||
FORCE_INLINE Color32 GetColor()
|
|
||||||
{
|
|
||||||
return _color;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// [ThreadPoolTask]
|
|
||||||
bool Run() override;
|
|
||||||
void OnFail() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool GetPixelData::Run()
|
|
||||||
{
|
|
||||||
LOG(Warning, "REAL");
|
|
||||||
TextureMipData *mipData = _data.GetData(0, 0);
|
|
||||||
Array<Color32> pixels;
|
|
||||||
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: 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetPixelData::OnFail()
|
|
||||||
{
|
|
||||||
LOG(Warning, "Cannot get pixel data.");
|
|
||||||
|
|
||||||
// Base
|
|
||||||
ThreadPoolTask::OnFail();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Screenshot::Capture(GPUTexture* target, const StringView& path)
|
void Screenshot::Capture(GPUTexture* target, const StringView& path)
|
||||||
{
|
{
|
||||||
// Validate
|
// Validate
|
||||||
@@ -307,18 +243,3 @@ void Screenshot::Capture(const StringView& path)
|
|||||||
|
|
||||||
Capture(mainTask, path);
|
Capture(mainTask, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color32 Screenshot::GetPixelAt(int32 x, int32 y) {
|
|
||||||
GPUSwapChain* swapChain = Engine::MainWindow->GetSwapChain();
|
|
||||||
|
|
||||||
auto getPixelTask = New<GetPixelData>();
|
|
||||||
getPixelTask->x = x;
|
|
||||||
getPixelTask->y = y;
|
|
||||||
|
|
||||||
Task* downloadTask = swapChain->DownloadDataAsync(getPixelTask->GetData());
|
|
||||||
downloadTask->ContinueWith(getPixelTask);
|
|
||||||
LOG(Warning, "Started download task. real");
|
|
||||||
downloadTask->Start();
|
|
||||||
|
|
||||||
return getPixelTask->GetColor();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -39,14 +39,4 @@ API_CLASS(Static) class FLAXENGINE_API Screenshot
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The custom file location. Use null or empty to use default one.</param>
|
/// <param name="path">The custom file location. Use null or empty to use default one.</param>
|
||||||
API_FUNCTION() static void Capture(const StringView& path = StringView::Empty);
|
API_FUNCTION() static void Capture(const StringView& path = StringView::Empty);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the pixel at specified coordinates.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">The x coordinate to read.</param>
|
|
||||||
/// <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;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user