2019-06-10 19:29:33 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibGUI/GWidget.h>
|
2019-06-14 18:51:57 +02:00
|
|
|
class Tool;
|
|
|
|
|
2019-06-10 19:29:33 +02:00
|
|
|
class PaintableWidget final : public GWidget {
|
2019-07-25 19:49:28 +02:00
|
|
|
C_OBJECT(PaintableWidget)
|
2019-06-10 19:29:33 +02:00
|
|
|
public:
|
2019-06-14 18:51:57 +02:00
|
|
|
static PaintableWidget& the();
|
|
|
|
|
2019-06-10 19:29:33 +02:00
|
|
|
explicit PaintableWidget(GWidget* parent);
|
|
|
|
virtual ~PaintableWidget() override;
|
|
|
|
|
2019-06-10 19:54:09 +02:00
|
|
|
Color primary_color() const { return m_primary_color; }
|
|
|
|
Color secondary_color() const { return m_secondary_color; }
|
|
|
|
|
2019-06-22 12:05:35 +02:00
|
|
|
void set_primary_color(Color);
|
|
|
|
void set_secondary_color(Color);
|
2019-06-10 19:54:09 +02:00
|
|
|
|
2019-06-16 11:33:20 +02:00
|
|
|
void set_tool(Tool* tool);
|
|
|
|
Tool* tool();
|
2019-06-14 18:51:57 +02:00
|
|
|
|
|
|
|
Color color_for(const GMouseEvent&);
|
|
|
|
|
2019-06-25 20:27:32 +02:00
|
|
|
void set_bitmap(const GraphicsBitmap&);
|
|
|
|
|
2019-06-14 18:51:57 +02:00
|
|
|
GraphicsBitmap& bitmap() { return *m_bitmap; }
|
|
|
|
const GraphicsBitmap& bitmap() const { return *m_bitmap; }
|
|
|
|
|
2019-06-22 12:05:35 +02:00
|
|
|
Function<void(Color)> on_primary_color_change;
|
|
|
|
Function<void(Color)> on_secondary_color_change;
|
|
|
|
|
2019-06-10 19:29:33 +02:00
|
|
|
private:
|
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
|
|
|
virtual void mousedown_event(GMouseEvent&) override;
|
|
|
|
virtual void mouseup_event(GMouseEvent&) override;
|
|
|
|
virtual void mousemove_event(GMouseEvent&) override;
|
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<GraphicsBitmap> m_bitmap;
|
2019-06-10 19:54:09 +02:00
|
|
|
|
|
|
|
Color m_primary_color { Color::Black };
|
|
|
|
Color m_secondary_color { Color::White };
|
2019-06-14 18:51:57 +02:00
|
|
|
|
|
|
|
Tool* m_tool { nullptr };
|
2019-06-10 19:29:33 +02:00
|
|
|
};
|