ladybird/Widgets/Widget.h

64 lines
1.7 KiB
C
Raw Normal View History

2018-10-10 13:12:38 +00:00
#pragma once
#include "Event.h"
#include "Object.h"
2018-10-10 14:49:36 +00:00
#include "Rect.h"
2018-10-10 23:48:09 +00:00
#include "Color.h"
2018-10-11 14:52:40 +00:00
#include <AK/String.h>
2018-10-10 13:12:38 +00:00
class Widget : public Object {
public:
explicit Widget(Widget* parent = nullptr);
virtual ~Widget();
virtual void event(Event&);
virtual void onPaint(PaintEvent&);
virtual void onShow(ShowEvent&);
virtual void onHide(HideEvent&);
virtual void onKeyDown(KeyEvent&);
virtual void onKeyUp(KeyEvent&);
virtual void onMouseMove(MouseEvent&);
virtual void onMouseDown(MouseEvent&);
virtual void onMouseUp(MouseEvent&);
2018-10-10 14:49:36 +00:00
Rect rect() const { return m_rect; }
int x() const { return rect().x(); }
int y() const { return rect().y(); }
int width() const { return rect().width(); }
int height() const { return rect().height(); }
2018-10-10 13:12:38 +00:00
void update();
2018-10-10 14:49:36 +00:00
struct HitTestResult {
Widget* widget { nullptr };
int localX { 0 };
int localY { 0 };
};
HitTestResult hitTest(int x, int y);
virtual const char* className() const override { return "Widget"; }
void setRect(const Rect&);
2018-10-10 23:48:09 +00: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; }
2018-10-11 14:52:40 +00:00
bool isWindow() const { return m_isWindow; }
void setIsWindow(bool);
void setWindowTitle(String&&);
String windowTitle() const { return m_windowTitle; }
2018-10-10 13:12:38 +00:00
private:
2018-10-10 14:49:36 +00:00
Rect m_rect;
2018-10-10 23:48:09 +00:00
Color m_backgroundColor;
Color m_foregroundColor;
2018-10-11 14:52:40 +00:00
String m_windowTitle;
2018-10-11 14:52:40 +00:00
bool m_isWindow { false };
bool m_hasPendingPaintEvent { false };
2018-10-10 13:12:38 +00:00
};