summaryrefslogtreecommitdiffstats
path: root/src/overlay.cpp
blob: 2445d95c6bf53f0e0dbe77ce325e8dfb3d2f77d5 (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// overlay.cpp — the single ISurface access layer.
#include "hl2h.h"
#include <ctime>

ISurface *g_surface = nullptr;

// ---------------------------------------------------------------------------
// per-frame draw budget
// ---------------------------------------------------------------------------

static bool g_drawn_this_frame = false;
static double g_frame_mark_at = 0.0;

static double overlay_now() {
  timespec ts;
  clock_gettime(CLOCK_MONOTONIC, &ts);
  return (double)ts.tv_sec + (double)ts.tv_nsec * 1e-9;
}

void overlay_frame_mark() {
  g_drawn_this_frame = false;
  g_frame_mark_at = overlay_now();
}

bool overlay_should_draw() {
  if (g_drawn_this_frame && overlay_now() - g_frame_mark_at < 0.10)
    return false;
  g_drawn_this_frame = true;
  return true;
}

void overlay_color(int r, int g, int b, int a) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int, int, int, int);
  vfunc<Fn>(g_surface, SURF_DrawSetColor)(g_surface, r, g, b, a);
}

void overlay_fill(int x0, int y0, int x1, int y1) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int, int, int, int);
  vfunc<Fn>(g_surface, SURF_DrawFilledRect)(g_surface, x0, y0, x1, y1);
}

void overlay_outline_rect(int x0, int y0, int x1, int y1) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int, int, int, int);
  vfunc<Fn>(g_surface, SURF_DrawOutlinedRect)(g_surface, x0, y0, x1, y1);
}

void overlay_line(int x0, int y0, int x1, int y1) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int, int, int, int);
  vfunc<Fn>(g_surface, SURF_DrawLine)(g_surface, x0, y0, x1, y1);
}

void overlay_text_font(HFont f) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, HFont);
  vfunc<Fn>(g_surface, SURF_DrawSetTextFont)(g_surface, f);
}

void overlay_text_color(int r, int g, int b, int a) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int, int, int, int);
  vfunc<Fn>(g_surface, SURF_DrawSetTextColor)(g_surface, r, g, b, a);
}

void overlay_text_pos(int x, int y) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int, int);
  vfunc<Fn>(g_surface, SURF_DrawSetTextPos)(g_surface, x, y);
}

void overlay_print_text(const wchar_t *text, int count, int draw_type) {
  if (!g_surface || !text || count <= 0)
    return;
  using Fn = void (*)(void *, const wchar_t *, int, int);
  vfunc<Fn>(g_surface, SURF_DrawPrintText)(g_surface, text, count, draw_type);
}

HFont overlay_create_font() {
  if (!g_surface)
    return 0;
  using Fn = HFont (*)(void *);
  return vfunc<Fn>(g_surface, SURF_CreateFont)(g_surface);
}

bool overlay_add_glyph_set(HFont f, const char *name, int tall, int weight,
                           int blur, int scanlines, int flags, int range_min,
                           int range_max) {
  if (!g_surface || !name)
    return false;
  using Fn = bool (*)(void *, HFont, const char *, int, int, int, int, int, int,
                      int);
  return vfunc<Fn>(g_surface, SURF_AddGlyphSetToFont)(
      g_surface, f, name, tall, weight, blur, scanlines, flags, range_min,
      range_max);
}

void overlay_screen_size(int &w, int &h) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int &, int &);
  vfunc<Fn>(g_surface, SURF_GetScreenSize)(g_surface, w, h);
}

void overlay_text_size(HFont f, const wchar_t *text, int &w, int &h) {
  if (!g_surface || !text)
    return;
  using Fn = void (*)(void *, HFont, const wchar_t *, int &, int &);
  vfunc<Fn>(g_surface, SURF_GetTextSize)(g_surface, f, text, w, h);
}

int overlay_embedded_panel() {
  if (!g_surface)
    return 0;
  using Fn = int (*)(void *);
  return vfunc<Fn>(g_surface, SURF_GetEmbeddedPanel)(g_surface);
}

void overlay_push_make_current(int panel, bool use_insets) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int, bool);
  vfunc<Fn>(g_surface, SURF_PushMakeCurrent)(g_surface, panel, use_insets);
}

void overlay_pop_make_current(int panel) {
  if (!g_surface)
    return;
  using Fn = void (*)(void *, int);
  vfunc<Fn>(g_surface, SURF_PopMakeCurrent)(g_surface, panel);
}