1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

ColorPicker: Add ability to select a color on the screen

This commit adds a `ColorSelectOverlay` class, and uses it to
allow the user to pick a color from the screen. The API for
`ColorSelectOverlay` is inspired from the `SelectableOverlay`
in `Utilities/shot.cpp`. In particular, it opens up it's own
window, so that we can have control over the cursor over the
whole screen.

There's one thing notably different: In addition to returning the
final selected color from the `exec()` function, it also provides
an `on_color_changed()` hook, which can be used to (optionally)
get live updated as the mouse is moving around.

This is a bit odd, but allows us to use the preview widget of the
color picker to see the current color under the mouse (which will
be selected upon clicking). When trying to select the color from
text / other small elements, this is very useful.
This commit is contained in:
Mustafa Quraish 2021-09-04 00:37:39 -04:00 committed by Andreas Kling
parent 69d708fb21
commit 253eb5c6d7
2 changed files with 76 additions and 1 deletions

View file

@ -14,6 +14,7 @@ namespace GUI {
class ColorButton;
class ColorPreview;
class CustomColorWidget;
class ColorSelectOverlay;
class ColorPicker final : public Dialog {
C_OBJECT(ColorPicker)
@ -40,6 +41,7 @@ private:
Vector<ColorButton&> m_color_widgets;
RefPtr<CustomColorWidget> m_custom_color;
RefPtr<ColorPreview> m_preview_widget;
RefPtr<Button> m_selector_button;
RefPtr<TextBox> m_html_text;
RefPtr<SpinBox> m_red_spinbox;
RefPtr<SpinBox> m_green_spinbox;