Cleanup and improve code from #1109
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEditor.Windows;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
using System;
|
||||
|
||||
namespace FlaxEditor.GUI.Dialogs
|
||||
{
|
||||
@@ -52,7 +50,7 @@ namespace FlaxEditor.GUI.Dialogs
|
||||
private TextBox _cHex;
|
||||
private Button _cCancel;
|
||||
private Button _cOK;
|
||||
private IconButton _cEyedropper;
|
||||
private Button _cEyedropper;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the selected color.
|
||||
@@ -109,7 +107,6 @@ namespace FlaxEditor.GUI.Dialogs
|
||||
{
|
||||
_initialValue = initialValue;
|
||||
_useDynamicEditing = useDynamicEditing;
|
||||
_activeEyedropper = false;
|
||||
_value = Color.Transparent;
|
||||
_onChanged = colorChanged;
|
||||
_onClosed = pickerClosed;
|
||||
@@ -199,46 +196,41 @@ namespace FlaxEditor.GUI.Dialogs
|
||||
_cOK.Clicked += OnSubmit;
|
||||
|
||||
// Eyedropper button
|
||||
_cEyedropper = new IconButton(_cOK.X - EyedropperMargin, _cHex.Bottom + PickerMargin, Editor.Instance.Icons.Add64, hideBorder: false)
|
||||
var style = Style.Current;
|
||||
_cEyedropper = new Button(_cOK.X - EyedropperMargin, _cHex.Bottom + PickerMargin)
|
||||
{
|
||||
TooltipText = "Eyedropper tool to pick a color directly from the screen",
|
||||
BackgroundBrush = new SpriteBrush(Editor.Instance.Icons.Search32),
|
||||
BackgroundColor = style.Foreground,
|
||||
BackgroundColorHighlighted = style.Foreground.RGBMultiplied(0.9f),
|
||||
BorderColor = Color.Transparent,
|
||||
BorderColorHighlighted = style.BorderSelected,
|
||||
Parent = this,
|
||||
};
|
||||
_cEyedropper.Clicked += OnEyedropStart;
|
||||
_cEyedropper.Height = (_cValue.Bottom - _cEyedropper.Y) * 0.5f;
|
||||
_cEyedropper.Width = _cEyedropper.Height;
|
||||
_cEyedropper.X -= _cEyedropper.Width;
|
||||
//_cEyedropper.SetColors(_cEyedropper.BackgroundColor);
|
||||
|
||||
// Set initial color
|
||||
SelectedColor = initialValue;
|
||||
}
|
||||
|
||||
private Color32 GetEyedropColor()
|
||||
private void OnColorPicked(Color32 colorPicked)
|
||||
{
|
||||
Int2 mousePosition = ScreenUtilities.GetScreenCursorPosition();
|
||||
Color32 pixelColor = ScreenUtilities.GetPixelAt(mousePosition.X, mousePosition.Y);
|
||||
|
||||
return pixelColor;
|
||||
}
|
||||
|
||||
private void ColorPicked(Color32 colorPicked)
|
||||
{
|
||||
_activeEyedropper = false;
|
||||
SelectedColor = colorPicked;
|
||||
ScreenUtilities.PickColorDone -= ColorPicked;
|
||||
if (_activeEyedropper)
|
||||
{
|
||||
_activeEyedropper = false;
|
||||
SelectedColor = colorPicked;
|
||||
ScreenUtilities.PickColorDone -= OnColorPicked;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEyedropStart()
|
||||
{
|
||||
_activeEyedropper = true;
|
||||
ScreenUtilities.PickColor();
|
||||
ScreenUtilities.PickColorDone += ColorPicked;
|
||||
}
|
||||
|
||||
private void UpdateEyedrop()
|
||||
{
|
||||
Color32 pixelColor = GetEyedropColor();
|
||||
SelectedColor = pixelColor;
|
||||
ScreenUtilities.PickColorDone += OnColorPicked;
|
||||
}
|
||||
|
||||
private void OnRGBAChanged()
|
||||
@@ -266,15 +258,16 @@ namespace FlaxEditor.GUI.Dialogs
|
||||
SelectedColor = color;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
// Update eye dropper tool
|
||||
if (_activeEyedropper)
|
||||
{
|
||||
UpdateEyedrop();
|
||||
Float2 mousePosition = Platform.MousePosition;
|
||||
SelectedColor = ScreenUtilities.GetColorAt(mousePosition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,6 +324,20 @@ namespace FlaxEditor.GUI.Dialogs
|
||||
base.OnShow();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool OnKeyDown(KeyboardKeys key)
|
||||
{
|
||||
if (_activeEyedropper && key == KeyboardKeys.Escape)
|
||||
{
|
||||
// Cancel eye dropping
|
||||
_activeEyedropper = false;
|
||||
ScreenUtilities.PickColorDone -= OnColorPicked;
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(key);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnSubmit()
|
||||
{
|
||||
|
||||
@@ -57,6 +57,11 @@ namespace FlaxEditor.GUI.Input
|
||||
/// </summary>
|
||||
protected Color _value;
|
||||
|
||||
/// <summary>
|
||||
/// Enables live preview of the selected value from the picker. Otherwise will update the value only when user confirms it on dialog closing.
|
||||
/// </summary>
|
||||
public bool UseDynamicEditing = true;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when value gets changed.
|
||||
/// </summary>
|
||||
@@ -143,7 +148,7 @@ namespace FlaxEditor.GUI.Input
|
||||
base.OnSubmit();
|
||||
|
||||
// Show color picker dialog
|
||||
_currentDialog = ShowPickColorDialog?.Invoke(this, _value, OnColorChanged, OnPickerClosed);
|
||||
_currentDialog = ShowPickColorDialog?.Invoke(this, _value, OnColorChanged, OnPickerClosed, UseDynamicEditing);
|
||||
}
|
||||
|
||||
private void OnColorChanged(Color color, bool sliding)
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace FlaxEditor.Surface.Elements
|
||||
{
|
||||
ParentNode = parentNode;
|
||||
Archetype = archetype;
|
||||
|
||||
UseDynamicEditing = false;
|
||||
ParentNode.ValuesChanged += OnNodeValuesChanged;
|
||||
}
|
||||
|
||||
|
||||
130
Source/Editor/Utilities/ScreenUtilities.cpp
Normal file
130
Source/Editor/Utilities/ScreenUtilities.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "ScreenUtilities.h"
|
||||
#include "Engine/Core/Math/Vector2.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
|
||||
Delegate<Color32> ScreenUtilities::PickColorDone;
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
|
||||
static HHOOK MouseCallbackHook;
|
||||
|
||||
LRESULT CALLBACK OnScreenUtilsMouseCallback(_In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM lParam)
|
||||
{
|
||||
if (nCode >= 0 && wParam == WM_LBUTTONDOWN)
|
||||
{
|
||||
UnhookWindowsHookEx(MouseCallbackHook);
|
||||
|
||||
// Push event with the picked color
|
||||
const Float2 cursorPos = Platform::GetMousePosition();
|
||||
const Color32 colorPicked = ScreenUtilities::GetColorAt(cursorPos);
|
||||
ScreenUtilities::PickColorDone(colorPicked);
|
||||
return 1;
|
||||
}
|
||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
Color32 ScreenUtilities::GetColorAt(const Float2& pos)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
HDC deviceContext = GetDC(NULL);
|
||||
COLORREF color = GetPixel(deviceContext, (int)pos.X, (int)pos.Y);
|
||||
ReleaseDC(NULL, deviceContext);
|
||||
return Color32(GetRValue(color), GetGValue(color), GetBValue(color), 255);
|
||||
}
|
||||
|
||||
void ScreenUtilities::PickColor()
|
||||
{
|
||||
MouseCallbackHook = SetWindowsHookEx(WH_MOUSE_LL, OnScreenUtilsMouseCallback, NULL, NULL);
|
||||
if (MouseCallbackHook == NULL)
|
||||
{
|
||||
LOG(Warning, "Failed to set mouse hook.");
|
||||
LOG(Warning, "Error: {0}", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
#elif PLATFORM_LINUX
|
||||
|
||||
#include "Engine/Platform/Linux/LinuxPlatform.h"
|
||||
#include "Engine/Platform/Linux/IncludeX11.h"
|
||||
|
||||
Color32 ScreenUtilities::GetColorAt(const Float2& pos)
|
||||
{
|
||||
X11::XColor color;
|
||||
|
||||
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
|
||||
int defaultScreen = X11::XDefaultScreen(display);
|
||||
|
||||
X11::XImage* image;
|
||||
image = X11::XGetImage(display, X11::XRootWindow(display, defaultScreen), x, y, 1, 1, AllPlanes, XYPixmap);
|
||||
color.pixel = XGetPixel(image, 0, 0);
|
||||
X11::XFree(image);
|
||||
|
||||
X11::XQueryColor(display, X11::XDefaultColormap(display, defaultScreen), &color);
|
||||
|
||||
Color32 outputColor;
|
||||
outputColor.R = color.red / 256;
|
||||
outputColor.G = color.green / 256;
|
||||
outputColor.B = color.blue / 256;
|
||||
return outputColor;
|
||||
}
|
||||
|
||||
void OnScreenUtilsXEventCallback(void* eventPtr)
|
||||
{
|
||||
X11::XEvent* event = (X11::XEvent*) eventPtr;
|
||||
X11::Display* display = (X11::Display*)LinuxPlatform::GetXDisplay();
|
||||
if (event->type == ButtonPress)
|
||||
{
|
||||
const Float2 cursorPos = Platform::GetMousePosition();
|
||||
const Color32 colorPicked = ScreenUtilities::GetColorAt(cursorPos);
|
||||
X11::XUngrabPointer(display, CurrentTime);
|
||||
ScreenUtilities::PickColorDone(colorPicked);
|
||||
LinuxPlatform::xEventRecieved.Unbind(OnScreenUtilsXEventCallback);
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenUtilities::PickColor()
|
||||
{
|
||||
PROFILE_CPU();
|
||||
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
|
||||
X11::Window rootWindow = X11::XRootWindow(display, X11::XDefaultScreen(display));
|
||||
|
||||
X11::Cursor cursor = XCreateFontCursor(display, 130);
|
||||
int grabbedPointer = X11::XGrabPointer(display, rootWindow, 0, ButtonPressMask, GrabModeAsync, GrabModeAsync, rootWindow, cursor, CurrentTime);
|
||||
if (grabbedPointer != GrabSuccess)
|
||||
{
|
||||
LOG(Error, "Failed to grab cursor for events.");
|
||||
X11::XFreeCursor(display, cursor);
|
||||
return;
|
||||
}
|
||||
|
||||
X11::XFreeCursor(display, cursor);
|
||||
LinuxPlatform::xEventRecieved.Bind(OnScreenUtilsXEventCallback);
|
||||
}
|
||||
|
||||
#elif PLATFORM_MAC
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
Color32 ScreenUtilities::GetColorAt(const Float2& pos)
|
||||
{
|
||||
// TODO: implement ScreenUtilities for macOS
|
||||
return { 0, 0, 0, 255 };
|
||||
}
|
||||
|
||||
void ScreenUtilities::PickColor()
|
||||
{
|
||||
// This is what C# calls to start the color picking sequence
|
||||
// This should stop mouse clicks from working for one click, and that click is on the selected color
|
||||
// There is a class called NSColorSample that might implement that for you, but maybe not.
|
||||
}
|
||||
|
||||
#endif
|
||||
33
Source/Editor/Utilities/ScreenUtilities.h
Normal file
33
Source/Editor/Utilities/ScreenUtilities.h
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Core/Types/BaseTypes.h"
|
||||
#include "Engine/Core/Math/Color32.h"
|
||||
#include "Engine/Core/Math/Vector2.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
|
||||
/// <summary>
|
||||
/// Platform-dependent screen utilities.
|
||||
/// </summary>
|
||||
API_CLASS(Static) class FLAXENGINE_API ScreenUtilities
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(ScreenUtilities);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the pixel color at the specified coordinates.
|
||||
/// </summary>
|
||||
/// <param name="pos">Screen-space coordinate to read.</param>
|
||||
/// <returns>Pixel color at the specified coordinates.</returns>
|
||||
API_FUNCTION() static Color32 GetColorAt(const Float2& pos);
|
||||
|
||||
/// <summary>
|
||||
/// Starts async color picking. Color will be returned through PickColorDone event when the actions ends (user selected the final color with a mouse). When action is active, GetColorAt can be used to read the current value.
|
||||
/// </summary>
|
||||
API_FUNCTION() static void PickColor();
|
||||
|
||||
/// <summary>
|
||||
/// Called when PickColor action is finished.
|
||||
/// </summary>
|
||||
API_EVENT() static Delegate<Color32> PickColorDone;
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Core/Types/BaseTypes.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
|
||||
API_INJECT_CODE(cpp, "#include \"Editor/Utilities/ScreenUtilities/ScreenUtilities.h\"");
|
||||
|
||||
/// <summary>
|
||||
/// Platform-dependent screen utilties.
|
||||
/// </summary>
|
||||
API_CLASS(Static, Name = "ScreenUtilities", Tag = "NativeInvokeUseName")
|
||||
class FLAXENGINE_API ScreenUtilities
|
||||
{
|
||||
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();
|
||||
|
||||
/// <summary>
|
||||
/// Starts async color picking. Will return a color through ColorReturnCallback.
|
||||
/// </summary
|
||||
API_FUNCTION() static void PickColor();
|
||||
|
||||
/// <summary>
|
||||
/// Called when PickColor() is finished.
|
||||
/// </summary>
|
||||
API_EVENT() static Delegate<Color32> PickColorDone;
|
||||
};
|
||||
@@ -1,104 +0,0 @@
|
||||
#if PLATFORM_LINUX
|
||||
|
||||
#include "ScreenUtilities.h"
|
||||
#include "Engine/Core/Math/Color32.h"
|
||||
#include "Engine/Core/Math/Vector2.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Platform/Linux/LinuxPlatform.h"
|
||||
|
||||
#include "Engine/Platform/Linux/IncludeX11.h"
|
||||
|
||||
Color32 ScreenUtilities::GetPixelAt(int32 x, int32 y)
|
||||
{
|
||||
X11::XColor color;
|
||||
Color32 outputColor;
|
||||
|
||||
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
|
||||
int defaultScreen = X11::XDefaultScreen(display);
|
||||
|
||||
X11::XImage* image;
|
||||
image = X11::XGetImage(display, X11::XRootWindow(display, defaultScreen), x, y, 1, 1, AllPlanes, XYPixmap);
|
||||
color.pixel = XGetPixel(image, 0, 0);
|
||||
X11::XFree(image);
|
||||
|
||||
X11::XQueryColor(display, X11::XDefaultColormap(display, defaultScreen), &color);
|
||||
outputColor.R = color.red / 256;
|
||||
outputColor.G = color.green / 256;
|
||||
outputColor.B = color.blue / 256;
|
||||
|
||||
return outputColor;
|
||||
}
|
||||
|
||||
Int2 ScreenUtilities::GetScreenCursorPosition()
|
||||
{
|
||||
Int2 cursorPosition = { 0, 0 };
|
||||
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
|
||||
X11::Window rootWindow = X11::XRootWindow(display, X11::XDefaultScreen(display));
|
||||
|
||||
// Buffers (Some useful, some not.)
|
||||
X11::Window rootWindowBuffer;
|
||||
int rootX, rootY;
|
||||
int winXBuffer, winYBuffer;
|
||||
unsigned int maskBuffer;
|
||||
|
||||
int gotPointer = X11::XQueryPointer(display, rootWindow, &rootWindowBuffer, &rootWindowBuffer, &rootX, &rootY, &winXBuffer, &winYBuffer, &maskBuffer);
|
||||
if (!gotPointer) {
|
||||
LOG(Error, "Failed to find the mouse pointer (Are you using multiple displays?)");
|
||||
return cursorPosition;
|
||||
}
|
||||
|
||||
cursorPosition.X = rootX;
|
||||
cursorPosition.Y = rootY;
|
||||
|
||||
return cursorPosition;
|
||||
}
|
||||
|
||||
class ScreenUtilitiesLinux
|
||||
{
|
||||
public:
|
||||
static void BlockAndReadMouse();
|
||||
static void xEventHandler(void* event);
|
||||
};
|
||||
|
||||
void ScreenUtilitiesLinux::xEventHandler(void* eventPtr) {
|
||||
X11::XEvent* event = (X11::XEvent*) eventPtr;
|
||||
|
||||
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
|
||||
|
||||
if (event->type == ButtonPress) {
|
||||
Int2 cursorPosition = ScreenUtilities::GetScreenCursorPosition();
|
||||
Color32 colorPicked = ScreenUtilities::GetPixelAt(cursorPosition.X, cursorPosition.Y);
|
||||
|
||||
ScreenUtilities::PickColorDone(colorPicked); // Run the callback for picking colors being complete.
|
||||
LinuxPlatform::xEventRecieved.Unbind(xEventHandler); // Unbind the event, we only want to handle one click event
|
||||
X11::XUngrabPointer(display, CurrentTime);
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenUtilitiesLinux::BlockAndReadMouse()
|
||||
{
|
||||
X11::Display* display = (X11::Display*) LinuxPlatform::GetXDisplay();
|
||||
X11::Window rootWindow = X11::XRootWindow(display, X11::XDefaultScreen(display));
|
||||
|
||||
X11::Cursor cursor = XCreateFontCursor(display, 130);
|
||||
int grabbedPointer = X11::XGrabPointer(display, rootWindow, 0, ButtonPressMask, GrabModeAsync, GrabModeAsync, rootWindow, cursor, CurrentTime);
|
||||
if (grabbedPointer != GrabSuccess) {
|
||||
LOG(Error, "Failed to grab cursor for events.");
|
||||
|
||||
X11::XFreeCursor(display, cursor);
|
||||
return;
|
||||
}
|
||||
|
||||
X11::XFreeCursor(display, cursor);
|
||||
LinuxPlatform::xEventRecieved.Bind(xEventHandler);
|
||||
}
|
||||
|
||||
Delegate<Color32> ScreenUtilities::PickColorDone;
|
||||
|
||||
void ScreenUtilities::PickColor()
|
||||
{
|
||||
ScreenUtilitiesLinux::BlockAndReadMouse();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,46 +0,0 @@
|
||||
#if PLATFORM_MAC
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
#include "ScreenUtilities.h"
|
||||
#include "Engine/Core/Math/Color32.h"
|
||||
#include "Engine/Core/Math/Vector2.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
|
||||
Color32 ScreenUtilities::GetPixelAt(int32 x, int32 y)
|
||||
{
|
||||
// Called from C# for live updates to the color.
|
||||
|
||||
return { 0, 0, 0, 255 };
|
||||
}
|
||||
|
||||
Int2 ScreenUtilities::GetScreenCursorPosition()
|
||||
{
|
||||
// Called from C# for live updates to the color.
|
||||
|
||||
return { 0, 0 };
|
||||
}
|
||||
|
||||
class ScreenUtilitiesMac
|
||||
{
|
||||
public:
|
||||
static void BlockAndReadMouse();
|
||||
};
|
||||
|
||||
void ScreenUtilitiesMac::BlockAndReadMouse()
|
||||
{
|
||||
// Maybe you don't need this if you go with NSColorSampler
|
||||
}
|
||||
|
||||
Delegate<Color32> ScreenUtilities::PickColorDone;
|
||||
|
||||
void ScreenUtilities::PickColor()
|
||||
{
|
||||
// This is what C# calls to start the color picking sequence
|
||||
// This should stop mouse clicks from working for one click, and that click is on the selected color
|
||||
// There is a class called NSColorSample that might implement that for you, but maybe not.
|
||||
// It also might just work to copy the Linux Impl since Mac uses X as well, right?
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,94 +0,0 @@
|
||||
#if PLATFORM_WINDOWS
|
||||
|
||||
#include "ScreenUtilities.h"
|
||||
#include "Engine/Core/Math/Color32.h"
|
||||
#include "Engine/Core/Math/Vector2.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MCore.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
#pragma comment(lib, "Gdi32.lib")
|
||||
|
||||
|
||||
Color32 ScreenUtilities::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 ScreenUtilities::GetScreenCursorPosition()
|
||||
{
|
||||
POINT cursorPos;
|
||||
GetCursorPos(&cursorPos);
|
||||
|
||||
Int2 returnCursorPos = { cursorPos.x, cursorPos.y };
|
||||
return returnCursorPos;
|
||||
}
|
||||
|
||||
class ScreenUtilitiesWindows
|
||||
{
|
||||
public:
|
||||
static void PickSelected();
|
||||
static void BlockAndReadMouse();
|
||||
};
|
||||
|
||||
void ScreenUtilitiesWindows::PickSelected() {
|
||||
Int2 cursorPos = ScreenUtilities::GetScreenCursorPosition();
|
||||
Color32 colorPicked = ScreenUtilities::GetPixelAt(cursorPos.X, cursorPos.Y);
|
||||
|
||||
// Push event with the picked color.
|
||||
ScreenUtilities::PickColorDone(colorPicked);
|
||||
}
|
||||
|
||||
static HHOOK _mouseCallbackHook;
|
||||
LRESULT CALLBACK ScreenUtilsMouseCallback(
|
||||
_In_ int nCode,
|
||||
_In_ WPARAM wParam,
|
||||
_In_ LPARAM lParam
|
||||
)
|
||||
{
|
||||
if (wParam != WM_LBUTTONDOWN) { // Return as early as possible.
|
||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
if (nCode < 0) {
|
||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
|
||||
if (nCode >= 0 && wParam == WM_LBUTTONDOWN) { // Now try to run our code.
|
||||
UnhookWindowsHookEx(_mouseCallbackHook);
|
||||
|
||||
ScreenUtilitiesWindows::PickSelected();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
void ScreenUtilitiesWindows::BlockAndReadMouse()
|
||||
{
|
||||
_mouseCallbackHook = SetWindowsHookEx(WH_MOUSE_LL, ScreenUtilsMouseCallback, NULL, NULL);
|
||||
if (_mouseCallbackHook == NULL)
|
||||
{
|
||||
LOG(Warning, "Failed to set mouse hook.");
|
||||
LOG(Warning, "Error: {0}", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
Delegate<Color32> ScreenUtilities::PickColorDone;
|
||||
|
||||
void ScreenUtilities::PickColor()
|
||||
{
|
||||
ScreenUtilitiesWindows::BlockAndReadMouse();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1037,9 +1037,7 @@ namespace FlaxEditor.Utilities
|
||||
/// <returns>The processed name path.</returns>
|
||||
public static string GetAssetNamePath(string path)
|
||||
{
|
||||
var projectFolder = Globals.ProjectFolder;
|
||||
if (path.StartsWith(projectFolder))
|
||||
path = path.Substring(projectFolder.Length + 1);
|
||||
path = GetAssetNamePathWithExt(path);
|
||||
return StringUtils.GetPathWithoutExtension(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "LinuxPlatform.h"
|
||||
#include "LinuxWindow.h"
|
||||
#include "LinuxInput.h"
|
||||
#include "IncludeX11.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Types/Guid.h"
|
||||
#include "Engine/Core/Types/String.h"
|
||||
@@ -31,6 +30,7 @@
|
||||
#include "Engine/Input/Input.h"
|
||||
#include "Engine/Input/Mouse.h"
|
||||
#include "Engine/Input/Keyboard.h"
|
||||
#include "IncludeX11.h"
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/time.h>
|
||||
@@ -88,6 +88,7 @@ X11::Cursor Cursors[(int32)CursorType::MAX];
|
||||
X11::XcursorImage* CursorsImg[(int32)CursorType::MAX];
|
||||
Dictionary<StringAnsi, X11::KeyCode> KeyNameMap;
|
||||
Array<KeyboardKeys> KeyCodeMap;
|
||||
Delegate<void*> LinuxPlatform::xEventRecieved;
|
||||
|
||||
// Message boxes configuration
|
||||
#define LINUX_DIALOG_MIN_BUTTON_WIDTH 64
|
||||
@@ -2217,8 +2218,6 @@ void LinuxPlatform::BeforeRun()
|
||||
{
|
||||
}
|
||||
|
||||
Delegate<void*> LinuxPlatform::xEventRecieved;
|
||||
|
||||
void LinuxPlatform::Tick()
|
||||
{
|
||||
UnixPlatform::Tick();
|
||||
@@ -2233,12 +2232,12 @@ void LinuxPlatform::Tick()
|
||||
{
|
||||
X11::XEvent event;
|
||||
X11::XNextEvent(xDisplay, &event);
|
||||
|
||||
if (X11::XFilterEvent(&event, 0))
|
||||
continue;
|
||||
|
||||
xEventRecieved(&event); // Fire this event, since we recieved an event.
|
||||
|
||||
|
||||
// External event handling
|
||||
xEventRecieved(&event);
|
||||
|
||||
LinuxWindow* window;
|
||||
switch (event.type)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
static const String& GetHomeDirectory();
|
||||
|
||||
/// <summary>
|
||||
/// An event that is fired when an XEvent is recieved by Flax.
|
||||
/// An event that is fired when an XEvent is received during platform tick.
|
||||
/// </summary>
|
||||
static Delegate<void*> xEventRecieved;
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
|
||||
namespace FlaxEngine.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Button with an icon.
|
||||
/// </summary>
|
||||
public class IconButton : Button
|
||||
{
|
||||
/// <summary>
|
||||
/// The sprite rendered on the button.
|
||||
/// </summary>
|
||||
public SpriteHandle ButtonSprite { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to hide the border of the button.
|
||||
/// </summary>
|
||||
public bool HideBorder = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IconButton"/> class.
|
||||
/// </summary>
|
||||
/// <param name="buttonSprite">The sprite used by the button.</param>
|
||||
public IconButton(SpriteHandle buttonSprite)
|
||||
: this(0, 0, buttonSprite)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IconButton"/> class.
|
||||
/// </summary>
|
||||
/// <param name="x">Position X coordinate</param>
|
||||
/// <param name="y">Position Y coordinate</param>
|
||||
/// <param name="buttonSprite">The sprite used by the button.</param>
|
||||
/// <param name="width">Width</param>
|
||||
/// <param name="height">Height</param>
|
||||
/// <param name="hideBorder">Whether or not to hide the border.</param>
|
||||
public IconButton(float x, float y, SpriteHandle buttonSprite, float width = 120, float height = DefaultHeight, bool hideBorder = true)
|
||||
: base(x, y, width, height)
|
||||
{
|
||||
ButtonSprite = buttonSprite;
|
||||
BackgroundBrush = new SpriteBrush(ButtonSprite);
|
||||
HideBorder = hideBorder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IconButton"/> class.
|
||||
/// </summary>
|
||||
/// <param name="location">Position</param>
|
||||
/// <param name="size">Size</param>
|
||||
/// <param name="buttonSprite">The sprite used by the button.</param>
|
||||
public IconButton(Float2 location, Float2 size, SpriteHandle buttonSprite)
|
||||
: this(location.X, location.Y, buttonSprite, size.X, size.Y)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the colors of the button, taking into account the <see cref="HideBorder"/> field.>
|
||||
/// </summary>
|
||||
/// <param name="color">The color to use.</param>
|
||||
public override void SetColors(Color color)
|
||||
{
|
||||
BackgroundColor = color;
|
||||
BackgroundColorSelected = color.RGBMultiplied(0.8f);
|
||||
BackgroundColorHighlighted = color.RGBMultiplied(1.2f);
|
||||
|
||||
BorderColor = HideBorder ? Color.Transparent : color.RGBMultiplied(0.5f);
|
||||
BorderColorSelected = BorderColor;
|
||||
BorderColorHighlighted = BorderColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "Screenshot.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Math/Math.h"
|
||||
#include "Engine/Core/Math/Color32.h"
|
||||
#include "Engine/Graphics/RenderTask.h"
|
||||
#include "Engine/Platform/FileSystem.h"
|
||||
#include "Engine/Graphics/Textures/TextureData.h"
|
||||
@@ -11,7 +10,6 @@
|
||||
#include "Engine/Graphics/GPUResourceProperty.h"
|
||||
#include "Engine/Graphics/GPUDevice.h"
|
||||
#include "Engine/Graphics/GPUSwapChain.h"
|
||||
#include "Engine/Engine/Engine.h"
|
||||
#include "Engine/Threading/ThreadPoolTask.h"
|
||||
#include "Engine/Engine/Globals.h"
|
||||
#if COMPILE_WITH_TEXTURE_TOOL
|
||||
|
||||
Reference in New Issue
Block a user