2019-01-20 04:49:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-02-20 09:22:38 +01:00
|
|
|
#include <LibGUI/GWidget.h>
|
|
|
|
#include <LibGUI/GStyle.h>
|
2019-01-20 04:49:48 +01:00
|
|
|
#include <AK/AKString.h>
|
|
|
|
#include <AK/Function.h>
|
2019-02-07 23:13:47 +01:00
|
|
|
#include <SharedGraphics/GraphicsBitmap.h>
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-02-08 00:14:37 +01:00
|
|
|
class GButton : public GWidget {
|
2019-01-20 04:49:48 +01:00
|
|
|
public:
|
|
|
|
explicit GButton(GWidget* parent);
|
|
|
|
virtual ~GButton() override;
|
|
|
|
|
|
|
|
String caption() const { return m_caption; }
|
2019-03-19 00:01:02 +01:00
|
|
|
void set_caption(const String&);
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-02-07 23:13:47 +01:00
|
|
|
void set_icon(RetainPtr<GraphicsBitmap>&& icon) { m_icon = move(icon); }
|
|
|
|
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
|
|
|
GraphicsBitmap* icon() { return m_icon.ptr(); }
|
|
|
|
|
2019-01-21 00:31:11 +01:00
|
|
|
Function<void(GButton&)> on_click;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-02-20 09:22:38 +01:00
|
|
|
void set_button_style(GButtonStyle style) { m_button_style = style; }
|
|
|
|
GButtonStyle button_style() const { return m_button_style; }
|
|
|
|
|
2019-03-16 12:57:04 +01:00
|
|
|
virtual const char* class_name() const override { return "GButton"; }
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
private:
|
2019-01-21 00:46:08 +01:00
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
|
|
|
virtual void mousedown_event(GMouseEvent&) override;
|
|
|
|
virtual void mouseup_event(GMouseEvent&) override;
|
2019-01-27 08:48:34 +01:00
|
|
|
virtual void mousemove_event(GMouseEvent&) override;
|
2019-02-20 10:12:19 +01:00
|
|
|
virtual void enter_event(GEvent&) override;
|
|
|
|
virtual void leave_event(GEvent&) override;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
|
|
|
String m_caption;
|
2019-02-07 23:13:47 +01:00
|
|
|
RetainPtr<GraphicsBitmap> m_icon;
|
2019-02-20 09:22:38 +01:00
|
|
|
GButtonStyle m_button_style { GButtonStyle::Normal };
|
2019-01-21 00:31:11 +01:00
|
|
|
bool m_being_pressed { false };
|
2019-01-27 08:48:34 +01:00
|
|
|
bool m_tracking_cursor { false };
|
2019-02-20 09:22:38 +01:00
|
|
|
bool m_hovered { false };
|
2019-01-20 04:49:48 +01:00
|
|
|
};
|
|
|
|
|