2020-04-10 12:05:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
2022-02-26 20:50:04 +03:00
|
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-04-10 12:05:37 +03:00
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-10 12:05:37 +03:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
|
|
|
|
#include <LibGUI/TextEditor.h>
|
|
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
2020-04-29 15:38:19 +03:00
|
|
|
|
class ColorInput final : public TextEditor {
|
|
|
|
|
C_OBJECT(ColorInput);
|
2020-04-10 12:05:37 +03:00
|
|
|
|
|
|
|
|
|
public:
|
2022-02-26 20:50:04 +03:00
|
|
|
|
virtual ~ColorInput() override = default;
|
2020-04-10 12:05:37 +03:00
|
|
|
|
|
2020-04-29 16:32:18 +03:00
|
|
|
|
bool has_alpha_channel() const { return m_color_has_alpha_channel; }
|
2020-04-29 17:22:09 +03:00
|
|
|
|
void set_color_has_alpha_channel(bool has_alpha) { m_color_has_alpha_channel = has_alpha; }
|
2020-04-29 16:32:18 +03:00
|
|
|
|
|
2022-04-29 12:46:56 +03:00
|
|
|
|
void set_color(Color, AllowCallback = AllowCallback::Yes);
|
2020-04-10 12:05:37 +03:00
|
|
|
|
Color color() { return m_color; }
|
|
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
|
void set_color_picker_title(ByteString title) { m_color_picker_title = move(title); }
|
|
|
|
|
ByteString color_picker_title() { return m_color_picker_title; }
|
2020-04-10 12:05:37 +03:00
|
|
|
|
|
|
|
|
|
Function<void()> on_change;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void mousedown_event(MouseEvent&) override;
|
2020-04-29 20:02:00 +03:00
|
|
|
|
virtual void mouseup_event(MouseEvent&) override;
|
2020-04-29 16:24:34 +03:00
|
|
|
|
virtual void mousemove_event(MouseEvent&) override;
|
2020-04-10 12:05:37 +03:00
|
|
|
|
virtual void paint_event(PaintEvent&) override;
|
|
|
|
|
|
|
|
|
|
private:
|
2020-04-29 16:32:18 +03:00
|
|
|
|
ColorInput();
|
|
|
|
|
|
2020-06-10 11:57:59 +03:00
|
|
|
|
Gfx::IntRect color_rect() const;
|
2022-04-29 12:46:56 +03:00
|
|
|
|
void set_color_internal(Color, AllowCallback, bool change_text);
|
2020-04-10 12:05:37 +03:00
|
|
|
|
|
|
|
|
|
Color m_color;
|
2023-12-16 17:19:34 +03:00
|
|
|
|
ByteString m_color_picker_title { "Color Picker" };
|
2020-04-29 16:32:18 +03:00
|
|
|
|
bool m_color_has_alpha_channel { true };
|
2020-04-29 20:02:00 +03:00
|
|
|
|
bool m_may_be_color_rect_click { false };
|
2020-04-10 12:05:37 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|