aboutsummaryrefslogtreecommitdiff
path: root/src/client/window/button_window.hh
blob: 6847696798e3079a216c52d14733dcabac01640a (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
#ifndef CLIENT_WINDOW_BUTTON_WINDOW_HH_
#define CLIENT_WINDOW_BUTTON_WINDOW_HH_

#include <functional>
#include <string>

#include "client/input.hh"
#include "client/render/render.hh"
#include "client/window/basic_window.hh"

namespace client {
namespace window {

class button_window : public basic_window {
protected:
    std::string name;
    std::function<void()> callback;
    bool is_pressed;

private:
    void handle_mousebuttondown(const SDL_Event& event) noexcept;
    void handle_mousebuttonup(const SDL_Event& event) noexcept;
    const glm::vec3& get_draw_colour() noexcept;

public:
    template <typename... Args>
    button_window(const std::string_view n, const decltype(callback)& c,
                  Args&&... args) noexcept
        : basic_window(std::forward<Args>(args)...), name(n), callback(c),
          is_pressed(false) {}
    virtual ~button_window() noexcept {}

    virtual bool maybe_handle_event(const SDL_Event& event) noexcept override;
    virtual void draw() noexcept override;
};

} // namespace window
} // namespace client

#endif