diff --git a/Applications/PaintBrush/Makefile b/Applications/PaintBrush/Makefile index 0163456c647..4c4b5e20f2b 100644 --- a/Applications/PaintBrush/Makefile +++ b/Applications/PaintBrush/Makefile @@ -9,6 +9,7 @@ OBJS = \ BucketTool.o \ ColorDialog.o \ SprayTool.o \ + PickerTool.o \ main.o APP = PaintBrush diff --git a/Applications/PaintBrush/PaintableWidget.cpp b/Applications/PaintBrush/PaintableWidget.cpp index ce0bf08dbfa..900c03f1ca1 100644 --- a/Applications/PaintBrush/PaintableWidget.cpp +++ b/Applications/PaintBrush/PaintableWidget.cpp @@ -72,3 +72,21 @@ void PaintableWidget::mousemove_event(GMouseEvent& event) if (m_tool) m_tool->on_mousemove(event); } + +void PaintableWidget::set_primary_color(Color color) +{ + if (m_primary_color == color) + return; + m_primary_color = color; + if (on_primary_color_change) + on_primary_color_change(color); +} + +void PaintableWidget::set_secondary_color(Color color) +{ + if (m_secondary_color == color) + return; + m_secondary_color = color; + if (on_secondary_color_change) + on_secondary_color_change(color); +} diff --git a/Applications/PaintBrush/PaintableWidget.h b/Applications/PaintBrush/PaintableWidget.h index 81df54c9ec7..26b5a70d913 100644 --- a/Applications/PaintBrush/PaintableWidget.h +++ b/Applications/PaintBrush/PaintableWidget.h @@ -15,8 +15,8 @@ public: Color primary_color() const { return m_primary_color; } Color secondary_color() const { return m_secondary_color; } - void set_primary_color(Color color) { m_primary_color = color; } - void set_secondary_color(Color color) { m_secondary_color = color; } + void set_primary_color(Color); + void set_secondary_color(Color); void set_tool(Tool* tool); Tool* tool(); @@ -26,6 +26,9 @@ public: GraphicsBitmap& bitmap() { return *m_bitmap; } const GraphicsBitmap& bitmap() const { return *m_bitmap; } + Function on_primary_color_change; + Function on_secondary_color_change; + private: virtual void paint_event(GPaintEvent&) override; virtual void mousedown_event(GMouseEvent&) override; diff --git a/Applications/PaintBrush/PaletteWidget.cpp b/Applications/PaintBrush/PaletteWidget.cpp index 5c3d61f4b0b..1ca570a96a2 100644 --- a/Applications/PaintBrush/PaletteWidget.cpp +++ b/Applications/PaintBrush/PaletteWidget.cpp @@ -73,6 +73,14 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent) m_primary_color_widget->set_fill_with_background_color(true); set_primary_color(paintable_widget.primary_color()); + paintable_widget.on_primary_color_change = [this](Color color) { + set_primary_color(color); + }; + + paintable_widget.on_secondary_color_change = [this](Color color) { + set_secondary_color(color); + }; + auto* color_container = new GWidget(this); color_container->set_relative_rect(m_secondary_color_widget->relative_rect().right() + 2, 2, 500, 32); color_container->set_layout(make(Orientation::Vertical)); diff --git a/Applications/PaintBrush/PickerTool.cpp b/Applications/PaintBrush/PickerTool.cpp new file mode 100644 index 00000000000..4e2433a3742 --- /dev/null +++ b/Applications/PaintBrush/PickerTool.cpp @@ -0,0 +1,22 @@ +#include "PickerTool.h" +#include + +PickerTool::PickerTool() +{ +} + +PickerTool::~PickerTool() +{ +} + +void PickerTool::on_mousedown(GMouseEvent& event) +{ + ASSERT(m_widget); + if (!m_widget->bitmap().rect().contains(event.position())) + return; + auto color = m_widget->bitmap().get_pixel(event.position()); + if (event.button() == GMouseButton::Left) + m_widget->set_primary_color(color); + else if (event.button() == GMouseButton::Right) + m_widget->set_secondary_color(color); +} diff --git a/Applications/PaintBrush/PickerTool.h b/Applications/PaintBrush/PickerTool.h new file mode 100644 index 00000000000..78aa59e5702 --- /dev/null +++ b/Applications/PaintBrush/PickerTool.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Tool.h" + +class PickerTool final : public Tool { +public: + PickerTool(); + virtual ~PickerTool() override; + + virtual void on_mousedown(GMouseEvent&) override; + +private: + virtual const char* class_name() const override { return "PickerTool"; } + +}; diff --git a/Applications/PaintBrush/ToolboxWidget.cpp b/Applications/PaintBrush/ToolboxWidget.cpp index 1db6943c51b..7c7d0c764d4 100644 --- a/Applications/PaintBrush/ToolboxWidget.cpp +++ b/Applications/PaintBrush/ToolboxWidget.cpp @@ -3,6 +3,7 @@ #include "SprayTool.h" #include "PaintableWidget.h" #include "PenTool.h" +#include "PickerTool.h" #include #include #include @@ -59,6 +60,7 @@ ToolboxWidget::ToolboxWidget(GWidget* parent) add_tool("Pen", "pen", make()); add_tool("Bucket Fill", "bucket", make()); add_tool("Spray", "spray", make()); + add_tool("Color Picker", "picker", make()); } ToolboxWidget::~ToolboxWidget() diff --git a/Base/res/icons/paintbrush/picker.png b/Base/res/icons/paintbrush/picker.png new file mode 100644 index 00000000000..a88f39fcd26 Binary files /dev/null and b/Base/res/icons/paintbrush/picker.png differ