Skip to content

Commit

Permalink
LibGUI: Allow disabling the alpha channel in ColorInput widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Apr 29, 2020
1 parent 17e76b4 commit c710738
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Libraries/LibGUI/ColorInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ void ColorInput::set_color(Color color)
set_text(color.to_string());
};

void ColorInput::set_color_has_alpha_channel(bool has_alpha)
{
if (m_color_has_alpha_channel == has_alpha)
return;

m_color_has_alpha_channel = has_alpha;
m_color.set_alpha(0xff);
if (!has_alpha)
set_text(m_color.to_string_without_alpha());
else
set_text(m_color.to_string());
}

void ColorInput::mousedown_event(MouseEvent& event)
{
if (event.button() == MouseButton::Left) {
Expand Down
7 changes: 6 additions & 1 deletion Libraries/LibGUI/ColorInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class ColorInput final : public TextEditor {
C_OBJECT(ColorInput);

public:
ColorInput();
virtual ~ColorInput() override;

bool has_alpha_channel() const { return m_color_has_alpha_channel; }
void set_color_has_alpha_channel(bool);

void set_color(Color);
Color color() { return m_color; }

Expand All @@ -52,11 +54,14 @@ class ColorInput final : public TextEditor {
virtual void paint_event(PaintEvent&) override;

private:
ColorInput();

Gfx::Rect color_rect() const;
void set_color_without_changing_text(Color);

Color m_color;
String m_color_picker_title { "Select color" };
bool m_color_has_alpha_channel { true };
};

}

0 comments on commit c710738

Please sign in to comment.