summaryrefslogtreecommitdiff
path: root/Widgets/Widget.h
blob: b934a157a9387ad8b504a9a4f9dd9a25f23cfc80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include "Event.h"
#include "Object.h"
#include "Rect.h"

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&);

    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(); }

    void update();

    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&);

private:
    Rect m_rect;
};