2018-10-10 15:12:38 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
#include "GEvent.h"
|
|
|
|
#include "GObject.h"
|
2019-01-19 23:49:56 +01:00
|
|
|
#include <SharedGraphics/Rect.h>
|
|
|
|
#include <SharedGraphics/Color.h>
|
|
|
|
#include <SharedGraphics/Font.h>
|
2018-12-21 02:18:16 +01:00
|
|
|
#include <AK/AKString.h>
|
2018-10-10 15:12:38 +02:00
|
|
|
|
2019-01-09 02:06:04 +01:00
|
|
|
class GraphicsBitmap;
|
2019-01-20 04:49:48 +01:00
|
|
|
class GWindow;
|
2018-10-12 01:03:22 +02:00
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
class GWidget : public GObject {
|
2018-10-10 15:12:38 +02:00
|
|
|
public:
|
2019-01-20 04:49:48 +01:00
|
|
|
explicit GWidget(GWidget* parent = nullptr);
|
|
|
|
virtual ~GWidget();
|
|
|
|
|
|
|
|
virtual void event(GEvent&) override;
|
|
|
|
virtual void paintEvent(GPaintEvent&);
|
|
|
|
virtual void showEvent(GShowEvent&);
|
|
|
|
virtual void hideEvent(GHideEvent&);
|
|
|
|
virtual void keyDownEvent(GKeyEvent&);
|
|
|
|
virtual void keyUpEvent(GKeyEvent&);
|
|
|
|
virtual void mouseMoveEvent(GMouseEvent&);
|
|
|
|
virtual void mouseDownEvent(GMouseEvent&);
|
|
|
|
virtual void mouseUpEvent(GMouseEvent&);
|
2018-10-10 15:12:38 +02:00
|
|
|
|
2018-10-12 14:15:14 +02:00
|
|
|
Rect relativeRect() const { return m_relativeRect; }
|
|
|
|
Point relativePosition() const { return m_relativeRect.location(); }
|
2018-10-12 10:06:50 +02:00
|
|
|
|
2018-10-12 14:15:14 +02:00
|
|
|
int x() const { return m_relativeRect.x(); }
|
|
|
|
int y() const { return m_relativeRect.y(); }
|
|
|
|
int width() const { return m_relativeRect.width(); }
|
|
|
|
int height() const { return m_relativeRect.height(); }
|
|
|
|
|
|
|
|
Rect rect() const { return { 0, 0, width(), height() }; }
|
2019-01-09 04:46:16 +01:00
|
|
|
Size size() const { return m_relativeRect.size(); }
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2018-10-10 15:12:38 +02:00
|
|
|
void update();
|
2018-10-12 19:39:48 +02:00
|
|
|
void repaint(const Rect&);
|
2018-10-10 15:12:38 +02:00
|
|
|
|
2018-10-13 17:52:47 +02:00
|
|
|
bool isFocused() const;
|
|
|
|
void setFocus(bool);
|
|
|
|
|
2018-10-10 16:49:36 +02:00
|
|
|
struct HitTestResult {
|
2019-01-20 04:49:48 +01:00
|
|
|
GWidget* widget { nullptr };
|
2018-10-10 16:49:36 +02:00
|
|
|
int localX { 0 };
|
|
|
|
int localY { 0 };
|
|
|
|
};
|
|
|
|
HitTestResult hitTest(int x, int y);
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
virtual const char* class_name() const override { return "GWidget"; }
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2019-01-09 04:46:16 +01:00
|
|
|
void setWindowRelativeRect(const Rect&, bool should_update = true);
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2018-10-11 01:48:09 +02:00
|
|
|
Color backgroundColor() const { return m_backgroundColor; }
|
|
|
|
Color foregroundColor() const { return m_foregroundColor; }
|
|
|
|
|
|
|
|
void setBackgroundColor(Color color) { m_backgroundColor = color; }
|
|
|
|
void setForegroundColor(Color color) { m_foregroundColor = color; }
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
GWindow* window()
|
2018-10-12 01:03:22 +02:00
|
|
|
{
|
|
|
|
if (auto* pw = parentWidget())
|
|
|
|
return pw->window();
|
|
|
|
return m_window;
|
|
|
|
}
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
const GWindow* window() const
|
2018-10-12 01:03:22 +02:00
|
|
|
{
|
|
|
|
if (auto* pw = parentWidget())
|
|
|
|
return pw->window();
|
|
|
|
return m_window;
|
|
|
|
}
|
2018-10-11 16:52:40 +02:00
|
|
|
|
2019-01-20 07:03:38 +01:00
|
|
|
void set_window(GWindow*);
|
2018-10-12 02:41:27 +02:00
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
GWidget* parentWidget() { return static_cast<GWidget*>(parent()); }
|
|
|
|
const GWidget* parentWidget() const { return static_cast<const GWidget*>(parent()); }
|
2018-10-11 16:52:40 +02:00
|
|
|
|
2018-10-14 00:21:42 +02:00
|
|
|
void setFillWithBackgroundColor(bool b) { m_fillWithBackgroundColor = b; }
|
|
|
|
bool fillWithBackgroundColor() const { return m_fillWithBackgroundColor; }
|
|
|
|
|
2018-10-14 13:06:05 +02:00
|
|
|
const Font& font() const { return *m_font; }
|
|
|
|
void setFont(RetainPtr<Font>&&);
|
|
|
|
|
2019-01-20 07:03:38 +01:00
|
|
|
GraphicsBitmap* backing();
|
2019-01-09 02:06:04 +01:00
|
|
|
|
2018-10-10 15:12:38 +02:00
|
|
|
private:
|
2019-01-20 04:49:48 +01:00
|
|
|
GWindow* m_window { nullptr };
|
2018-10-12 01:03:22 +02:00
|
|
|
|
2018-10-12 14:15:14 +02:00
|
|
|
Rect m_relativeRect;
|
2019-01-13 06:25:30 +01:00
|
|
|
Color m_backgroundColor { 0xffffff };
|
|
|
|
Color m_foregroundColor { 0x000000 };
|
2018-10-14 13:06:05 +02:00
|
|
|
RetainPtr<Font> m_font;
|
2018-10-11 12:33:03 +02:00
|
|
|
|
|
|
|
bool m_hasPendingPaintEvent { false };
|
2019-01-13 06:25:30 +01:00
|
|
|
bool m_fillWithBackgroundColor { true };
|
2018-10-10 15:12:38 +02:00
|
|
|
};
|