aboutsummaryrefslogtreecommitdiff
path: root/src/client/window/basic_window.hh
blob: 292cc649969616a6a51a7aaaf5efb51f800f9394 (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
44
45
46
47
48
49
50
51
52
#ifndef CLIENT_WINDOW_BASIC_WINDOW_HH_
#define CLIENT_WINDOW_BASIC_WINDOW_HH_

#include <glm/glm.hpp>

#include "client/entity/player.hh"
#include "client/render/render.hh"
#include "client/render/struct.hh"

namespace client {
namespace window {

// All window objects should derive from basic_window, and make use of multiple
// inheritance for specific behaviours.
class basic_window {
protected:
    // Colours borrowed from arc-dark(er).
    static constexpr glm::vec3 primary_clr{0.21f, 0.23f, 0.29f};   // dark
    static constexpr glm::vec3 secondary_clr{0.29f, 0.32f, 0.38f}; // less dark
    static constexpr glm::vec3 tertiary_clr{0.48, 0.50, 0.54};  // less dark ^2
    static constexpr glm::vec3 highlight_clr{0.32, 0.58, 0.88}; // light blue
    static constexpr glm::vec3 font_colour{0.88, 0.88, 0.88};   // light grey

protected:
    static constexpr float OUTLINE_WIDTH = 2.0f;
    float get_item_size() const noexcept { return this->size.x / 10.0f; }

protected:
    glm::vec2 pos;
    glm::vec2 size;

public:
    // Test if a vec2 v is inside a square starting at position p with size s.
    static bool is_inside(const glm::vec2& v, const glm::vec2& p,
                          const glm::vec2& s) noexcept;
    // Test if v is inside this->pos, this->size
    bool is_inside(const glm::vec2& v) const noexcept;

public:
    basic_window(const client::render::relative_arg& pos,
                 const client::render::relative_arg& size) noexcept
        : pos(pos.to_vec2()), size(size.to_vec2()) {}
    virtual ~basic_window() noexcept {}

    virtual bool maybe_handle_event(const SDL_Event&) noexcept { return false; }
    virtual void draw() noexcept;
};

} // namespace window
} // namespace client

#endif