summaryrefslogtreecommitdiff
path: root/Servers/WindowServer/WSButton.h
blob: 780e55aaa34788266ca3cfadd884780ebb7903cc (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
#pragma once

#include <AK/Function.h>
#include <AK/Retained.h>
#include <AK/Weakable.h>
#include <SharedGraphics/Rect.h>

class CharacterBitmap;
class Painter;
class WSMouseEvent;
class WSWindowFrame;

class WSButton : public Weakable<WSButton> {
public:
    WSButton(WSWindowFrame&, Retained<CharacterBitmap>&&, Function<void(WSButton&)>&& on_click_handler);
    ~WSButton();

    Rect relative_rect() const { return m_relative_rect; }
    void set_relative_rect(const Rect& rect) { m_relative_rect = rect; }

    Rect rect() const { return { {}, m_relative_rect.size() }; }
    Rect screen_rect() const;

    void paint(Painter&);

    void on_mouse_event(const WSMouseEvent&);

    Function<void(WSButton&)> on_click;

    bool is_visible() const { return m_visible; }

    void set_bitmap(const CharacterBitmap& bitmap) { m_bitmap = bitmap; }

private:
    WSWindowFrame& m_frame;
    Rect m_relative_rect;
    Retained<CharacterBitmap> m_bitmap;
    bool m_pressed { false };
    bool m_visible { true };
    bool m_hovered { false };
};