From 55a53816a6ace591986b26ba69e574ca05a90ea3 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Thu, 16 Nov 2017 21:10:09 +0300 Subject: [PATCH] Working overlay --- include/visual/drawex.hpp | 8 +++++--- makefile | 2 +- src/visual/drawex.cpp | 18 +++++++++++++----- src/visual/drawing.cpp | 1 - src/visual/drawmgr.cpp | 6 +++--- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/visual/drawex.hpp b/include/visual/drawex.hpp index 9b56f37a..128a4b71 100644 --- a/include/visual/drawex.hpp +++ b/include/visual/drawex.hpp @@ -25,6 +25,8 @@ namespace api struct font_handle_t { xoverlay_font_handle_t handle; + std::string filename; + float size; }; struct texture_handle_t @@ -47,9 +49,9 @@ void draw_rect_outlined(float x, float y, float w, float h, const rgba_t& rgba, void draw_line(float x, float y, float dx, float dy, const rgba_t& rgba, float thickness); void draw_rect_textured(float x, float y, float w, float h, const rgba_t& rgba, texture_handle_t texture, float u, float v, float s, float t); void draw_circle(float x, float y, float radius, const rgba_t& rgba, float thickness, int steps); -void draw_string(float x, float y, const char *string, font_handle_t font, const rgba_t& rgba); -void draw_string_with_outline(float x, float y, const char *string, font_handle_t font, const rgba_t& rgba, const rgba_t& rgba_outline, float thickness); -void get_string_size(const char *string, font_handle_t font, float *x, float *y); +void draw_string(float x, float y, const char *string, font_handle_t& font, const rgba_t& rgba); +void draw_string_with_outline(float x, float y, const char *string, font_handle_t& font, const rgba_t& rgba, const rgba_t& rgba_outline, float thickness); +void get_string_size(const char *string, font_handle_t& font, float *x, float *y); void draw_begin(); void draw_end(); diff --git a/makefile b/makefile index 508704fc..0161966a 100644 --- a/makefile +++ b/makefile @@ -53,7 +53,7 @@ TARGET = $(OUT_DIR)/$(OUT_NAME) INCLUDES=-I. -Iinclude -Iucccccp -isystem/usr/include/c++/6.3.1 -isystem$(SSDK_DIR)/public -isystem$(SSDK_DIR)/mathlib -isystem$(SSDK_DIR)/common -isystem$(SSDK_DIR)/public/tier1 -isystem$(SSDK_DIR)/public/tier0 -isystem$(SSDK_DIR) LDLIBS=-static -l:libc.so.6 -l:libstdc++.so.6 -l:libtier0.so -l:libvstdlib.so -LDFLAGS=-shared -L$(realpath $(LIB_DIR)) +LDFLAGS=-shared -L$(realpath $(LIB_DIR)) SOURCES=$(shell find $(SRC_DIR) -name "*.c*" -print) ifndef CLANG diff --git a/src/visual/drawex.cpp b/src/visual/drawex.cpp index 73bc1d04..05a152ef 100644 --- a/src/visual/drawex.cpp +++ b/src/visual/drawex.cpp @@ -26,8 +26,9 @@ font_handle_t create_font(const char *path, float size) { logging::Info("Creating font '%s':%f", path, size); font_handle_t result; - result.handle = xoverlay_font_load(path, size); - logging::Info("Font handle: %d", result.handle); + result.filename = std::string(path); + result.size = size; + result.handle = 0; return result; } @@ -90,18 +91,25 @@ void draw_circle(float x, float y, float radius, const rgba_t& rgba, float thick xoverlay_draw_circle(x, y, radius, *reinterpret_cast(&rgba), thickness, steps); } -void draw_string(float x, float y, const char *string, font_handle_t font, const rgba_t& rgba) +void draw_string(float x, float y, const char *string, font_handle_t& font, const rgba_t& rgba) { + if (!font.handle) + font.handle = xoverlay_font_load(font.filename.c_str(), font.size); xoverlay_draw_string(x, y, string, font.handle, *reinterpret_cast(&rgba), nullptr, nullptr); } -void draw_string_with_outline(float x, float y, const char *string, font_handle_t font, const rgba_t& rgba, const rgba_t& rgba_outline, float thickness) +void draw_string_with_outline(float x, float y, const char *string, font_handle_t& font, const rgba_t& rgba, const rgba_t& rgba_outline, float thickness) { + if (!font.handle) + font.handle = xoverlay_font_load(font.filename.c_str(), font.size); xoverlay_draw_string_with_outline(x, y, string, font.handle, *reinterpret_cast(&rgba), *reinterpret_cast(&rgba_outline), thickness, 1, nullptr, nullptr); + //xoverlay_draw_string(x, y, string, font.handle, *reinterpret_cast(&rgba), nullptr, nullptr); } -void get_string_size(const char *string, font_handle_t font, float *x, float *y) +void get_string_size(const char *string, font_handle_t& font, float *x, float *y) { + if (!font.handle) + font.handle = xoverlay_font_load(font.filename.c_str(), font.size); xoverlay_get_string_size(string, font.handle, x, y); } diff --git a/src/visual/drawing.cpp b/src/visual/drawing.cpp index ae64c9aa..af1fb8ed 100644 --- a/src/visual/drawing.cpp +++ b/src/visual/drawing.cpp @@ -73,7 +73,6 @@ void draw::Initialize() { g_IEngine->GetScreenSize(draw::width, draw::height); } xoverlay_preinit(); - fonts::main_font = draw_api::create_font(DATA_PATH "/fonts/tahoma.ttf", 14); fonts::main_font = draw_api::create_font(DATA_PATH "/fonts/tahoma.ttf", 14); } diff --git a/src/visual/drawmgr.cpp b/src/visual/drawmgr.cpp index e43568f9..3bfda1a6 100644 --- a/src/visual/drawmgr.cpp +++ b/src/visual/drawmgr.cpp @@ -12,10 +12,10 @@ void render_cheat_visuals() { BeginCheatVisuals(); - xoverlay_draw_rect(300, 300, 100, 100, xoverlay_rgba(200, 100, 100, 255)); +// xoverlay_draw_rect(300, 300, 100, 100, xoverlay_rgba(200, 100, 100, 255)); //draw_api::draw_string(100, 100, "Testing", fonts::main_font, colors::white); - static draw_api::font_handle_t fh = draw_api::create_font(DATA_PATH "/fonts/tf2build.ttf", 14); - xoverlay_draw_string(100, 100, "TestingSTR", fh.handle, *reinterpret_cast(&colors::white), 0, 0); +// static draw_api::font_handle_t fh = draw_api::create_font(DATA_PATH "/fonts/tf2build.ttf", 14); +// xoverlay_draw_string(100, 100, "TestingSTR", fh.handle, *reinterpret_cast(&colors::white), 0, 0); //xoverlay_draw_string_with_outline(100, 20, "Testing2", ) DrawCheatVisuals(); EndCheatVisuals();