Working overlay

This commit is contained in:
nullifiedcat 2017-11-16 21:10:09 +03:00
parent b4274a6b53
commit 55a53816a6
5 changed files with 22 additions and 13 deletions

View File

@ -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();

View File

@ -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

View File

@ -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<const xoverlay_rgba_t *>(&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<const xoverlay_rgba_t *>(&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<const xoverlay_rgba_t *>(&rgba), *reinterpret_cast<const xoverlay_rgba_t *>(&rgba_outline), thickness, 1, nullptr, nullptr);
//xoverlay_draw_string(x, y, string, font.handle, *reinterpret_cast<const xoverlay_rgba_t *>(&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);
}

View File

@ -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);
}

View File

@ -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<const xoverlay_rgba_t *>(&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<const xoverlay_rgba_t *>(&colors::white), 0, 0);
//xoverlay_draw_string_with_outline(100, 20, "Testing2", )
DrawCheatVisuals();
EndCheatVisuals();