aboutsummaryrefslogtreecommitdiff
path: root/src/client/draw.hh
blob: 821d67bcf9cfdfcf8220785c85eb0a7e1914a98f (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
53
54
55
56
57
58
59
#ifndef CLIENT_DRAW_HH_
#define CLIENT_DRAW_HH_

#include <string_view>

#include <glm/glm.hpp>

#include "client/movement.hh"
#include "client/player.hh"
#include "client/render/camera.hh"
#include "client/render/render.hh"
#include "client/render/program.hh"
#include "client/shared.hh"
#include "client/window.hh"
#include "client/world.hh"

namespace client {
namespace draw {

// Scale takes the range [0, 1] and represents an amount of the screen.
// Offset is any value that is added after scale.
struct relative_arg {
    glm::vec2 extent;
    glm::vec2 offset;

    glm::vec2 to_vec2() const noexcept {
        const glm::vec2& window = render::get_window_size();
        const float x = this->extent.x * window.x + this->offset.x;
        const float y = this->extent.y * window.y + this->offset.y;
        return {x, y};
    }
};

struct rectangle_args {
    relative_arg pos;
    relative_arg size;
    glm::vec4 colour;
};

struct text_args {
    relative_arg pos;
    float extent_height; // we don't get width here,
    float offset_height;
    glm::vec4 colour;
    bool has_backing;
    bool is_centered;
    bool is_vcentered;
};

void draw_rectangle(const rectangle_args& args) noexcept;
void draw_colour(const glm::vec4& colour) noexcept;
void draw_text(const std::string_view text, const text_args& args) noexcept;

void draw(client::players& players, client::world::chunk::map& chunks) noexcept;

} // namespace draw
} // namespace client

#endif