// overlay.cpp — the single ISurface access layer. #include "hl2h.h" #include 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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(g_surface, SURF_PopMakeCurrent)(g_surface, panel); }